diff options
author | Josh Guilfoyle <jasta@devtcg.org> | 2023-01-25 14:54:19 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-25 17:54:19 -0500 |
commit | a7ff8e136027c9542f65eca97a7ff3c0b870518d (patch) | |
tree | f9933e21fe479de1a9d1501d8902d45c628fb4cc | |
parent | bca47cd9c2e718012f7f953be25bb3a6a9ca400b (diff) |
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.
-rw-r--r-- | bindgen/lib.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/bindgen/lib.rs b/bindgen/lib.rs index cf1486c2..8c8ffe5c 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -2428,6 +2428,15 @@ fn rust_to_clang_target(rust_target: &str) -> String { let mut clang_target = "riscv64-".to_owned(); clang_target.push_str(rust_target.strip_prefix("riscv64gc-").unwrap()); return clang_target; + } else if rust_target.ends_with("-espidf") { + let mut clang_target = + rust_target.strip_suffix("-espidf").unwrap().to_owned(); + clang_target.push_str("-elf"); + if clang_target.starts_with("riscv32imc-") { + clang_target = "riscv32-".to_owned() + + clang_target.strip_prefix("riscv32imc-").unwrap(); + } + return clang_target; } rust_target.to_owned() } @@ -3011,3 +3020,15 @@ fn test_rust_to_clang_target_riscv() { "riscv64-unknown-linux-gnu" ) } + +#[test] +fn test_rust_to_clang_target_espidf() { + assert_eq!( + rust_to_clang_target("riscv32imc-esp-espidf"), + "riscv32-esp-elf" + ); + assert_eq!( + rust_to_clang_target("xtensa-esp32-espidf"), + "xtensa-esp32-elf" + ); +} |