Merge branch 'fix/rocksdb-cross-compiling' into 'next'
Fix cross-compiling for RocksDB Closes #213 See merge request famedly/conduit!261
This commit is contained in:
commit
4a34d757d7
7 changed files with 130 additions and 24 deletions
|
@ -21,27 +21,46 @@ variables:
|
|||
- if: '$CI_COMMIT_BRANCH == "next"'
|
||||
- if: "$CI_COMMIT_TAG"
|
||||
interruptible: true
|
||||
image: "rust:1.56"
|
||||
image: "rust:1.58"
|
||||
tags: ["docker"]
|
||||
services: ["docker:dind"]
|
||||
variables:
|
||||
DOCKER_HOST: tcp://docker:2375/
|
||||
DOCKER_TLS_CERTDIR: ""
|
||||
DOCKER_DRIVER: overlay2
|
||||
SHARED_PATH: $CI_PROJECT_DIR/shared/
|
||||
CARGO_PROFILE_RELEASE_LTO: "true"
|
||||
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: "1"
|
||||
CARGO_INCREMENTAL: "false" # https://matklad.github.io/2021/09/04/fast-rust-builds.html#ci-workflow
|
||||
before_script:
|
||||
- 'echo "Building for target $TARGET"'
|
||||
- "rustc --version && cargo --version && rustup show" # Print version info for debugging
|
||||
- "rustup target add $TARGET"
|
||||
- "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
|
||||
- 'apt-get update && apt-get install -y docker.io && docker version' # install docker
|
||||
- 'cargo install cross && cross --version' # install cross
|
||||
# fix cargo and rustup mounts from this container (https://gitlab.com/gitlab-org/gitlab-foss/-/issues/41227)
|
||||
- 'mkdir -p $SHARED_PATH/cargo'
|
||||
- 'cp -r $CARGO_HOME/bin $SHARED_PATH/cargo'
|
||||
- 'cp -r $RUSTUP_HOME $SHARED_PATH'
|
||||
- 'export CARGO_HOME=$SHARED_PATH/cargo RUSTUP_HOME=$SHARED_PATH/rustup'
|
||||
script:
|
||||
- time cargo build --target $TARGET --release
|
||||
- 'cp "target/$TARGET/release/conduit" "conduit-$TARGET"'
|
||||
# cross-compile conduit for target
|
||||
- 'time ./cross/build.sh --locked --release'
|
||||
- 'mv "target/$TARGET/release/conduit" "conduit-$TARGET"'
|
||||
cache:
|
||||
# https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci
|
||||
key: 'cargo-cache-$TARGET'
|
||||
paths:
|
||||
- $SHARED_PATH/cargo/registry/index
|
||||
- $SHARED_PATH/cargo/registry/cache
|
||||
- $SHARED_PATH/cargo/git/db
|
||||
artifacts:
|
||||
expire_in: never
|
||||
|
||||
build:release:cargo:x86_64-unknown-linux-musl-with-debug:
|
||||
extends: .build-cargo-shared-settings
|
||||
image: messense/rust-musl-cross:x86_64-musl
|
||||
variables:
|
||||
CARGO_PROFILE_RELEASE_DEBUG: 2 # Enable debug info for flamegraph profiling
|
||||
TARGET: "x86_64-unknown-linux-musl"
|
||||
|
@ -55,7 +74,6 @@ build:release:cargo:x86_64-unknown-linux-musl-with-debug:
|
|||
|
||||
build:release:cargo:x86_64-unknown-linux-musl:
|
||||
extends: .build-cargo-shared-settings
|
||||
image: messense/rust-musl-cross:x86_64-musl
|
||||
variables:
|
||||
TARGET: "x86_64-unknown-linux-musl"
|
||||
artifacts:
|
||||
|
@ -64,9 +82,18 @@ build:release:cargo:x86_64-unknown-linux-musl:
|
|||
- "conduit-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:
|
||||
extends: .build-cargo-shared-settings
|
||||
image: messense/rust-musl-cross:arm-musleabihf
|
||||
variables:
|
||||
TARGET: "arm-unknown-linux-musleabihf"
|
||||
artifacts:
|
||||
|
@ -77,7 +104,6 @@ build:release:cargo:arm-unknown-linux-musleabihf:
|
|||
|
||||
build:release:cargo:armv7-unknown-linux-musleabihf:
|
||||
extends: .build-cargo-shared-settings
|
||||
image: messense/rust-musl-cross:armv7-musleabihf
|
||||
variables:
|
||||
TARGET: "armv7-unknown-linux-musleabihf"
|
||||
artifacts:
|
||||
|
@ -88,7 +114,6 @@ build:release:cargo:armv7-unknown-linux-musleabihf:
|
|||
|
||||
build:release:cargo:aarch64-unknown-linux-musl:
|
||||
extends: .build-cargo-shared-settings
|
||||
image: messense/rust-musl-cross:aarch64-musl
|
||||
variables:
|
||||
TARGET: "aarch64-unknown-linux-musl"
|
||||
artifacts:
|
||||
|
@ -104,14 +129,14 @@ build:release:cargo:aarch64-unknown-linux-musl:
|
|||
cache:
|
||||
key: "build_cache--$TARGET--$CI_COMMIT_BRANCH--debug"
|
||||
script:
|
||||
- "time cargo build --target $TARGET"
|
||||
# cross-compile conduit for target
|
||||
- 'time ./cross/build.sh --locked'
|
||||
- 'mv "target/$TARGET/debug/conduit" "conduit-debug-$TARGET"'
|
||||
artifacts:
|
||||
expire_in: 4 weeks
|
||||
|
||||
build:debug:cargo:x86_64-unknown-linux-musl:
|
||||
extends: ".cargo-debug-shared-settings"
|
||||
image: messense/rust-musl-cross:x86_64-musl
|
||||
variables:
|
||||
TARGET: "x86_64-unknown-linux-musl"
|
||||
artifacts:
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
Install docker:
|
||||
|
||||
```
|
||||
$ sudo apt install docker
|
||||
$ sudo usermod -aG docker $USER
|
||||
$ exec sudo su -l $USER
|
||||
$ sudo systemctl start docker
|
||||
$ cargo install cross
|
||||
$ cross build --release --target armv7-unknown-linux-musleabihf
|
||||
```
|
||||
The cross-compiled binary is at target/armv7-unknown-linux-musleabihf/release/conduit
|
14
Cross.toml
Normal file
14
Cross.toml
Normal file
|
@ -0,0 +1,14 @@
|
|||
[target.aarch64-unknown-linux-musl]
|
||||
image = "rust-cross:aarch64-unknown-linux-musl"
|
||||
|
||||
[target.arm-unknown-linux-musleabihf]
|
||||
image = "rust-cross:arm-unknown-linux-musleabihf"
|
||||
|
||||
[target.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]
|
||||
image = "rust-cross:x86_64-unknown-linux-musl"
|
|
@ -37,7 +37,7 @@ $ cargo build --release
|
|||
|
||||
Note that this currently requires Rust 1.50.
|
||||
|
||||
If you want to cross compile Conduit to another architecture, read the [Cross-Compile Guide](CROSS_COMPILE.md).
|
||||
If you want to cross compile Conduit to another architecture, read the [Cross-Compile Guide](cross/README.md).
|
||||
|
||||
## Adding a Conduit user
|
||||
|
||||
|
|
37
cross/README.md
Normal file
37
cross/README.md
Normal file
|
@ -0,0 +1,37 @@
|
|||
## Cross compilation
|
||||
|
||||
The `cross` folder contains a set of convenience scripts (`build.sh` and `test.sh`) for cross-compiling Conduit.
|
||||
|
||||
Currently supported targets are
|
||||
|
||||
- aarch64-unknown-linux-musl
|
||||
- arm-unknown-linux-musleabihf
|
||||
- armv7-unknown-linux-musleabihf
|
||||
- x86\_64-unknown-linux-musl
|
||||
|
||||
### Install prerequisites
|
||||
#### Docker
|
||||
[Installation guide](https://docs.docker.com/get-docker/).
|
||||
```sh
|
||||
$ sudo apt install docker
|
||||
$ sudo systemctl start docker
|
||||
$ sudo usermod -aG docker $USER
|
||||
$ newgrp docker
|
||||
```
|
||||
|
||||
#### Cross
|
||||
[Installation guide](https://github.com/rust-embedded/cross/#installation).
|
||||
```sh
|
||||
$ cargo install cross
|
||||
```
|
||||
|
||||
### Buiding Conduit
|
||||
```sh
|
||||
$ TARGET=armv7-unknown-linux-musleabihf ./cross/build.sh --release
|
||||
```
|
||||
The cross-compiled binary is at `target/armv7-unknown-linux-musleabihf/release/conduit`
|
||||
|
||||
### Testing Conduit
|
||||
```sh
|
||||
$ TARGET=armv7-unknown-linux-musleabihf ./cross/test.sh --release
|
||||
```
|
33
cross/build.sh
Executable file
33
cross/build.sh
Executable file
|
@ -0,0 +1,33 @@
|
|||
#!/bin/bash
|
||||
set -ex
|
||||
|
||||
# build custom container with libclang and static compilation
|
||||
tag="rust-cross:${TARGET:?}"
|
||||
docker build --tag="$tag" - << EOF
|
||||
FROM rustembedded/cross:$TARGET
|
||||
|
||||
# Install libclang for generating bindings with rust-bindgen
|
||||
# The architecture is not relevant here since it's not used for compilation
|
||||
RUN apt-get update && \
|
||||
apt-get install --assume-yes libclang-dev
|
||||
|
||||
# Set the target prefix
|
||||
ENV TARGET_PREFIX="/usr/local/$(echo "${TARGET:?}" | sed -e 's/armv7/arm/' -e 's/-unknown//')"
|
||||
|
||||
# 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
|
||||
ENV RUSTFLAGS="-L\$TARGET_PREFIX/lib" CXXSTDLIB="static=stdc++"
|
||||
# Forcefully linking against libatomic and libgcc is required for arm32, otherwise symbols are missing
|
||||
$([[ $TARGET =~ arm ]] && echo 'ENV RUSTFLAGS="$RUSTFLAGS -Clink-arg=-lgcc -Clink-arg=-latomic"')
|
||||
# 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
|
||||
$([[ $@ =~ -r ]] && echo 'ENV RUSTFLAGS="$RUSTFLAGS -Clink-arg=-s"')
|
||||
|
||||
# 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
|
||||
ENV BINDGEN_EXTRA_CLANG_ARGS="-I\$TARGET_PREFIX/include"
|
||||
EOF
|
||||
|
||||
# build conduit for a specific target
|
||||
cross build --target="$TARGET" $@
|
8
cross/test.sh
Executable file
8
cross/test.sh
Executable file
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env sh
|
||||
set -ex
|
||||
|
||||
# Build conduit for a specific target
|
||||
cross/build.sh $@
|
||||
|
||||
# Test conduit for a specific target
|
||||
cross test --target="$TARGET" $@
|
Loading…
Add table
Reference in a new issue