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

Loongarch cross-compilation issue #2765

Open
ionut-arm opened this issue Feb 21, 2024 · 0 comments
Open

Loongarch cross-compilation issue #2765

ionut-arm opened this issue Feb 21, 2024 · 0 comments

Comments

@ionut-arm
Copy link

Hi all,

While trying to update the bindings for a crate from using v0.66.1 to v0.69.4, I get a problem for loongarch64-unknown-linux-gnu.

Input C/C++ Header

The header is quite large, you can find it here.

Bindgen Invocation

This works as a cross-compilation for most architectures I need, but fails for loongarch64-unknown-linux-gnu. You can see the build script that regenerates the bindings here. To upgrade to a newer bindgen version we rely on this shell script to iterate over the architectures we target.

        let mut builder = bindgen::Builder::default();
        if make_generic {
            // only WIN32 bindings are "packed". It's easier to "unpack" for other architectures
            // __declspec is not needed and causes problems
            const GENERIC_PRELUDE: &str = "#define _WIN32 1\n#define __declspec(x)\n";
            builder = builder
                // layout tests are not generic
                .layout_tests(false)
                .header_contents("generic-prelude.h", GENERIC_PRELUDE)
        }

        builder = builder
            .header("pkcs11.h")
            .dynamic_library_name("Pkcs11")
            // The PKCS11 library works in a slightly different way to most shared libraries. We have
            // to call `C_GetFunctionList`, which returns a list of pointers to the _actual_ library
            // functions. This is the only function we need to create a binding for.
            .allowlist_function("C_GetFunctionList")
            // This is needed because no types will be generated if `allowlist_function` is used.
            // Unsure if this is a bug.
            .allowlist_type("*")
            .allowlist_file("pkcs11.h")
            // See this issue: https://github.com/parallaxsecond/rust-cryptoki/issues/12
            .blocklist_type("max_align_t")
            // Derive the `Debug` trait for the generated structs where possible.
            .derive_debug(true)
            // Derive the `Default` trait for the generated structs where possible.
            .derive_default(true)
            .parse_callbacks(Box::new(CargoCallbacks));

Actual Results

Caused by:
  process didn't exit successfully: `/data/ionmih01/rust-cryptoki/target/debug/build/cryptoki-sys-029c7783f44b6e05/build-script-build` (exit status: 101)
  --- stderr
  thread 'main' panicked at /home/ionmih01/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bindgen-0.69.4/ir/context.rs:556:15:
  libclang error; possible causes include:
  - Invalid flag syntax
  - Unrecognized flags
  - Invalid flag arguments
  - File I/O errors
  - Host vs. target architecture mismatch
  If you encounter an error missing from this list, please file an issue or a PR!
  stack backtrace:
     0: rust_begin_unwind
               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:645:5
     1: core::panicking::panic_fmt
               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:72:14
     2: core::panicking::panic_display
               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:178:5
     3: core::panicking::panic_str
               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:152:5
     4: core::option::expect_failed
               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/option.rs:1985:5
     5: core::option::Option<T>::expect
               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/option.rs:894:21
     6: bindgen::ir::context::BindgenContext::new
               at /home/ionmih01/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bindgen-0.69.4/ir/context.rs:550:13
     7: bindgen::Bindings::generate
               at /home/ionmih01/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bindgen-0.69.4/lib.rs:896:27
     8: bindgen::Builder::generate
               at /home/ionmih01/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bindgen-0.69.4/lib.rs:349:9
     9: build_script_build::generate::generate_bindings
               at ./build.rs:91:24
    10: build_script_build::main
               at ./build.rs:6:9
    11: core::ops::function::FnOnce::call_once
               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5

Expected Results

I'd be interested to know if this is a problem with our script, our header, or some issue with bindgen.

Please let me know if I've missed any important details.

Also, many thanks for your work, it's empowered so many of our crates 🙏🏻

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

1 participant