Skip to content

Commit

Permalink
Temp 3
Browse files Browse the repository at this point in the history
Signed-off-by: Klimenty Tsoutsman <klim@tsoutsman.com>
  • Loading branch information
tsoutsman committed Oct 31, 2023
1 parent 091465f commit 0d70f4c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 25 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 16 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand All @@ -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.
Expand Down Expand Up @@ -329,15 +339,16 @@ 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)\""
@echo -e "\t KERNEL_PREFIX: \"$(KERNEL_PREFIX)\""
@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).
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions applications/test_std/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{string::String, vec::Vec};

pub fn main(_: Vec<String>) -> isize {
println!("hello world");
0
}
11 changes: 3 additions & 8 deletions cfg/Config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions kernel/nano_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down

0 comments on commit 0d70f4c

Please sign in to comment.