Created
September 8, 2022 11:29
-
-
Save csmoe/1845ce76b6ddc11346e323f64d8c74c5 to your computer and use it in GitHub Desktop.
Cross compile Rust project for Windows/macOS/Android/Linux(arm64,mips64el) on Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM rust:latest | |
ENV LLVM_VERSION 14.0.0 | |
ENV NODE_ARCH x64 | |
ENV MSVC_ROOT /msvc | |
ENV ANDROID_NDK /android-ndk-r25b | |
ENV PATH="/llvm/bin:/osxcross/target/bin:$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin" | |
RUN apt-get update \ | |
&& apt-get install -y \ | |
git \ | |
unzip \ | |
tar \ | |
curl \ | |
wget \ | |
cmake \ | |
ssh-client \ | |
libssl-dev \ | |
file \ | |
zlib1g-dev \ | |
libmpc-dev \ | |
libmpfr-dev \ | |
libgmp-dev \ | |
lib32stdc++6 \ | |
libstdc++6 \ | |
gcc-mips64el-linux-gnuabi64 \ | |
libc6-dev-mips64el-cross \ | |
gcc-aarch64-linux-gnu \ | |
libc6-dev-arm64-cross \ | |
&& apt-get clean | |
RUN wget -q https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VERSION/clang+llvm-$LLVM_VERSION-x86_64-linux-ubuntu-18.04.5.tar.xz \ | |
-O llvm.tar.xz \ | |
&& rm -rf /llvm && mkdir -p /llvm \ | |
&& tar xf lvm.tar.xz --strip-components 1 -C /llvm \ | |
&& command -v clang | |
# cross compile for macOS | |
RUN git clone https://github.com/tpoechtrager/osxcross --depth 1 \ | |
&& cd osxcross \ | |
&& wget -q https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz -O tarballs/MacOSX11.3.sdk.tar.xz \ | |
&& UNATTENDED=yes OSX_VERSION_MIN=10.13 ./build.sh \ | |
&& mkdir -p /usr/local/bin \ | |
&& ln -s target/bin/x86_64-apple-darwin21.4-clang /usr/local/bin/x86_64-apple-darwin-clang \ | |
&& ln -s target/bin/x86_64-apple-darwin21.4-ar /usr/local/bin/x86_64-apple-darwin-ar | |
# cross compile for Windows | |
RUN wget -q https://github.com/Jake-Shadle/xwin/releases/download/0.2.8/xwin-0.2.8-x86_64-unknown-linux-musl.tar.gz -O /xwin.tar.gz | |
\ | |
&& tar xf /xwin.tar.gz --strip-components 1 -C /usr/local/bin/ | |
&& chmod a+x /usr/local/bin/xwin \ | |
&& command -v xwin | |
# msvc sdk will be installed into $MSVC_ROOT | |
RUN xwin --accept-license \ | |
--arch x86_64 \ | |
--cache-dir $MSVC_ROOT \ | |
--channel release \ | |
--log-level warn \ | |
splat | |
RUN xwin --accept-license \ | |
--arch x86 \ | |
--cache-dir $MSVC_ROOT \ | |
--channel release \ | |
--log-level warn \ | |
splat | |
# android ndk | |
RUN wget -q https://dl.google.com/android/repository/android-ndk-r25b-linux.zip -O ndk.zip && unzip ndk.zip && rm -rf ndk.zip | |
RUN rm -rf *.tar.{gz,xz,zip} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment