Skip to content

Commit

Permalink
riscv: build: make cfg variables more robust
Browse files Browse the repository at this point in the history
Change which Cargo `CFG` environment variables are used to select the
custom `cfg` variables.

See
#204 (comment)
for discussion.
  • Loading branch information
rmsyn committed May 4, 2024
1 parent a9d3e33 commit 75bca98
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions riscv/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed

- Made `asm::wfi`, `fence`, `fence_i` and `sfence` safe (ie, removed `unsafe` from their definitions)
- Made `cfg` variable selection more robust for custom targets and downstream users

## [v0.11.0] - 2024-01-14

Expand Down
7 changes: 4 additions & 3 deletions riscv/build.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::env;

fn main() {
let target = env::var("TARGET").unwrap();
let target = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
let ptr_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap();

if target.starts_with("riscv32") {
if target.contains("riscv") && ptr_width == "32" {
println!("cargo:rustc-cfg=riscv");
println!("cargo:rustc-cfg=riscv32");
} else if target.starts_with("riscv64") {
} else if target.contains("riscv") && ptr_width == "64" {
println!("cargo:rustc-cfg=riscv");
println!("cargo:rustc-cfg=riscv64");
}
Expand Down

0 comments on commit 75bca98

Please sign in to comment.