Skip to content

Commit 9c3d91d

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

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

riscv-rt/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ 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+
riscv-rt-macros = { path = "macros", version = "0.3.0" }
2929

3030
[dev-dependencies]
3131
panic-halt = "1.0.0"

riscv-rt/build.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,20 @@ fn main() {
2929

3030
if let Ok(target) = RiscvTarget::build(&target, &cargo_flags) {
3131
let width = target.width();
32-
if matches!(width, riscv_target_parser::Width::W128) {
33-
panic!("Unsupported RISC-V target: {width}");
34-
}
35-
if target.base_extension().is_none() {
36-
panic!("Unsupported RISC-V target: no base extension");
37-
}
32+
let base_extension = match width {
33+
riscv_target_parser::Width::W32 => match target.base_extension() {
34+
Some(riscv_target_parser::Extension::I) => "RV32I",
35+
Some(riscv_target_parser::Extension::E) => "RV32E",
36+
other => panic!("Unsupported RISC-V target: {:?}-{:?}", width, other),
37+
},
38+
riscv_target_parser::Width::W64 => match target.base_extension() {
39+
Some(riscv_target_parser::Extension::I) => "RV64I",
40+
Some(riscv_target_parser::Extension::E) => "RV64E",
41+
other => panic!("Unsupported RISC-V target: {:?}-{:?}", width, other),
42+
},
43+
_ => panic!("Unsupported RISC-V target width: {:?}", width),
44+
};
45+
println!("cargo:rustc-env=RUSTC_CFG_RISCV32I={base_extension}");
3846
for flag in target.rustc_flags() {
3947
// Required until target_feature risc-v is stable and in-use
4048
println!("cargo:rustc-check-cfg=cfg({flag})");

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+
fn main() {
2+
match option_env!("RISCV_BASE_EXTENSION") {
3+
Some("RV32I") => {
4+
println!("cargo:rustc-cfg=feature=\"riscv32\"");
5+
}
6+
Some("RV32E") => {
7+
println!("cargo:rustc-cfg=feature=\"riscv32e\"");
8+
}
9+
Some("RV64I") | None => {
10+
// RV64I is the default base extension for docs
11+
println!("cargo:rustc-cfg=feature=\"riscv64\"");
12+
}
13+
Some("RV64E") => {
14+
println!("cargo:rustc-cfg=feature=\"riscv64e\"");
15+
}
16+
Some(other) => {
17+
panic!("Unsupported RISC-V base extension: {other}");
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)