Skip to content

Compilation fails when cross-compiling for Linux #12394

@xtqqczze

Description

@xtqqczze

Summary

Running cargo check --target x86_64-unknown-linux-gnu in the project directory results in a build failure.

This also breaks development workflows using rust-analyzer when targeting Linux from a non-Linux host with:

"rust-analyzer.cargo.target": "x86_64-unknown-linux-gnu"

because rust-analyzer triggers the same Cargo check internally.

Steps to Reproduce

From a non-Linux host system, run:

cargo check --workspace --all-targets --all-features --target x86_64-unknown-linux-gnu --quiet --keep-going

Error Output

Click to expand the error output
error: failed to run custom build command for `selinux-sys v0.7.0`

Caused by:
  process didn't exit successfully: `~/coreutils/target/debug/build/selinux-sys-2d2240d79fb5bd09/build-script-build` (exit status: 101)
  --- stdout
  cargo:root=~/coreutils/target/x86_64-unknown-linux-gnu/debug/build/selinux-sys-7293234591ad2f74/out
  cargo:rerun-if-env-changed=SYSROOT_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=SYSROOT_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_SYSROOT
  cargo:rerun-if-env-changed=SYSROOT
  cargo:rerun-if-env-changed=SELINUX_STATIC_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=SELINUX_STATIC_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_SELINUX_STATIC
  cargo:rerun-if-env-changed=SELINUX_STATIC
  cargo:rerun-if-env-changed=SELINUX_PATH_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=SELINUX_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_SELINUX_PATH
  cargo:rerun-if-env-changed=SELINUX_PATH
  cargo:rerun-if-env-changed=SELINUX_INCLUDE_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=SELINUX_INCLUDE_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_SELINUX_INCLUDE_DIR
  cargo:rerun-if-env-changed=SELINUX_INCLUDE_DIR
  cargo:rerun-if-env-changed=SELINUX_LIB_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=SELINUX_LIB_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_SELINUX_LIB_DIR
  cargo:rerun-if-env-changed=SELINUX_LIB_DIR
  cargo:rerun-if-env-changed=CC_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=CC_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_CC
  cargo:rerun-if-env-changed=CC
  cargo:rerun-if-env-changed=CFLAGS_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=CFLAGS_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  cargo:rerun-if-env-changed=CFLAGS
  cargo:rerun-if-env-changed=CC_x86_64-unknown-linux-gnu
  CC_x86_64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CC_x86_64_unknown_linux_gnu
  CC_x86_64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=TARGET_CC
  TARGET_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  cargo:rerun-if-env-changed=CROSS_COMPILE
  CROSS_COMPILE = None
  PATH = ✂
  cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
  cargo:warning=Compiler family detection failed due to error: ToolNotFound: failed to find tool "x86_64-linux-gnu-gcc": No such file or directory (os error 2)
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  TARGET_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64_unknown_linux_gnu
  CFLAGS_x86_64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64-unknown-linux-gnu
  CFLAGS_x86_64-unknown-linux-gnu = None

  --- stderr

  thread 'main' (11825782) panicked at ~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/selinux-sys-0.7.0/build.rs:88:14:
  selinux-sys: Failed to discover default compiler search paths: Os { code: 2, kind: NotFound, message: "No such file or directory" }
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: failed to run custom build command for `onig_sys v69.9.3`

Caused by:
  process didn't exit successfully: `~/coreutils/target/debug/build/onig_sys-98ad9bab2e59d099/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=RUSTONIG_DYNAMIC_LIBONIG
  cargo:rerun-if-env-changed=RUSTONIG_STATIC_LIBONIG
  cargo:rerun-if-env-changed=RUSTONIG_SYSTEM_LIBONIG
  cargo:rerun-if-env-changed=CC_FORCE_DISABLE
  CC_FORCE_DISABLE = None
  cargo:rerun-if-env-changed=CC_x86_64-unknown-linux-gnu
  CC_x86_64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CC_x86_64_unknown_linux_gnu
  CC_x86_64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=TARGET_CC
  TARGET_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  cargo:rerun-if-env-changed=CROSS_COMPILE
  CROSS_COMPILE = None
  PATH = ✂
  cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
  cargo:warning=Compiler family detection failed due to error: ToolNotFound: failed to find tool "x86_64-linux-gnu-gcc": No such file or directory (os error 2)
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  TARGET_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64_unknown_linux_gnu
  CFLAGS_x86_64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64-unknown-linux-gnu
  CFLAGS_x86_64-unknown-linux-gnu = None

  --- stderr


  error occurred in cc-rs: failed to find tool "x86_64-linux-gnu-gcc": No such file or directory (os error 2)


