331 lines
8.8 KiB
Makefile
331 lines
8.8 KiB
Makefile
SRC_DIR := "std/src"
|
|
PATCH_DIR := "std/patches"
|
|
RUST_SRC := `rustc --print sysroot` / "lib/rustlib/src/rust/library"
|
|
|
|
patch-std:
|
|
@echo "Start patching the std..."
|
|
@find {{ PATCH_DIR }} -type f | while read -r patch_file; do \
|
|
relative_path="${patch_file#{{ PATCH_DIR }}/}"; \
|
|
target_file="${relative_path%.sed}.rs"; \
|
|
if [ -f "{{ SRC_DIR }}/$target_file" ]; then \
|
|
echo " [SED] $target_file"; \
|
|
sed -i -f "$patch_file" "{{ SRC_DIR }}/$target_file"; \
|
|
else \
|
|
echo "⚠ [WARN] target doesn't exist: $target_file"; \
|
|
fi; \
|
|
done
|
|
@echo "✅ Patching done."
|
|
|
|
update-std:
|
|
@just setup-std
|
|
@just patch-std
|
|
|
|
cp_std path:
|
|
@echo "Linking {{ path }}"
|
|
@mkdir {{ "std/src" / parent_directory(path) }} -p
|
|
@ln -fs {{ RUST_SRC / "std/src" / path }} {{ "std/src" / parent_directory(path) }}
|
|
|
|
real_cp_std path:
|
|
@echo "Copying {{ path }}"
|
|
@mkdir {{ "std/src" / parent_directory(path) }} -p
|
|
@cp {{ RUST_SRC / "std/src" / path }} {{ "std/src" / path }}
|
|
|
|
setup-std:
|
|
ln -fs {{ RUST_SRC / "Cargo.toml" }} "."
|
|
|
|
ln -fs {{ RUST_SRC / "backtrace" }} "."
|
|
ln -fs {{ RUST_SRC / "std_detect" }} "."
|
|
ln -fs {{ RUST_SRC / "panic_abort" }} "."
|
|
ln -fs {{ RUST_SRC / "panic_unwind" }} "."
|
|
ln -fs {{ RUST_SRC / "windows_link" }} "."
|
|
ln -fs {{ RUST_SRC / "unwind" }} "."
|
|
ln -fs {{ RUST_SRC / "alloc" }} "."
|
|
ln -fs {{ RUST_SRC / "rustc-std-workspace-alloc" }} "."
|
|
ln -fs {{ RUST_SRC / "rustc-std-workspace-core" }} "."
|
|
ln -fs {{ RUST_SRC / "rustc-std-workspace-std" }} "."
|
|
ln -fs {{ RUST_SRC / "compiler-builtins" }} "."
|
|
ln -fs {{ RUST_SRC / "core" }} "."
|
|
ln -fs {{ RUST_SRC / "stdarch" }} "."
|
|
ln -fs {{ RUST_SRC / "portable-simd" }} "."
|
|
ln -fs {{ RUST_SRC / "proc_macro" }} "."
|
|
ln -fs {{ RUST_SRC / "profiler_builtins" }} "."
|
|
ln -fs {{ RUST_SRC / "test" }} "."
|
|
ln -fs {{ RUST_SRC / "coretests" }} "."
|
|
ln -fs {{ RUST_SRC / "alloctests" }} "."
|
|
ln -fs {{ RUST_SRC / "sysroot" }} "."
|
|
|
|
@just cp_std "../build.rs"
|
|
@sed -i "59a\ || target_os == \"survos\"" std/build.rs
|
|
|
|
@just cp_std "../Cargo.toml"
|
|
|
|
@just cp_std "alloc.rs"
|
|
@just cp_std "ascii.rs"
|
|
@just cp_std "backtrace.rs"
|
|
@just cp_std "bstr.rs"
|
|
@just cp_std "env.rs"
|
|
@just cp_std "error.rs"
|
|
@just cp_std "fs.rs"
|
|
@just cp_std "keyword_docs.rs"
|
|
@just cp_std "lib.rs"
|
|
@just cp_std "macros.rs"
|
|
@just cp_std "panic.rs"
|
|
@just cp_std "panicking.rs"
|
|
@just cp_std "pat.rs"
|
|
@just cp_std "path.rs"
|
|
@just cp_std "process.rs"
|
|
@just cp_std "random.rs"
|
|
@just cp_std "rt.rs"
|
|
@just cp_std "tests_helpers.rs"
|
|
@just cp_std "time.rs"
|
|
|
|
@just cp_std "backtrace"
|
|
|
|
@just cp_std "collections"
|
|
|
|
@just cp_std "ffi"
|
|
|
|
@just cp_std "fs"
|
|
|
|
@just cp_std "hash"
|
|
|
|
@just cp_std "io"
|
|
|
|
@just cp_std "net"
|
|
|
|
@just cp_std "num"
|
|
|
|
@just cp_std "os/raw/mod.rs"
|
|
@just cp_std "os/raw/tests.rs"
|
|
@just cp_std "os/mod.rs"
|
|
|
|
@just cp_std "prelude"
|
|
|
|
@just cp_std "process"
|
|
|
|
@just cp_std "sync"
|
|
|
|
@just cp_std "sys/alloc/mod.rs"
|
|
|
|
@just real_cp_std "sys/args/mod.rs"
|
|
@just cp_std "sys/args/unsupported.rs"
|
|
|
|
@just cp_std "sys/env/mod.rs"
|
|
@just cp_std "sys/env/common.rs"
|
|
@just cp_std "sys/env/unsupported.rs"
|
|
|
|
@just cp_std "sys/fd/mod.rs"
|
|
|
|
@just cp_std "sys/fs/mod.rs"
|
|
@just cp_std "sys/fs/common.rs"
|
|
@just cp_std "sys/fs/unsupported.rs"
|
|
|
|
@just cp_std "sys/helpers/mod.rs"
|
|
@just cp_std "sys/helpers/small_c_string.rs"
|
|
@just cp_std "sys/helpers/tests.rs"
|
|
@just cp_std "sys/helpers/wstr.rs"
|
|
|
|
@just cp_std "sys/io/error/generic.rs"
|
|
@just real_cp_std "sys/io/error/mod.rs"
|
|
@just cp_std "sys/io/io_slice/unsupported.rs"
|
|
@just cp_std "sys/io/is_terminal/unsupported.rs"
|
|
@just cp_std "sys/io/kernel_copy/mod.rs"
|
|
@just cp_std "sys/io/mod.rs"
|
|
|
|
@just cp_std "sys/net/connection/mod.rs"
|
|
@just cp_std "sys/net/connection/unsupported.rs"
|
|
@just cp_std "sys/net/hostname/mod.rs"
|
|
@just cp_std "sys/net/hostname/unsupported.rs"
|
|
@just cp_std "sys/net/mod.rs"
|
|
|
|
@just cp_std "sys/os_str/bytes/tests.rs"
|
|
@just cp_std "sys/os_str/bytes.rs"
|
|
@just cp_std "sys/os_str/mod.rs"
|
|
|
|
@just real_cp_std "sys/pal/mod.rs"
|
|
@just cp_std "sys/pal/unsupported/mod.rs"
|
|
@just cp_std "sys/pal/unsupported/common.rs"
|
|
@just cp_std "sys/pal/unsupported/os.rs"
|
|
|
|
@just cp_std "sys/path/mod.rs"
|
|
@just cp_std "sys/path/unix.rs"
|
|
|
|
@just cp_std "sys/personality/dwarf/eh.rs"
|
|
@just cp_std "sys/personality/dwarf/mod.rs"
|
|
@just cp_std "sys/personality/dwarf/tests.rs"
|
|
@just cp_std "sys/personality/mod.rs"
|
|
|
|
@just cp_std "sys/pipe/mod.rs"
|
|
@just cp_std "sys/pipe/unsupported.rs"
|
|
|
|
@just cp_std "sys/platform_version/mod.rs"
|
|
|
|
@just cp_std "sys/process/mod.rs"
|
|
@just cp_std "sys/process/env.rs"
|
|
@just cp_std "sys/process/unsupported.rs"
|
|
|
|
@just real_cp_std "sys/random/mod.rs"
|
|
@just cp_std "sys/random/unsupported.rs"
|
|
|
|
@just cp_std "sys/stdio/mod.rs"
|
|
@just cp_std "sys/stdio/unsupported.rs"
|
|
|
|
@just cp_std "sys/sync/condvar/mod.rs"
|
|
@just cp_std "sys/sync/condvar/no_threads.rs"
|
|
@just cp_std "sys/sync/mutex/mod.rs"
|
|
@just cp_std "sys/sync/mutex/no_threads.rs"
|
|
@just cp_std "sys/sync/once/mod.rs"
|
|
@just cp_std "sys/sync/once/no_threads.rs"
|
|
@just cp_std "sys/sync/rwlock/mod.rs"
|
|
@just cp_std "sys/sync/rwlock/no_threads.rs"
|
|
@just cp_std "sys/sync/thread_parking/mod.rs"
|
|
@just cp_std "sys/sync/thread_parking/unsupported.rs"
|
|
@just cp_std "sys/sync/mod.rs"
|
|
@just cp_std "sys/sync/once_box.rs"
|
|
|
|
@just cp_std "sys/thread/mod.rs"
|
|
@just cp_std "sys/thread/unsupported.rs"
|
|
|
|
@just real_cp_std "sys/thread_local/mod.rs"
|
|
@just cp_std "sys/thread_local/no_threads.rs"
|
|
@just cp_std "sys/thread_local/os.rs"
|
|
|
|
@just cp_std "sys/time/mod.rs"
|
|
@just cp_std "sys/time/unsupported.rs"
|
|
|
|
@just cp_std "sys/backtrace.rs"
|
|
@just cp_std "sys/cmath.rs"
|
|
@just cp_std "sys/configure_builtins.rs"
|
|
@just cp_std "sys/env_consts.rs"
|
|
@just cp_std "sys/exit.rs"
|
|
@just cp_std "sys/mod.rs"
|
|
|
|
@just cp_std "thread"
|
|
|
|
STD_FILES := "alloc.rs \
|
|
ascii.rs \
|
|
backtrace.rs \
|
|
bstr.rs \
|
|
env.rs \
|
|
error.rs \
|
|
fs.rs \
|
|
keyword_docs.rs \
|
|
lib.rs \
|
|
macros.rs \
|
|
panic.rs \
|
|
panicking.rs \
|
|
pat.rs \
|
|
path.rs \
|
|
process.rs \
|
|
random.rs \
|
|
rt.rs \
|
|
tests_helpers.rs \
|
|
time.rs \
|
|
backtrace \
|
|
collections \
|
|
ffi \
|
|
fs \
|
|
hash \
|
|
io \
|
|
net \
|
|
num \
|
|
os/raw/mod.rs \
|
|
os/raw/tests.rs \
|
|
os/mod.rs \
|
|
prelude \
|
|
process \
|
|
sync \
|
|
sys/alloc/mod.rs \
|
|
sys/args/mod.rs \
|
|
sys/args/unsupported.rs \
|
|
sys/env/mod.rs \
|
|
sys/env/common.rs \
|
|
sys/env/unsupported.rs \
|
|
sys/fd/mod.rs \
|
|
sys/fs/mod.rs \
|
|
sys/fs/common.rs \
|
|
sys/fs/unsupported.rs \
|
|
sys/helpers/mod.rs \
|
|
sys/helpers/small_c_string.rs \
|
|
sys/helpers/tests.rs \
|
|
sys/helpers/wstr.rs \
|
|
sys/io/error/generic.rs \
|
|
sys/io/error/mod.rs \
|
|
sys/io/io_slice/unsupported.rs \
|
|
sys/io/is_terminal/unsupported.rs \
|
|
sys/io/kernel_copy/mod.rs \
|
|
sys/io/mod.rs \
|
|
sys/net/connection/mod.rs \
|
|
sys/net/connection/unsupported.rs \
|
|
sys/net/hostname/mod.rs \
|
|
sys/net/hostname/unsupported.rs \
|
|
sys/net/mod.rs \
|
|
sys/os_str/bytes/tests.rs \
|
|
sys/os_str/bytes.rs \
|
|
sys/os_str/mod.rs \
|
|
sys/pal/mod.rs \
|
|
sys/pal/unsupported/mod.rs \
|
|
sys/pal/unsupported/common.rs \
|
|
sys/pal/unsupported/os.rs \
|
|
sys/path/mod.rs \
|
|
sys/path/unix.rs \
|
|
sys/personality/dwarf/eh.rs \
|
|
sys/personality/dwarf/mod.rs \
|
|
sys/personality/dwarf/tests.rs \
|
|
sys/personality/mod.rs \
|
|
sys/pipe/mod.rs \
|
|
sys/pipe/unsupported.rs \
|
|
sys/platform_version/mod.rs \
|
|
sys/process/mod.rs \
|
|
sys/process/env.rs \
|
|
sys/process/unsupported.rs \
|
|
sys/random/mod.rs \
|
|
sys/random/unsupported.rs \
|
|
sys/stdio/mod.rs \
|
|
sys/stdio/unsupported.rs \
|
|
sys/sync/condvar/mod.rs \
|
|
sys/sync/condvar/no_threads.rs \
|
|
sys/sync/mutex/mod.rs \
|
|
sys/sync/mutex/no_threads.rs \
|
|
sys/sync/once/mod.rs \
|
|
sys/sync/once/no_threads.rs \
|
|
sys/sync/rwlock/mod.rs \
|
|
sys/sync/rwlock/no_threads.rs \
|
|
sys/sync/thread_parking/mod.rs \
|
|
sys/sync/thread_parking/unsupported.rs \
|
|
sys/sync/mod.rs \
|
|
sys/sync/once_box.rs \
|
|
sys/thread/mod.rs \
|
|
sys/thread/unsupported.rs \
|
|
sys/thread_local/mod.rs \
|
|
sys/thread_local/no_threads.rs \
|
|
sys/thread_local/os.rs \
|
|
sys/time/mod.rs \
|
|
sys/time/unsupported.rs \
|
|
sys/backtrace.rs \
|
|
sys/cmath.rs \
|
|
sys/configure_builtins.rs \
|
|
sys/env_consts.rs \
|
|
sys/exit.rs \
|
|
sys/mod.rs \
|
|
thread"
|
|
|
|
build-sysroot:
|
|
RUSTFLAGS="-Zforce-unstable-if-unmarked -C relocation-model=pic -C link-arg=-pie" cargo build --package std --target ../riscv64.json \
|
|
--features compiler-builtins-mem
|
|
mkdir ../sysroot/lib/rustlib/riscv64/lib -p
|
|
rm ../sysroot/lib/rustlib/riscv64/lib/* -rf
|
|
cp target/riscv64/debug/deps/*.rlib ../sysroot/lib/rustlib/riscv64/lib
|
|
|
|
clean:
|
|
cargo clean
|
|
rm ../sysroot/lib/rustlib/riscv64/lib/* -rf
|
|
|
|
for file in {{ STD_FILES }}; do \
|
|
rm -rf std/src/$file; \
|
|
done
|
|
|
|
rm -rf std/build.rs
|
|
rm -rf std/Cargo.toml
|
|
rm -rf Cargo.toml
|