Skip to content

Commit 2e75fe7

Browse files
committed
Use conditional dependencies in riscv-rt depending on base extension
1 parent 289206a commit 2e75fe7

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

riscv-rt/Cargo.toml

+16-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,22 @@ riscv-target-parser = { path = "../riscv-target-parser", version = "0.1.0" }
2525
[dependencies]
2626
riscv = { path = "../riscv", version = "0.12.0" }
2727
riscv-pac = { path = "../riscv-pac", version = "0.2.0" }
28-
riscv-rt-macros = { path = "macros", version = "0.2.2" }
28+
29+
# For RV32I targets
30+
[target.'cfg(all(target_arch = "riscv32", riscvi))'.dependencies]
31+
riscv-rt-macros = { path = "macros", version = "0.3.0", features = ["riscv32i"] }
32+
# For RV32E targets (not that, in case of collision, RV32I has precedence over RV32E)
33+
[target.'cfg(all(target_arch = "riscv32", not(riscvi), riscve))'.dependencies]
34+
riscv-rt-macros = { path = "macros", version = "0.3.0", features = ["riscv32e"] }
35+
# For RV64I targets
36+
[target.'cfg(all(target_arch = "riscv64", riscvi))'.dependencies]
37+
riscv-rt-macros = { path = "macros", version = "0.3.0", features = ["riscv64i"] }
38+
# For RV64E targets (not that, in case of collision, RV64I has precedence over RV64E)
39+
[target.'cfg(all(target_arch = "riscv64", not(riscvi), riscve))'.dependencies]
40+
riscv-rt-macros = { path = "macros", version = "0.3.0", features = ["riscv64e"] }
41+
# For documentations, RV64I is the default
42+
[target.'cfg(not(any(target_arch = "riscv32", target_arch = "riscv64")))'.dependencies]
43+
riscv-rt-macros = { path = "macros", version = "0.3.0", features = ["riscv64i"] }
2944

3045
[dev-dependencies]
3146
panic-halt = "1.0.0"

riscv-rt/macros/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ keywords = ["riscv", "runtime", "startup"]
1010
license = "MIT OR Apache-2.0"
1111
name = "riscv-rt-macros"
1212
repository = "https://github.com/rust-embedded/riscv"
13-
version = "0.2.2"
13+
version = "0.3.0"
1414
edition = "2021"
1515

1616
[lib]
@@ -25,3 +25,7 @@ syn = { version = "2.0", features = ["extra-traits", "full"] }
2525
s-mode = []
2626
v-trap = []
2727
u-boot = []
28+
riscv32i = []
29+
riscv32e = []
30+
riscv64i = []
31+
riscv64e = []

riscv-rt/macros/build.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use std::env;
2+
3+
fn main() {
4+
let features: Vec<String> = env::vars()
5+
.filter_map(|(key, _)| {
6+
if key.starts_with("CARGO_FEATURE_RISCV") {
7+
Some(key)
8+
} else {
9+
None
10+
}
11+
})
12+
.collect();
13+
14+
if features.len() != 1 {
15+
panic!(
16+
"Exactly one RISC-V Base Extension feature must be enabled. Provided: {:?}",
17+
features
18+
);
19+
}
20+
}

0 commit comments

Comments
 (0)