Open dufferzafar opened 2 years ago
For me, this fails with libxcb errors, so not really a rust issue per se:
$ cargo build --release --target x86_64-unknown-linux-musl
...
Compiling x11-clipboard v0.3.3
Compiling clipboard v0.5.0
Compiling jless v0.8.0 (/spare/ssd/szafar/apps/_rust/jless)
error: linking with `cc` failed: exit status: 1
...
= note: /spare/local/szafar/.conda/envs/gcc93cxx17/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/9.3.0/../../../../x86_64-conda_cos6-linu
x-gnu/bin/ld: cannot find -lxcb
/spare/local/szafar/.conda/envs/gcc93cxx17/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/9.3.0/../../../../x86_64-conda_cos6-linu
x-gnu/bin/ld: cannot find -lxcb-render
/spare/local/szafar/.conda/envs/gcc93cxx17/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/9.3.0/../../../../x86_64-conda_cos6-linu
x-gnu/bin/ld: cannot find -lxcb-shape
/spare/local/szafar/.conda/envs/gcc93cxx17/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/9.3.0/../../../../x86_64-conda_cos6-linu
x-gnu/bin/ld: cannot find -lxcb-xfixes
collect2: error: ld returned 1 exit status
I already have this in my environment though:
$ mamba env export | grep xcb
- libxcb=1.12=h87c99fc_4
FWIW, I was able to build a static musl build for myself with:
cargo build --release --target x86_64-unknown-linux-musl
From your errors above, it sounds like you're missing some libxcb libraries
FWIW, I was able to build a static musl build for myself with:
@eminence would you mind pasting the output of ldd --verbose <executable>
for the executable you generated? I'd like to understand if this would work on my custom Linux distro 🙇
❯ ldd --verbose target/x86_64-unknown-linux-musl/release/jless
statically linked
Thanks @eminence! Did you do anything special to get it to compile? I'm getting the following error:
# cargo build --release --target x86_64-unknown-linux-musl
Compiling xcb v0.8.2
Compiling memoffset v0.6.4
Compiling proc-macro-error-attr v1.0.4
Compiling cc v1.0.69
error: failed to run custom build command for `xcb v0.8.2`
Caused by:
process didn't exit successfully: `/jless/target/release/build/xcb-69f318fcc254c3b5/build-script-build` (exit status: 101)
--- stderr
thread 'main' panicked at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/xcb-0.8.2/build.rs:73:22:
Unable to find build dependency python3: Os { code: 2, kind: NotFound, message: "No such file or directory" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
This is what I did in a ubuntu:latest
Docker machine:
apt install curl git gcc libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup target add x86_64-unknown-linux-musl
git clone https://github.com/PaulJuliusMartinez/jless.git && cd jless
cargo build --release --target x86_64-unknown-linux-musl
Duh, I should have started with an Alpine container. But I still get an error:
error: linking with `cc` failed: exit status: 1
|
...
= note: /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find crti.o: No such file or directory
collect2: error: ld returned 1 exit status
error: could not compile `proc-macro-error-attr` (lib) due to previous error
warning: build failed, waiting for other jobs to finish...
Unable to find build dependency python3
Did you try to install python3?
I was able to almost get it to work with the following flow:
apk add curl git build-base g++ libc-dev libxcb-dev
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
git clone https://github.com/PaulJuliusMartinez/jless.git && cd jless
RUSTFLAGS="-C target-feature=+crt-static" cargo build --release --target x86_64-unknown-linux-musl
but still get linking issues:
= note: /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lxcb: No such file or directory
/usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lxcb-render: No such file or directory
/usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lxcb-shape: No such file or directory
/usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lxcb-xfixes: No such file or directory
oh, you probably need to be building with the patch at #121
oh, you probably need to be building with the patch at #121
I tried that and it built successfully, but the resulting executable is still dynamically linked 🤯 :
$ file target/release/jless
target/release/jless: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, with debug_info, not stripped
are you sure you're looking at the right binary? Normally the binary would be in ./target/x86_64-unknown-linux-musl/release/
if you're building with cargo build --release --target x86_64-unknown-linux-musl
are you sure you're looking at the right binary? Normally the binary would be in
./target/x86_64-unknown-linux-musl/release/
if you're building withcargo build --release --target x86_64-unknown-linux-musl
Duh, I was so focused on fixing the build errors that I forgot that aspect. Thanks for pointing me to the right direction, it works now on the target system!
Here are the complete instructions for reference:
apk add curl git build-base g++ libc-dev libxcb-dev
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
git clone https://github.com/PaulJuliusMartinez/jless.git && cd jless
git remote add bew https://github.com/bew/jless
git fetch --all
git switch optional-clip-via-shell-cmd
git rebase origin/main
RUSTFLAGS="-C target-feature=+crt-static" cargo build --release --no-default-features --target x86_64-unknown-linux-musl
Running file
on the target:
$ file target/x86_64-unknown-linux-musl/release/jless
target/x86_64-unknown-linux-musl/release/jless: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), static-pie linked, with debug_info, not stripped
cc @PaulJuliusMartinez
Will fix issues like #74