Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RISC-V has different triples for clang and rustc. #2136

Closed
trissylegs opened this issue Dec 12, 2021 · 3 comments
Closed

RISC-V has different triples for clang and rustc. #2136

trissylegs opened this issue Dec 12, 2021 · 3 comments

Comments

@trissylegs
Copy link
Contributor

trissylegs commented Dec 12, 2021

Same as #1211 Clang and rust use a different target triples on riscv.

I'm already trying to fix it. Using a similar solution to #1211. (I found the issue due to a comment on rust_to_clang_target)

Rust uses riscv64gc-unknown-linux-gnu, but clang uses riscv64-unknown-linux-gnu.
The difference is that riscv64gc has the extra features needed to run Linux. (ie Mutiplication, Floats, Atomics, Fences and CSRs), as well as Compressed instructions (16-bit encodings).

Clang instead uses -march to specify which extensions to use: eg (-march=rv6gc). Maybe should consider setting that too.

The example below is taken from authenticator-rs: https://github.com/mozilla/authenticator-rs/blob/660a701b45977cb5d184380061dfc8cec4f696be/build.rs#L12

Input C/C++ Header

// Literally anything

Bindgen Invocation

    let bindings = bindgen::Builder::default()
        .header("src/linux/hidwrapper.h")
        .whitelist_var("_HIDIOCGRDESCSIZE")
        .whitelist_var("_HIDIOCGRDESC")
        .generate()
        .expect("Unable to get hidraw bindings");

Actual Results

  error: unknown target triple 'riscv64gc-unknown-linux-gnu', please use -triple or -arch
  thread 'main' panicked at 'libclang error; possible causes include:
  - Invalid flag syntax
  - Unrecognized flags
  - Invalid flag arguments
  - File I/O errors
  If you encounter an error missing from this list, please file an issue or a PR!', /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.51.1/src/ir/context.rs:571:15
  stack backtrace:
     0: rust_begin_unwind
               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/panicking.rs:517:5
     1: core::panicking::panic_fmt
               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:100:14
     2: core::panicking::panic_display
               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:64:5
     3: core::option::expect_failed
               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/option.rs:1638:5
     4: core::option::Option<T>::expect
               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/option.rs:709:21
     5: bindgen::ir::context::BindgenContext::new
               at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.51.1/src/ir/context.rs:565:13
     6: bindgen::Bindings::generate
               at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.51.1/src/lib.rs:1875:27
     7: bindgen::Builder::generate
               at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.51.1/src/lib.rs:1244:9
     8: build_script_build::main
               at ./build.rs:12:20
     9: core::ops::function::FnOnce::call_once
               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/ops/function.rs:227:5
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Expected Results

Expected results are that bindgen uses clang with the matching target triple.

Workarond

Specify .clang_arg("--target=riscv64-unknown-linux-gnu") on riscv
Eg: https://github.com/trissylegs/authenticator-rs/blob/abcf07a231667e16a50da855d3e86765c158f0a2/build.rs#L19

@emilio
Copy link
Contributor

emilio commented Jan 29, 2022

Fixed by #2137

@emilio emilio closed this as completed Jan 29, 2022
@XieJiSS
Copy link

XieJiSS commented Feb 18, 2022

Hi @emilio , would it be possible for you to release a new minor version which contains PR #2137's code? Currently we have to manually import the patch from that PR. Thanks in advance!

@trissylegs trissylegs changed the title RISC-V has different triples for clang and risc-v. RISC-V has different triples for clang and rustc. Feb 26, 2022
@kupiakos
Copy link

kupiakos commented Aug 3, 2022

This is also a problem for riscv32imc-unknown-none-elf. Our workaround is to do .clang_arg("--target=riscv32-unknown-none-elf").

TheConner added a commit to TheConner/rust-bindgen that referenced this issue Jun 10, 2023
Similar problem as the one mentioned in rust-lang#2136, just continuing by adding
the 32 bit risc tuple mappings. Tuples like riscv32imc- should map to
the clang riscv32- tuple.

Fixed by adding mappings and tests for the mappings.
TheConner added a commit to TheConner/rust-bindgen that referenced this issue Jun 10, 2023
Similar problem as the one mentioned in rust-lang#2136, just continuing by adding
the 32 bit risc tuple mappings. Tuples like riscv32imc- and riscv32imac- should map to
the clang riscv32- tuple.

Fixed by adding mappings and tests for the mappings. Projects that now
failed to build the "riscv32imac-unknown-none-elf" target tuple now
build without issue.
TheConner added a commit to TheConner/rust-bindgen that referenced this issue Jun 10, 2023
Similar problem as the one mentioned in rust-lang#2136, just continuing by adding
the 32 bit risc tuple mappings. Tuples like riscv32imc- and riscv32imac- should map to
the clang riscv32- tuple.

Fixed by adding mappings and tests for the mappings. Projects that now
failed to build the "riscv32imac-unknown-none-elf" target tuple now
build without issue.
pvdrz pushed a commit that referenced this issue Jun 10, 2023
Similar problem as the one mentioned in #2136, just continuing by adding
the 32 bit risc tuple mappings. Tuples like riscv32imc- and riscv32imac- should map to
the clang riscv32- tuple.

Fixed by adding mappings and tests for the mappings. Projects that now
failed to build the "riscv32imac-unknown-none-elf" target tuple now
build without issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants