Skip to content

Cross compilation (of libc) on MacOS fails #66

Open
@raphaelcohn

Description

@raphaelcohn

I'm cross compiling for a linux musl target on MacOS, using the latest version of the homebrew musl-cross package.
This works fine for normal work I do.
However, when attempting to do a standard build, the libc rust crate fails with error: could not find native static library c, perhaps an -L flag is missing?. Rightly so, as it has been linked added as a dependency to rustc command line (long trace below).

This is because libc is odd; it doesn't emit use cargo:rustc-link-search in it's build script, build.rs. A patch to do this back in 2015 was rejected because it's 'fixed upstream' (rust-lang/libc#17) in rust itself (rust-lang/rust@52862e4). I have to say, I didn't follow this reasoning.

This is a place where one would like to inject a custom flag - I know where and how to search for the libc - but I can only do so by modifying RUSTFLAGS, which affects everything else being built. Of course, I could write a rustc wrapper script, do a bit of argument sense checking, and then call rustc, but that's... work. (As an aside, when doing controlled, reproducible builds, I do this a lot, unsetting PATH and then providing shim wrappers for tools until I build up a profile of what's needed to do a reproducible build, especially if build tools call date and the like).

This seems related to #14 and other issues.

   Compiling alloc v0.0.0 (/Users/raph/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc)
     Running `CARGO=/Users/raph/.rustup/toolchains/nightly-x86_64-apple-darwin/bin/cargo CARGO_CRATE_NAME=alloc CARGO_MANIFEST_DIR=/Users/raph/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc CARGO_PKG_AUTHORS='The Rust Project Developers' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=alloc CARGO_PKG_REPOSITORY='' CARGO_PKG_VERSION=0.0.0 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=0 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' DYLD_FALLBACK_LIBRARY_PATH='/Volumes/Source/lemonrock/linux-support/rust-custom-target.workspace/target/release/deps:/Users/raph/.rustup/toolchains/nightly-x86_64-apple-darwin/lib:/Users/raph/.rustup/toolchains/nightly-x86_64-apple-darwin/lib:/Users/raph/lib:/usr/local/lib:/usr/lib' RUSTC_BOOTSTRAP=1 rustc --crate-name alloc --edition=2018 /Users/raph/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C metadata=d600ad6f2ddde8a8 -C extra-filename=-d600ad6f2ddde8a8 --out-dir /Volumes/Source/lemonrock/linux-support/rust-custom-target.workspace/target/x86_64-unknown-linux-musl-tiger-lake/release/deps --target /Volumes/Source/lemonrock/linux-support/rust-custom-target.workspace/x86_64-unknown-linux-musl-tiger-lake.json -C linker=x86_64-linux-musl-cc -Z force-unstable-if-unmarked -L dependency=/Volumes/Source/lemonrock/linux-support/rust-custom-target.workspace/target/x86_64-unknown-linux-musl-tiger-lake/release/deps -L dependency=/Volumes/Source/lemonrock/linux-support/rust-custom-target.workspace/target/release/deps --extern compiler_builtins=/Volumes/Source/lemonrock/linux-support/rust-custom-target.workspace/target/x86_64-unknown-linux-musl-tiger-lake/release/deps/libcompiler_builtins-e59aa6ff3d802cf9.rmeta --extern core=/Volumes/Source/lemonrock/linux-support/rust-custom-target.workspace/target/x86_64-unknown-linux-musl-tiger-lake/release/deps/libcore-0e79ae0d5145d2a2.rmeta --cap-lints warn -Z verbose=yes -Z print-link-args=yes -L native=c`
error: could not compile `libc`

Caused by:
  process didn't exit successfully: `CARGO=/Users/raph/.rustup/toolchains/nightly-x86_64-apple-darwin/bin/cargo CARGO_CRATE_NAME=libc CARGO_MANIFEST_DIR=/Volumes/Source/lemonrock/linux-support/rust-custom-target.workspace/vendor/libc-0.2.79 CARGO_PKG_AUTHORS='The Rust Project Developers' CARGO_PKG_DESCRIPTION='Raw FFI bindings to platform libraries like libc.
  ' CARGO_PKG_HOMEPAGE='https://github.com/rust-lang/libc' CARGO_PKG_LICENSE='MIT OR Apache-2.0' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=libc CARGO_PKG_REPOSITORY='https://github.com/rust-lang/libc' CARGO_PKG_VERSION=0.2.79 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=2 CARGO_PKG_VERSION_PATCH=79 CARGO_PKG_VERSION_PRE='' DYLD_FALLBACK_LIBRARY_PATH='/Volumes/Source/lemonrock/linux-support/rust-custom-target.workspace/target/release/deps:/Users/raph/.rustup/toolchains/nightly-x86_64-apple-darwin/lib:/Users/raph/.rustup/toolchains/nightly-x86_64-apple-darwin/lib:/Users/raph/lib:/usr/local/lib:/usr/lib' OUT_DIR=/Volumes/Source/lemonrock/linux-support/rust-custom-target.workspace/target/x86_64-unknown-linux-musl-tiger-lake/release/build/libc-19f238fd5225b055/out RUSTC_BOOTSTRAP=1 rustc --crate-name libc /Volumes/Source/lemonrock/linux-support/rust-custom-target.workspace/vendor/libc-0.2.79/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no --cfg 'feature="align"' --cfg 'feature="rustc-dep-of-std"' --cfg 'feature="rustc-std-workspace-core"' -C metadata=a26b5536f1af61b7 -C extra-filename=-a26b5536f1af61b7 --out-dir /Volumes/Source/lemonrock/linux-support/rust-custom-target.workspace/target/x86_64-unknown-linux-musl-tiger-lake/release/deps --target /Volumes/Source/lemonrock/linux-support/rust-custom-target.workspace/x86_64-unknown-linux-musl-tiger-lake.json -C linker=x86_64-linux-musl-cc -Z force-unstable-if-unmarked -L dependency=/Volumes/Source/lemonrock/linux-support/rust-custom-target.workspace/target/x86_64-unknown-linux-musl-tiger-lake/release/deps -L dependency=/Volumes/Source/lemonrock/linux-support/rust-custom-target.workspace/target/release/deps --extern rustc_std_workspace_core=/Volumes/Source/lemonrock/linux-support/rust-custom-target.workspace/target/x86_64-unknown-linux-musl-tiger-lake/release/deps/librustc_std_workspace_core-a9fcb53369c5d212.rmeta --cap-lints warn -Z verbose=yes -Z print-link-args=yes -L native=c --cfg freebsd11 --cfg libc_priv_mod_use --cfg libc_union --cfg libc_const_size_of --cfg libc_align --cfg libc_core_cvoid --cfg libc_packedN --cfg libc_cfg_target_vendor --cfg libc_thread_local` (exit code: 1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    S-needs-investigationStatus: needs investigationupstreamAn issue with the standard library itself or its dependencies.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions