From 0d70f4c26b184a3524137d2f703e8221b0df8404 Mon Sep 17 00:00:00 2001 From: Klimenty Tsoutsman Date: Wed, 1 Nov 2023 09:31:40 +1100 Subject: [PATCH] Temp 3 Signed-off-by: Klimenty Tsoutsman --- Cargo.lock | 1 + Cargo.toml | 13 ------------- Makefile | 20 ++++++++++++++++---- applications/test_std/src/lib.rs | 1 + cfg/Config.mk | 11 +++-------- kernel/nano_core/Cargo.toml | 1 + 6 files changed, 22 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f9309c2073..29b7df2dcf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2331,6 +2331,7 @@ dependencies = [ "boot_info", "captain", "cfg-if 1.0.0", + "compiler_builtins", "early_printer", "early_tls", "exceptions_early", diff --git a/Cargo.toml b/Cargo.toml index 7b0e4c295f..7619c88dd4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -121,16 +121,3 @@ backtrace = { path = "ports/backtrace" } region = { path = "ports/region" } noline = { git = "https://github.com/theseus-os/noline", branch = "history-dedup" } target-lexicon = { git = "https://github.com/theseus-os/target-lexicon", branch = "theseus" } - -### These profiles fix the new rustc behavior of splitting one crate into many object files. -### That messes up our module loading, which is bad! -### See this link about profiles: https://doc.rust-lang.org/cargo/reference/manifest.html -# workaround rust-lang/rust#47074 -[profile.dev] -codegen-units = 1 -incremental = false - -# workaround rust-lang/rust#47074 -[profile.release] -codegen-units = 1 -incremental = false diff --git a/Makefile b/Makefile index 12fe2a37b2..5f4d350ea4 100644 --- a/Makefile +++ b/Makefile @@ -243,7 +243,7 @@ build: $(nano_core_binary) done; wait ## Second, copy all object files into the main build directory and prepend the kernel or app prefix appropriately. - @RUSTFLAGS="" cargo run --release --manifest-path $(ROOT_DIR)/tools/copy_latest_crate_objects/Cargo.toml -- \ + RUSTFLAGS="" cargo run --release --manifest-path $(ROOT_DIR)/tools/copy_latest_crate_objects/Cargo.toml -- \ -i "$(TARGET_DEPS_DIR)" \ --output-objects $(OBJECT_FILES_BUILD_DIR) \ --output-deps $(DEPS_BUILD_DIR) \ @@ -253,6 +253,16 @@ build: $(nano_core_binary) --kernel-prefix $(KERNEL_PREFIX) \ --app-prefix $(APP_PREFIX) \ -e "$(EXTRA_APP_CRATE_NAMES) libtheseus" + RUSTFLAGS="" cargo run --release --manifest-path $(ROOT_DIR)/tools/copy_latest_crate_objects/Cargo.toml -- \ + -i "$(STD_BUILD_DIR)/aarch64-apple-darwin/stage0-std/$(TARGET)/release/deps" \ + --output-objects $(OBJECT_FILES_BUILD_DIR) \ + --output-deps $(DEPS_BUILD_DIR) \ + --output-sysroot $(DEPS_SYSROOT_DIR)/lib/rustlib/$(TARGET)/lib \ + -k ./kernel \ + -a ./applications \ + --kernel-prefix $(KERNEL_PREFIX) \ + --app-prefix $(APP_PREFIX) \ + -e "$(EXTRA_APP_CRATE_NAMES) libtheseus" ## Third, perform partial linking on each object file, which shrinks their size ## and most importantly, accelerates their loading and linking at runtime. @@ -329,7 +339,8 @@ ifneq (,$(findstring vga_text_mode, $(THESEUS_CONFIG))) endif printenv - RUSTFLAGS="" CARGOFLAGS="" ports/rust/x.py build --stage 0 library/std --target /Users/klim/Projects/theseus-5/cfg/$(TARGET).json --build-dir $(STD_BUILD_DIR) + echo $(RUSTFLAGS) + RUST_TARGET_PATH='$(CFG_DIR)' CARGOFLAGS="" RUSTFLAGS='$(RUSTFLAGS)' ports/rust/x.py build --stage 0 library/std --target $(TARGET) --build-dir $(STD_BUILD_DIR) @echo -e "\n=================== BUILDING ALL CRATES ===================" @echo -e "\t TARGET: \"$(TARGET)\"" @@ -337,7 +348,7 @@ endif @echo -e "\t APP_PREFIX: \"$(APP_PREFIX)\"" @echo -e "\t CFLAGS: \"$(CFLAGS)\"" @echo -e "\t THESEUS_CONFIG (before build.rs script): \"$(THESEUS_CONFIG)\"" - THESEUS_CFLAGS='$(CFLAGS)' THESEUS_NANO_CORE_BUILD_DIR='$(NANO_CORE_BUILD_DIR)' RUST_TARGET_PATH='$(CFG_DIR)' RUSTFLAGS='$(RUSTFLAGS)' cargo build $(CARGOFLAGS) $(FEATURES) $(BUILD_STD_CARGOFLAGS) --target $(TARGET) + THESEUS_CFLAGS='$(CFLAGS)' THESEUS_NANO_CORE_BUILD_DIR='$(NANO_CORE_BUILD_DIR)' RUST_TARGET_PATH='$(CFG_DIR)' RUSTFLAGS='$(RUSTFLAGS)' cargo build $(CARGOFLAGS) $(FEATURES) --target $(TARGET) $(BUILD_STD_CARGOFLAGS) ## We tried using the "cargo rustc" command here instead of "cargo build" to avoid cargo unnecessarily rebuilding core/alloc crates, ## But it doesn't really seem to work (it's not the cause of cargo rebuilding everything). @@ -621,9 +632,10 @@ clippy : export override FEATURES := $(subst --workspace,,$(FEATURES)) endif clippy : export override RUSTFLAGS = $(patsubst %,--cfg %, $(THESEUS_CONFIG)) clippy: +# TODO: x.py RUST_TARGET_PATH='$(CFG_DIR)' RUSTFLAGS='$(RUSTFLAGS)' \ cargo clippy \ - $(BUILD_STD_CARGOFLAGS) $(FEATURES) \ + $(FEATURES) \ --target $(TARGET) \ -- -D clippy::all diff --git a/applications/test_std/src/lib.rs b/applications/test_std/src/lib.rs index a86efb49e5..a5badebe42 100644 --- a/applications/test_std/src/lib.rs +++ b/applications/test_std/src/lib.rs @@ -1,5 +1,6 @@ use std::{string::String, vec::Vec}; pub fn main(_: Vec) -> isize { + println!("hello world"); 0 } diff --git a/cfg/Config.mk b/cfg/Config.mk index f01a672d54..03969fee5c 100644 --- a/cfg/Config.mk +++ b/cfg/Config.mk @@ -66,14 +66,6 @@ $(error 'BUILD_MODE' value of '$(BUILD_MODE)' is invalid, it must be either 'deb endif -## Tell cargo to build our own target-specific version of the `core` and `alloc` crates. -## Also ensure that core memory functions (e.g., memcpy) are included in the build and not name-mangled. -## We keep these flags separate from the regular CARGOFLAGS for purposes of easily creating a sysroot directory. -BUILD_STD_CARGOFLAGS += -Z unstable-options -BUILD_STD_CARGOFLAGS += -Z build-std=core,alloc -BUILD_STD_CARGOFLAGS += -Z build-std-features=compiler-builtins-mem - - ## Tell rustc to output the native object file for each crate, ## which avoids always having to unpack the crate's .rlib archive to extract the object files within. ## Note that we still do have to extract and partially link object files from .rlib archives for crates that @@ -96,6 +88,9 @@ export override RUSTFLAGS += -D unused-must-use ## without breaking our loader/linker assumptions. export override RUSTFLAGS += -Z share-generics=no +export override RUSTFLAGS += -C codegen-units=1 +export override RUSTFLAGS += -C incremental=no + ## This forces frame pointers to be generated, i.e., the stack base pointer (RBP register on x86_64) ## will be used to store the starting address of the current stack frame. ## This can be used for obtaining a backtrace/stack trace, diff --git a/kernel/nano_core/Cargo.toml b/kernel/nano_core/Cargo.toml index 0908124d26..63151df523 100644 --- a/kernel/nano_core/Cargo.toml +++ b/kernel/nano_core/Cargo.toml @@ -13,6 +13,7 @@ libm = "0.2.1" log = "0.4.8" irq_safety = { git = "https://github.com/theseus-os/irq_safety" } +compiler_builtins = { version = "*", features = ["mem"] } kernel_config = { path = "../kernel_config" } state_store = { path = "../state_store" }