|
| 1 | +FROM quay.io/pypa/manylinux2014_x86_64:latest |
| 2 | + |
| 3 | +# The Rust toolchain to use when building our image |
| 4 | +ARG TOOLCHAIN=stable |
| 5 | +ARG TARGET=x86_64-unknown-linux-musl |
| 6 | +ARG OPENSSL_ARCH=linux-x86_64 |
| 7 | + |
| 8 | +ENV RUST_MUSL_CROSS_TARGET=$TARGET |
| 9 | + |
| 10 | +# Make sure we have basic dev tools for building C libraries. Our goal |
| 11 | +# here is to support the musl-libc builds and Cargo builds needed for a |
| 12 | +# large selection of the most popular crates. |
| 13 | +# |
| 14 | +RUN yum install -y sudo |
| 15 | + |
| 16 | +# Install cross-signed Let's Encrypt R3 CA certificate |
| 17 | +ADD lets-encrypt-r3-cross-signed.crt /etc/pki/ca-trust/source/anchors/ |
| 18 | +RUN update-ca-trust |
| 19 | + |
| 20 | +ADD config.mak /tmp/config.mak |
| 21 | +RUN cd /tmp && \ |
| 22 | + curl -Lsq -o musl-cross-make.zip https://github.com/richfelker/musl-cross-make/archive/v0.9.8.zip && \ |
| 23 | + unzip -q musl-cross-make.zip && \ |
| 24 | + rm musl-cross-make.zip && \ |
| 25 | + mv musl-cross-make-0.9.8 musl-cross-make && \ |
| 26 | + cp /tmp/config.mak /tmp/musl-cross-make/config.mak && \ |
| 27 | + cd /tmp/musl-cross-make && \ |
| 28 | + TARGET=$TARGET make -j 4 install > /tmp/musl-cross-make.log && \ |
| 29 | + ln -s /usr/local/musl/bin/$TARGET-strip /usr/local/musl/bin/musl-strip && \ |
| 30 | + cd /tmp && \ |
| 31 | + rm -rf /tmp/musl-cross-make /tmp/musl-cross-make.log |
| 32 | + |
| 33 | +RUN mkdir -p /home/rust/libs /home/rust/src |
| 34 | + |
| 35 | +# Set up our path with all our binary directories, including those for the |
| 36 | +# musl-gcc toolchain and for our Rust toolchain. |
| 37 | +ENV PATH=/root/.cargo/bin:/usr/local/musl/bin:/opt/rh/devtoolset-9/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin |
| 38 | +ENV TARGET_CC=$TARGET-gcc |
| 39 | +ENV TARGET_CXX=$TARGET-g++ |
| 40 | +ENV TARGET_C_INCLUDE_PATH=/usr/local/musl/$TARGET/include/ |
| 41 | + |
| 42 | +# Install our Rust toolchain and the `musl` target. We patch the |
| 43 | +# command-line we pass to the installer so that it won't attempt to |
| 44 | +# interact with the user or fool around with TTYs. We also set the default |
| 45 | +# `--target` to musl so that our users don't need to keep overriding it |
| 46 | +# manually. |
| 47 | +# Chmod 755 is set for root directory to allow access execute binaries in /root/.cargo/bin (azure piplines create own user). |
| 48 | +RUN chmod 755 /root/ && \ |
| 49 | + curl https://sh.rustup.rs -sqSf | \ |
| 50 | + sh -s -- -y --default-toolchain $TOOLCHAIN && \ |
| 51 | + rustup target add $TARGET && \ |
| 52 | + rm -rf /root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/share/ |
| 53 | +RUN printf "[build]\ntarget = \"$TARGET\"\n\n[target.$TARGET]\nlinker = \"$TARGET-gcc\"\n" > /root/.cargo/config && \ |
| 54 | + cat /root/.cargo/config |
| 55 | + |
| 56 | +# We'll build our libraries in subdirectories of /home/rust/libs. Please |
| 57 | +# clean up when you're done. |
| 58 | +WORKDIR /home/rust/libs |
| 59 | + |
| 60 | +# Build a static library version of OpenSSL using musl-libc. This is |
| 61 | +# needed by the popular Rust `hyper` crate. |
| 62 | +RUN export CC=$TARGET_CC && \ |
| 63 | + export C_INCLUDE_PATH=$TARGET_C_INCLUDE_PATH && \ |
| 64 | + echo "Building zlib" && \ |
| 65 | + VERS=1.2.11 && \ |
| 66 | + CHECKSUM=c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1 && \ |
| 67 | + cd /home/rust/libs && \ |
| 68 | + curl -sqLO https://zlib.net/zlib-$VERS.tar.gz && \ |
| 69 | + echo "$CHECKSUM zlib-$VERS.tar.gz" > checksums.txt && \ |
| 70 | + sha256sum -c checksums.txt && \ |
| 71 | + tar xzf zlib-$VERS.tar.gz && cd zlib-$VERS && \ |
| 72 | + ./configure --static --archs="-fPIC" --prefix=/usr/local/musl/$TARGET && \ |
| 73 | + make && make install && \ |
| 74 | + cd .. && rm -rf zlib-$VERS.tar.gz zlib-$VERS checksums.txt && \ |
| 75 | + echo "Building OpenSSL" && \ |
| 76 | + VERS=1.0.2q && \ |
| 77 | + CHECKSUM=5744cfcbcec2b1b48629f7354203bc1e5e9b5466998bbccc5b5fcde3b18eb684 && \ |
| 78 | + curl -sqO https://www.openssl.org/source/openssl-$VERS.tar.gz && \ |
| 79 | + echo "$CHECKSUM openssl-$VERS.tar.gz" > checksums.txt && \ |
| 80 | + sha256sum -c checksums.txt && \ |
| 81 | + tar xzf openssl-$VERS.tar.gz && cd openssl-$VERS && \ |
| 82 | + ./Configure $OPENSSL_ARCH -fPIC --prefix=/usr/local/musl/$TARGET && \ |
| 83 | + make depend && \ |
| 84 | + make && make install && \ |
| 85 | + cd .. && rm -rf openssl-$VERS.tar.gz openssl-$VERS checksums.txt |
| 86 | + |
| 87 | +ENV OPENSSL_DIR=/usr/local/musl/$TARGET/ \ |
| 88 | + OPENSSL_INCLUDE_DIR=/usr/local/musl/$TARGET/include/ \ |
| 89 | + DEP_OPENSSL_INCLUDE=/usr/local/musl/$TARGET/include/ \ |
| 90 | + OPENSSL_LIB_DIR=/usr/local/musl/$TARGET/lib/ \ |
| 91 | + OPENSSL_STATIC=1 |
| 92 | + |
| 93 | +# Expect our source code to live in /home/rust/src |
| 94 | +WORKDIR /home/rust/src |
0 commit comments