-
Notifications
You must be signed in to change notification settings - Fork 93
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
x86_64-unknown-linux-musl: error: could not find native static library c
, perhaps an -L flag is missing?
#133
Comments
c
, perhaps an -L flag is missing?c
, perhaps an -L flag is missing?
By the way even with |
The Rust compiler assumes that the musl libc.a will be contained in the sysroot for this particular target. That library won't be in Xargo sysroot because Xargo doesn't build libc.a when it builds sysroot. It doesn't do that because the standard crates don't contain instructions for that in their build scripts. To fix this you'll have to compile musl libc.a yourself and then pass a -L to the linker (xargo rustc -- -C link-arg=..)
Formatting stuff heavily bloats Rust programs. Even an empty program |
It was 111K because, although being built by xargo, usual non-customized libstd was linked in. A copy of usual libstd_....rlib was delivered to After manual compilation of libstd and manually linking it it got to about 51K. |
That ... sounds like a bug?
You can profile the binary size if you run
btw, this only builds the top crate with opt-level=z. You should set opt-level in Cargo.toml (profile.release) if you want to compile the whole dependency graph with opt-level=z. I think there's nothing actionable left to be done for this issue? |
It fails to recognize
There was a lot of things about backtracing. I also used Codesize which shows it as a tree in GUI, which emphasized that backtracing-related things are about 30k.
Maybe I'll reproduce it again and file a dedicated report. |
IIRC, |
Yes. The problem was that all those feature settings in Xargo.toml for Anyway it is offtopic to this issue, because of topic of the issue is that xargo fails when I specify target Musl. |
All, I've been experimenting with building std from source, using both Xargo and the new Cargo Install a known-good nightly toolchain, with Rust library source, and support for the rustup install nightly-2020-08-20
rustup default nightly-2020-08-20
rustup component add rust-src
rustup target add x86_64-unknown-linux-musl
cargo install xargo Create a temporary directory for testing, and a new project mkdir -p ~/tmp/xargo
cd ~/tmp/xargo
cargo new hello-xargo
cd hello-xargo
cat <<EOF > Xargo.toml
[dependencies]
std = {default-features=false, features=["panic_immediate_abort"]}
EOF
cat <<EOF >> Cargo.toml
[profile.dev]
panic = "abort"
[profile.release]
lto = true
codegen-units = 1
opt-level = "z"
panic = "abort"
EOF Attempt build: xargo build --target x86_64-unknown-linux-musl --release Failed:
Install Ubuntu package sudo apt install -y musl-tools Retry build: xargo build --target x86_64-unknown-linux-musl --release Failed:
This file is part of the Clone source repositories: cd ~/tmp/xargo
git clone https://github.com/rust-lang/rust
git clone https://github.com/rust-lang/llvm-project Determine the rustc -vV | grep commit-hash Output:
Determine the cd rust
git ls-tree 32c654a9795b0d88541e56ba9da4150e34f1d5f9 src/llvm-project Output:
Create source tarball for this version of cd ../llvm-project
git archive 86b120e6f302d39cd6973b6391fb299d7bc22122 \
--prefix llvm-project/ \
--output ../llvm-project-src.tar.gz Install cd ~/.rustup/toolchains/nightly-2020-08-20-x86_64-unknown-linux-gnu
mkdir lib/rustlib/src/rust/src
tar -C lib/rustlib/src/rust/src -xf ~/tmp/xargo/llvm-project-src.tar.gz Retry build: cd ~/tmp/xargo/hello-xargo
xargo build --target x86_64-unknown-linux-musl --release Output:
Though installed, Musl's Determine the dpkg -L 'musl-dev' | grep 'libc\.a' Output:
Setup an cat <<EOF >> ~/.cargo/config
[build]
# Work-around for https://github.com/japaric/xargo/issues/292:
rustflags = ["-Cembed-bitcode=yes"]
[target.x86_64-unknown-linux-musl]
# Path to Musl libc.a (plus bitcode work-around)
rustflags = ["-L/usr/lib/x86_64-linux-musl", "-Cembed-bitcode=yes"]
EOF Retry build: xargo build --target x86_64-unknown-linux-musl --release Success; it's a statically linked executable: file ./target/x86_64-unknown-linux-musl/release/hello-xargo Output:
It runs: ./target/x86_64-unknown-linux-musl/release/hello-xargo Output::
Size: size ./target/x86_64-unknown-linux-musl/release/hello-xargo
Stripped file size: strip ./target/x86_64-unknown-linux-musl/release/hello-xargo
ls -lh ./target/x86_64-unknown-linux-musl/release/hello-xargo
For comparison, here is a build using Cargo's build-std feature (https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#build-std): cargo clean
cargo build \
--target x86_64-unknown-linux-musl \
--release \
-Z build-std \
-Z build-std-features=panic_immediate_abort Failed with many errors like this:
This is fixed by restricting the crates to be built to cargo clean
cargo build \
--target x86_64-unknown-linux-musl \
--release \
-Z build-std=std,panic_abort \
-Z build-std-features=panic_immediate_abort Success: size ./target/x86_64-unknown-linux-musl/release/hello-xargo
Hopefully these terse notes are helpful for using the |
How do I use Xargo for x86_64-unknown-linux-musl?
My attempt:
Building without
--target=x86_64-unknown-linux-musl
works.The text was updated successfully, but these errors were encountered: