Skip to content

Commit

Permalink
Use conditional dependencies in riscv-rt depending on base extension
Browse files Browse the repository at this point in the history
  • Loading branch information
romancardenas committed Nov 19, 2024
1 parent 289206a commit 2e75fe7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
17 changes: 16 additions & 1 deletion riscv-rt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,22 @@ riscv-target-parser = { path = "../riscv-target-parser", version = "0.1.0" }
[dependencies]
riscv = { path = "../riscv", version = "0.12.0" }
riscv-pac = { path = "../riscv-pac", version = "0.2.0" }
riscv-rt-macros = { path = "macros", version = "0.2.2" }

# For RV32I targets
[target.'cfg(all(target_arch = "riscv32", riscvi))'.dependencies]
riscv-rt-macros = { path = "macros", version = "0.3.0", features = ["riscv32i"] }
# For RV32E targets (not that, in case of collision, RV32I has precedence over RV32E)
[target.'cfg(all(target_arch = "riscv32", not(riscvi), riscve))'.dependencies]
riscv-rt-macros = { path = "macros", version = "0.3.0", features = ["riscv32e"] }
# For RV64I targets
[target.'cfg(all(target_arch = "riscv64", riscvi))'.dependencies]
riscv-rt-macros = { path = "macros", version = "0.3.0", features = ["riscv64i"] }
# For RV64E targets (not that, in case of collision, RV64I has precedence over RV64E)
[target.'cfg(all(target_arch = "riscv64", not(riscvi), riscve))'.dependencies]
riscv-rt-macros = { path = "macros", version = "0.3.0", features = ["riscv64e"] }
# For documentations, RV64I is the default
[target.'cfg(not(any(target_arch = "riscv32", target_arch = "riscv64")))'.dependencies]
riscv-rt-macros = { path = "macros", version = "0.3.0", features = ["riscv64i"] }

[dev-dependencies]
panic-halt = "1.0.0"
Expand Down
6 changes: 5 additions & 1 deletion riscv-rt/macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ keywords = ["riscv", "runtime", "startup"]
license = "MIT OR Apache-2.0"
name = "riscv-rt-macros"
repository = "https://github.com/rust-embedded/riscv"
version = "0.2.2"
version = "0.3.0"
edition = "2021"

[lib]
Expand All @@ -25,3 +25,7 @@ syn = { version = "2.0", features = ["extra-traits", "full"] }
s-mode = []
v-trap = []
u-boot = []
riscv32i = []
riscv32e = []
riscv64i = []
riscv64e = []
20 changes: 20 additions & 0 deletions riscv-rt/macros/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use std::env;

fn main() {
let features: Vec<String> = env::vars()
.filter_map(|(key, _)| {
if key.starts_with("CARGO_FEATURE_RISCV") {
Some(key)
} else {
None
}
})
.collect();

if features.len() != 1 {
panic!(
"Exactly one RISC-V Base Extension feature must be enabled. Provided: {:?}",
features
);
}
}

0 comments on commit 2e75fe7

Please sign in to comment.