Skip to content

Commit 4d692e6

Browse files
committed
Add *-espidf target triple mappings
Fixes rust-lang#2396. This makes it possible to workaround cc/bindgen issues with esp-rs projects by using only environment varaibles (TARGET_CC, CLANG_PATH, etc). Without this, it requires modifying each crate's build.rs that you try to depend on to add a target option passed along to clang.
1 parent bca47cd commit 4d692e6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

bindgen/lib.rs

+20
Original file line numberDiff line numberDiff line change
@@ -2428,6 +2428,14 @@ fn rust_to_clang_target(rust_target: &str) -> String {
24282428
let mut clang_target = "riscv64-".to_owned();
24292429
clang_target.push_str(rust_target.strip_prefix("riscv64gc-").unwrap());
24302430
return clang_target;
2431+
} else if rust_target.ends_with("-espidf") {
2432+
let mut clang_target = rust_target.strip_suffix("-espidf").unwrap().to_owned();
2433+
clang_target.push_str("-elf");
2434+
if clang_target.starts_with("riscv32imc-") {
2435+
clang_target = "riscv32-".to_owned() +
2436+
clang_target.strip_prefix("riscv32imc-").unwrap();
2437+
}
2438+
return clang_target;
24312439
}
24322440
rust_target.to_owned()
24332441
}
@@ -3011,3 +3019,15 @@ fn test_rust_to_clang_target_riscv() {
30113019
"riscv64-unknown-linux-gnu"
30123020
)
30133021
}
3022+
3023+
#[test]
3024+
fn test_rust_to_clang_target_espidf() {
3025+
assert_eq!(
3026+
rust_to_clang_target("riscv32imc-esp-espidf"),
3027+
"riscv32-esp-elf"
3028+
);
3029+
assert_eq!(
3030+
rust_to_clang_target("xtensa-esp32-espidf"),
3031+
"xtensa-esp32-elf"
3032+
);
3033+
}

0 commit comments

Comments
 (0)