mirror of https://gitlab.com/famedly/conduit
feat: use rustembedded/cross images and use static relocation model to fix cross-compile
parent
a021680591
commit
cd9902637d
@ -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
|
|
@ -0,0 +1,11 @@
|
|||||||
|
[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.x86_64-unknown-linux-musl]
|
||||||
|
image = "rust-cross:x86_64-unknown-linux-musl"
|
@ -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
|
||||||
|
```
|
@ -0,0 +1,31 @@
|
|||||||
|
#!/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, libc and libgcc is required for arm32, otherwise symbols are missing
|
||||||
|
$([[ $TARGET =~ arm ]] && echo 'ENV RUSTFLAGS="$RUSTFLAGS -Clink-arg=-lgcc -Clink-arg=-latomic -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" $@
|
@ -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…
Reference in New Issue