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 9c3d91d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion riscv-rt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ 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" }
riscv-rt-macros = { path = "macros", version = "0.3.0" }

[dev-dependencies]
panic-halt = "1.0.0"
Expand Down
20 changes: 14 additions & 6 deletions riscv-rt/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,20 @@ fn main() {

if let Ok(target) = RiscvTarget::build(&target, &cargo_flags) {
let width = target.width();
if matches!(width, riscv_target_parser::Width::W128) {
panic!("Unsupported RISC-V target: {width}");
}
if target.base_extension().is_none() {
panic!("Unsupported RISC-V target: no base extension");
}
let base_extension = match width {
riscv_target_parser::Width::W32 => match target.base_extension() {
Some(riscv_target_parser::Extension::I) => "RV32I",
Some(riscv_target_parser::Extension::E) => "RV32E",
other => panic!("Unsupported RISC-V target: {:?}-{:?}", width, other),
},
riscv_target_parser::Width::W64 => match target.base_extension() {
Some(riscv_target_parser::Extension::I) => "RV64I",
Some(riscv_target_parser::Extension::E) => "RV64E",
other => panic!("Unsupported RISC-V target: {:?}-{:?}", width, other),
},
_ => panic!("Unsupported RISC-V target width: {:?}", width),
};
println!("cargo:rustc-env=RUSTC_CFG_RISCV32I={base_extension}");
for flag in target.rustc_flags() {
// Required until target_feature risc-v is stable and in-use
println!("cargo:rustc-check-cfg=cfg({flag})");
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 @@
fn main() {
match option_env!("RISCV_BASE_EXTENSION") {
Some("RV32I") => {
println!("cargo:rustc-cfg=feature=\"riscv32\"");
}
Some("RV32E") => {
println!("cargo:rustc-cfg=feature=\"riscv32e\"");
}
Some("RV64I") | None => {
// RV64I is the default base extension for docs
println!("cargo:rustc-cfg=feature=\"riscv64\"");
}
Some("RV64E") => {
println!("cargo:rustc-cfg=feature=\"riscv64e\"");
}
Some(other) => {
panic!("Unsupported RISC-V base extension: {other}");
}
}
}

0 comments on commit 9c3d91d

Please sign in to comment.