fix: pass RUSTC_WRAPPER to the cross container and enforce static builds

This commit is contained in:
Maxim De Clercq 2022-01-23 17:31:12 +01:00
parent fd67cd7450
commit 219dfbabd5
No known key found for this signature in database
GPG key ID: D35643779C52BA70
3 changed files with 11 additions and 19 deletions

View file

@ -35,8 +35,6 @@ variables:
before_script: before_script:
- 'echo "Building for target $TARGET"' - 'echo "Building for target $TARGET"'
- "rustup show && rustc --version && cargo --version" # Print version info for debugging - "rustup show && rustc --version && cargo --version" # Print version info for debugging
# If provided, bring in caching through sccache, which uses an external S3 endpoint to store compilation results:
- if [ -n "${SCCACHE_BIN_URL}" ]; then curl $SCCACHE_BIN_URL --output /sccache && chmod +x /sccache && export RUSTC_WRAPPER=/sccache; fi
# install cross-compiling prerequisites # install cross-compiling prerequisites
- 'apt-get update && apt-get install -y docker.io && docker version' # install docker - 'apt-get update && apt-get install -y docker.io && docker version' # install docker
- 'cargo install cross && cross --version' # install cross - 'cargo install cross && cross --version' # install cross
@ -45,10 +43,14 @@ variables:
- 'cp -r $CARGO_HOME/bin $SHARED_PATH/cargo' - 'cp -r $CARGO_HOME/bin $SHARED_PATH/cargo'
- 'cp -r $RUSTUP_HOME $SHARED_PATH' - 'cp -r $RUSTUP_HOME $SHARED_PATH'
- 'export CARGO_HOME=$SHARED_PATH/cargo RUSTUP_HOME=$SHARED_PATH/rustup' - 'export CARGO_HOME=$SHARED_PATH/cargo RUSTUP_HOME=$SHARED_PATH/rustup'
# If provided, bring in caching through sccache, which uses an external S3 endpoint to store compilation results:
- if [ -n "${SCCACHE_BIN_URL}" ]; then export RUSTC_WRAPPER=$SHARED_PATH/cargo/bin/sccache && curl $SCCACHE_BIN_URL --output $RUSTC_WRAPPER && chmod +x $RUSTC_WRAPPER; fi
script: script:
# cross-compile conduit for target # cross-compile conduit for target
- 'time ./cross/build.sh --locked --release' - 'time ./cross/build.sh --locked --release'
- 'mv "target/$TARGET/release/conduit" "conduit-$TARGET"' - 'mv "target/$TARGET/release/conduit" "conduit-$TARGET"'
# assert that the binary is statically linked
- 'file conduit-$TARGET | grep "static\(-pie\|ally\) linked"'
cache: cache:
# https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci # https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci
key: 'cargo-cache-$TARGET' key: 'cargo-cache-$TARGET'
@ -82,16 +84,6 @@ build:release:cargo:x86_64-unknown-linux-musl:
- "conduit-x86_64-unknown-linux-musl" - "conduit-x86_64-unknown-linux-musl"
expose_as: "Conduit for x86_64-unknown-linux-musl" expose_as: "Conduit for x86_64-unknown-linux-musl"
build:release:cargo:i686-unknown-linux-musl:
extends: .build-cargo-shared-settings
variables:
TARGET: "i686-unknown-linux-musl"
artifacts:
name: "conduit-i686-unknown-linux-musl"
paths:
- "conduit-i686-unknown-linux-musl"
expose_as: "Conduit for i686-unknown-linux-musl"
build:release:cargo:arm-unknown-linux-musleabihf: build:release:cargo:arm-unknown-linux-musleabihf:
extends: .build-cargo-shared-settings extends: .build-cargo-shared-settings
variables: variables:
@ -132,6 +124,8 @@ build:release:cargo:aarch64-unknown-linux-musl:
# cross-compile conduit for target # cross-compile conduit for target
- 'time ./cross/build.sh --locked' - 'time ./cross/build.sh --locked'
- 'mv "target/$TARGET/debug/conduit" "conduit-debug-$TARGET"' - 'mv "target/$TARGET/debug/conduit" "conduit-debug-$TARGET"'
# assert that the binary is statically linked
- 'file conduit-debug-$TARGET | grep "static\(-pie\|ally\) linked"'
artifacts: artifacts:
expire_in: 4 weeks expire_in: 4 weeks

View file

@ -7,8 +7,5 @@ image = "rust-cross:arm-unknown-linux-musleabihf"
[target.armv7-unknown-linux-musleabihf] [target.armv7-unknown-linux-musleabihf]
image = "rust-cross:armv7-unknown-linux-musleabihf" image = "rust-cross:armv7-unknown-linux-musleabihf"
[target.i686-unknown-linux-musl]
image = "rust-cross:i686-unknown-linux-musl"
[target.x86_64-unknown-linux-musl] [target.x86_64-unknown-linux-musl]
image = "rust-cross:x86_64-unknown-linux-musl" image = "rust-cross:x86_64-unknown-linux-musl"

View file

@ -17,13 +17,14 @@ ENV TARGET_PREFIX="/usr/local/$(echo "${TARGET:?}" | sed -e 's/armv7/arm/' -e 's
# Make sure that cc-rs links libc/libstdc++ statically when cross-compiling # Make sure that cc-rs links libc/libstdc++ statically when cross-compiling
# See https://github.com/alexcrichton/cc-rs#external-configuration-via-environment-variables for more information # See https://github.com/alexcrichton/cc-rs#external-configuration-via-environment-variables for more information
ENV RUSTFLAGS="-L\$TARGET_PREFIX/lib" CXXSTDLIB="static=stdc++" ENV RUSTFLAGS="-L\$TARGET_PREFIX/lib" CXXSTDLIB="static=stdc++"
# Forcefully linking against libatomic and libgcc is required for arm32, otherwise symbols are missing # Forcefully linking against libatomic, libc and libgcc is required for arm32, otherwise symbols are missing
$([[ $TARGET =~ arm ]] && echo 'ENV RUSTFLAGS="$RUSTFLAGS -Clink-arg=-lgcc -Clink-arg=-latomic"') $([[ $TARGET =~ arm ]] && echo 'ENV RUSTFLAGS="$RUSTFLAGS -Clink-arg=-lgcc -Clink-arg=-latomic -lstatic=c"')
# Forcefully linking against libc is required for 32-bit, otherwise symbols are missing
$([[ $TARGET =~ arm|i686 ]] && echo 'ENV RUSTFLAGS="$RUSTFLAGS -lstatic=c"')
# Strip symbols while compiling in release mode # Strip symbols while compiling in release mode
$([[ $@ =~ -r ]] && echo 'ENV RUSTFLAGS="$RUSTFLAGS -Clink-arg=-s"') $([[ $@ =~ -r ]] && echo 'ENV RUSTFLAGS="$RUSTFLAGS -Clink-arg=-s"')
# Support a rustc wrapper like sccache when cross-compiling
ENV RUSTC_WRAPPER="$RUSTC_WRAPPER"
# Make sure that rust-bindgen uses the correct include path when cross-compiling # Make sure that rust-bindgen uses the correct include path when cross-compiling
# See https://github.com/rust-lang/rust-bindgen#environment-variables for more information # See https://github.com/rust-lang/rust-bindgen#environment-variables for more information
ENV BINDGEN_EXTRA_CLANG_ARGS="-I\$TARGET_PREFIX/include" ENV BINDGEN_EXTRA_CLANG_ARGS="-I\$TARGET_PREFIX/include"