Skip to content

Commit

Permalink
riscv-rt: build: use cfg-check directives in build script
Browse files Browse the repository at this point in the history
Uses new lint checks for `cfg` variables.
  • Loading branch information
rmsyn committed May 7, 2024
1 parent 2afe387 commit 4dd8a43
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions riscv-rt/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Moved all the assembly code to `asm.rs`
- Use `weak` symbols for functions such as `_mp_hook` or `_start_trap`
- `abort` is now `weak`, so it is possible to link third-party libraries including this symbol.
- Made `cfg` variable selection more robust for custom targets

### Removed

Expand Down
11 changes: 10 additions & 1 deletion riscv-rt/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,23 @@ fn parse_target(target: &str, cargo_flags: &str) -> (u32, HashSet<char>) {
}

fn main() {
println!("cargo:rustc-check-cfg=cfg(riscv)");
println!("cargo:rustc-check-cfg=cfg(riscv32)");
println!("cargo:rustc-check-cfg=cfg(riscv64)");
println!("cargo:rustc-check-cfg=cfg(riscvi)");
println!("cargo:rustc-check-cfg=cfg(riscvm)");
println!("cargo:rustc-check-cfg=cfg(riscva)");
println!("cargo:rustc-check-cfg=cfg(riscvf)");
println!("cargo:rustc-check-cfg=cfg(riscvd)");
println!("cargo:rustc-check-cfg=cfg(riscvc)");

let target = env::var("TARGET").unwrap();
let cargo_flags = env::var("CARGO_ENCODED_RUSTFLAGS").unwrap();
let _name = env::var("CARGO_PKG_NAME").unwrap();

// set configuration flags depending on the target
if target.starts_with("riscv") {
println!("cargo:rustc-cfg=riscv");

// This is required until target_arch & target_feature risc-v work is
// stable and in-use (rust 1.75.0)
let (bits, extensions) = parse_target(&target, &cargo_flags);
Expand Down

0 comments on commit 4dd8a43

Please sign in to comment.