Skip to content

Commit 60fde89

Browse files
committed
rust: zephyr-sys: Fixup clang targets for RISCV
Rustc for RISCV encodes optional features on the CPU available as part of the target tuple. Clang, on the other hand does not. In order to be able to use libclang with bindgen on RISCV, we need to simplify the target tuples a bit. Do this by just matching 'riscv32' or 'riscv64' and then passing in a generic tuple. We aren't generating any code, and the structs should always match between the targets. Signed-off-by: David Brown <[email protected]>
1 parent 0332ce8 commit 60fde89

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

lib/rust/zephyr-sys/build.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,30 @@ use std::env;
1919
use std::path::{Path, PathBuf};
2020

2121
fn main() -> Result<()> {
22+
// Determine which version of Clang we linked with.
23+
let version = bindgen::clang_version();
24+
println!("Clang version: {:?}", version);
25+
2226
// Pass in the target used to build the native code.
23-
let target_arg = format!("--target={}", env::var("TARGET")?);
27+
let target = env::var("TARGET")?;
28+
29+
// Rustc uses some complex target tuples for the riscv targets, whereas clang uses other
30+
// options. Fortunately, these variants shouldn't affect the structures generated, so just
31+
// turn this into a generic target.
32+
let target = if target.starts_with("riscv32") {
33+
"riscv32-unknown-none-elf".to_string()
34+
} else {
35+
target
36+
};
37+
38+
// Likewise, do the same with RISCV-64.
39+
let target = if target.starts_with("riscv64") {
40+
"riscv64-unknown-none-elf".to_string()
41+
} else {
42+
target
43+
};
44+
45+
let target_arg = format!("--target={}", target);
2446

2547
// println!("includes: {:?}", env::var("INCLUDE_DIRS"));
2648
// println!("defines: {:?}", env::var("INCLUDE_DEFINES"));

0 commit comments

Comments
 (0)