error: failed to run custom build command for `fts-sys v0.2.17`

Caused by:
  process didn't exit successfully: `~/coreutils/target/debug/build/fts-sys-f7b95a1620196544/build-script-build` (exit status: 101)
  --- stdout
  cargo:root=~/coreutils/target/x86_64-unknown-linux-gnu/debug/build/fts-sys-d2253a514f78033a/out
  cargo:rerun-if-env-changed=SYSROOT_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=SYSROOT_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_SYSROOT
  cargo:rerun-if-env-changed=SYSROOT
  cargo:rerun-if-env-changed=TARGET
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS
  cargo:rerun-if-changed=src/fts-sys.h

  --- stderr
  src/fts-sys.h:1:10: fatal error: 'sys/types.h' file not found

  thread 'main' (11825803) panicked at ~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/fts-sys-0.2.17/build.rs:123:10:
  fts-sys: Failed to generate Rust bindings for 'fts.h'.: ClangDiagnostic("src/fts-sys.h:1:10: fatal error: 'sys/types.h' file not found\n")
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: failed to run custom build command for `uu_stdbuf v0.8.0 (~/coreutils/src/uu/stdbuf)`

Caused by:
  process didn't exit successfully: `~/coreutils/target/debug/build/uu_stdbuf-1bc3a7bc68365c7b/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-changed=build.rs
  cargo:rerun-if-changed=src/libstdbuf/src/libstdbuf.rs

  --- stderr
     Compiling libc v0.2.186
     Compiling link-section v0.17.0
     Compiling uu_stdbuf_libstdbuf v0.8.0 (~/coreutils/src/uu/stdbuf/src/libstdbuf)
     Compiling linktime-proc-macro v0.1.0
     Compiling ctor v1.0.6
  error: linking with `cc` failed: exit status: 1
    |
    = note:  "cc" "-Wl,--version-script=~/coreutils/target/x86_64-unknown-linux-gnu/debug/build/uu_stdbuf-3f75799b4b3fd574/out/libstdbuf-build/x86_64-unknown-linux-gnu/debug/deps/rustcCSkyHN/list" "-Wl,--no-undefined-version" "-m64" "~/coreutils/target/x86_64-unknown-linux-gnu/debug/build/uu_stdbuf-3f75799b4b3fd574/out/libstdbuf-build/x86_64-unknown-linux-gnu/debug/deps/rustcCSkyHN/symbols.o" "<23 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "~/coreutils/target/x86_64-unknown-linux-gnu/debug/build/uu_stdbuf-3f75799b4b3fd574/out/libstdbuf-build/x86_64-unknown-linux-gnu/debug/deps/{liblibc-99e6bf1a526d047e,libctor-abde2ab26ba4adbf}.rlib" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,libcfg_if-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,liblibc-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "~/coreutils/target/x86_64-unknown-linux-gnu/debug/build/uu_stdbuf-3f75799b4b3fd574/out/libstdbuf-build/x86_64-unknown-linux-gnu/debug/deps/rustcCSkyHN/raw-dylibs" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "~/coreutils/target/x86_64-unknown-linux-gnu/debug/build/uu_stdbuf-3f75799b4b3fd574/out/libstdbuf-build/x86_64-unknown-linux-gnu/debug/deps/libstdbuf.so" "-Wl,--gc-sections" "-shared" "-Wl,-z,relro,-z,now" "-nodefaultlibs" "-fPIC" "-z" "defs"
    = note: some arguments are omitted. use `--verbose` to show all linker arguments
    = note: ld: unknown options: --version-script=~/coreutils/target/x86_64-unknown-linux-gnu/debug/build/uu_stdbuf-3f75799b4b3fd574/out/libstdbuf-build/x86_64-unknown-linux-gnu/debug/deps/rustcCSkyHN/list --no-undefined-version --as-needed -Bstatic -Bdynamic --eh-frame-hdr -z --gc-sections -z -z -z 
            clang: error: linker command failed with exit code 1 (use -v to see invocation)
            

  error: could not compile `uu_stdbuf_libstdbuf` (lib) due to 1 previous error

  thread 'main' (11826540) panicked at src/uu/stdbuf/build.rs:101:5:
  Failed to build libstdbuf
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions