[O] Build rust using musl static
This commit is contained in:
parent
afd9ad33d4
commit
ca74acbafb
2 changed files with 40 additions and 19 deletions
|
|
@ -1,21 +1,27 @@
|
||||||
FROM debian:10-slim
|
FROM debian
|
||||||
|
|
||||||
# Install Rust building environment
|
# Install Rust building environment
|
||||||
RUN apt update && apt install -y curl build-essential gcc libssl-dev bash musl-tools mingw-w64
|
RUN apt update && apt install -y curl build-essential gcc libssl-dev bash musl-tools mingw-w64 \
|
||||||
|
gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu gcc-riscv64-linux-gnu
|
||||||
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
||||||
|
|
||||||
# Add toolchains for building for gnu[x86_64, aarch64, armv7l], musl[x86_64], and windows[x86_64, aarch64]
|
# Add toolchains for building for musl[x86_64, aarch64, armv7l, riscv64], windows[x86_64]
|
||||||
RUN /root/.cargo/bin/rustup target add \
|
RUN /root/.cargo/bin/rustup target add \
|
||||||
x86_64-unknown-linux-gnu \
|
x86_64-unknown-linux-musl aarch64-unknown-linux-musl armv7-unknown-linux-musleabihf riscv64gc-unknown-linux-musl \
|
||||||
aarch64-unknown-linux-gnu \
|
|
||||||
armv7-unknown-linux-gnueabihf \
|
|
||||||
x86_64-unknown-linux-musl \
|
|
||||||
x86_64-pc-windows-gnu
|
x86_64-pc-windows-gnu
|
||||||
|
|
||||||
# Install armv7l & aarch64 toolchains
|
# Compile musl for multiple architectures
|
||||||
RUN apt install -y gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu
|
RUN curl "https://musl.libc.org/releases/musl-1.2.5.tar.gz" --output musl.tgz && \
|
||||||
|
tar -xvf musl.tgz && \
|
||||||
# Add cargo to path
|
cd musl-*/ && \
|
||||||
ENV PATH="/root/.cargo/bin:${PATH}"
|
./configure --prefix=/musl/aarch64 --exec-prefix=/musl/aarch64 --target=aarch64-linux-gnu --enable-wrapper=all && \
|
||||||
|
make -j18 install && \
|
||||||
WORKDIR /app
|
make clean && \
|
||||||
|
./configure --prefix=/musl/armv7l --exec-prefix=/musl/armv7l --target=arm-linux-gnueabihf --enable-wrapper=all && \
|
||||||
|
make -j18 install && \
|
||||||
|
make clean && \
|
||||||
|
./configure --prefix=/musl/riscv64 --exec-prefix=/musl/riscv64 --target=riscv64-linux-gnu --enable-wrapper=all && \
|
||||||
|
make -j18 install && \
|
||||||
|
make clean && \
|
||||||
|
cd .. && \
|
||||||
|
rm -rf musl-*
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,28 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
# Add cargo to path
|
||||||
|
export PATH="$HOME/.cargo/bin:$PATH"
|
||||||
|
cd /app
|
||||||
|
|
||||||
# Set linkers for cross-compilation
|
# Set linkers for cross-compilation
|
||||||
export CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=/usr/bin/arm-linux-gnueabihf-gcc
|
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=musl-gcc
|
||||||
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=/usr/bin/aarch64-linux-gnu-gcc
|
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=/musl/aarch64/bin/musl-gcc
|
||||||
|
export CARGO_TARGET_ARMV7_UNKNOWN_LINUX_MUSLEABIHF_LINKER=/musl/armv7l/bin/musl-gcc
|
||||||
|
export CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_MUSL_LINKER=/musl/riscv64/bin/musl-gcc
|
||||||
|
|
||||||
|
# OSX linker and ar
|
||||||
|
#export OSX_VER=20.4
|
||||||
|
#export CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER=/osxcross/bin/x86_64-apple-darwin$OSX_VER-clang
|
||||||
|
#export CARGO_TARGET_X86_64_APPLE_DARWIN_AR=/osxcross/bin/x86_64-apple-darwin$OSX_VER-ar
|
||||||
|
#export CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER=/osxcross/bin/aarch64-apple-darwin$OSX_VER-clang
|
||||||
|
#export CARGO_TARGET_AARCH64_APPLE_DARWIN_AR=/osxcross/bin/aarch64-apple-darwin$OSX_VER-ar
|
||||||
|
|
||||||
# Build for platforms
|
# Build for platforms
|
||||||
cargo build --release --target x86_64-unknown-linux-gnu
|
|
||||||
cargo build --release --target aarch64-unknown-linux-gnu
|
|
||||||
cargo build --release --target armv7-unknown-linux-gnueabihf
|
|
||||||
cargo build --release --target x86_64-unknown-linux-musl
|
cargo build --release --target x86_64-unknown-linux-musl
|
||||||
|
cargo build --release --target aarch64-unknown-linux-musl
|
||||||
|
cargo build --release --target armv7-unknown-linux-musleabihf
|
||||||
|
#cargo build --release --target riscv64gc-unknown-linux-musl
|
||||||
cargo build --release --target x86_64-pc-windows-gnu
|
cargo build --release --target x86_64-pc-windows-gnu
|
||||||
|
#cargo build --release --target x86_64-apple-darwin
|
||||||
|
#cargo build --release --target aarch64-apple-darwin
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue