Commit 60fde89b authored by David Brown's avatar David Brown Committed by David Brown
Browse files

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: default avatarDavid Brown <david.brown@linaro.org>
parent 0332ce85
Loading
Loading
Loading
Loading
+23 −1
Changes for lib/rust/zephyr-sys/build.rs: 23 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -19,8 +19,30 @@ use std::env;
use std::path::{Path, PathBuf};

fn main() -> Result<()> {
    // Determine which version of Clang we linked with.
    let version = bindgen::clang_version();
    println!("Clang version: {:?}", version);

    // Pass in the target used to build the native code.
    let target_arg = format!("--target={}", env::var("TARGET")?);
    let target = env::var("TARGET")?;

    // Rustc uses some complex target tuples for the riscv targets, whereas clang uses other
    // options.  Fortunately, these variants shouldn't affect the structures generated, so just
    // turn this into a generic target.
    let target = if target.starts_with("riscv32") {
        "riscv32-unknown-none-elf".to_string()
    } else {
        target
    };

    // Likewise, do the same with RISCV-64.
    let target = if target.starts_with("riscv64") {
        "riscv64-unknown-none-elf".to_string()
    } else {
        target
    };

    let target_arg = format!("--target={}", target);

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