mozilla / mozilla/cbindgen

Failed to generate bindings when use `cargo-xwin`

Open
#1,124 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
3k
Forks
386
Avg merge
1h 43m
Merged PRs (30d)
1

Description

Im using cargo-xwin.

build.rs(error comes from .generate()):

use std::env;
use std::path::PathBuf;

fn main() {
    println!("cargo::rerun-if-changed=src");
    println!("cargo::rerun-if-changed=cbindgen.toml");
    // println!("cargo::rustc-flags=-C linker-flavor=gcc");

    let crate_dir: String = env::var("CARGO_MANIFEST_DIR").unwrap();
    let c_out_path: PathBuf = PathBuf::from(&crate_dir).join("include/plugin_api.h");
    let cxx_out_path: PathBuf = PathBuf::from(&crate_dir).join("include/plugin_api.hpp");

    cbindgen::Builder::new()
        .with_crate(&crate_dir)
        .with_config(cbindgen::Config::from_file("cbindgen.toml").unwrap())
        .with_language(cbindgen::Language::C)
        .with_include_guard("CG_PLUGIN_API_H")
        .generate()
        .expect("Unable to generate bindings")
        .write_to_file(c_out_path);

    cbindgen::Builder::new()
        .with_crate(&crate_dir)
        .with_config(cbindgen::Config::from_file("cbindgen.toml").unwrap())
        .with_language(cbindgen::Language::Cxx)
        .with_pragma_once(true)
        .generate()
        .expect("Unable to generate bindings")
        .write_to_file(cxx_out_path);
}

Build command:
cargo xwin build --target x86_64-pc-windows-msvc

I got that error:

error: failed to run custom build command for `plugin_runtime v0.1.0 (/crates/plugin_runtime)`

Caused by:
  process didn't exit successfully: `/target/release/build/plugin_runtime-2d8d4dbe88cdc80e/build-script-build` (exit status: 101)
  --- stdout
  cargo::rerun-if-changed=src
  cargo::rerun-if-changed=cbindgen.toml

  --- stderr

  thread 'main' (371664) panicked at crates/plugin_runtime/build.rs:19:10:
  Unable to generate bindings: CargoMetadata("/crates/plugin_runtime/Cargo.toml", Metadata(Output { status: ExitStatus(unix_wait_status(25856)), stdout: "", stderr: "error: failed to run `rustc` to learn about target-specific information\n\nCaused by:\n  process didn't exit successfully: `/home/corrm/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc - --crate-name ___ --print=file-names -C 'link-arg=/STACK:8000000' -C linker-flavor=lld-link -Lnative=/home/corrm/.cache/cargo-xwin/xwin/crt/lib/x86_64 -Lnative=/home/corrm/.cache/cargo-xwin/xwin/sdk/lib/um/x86_64 -Lnative=/home/corrm/.cache/cargo-xwin/xwin/sdk/lib/ucrt/x86_64 --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=split-debuginfo --print=crate-name --print=cfg -Wwarnings` (exit status: 1)\n  --- stdout\n  ___\n  lib___.rlib\n  lib___.so\n  lib___.so\n  lib___.a\n  lib___.so\n  /home/corrm/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\n  off\n  packed\n  unpacked\n  ___\n  debug_assertions\n  panic=\"unwind\"\n  proc_macro\n  target_abi=\"\"\n  target_arch=\"x86_64\"\n  target_endian=\"little\"\n  target_env=\"gnu\"\n  target_family=\"unix\"\n  target_feature=\"fxsr\"\n  target_feature=\"sse\"\n  target_feature=\"sse2\"\n  target_has_atomic=\"16\"\n  target_has_atomic=\"32\"\n  target_has_atomic=\"64\"\n  target_has_atomic=\"8\"\n  target_has_atomic=\"ptr\"\n  target_os=\"linux\"\n  target_pointer_width=\"64\"\n  target_vendor=\"unknown\"\n  unix\n\n  --- stderr\n  error: linker flavor `lld-link` is incompatible with the current target\n    |\n    = note: compatible flavors are: gnu, gnu-lld, gnu-cc, gnu-lld-cc, gcc, ld, ld.lld\n\n  error: aborting due to 1 previous error\n\n" }))
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

To make it ez to read:

error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `/home/corrm/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc - --crate-name ___ --print=file-names -C 'link-arg=/STACK:8000000' -C linker-flavor=lld-link -Lnative=/home/corrm/.cache/cargo-xwin/xwin/crt/lib/x86_64 -Lnative=/home/corrm/.cache/cargo-xwin/xwin/sdk/lib/um/x86_64 -Lnative=/home/corrm/.cache/cargo-xwin/xwin/sdk/lib/ucrt/x86_64 --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=split-debuginfo --print=crate-name --print=cfg -Wwarnings` (exit status: 1)
  --- stdout
  ___
  lib___.rlib
  lib___.so
  lib___.so
  lib___.a
  lib___.so
  /home/corrm/.rustup/toolchains/stable-x86_64-unknown-linux-gnu
  off
  packed
  unpacked
  ___
  debug_assertions
  panic=\"unwind\"
  proc_macro
  target_abi=\"\"
  target_arch=\"x86_64\"
  target_endian=\"little\"
  target_env=\"gnu\"
  target_family=\"unix\"
  target_feature=\"fxsr\"
  target_feature=\"sse\"
  target_feature=\"sse2\"
  target_has_atomic=\"16\"
  target_has_atomic=\"32\"
  target_has_atomic=\"64\"
  target_has_atomic=\"8\"
  target_has_atomic=\"ptr\"
  target_os=\"linux\"
  target_pointer_width=\"64\"
  target_vendor=\"unknown\"
  unix

  --- stderr
  error: linker flavor `lld-link` is incompatible with the current target
    |
    = note: compatible flavors are: gnu, gnu-lld, gnu-cc, gnu-lld-cc, gcc, ld, ld.lld

  error: aborting due to 1 previous error

i tired to change rustflags(.cargo/config.toml):

[target.x86_64-pc-windows-msvc]
rustflags = [
    "-C",
    "linker-flavor=gcc",
]

but that give the same error but with(-C linker-flavor=gcc -C linker-flavor=lld-link):

process didn't exit successfully: `/home/corrm/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc - --crate-name ___ --print=file-names -C linker-flavor=gcc -C linker-flavor=lld-link -Lnative=/home/corrm/.cache/cargo-xwin/xwin/crt/lib/x86_64 -Lnative=/home/corrm/.cache/cargo-xwin/xwin/sdk/lib/um/x86_64 -Lnative=/home/corrm/.cache/cargo-xwin/xwin/sdk/lib/ucrt/x86_64 --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=split-debuginfo --print=crate-name --print=cfg -Wwarnings`

If there any workaround I would really appreciate

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the build.rs generation steps and cbindgen.toml, then reproduce the failure with cargo xwin build --target x86_64-pc-windows-msvc. Trace the generated cargo metadata invocation and its Rust flags, including the conflicting linker-flavor values. Done means bindings generate successfully during this cross-target build without the incompatible-target error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.