Skip to content

Commit a040c83

Browse files
committed
rust: Add chainload cargo feature
Commit 590552a ("Makefile: unconditionally build rust stuff") started building the rust chainloading code unconditionally. Add a cargo "chainload" feature to build the code only if it is used as indicated by the CHAINLOADING build config variable. The dependency handling via `src/../build/build_cfg.h` is a quirk coming from the C side. Not all CFG values (like RELEASE) require a rebuild of the rust library but creating an additional dependency file for cargo features seems overkill. Signed-off-by: Janne Grunau <[email protected]>
1 parent ce3bb58 commit a040c83

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,17 @@ endif
7474
# Required for no_std + alloc for now
7575
export RUSTC_BOOTSTRAP=1
7676
RUST_LIB := librust.a
77-
ifeq ($(CHAINLOADING),1)
78-
CFG += CHAINLOADING
79-
endif
80-
8177
ifeq ($(BUILDSTD),1)
8278
CARGO_FLAGS := -Z build-std=alloc,core
8379
else
8480
CARGO_FLAGS :=
8581
endif
8682

83+
ifeq ($(CHAINLOADING),1)
84+
CFG += CHAINLOADING
85+
CARGO_FLAGS += --features chainload
86+
endif
87+
8788
LDFLAGS := -EL -maarch64elf --no-undefined -X -Bsymbolic \
8889
-z notext --no-apply-dynamic-relocs --orphan-handling=warn \
8990
-z nocopyreloc --gc-sections -pie
@@ -208,7 +209,7 @@ rustfmt:
208209
rustfmt-check:
209210
cd rust && cargo fmt --check
210211

211-
build/$(RUST_LIB): rust/src/*.rs rust/src/gpu/*.rs rust/src/gpu/hw/*.rs rust/Cargo.toml rust/Cargo.lock
212+
build/$(RUST_LIB): src/../build/build_cfg.h rust/src/*.rs rust/src/gpu/*.rs rust/src/gpu/hw/*.rs rust/Cargo.toml rust/Cargo.lock
212213
$(QUIET)echo " RS $@"
213214
$(QUIET)mkdir -p $(DEPDIR)
214215
$(QUIET)mkdir -p "$(dir $@)"

rust/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ crate-type = [ "staticlib" ]
1111

1212
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1313
[dependencies]
14-
fatfs = { path = "vendor/rust-fatfs", default-features = false, features = ["lfn", "alloc"] }
15-
uuid = { version = "1.7.0", default-features = false }
14+
fatfs = { path = "vendor/rust-fatfs", default-features = false, features = ["lfn", "alloc"], optional = true }
15+
uuid = { version = "1.7.0", default-features = false, optional = true }
1616
versions = { path = "./versions" }
17+
18+
[features]
19+
chainload = ["dep:fatfs", "dep:uuid"]

rust/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@
77
#![feature(stmt_expr_attributes)]
88
#![cfg_attr(all(version("1.82"), not(version("1.92"))), feature(new_zeroed_alloc))]
99

10+
#[allow(unused_imports)]
1011
#[macro_use]
1112
extern crate alloc;
1213

1314
pub mod adt;
15+
#[cfg(feature = "chainload")]
1416
pub mod chainload;
1517
pub mod dlmalloc;
1618
pub mod float;
19+
#[cfg(feature = "chainload")]
1720
pub mod gpt;
1821
pub mod gpu;
22+
#[cfg(feature = "chainload")]
1923
pub mod nvme;
2024
pub mod print;
2125

0 commit comments

Comments
 (0)