rapiz1 / rathole

A lightweight and high-performance reverse proxy for NAT traversal, written in Rust. An alternative to frp and ngrok.
Apache License 2.0
9.44k stars 475 forks source link

easy musl support #300

Open zhfish opened 11 months ago

zhfish commented 11 months ago

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
hillct commented 10 months ago

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: https://github.com/rust-lang/rustup/issues/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 https://github.com/rapiz1/rathole/pull/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.