Skip to content
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

easy musl support #300

Open
zhfish opened this issue Oct 29, 2023 · 1 comment
Open

easy musl support #300

zhfish opened this issue Oct 29, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@zhfish
Copy link
Contributor

zhfish commented Oct 29, 2023

Feature Proposed
add x86_64-unknown-linux-musl release

Use Case

apt install musl-tools
rustup target add x86_64-unknown-linux-musl
cargo build --target x86_64-unknown-linux-musl --release
@zhfish zhfish added the enhancement New feature or request label Oct 29, 2023
@zhfish zhfish mentioned this issue Oct 29, 2023
@hillct
Copy link

hillct commented Nov 12, 2023

I too, have been looking into this and I apologize if I'm rehashing known issues, but in my case I'm building for arm64 using Alpine linux (musl). I imagine he same issues arise in the build as indicated here:

  = note: /usr/lib/gcc/aarch64-alpine-linux-musl/12.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /usr/local/rustup/toolchains/1.73.0-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/libcompiler_builtins-d27000ea39d51bc8.rlib(45c91108d938afe8-cpu_model.o): in function `init_have_lse_atomics':
          /cargo/registry/src/index.crates.io-6f17d22bba15001f/compiler_builtins-0.1.98/./lib/builtins/cpu_model.c:1075: undefined reference to `getauxval'
          /usr/lib/gcc/aarch64-alpine-linux-musl/12.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /usr/local/rustup/toolchains/1.73.0-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/libcompiler_builtins-d27000ea39d51bc8.rlib(45c91108d938afe8-cpu_model.o): in function `init_cpu_features':
          /cargo/registry/src/index.crates.io-6f17d22bba15001f/compiler_builtins-0.1.98/./lib/builtins/cpu_model.c:1373: undefined reference to `getauxval'
          /usr/lib/gcc/aarch64-alpine-linux-musl/12.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /cargo/registry/src/index.crates.io-6f17d22bba15001f/compiler_builtins-0.1.98/./lib/builtins/cpu_model.c:1374: undefined reference to `getauxval'
          collect2: error: ld returned 1 exit status
          
  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

For ease of testing, my Dockerfile below w/ strategic comments for test environment):

ARG OS_VER=3.18
ARG BASE_IMAGE=rust:alpine${OS_VER}
FROM ${BASE_IMAGE} as builder
WORKDIR /home/rust/src
COPY . .
ARG FEATURES
RUN apk add build-base pkgconfig perl openssl-dev
RUN rustup target add aarch64-unknown-linux-musl
#    cargo build --target=aarch64-unknown-linux-musl --release --features ${FEATURES:-default} && \
#    mkdir -p build-out &&  cp target/release/rathole build-out/

#FROM alpine:${OS_VER} as runtime
#WORKDIR /app
#COPY --from=builder /home/rust/src/build-out/rathole .
#USER 1000:1000
#ENTRYPOINT ["./rathole"]
ENTRYPOINT ["/bin/sh"]

In my case, I'm on an Nvidia AGX Orin host but it should be reproducible in a container on a Raspberry Pi host.
In reading up on he issue of getauxval calls, I came across this discussion: rust-lang/rustup#3324 wherein the problem is narrowed down to the rust-openssl implementation, and for at lead one project lead moving to rusttls was the optimal solution.

I tested the various solutions discussed in that thread (build flags etc) to no avail, but my rust is a bit rusty so I didn't delve too deeply into migrating to rusttls, even though by most accounts, it's more performant (and scure) than OpenSSL/rust-openssl, with he added advantage of improving platform agnosticism.

UPDATE: Looks like @sunng87 beat me to this conclusion #152
UPDATE 2: As a last resort I looked at gain a releases, seeing the arm64 musl build zipped up there, so found this https://github.com/rapiz1/rathole/blob/main/.github/workflows/release.yml#L114C9-L114C107 but even with these featire flags the build fails with the same errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants