Skip to content

Commit a7ff8e1

Browse files
authored
Add *-espidf target triple mappings (#2397)
Fixes #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 a7ff8e1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

bindgen/lib.rs

+21
Original file line numberDiff line numberDiff line change
@@ -2428,6 +2428,15 @@ 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 =
2433+
rust_target.strip_suffix("-espidf").unwrap().to_owned();
2434+
clang_target.push_str("-elf");
2435+
if clang_target.starts_with("riscv32imc-") {
2436+
clang_target = "riscv32-".to_owned() +
2437+
clang_target.strip_prefix("riscv32imc-").unwrap();
2438+
}
2439+
return clang_target;
24312440
}
24322441
rust_target.to_owned()
24332442
}
@@ -3011,3 +3020,15 @@ fn test_rust_to_clang_target_riscv() {
30113020
"riscv64-unknown-linux-gnu"
30123021
)
30133022
}
3023+
3024+
#[test]
3025+
fn test_rust_to_clang_target_espidf() {
3026+
assert_eq!(
3027+
rust_to_clang_target("riscv32imc-esp-espidf"),
3028+
"riscv32-esp-elf"
3029+
);
3030+
assert_eq!(
3031+
rust_to_clang_target("xtensa-esp32-espidf"),
3032+
"xtensa-esp32-elf"
3033+
);
3034+
}

0 commit comments

Comments
 (0)