Skip to content

Commit

Permalink
Add cross-compilation capabilities
Browse files Browse the repository at this point in the history
Signed-off-by: Valerian Saliou <valerian@valeriansaliou.name>
  • Loading branch information
valeriansaliou committed Jun 25, 2020
1 parent 29ddf5a commit 961bab9
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Cross.toml
@@ -0,0 +1,10 @@
[build.env]
passthrough = [
"RUSTFLAGS"
]

[target.x86_64-unknown-linux-musl]
image = "valeriansaliou/sonic:cross-x86_64-unknown-linux-musl"

[target.armv7-unknown-linux-musleabihf]
image = "valeriansaliou/sonic:cross-armv7-unknown-linux-musleabihf"
76 changes: 76 additions & 0 deletions scripts/release_binaries.sh
@@ -0,0 +1,76 @@
#!/bin/bash

##
# Sonic
#
# Fast, lightweight and schema-less search backend
# Copyright: 2020, Valerian Saliou <valerian@valeriansaliou.name>
# License: Mozilla Public License v2.0 (MPL v2.0)
##

# Read arguments
while [ "$1" != "" ]; do
argument_key=`echo $1 | awk -F= '{print $1}'`
argument_value=`echo $1 | awk -F= '{print $2}'`

case $argument_key in
-v | --version)
SONIC_VERSION="$argument_value"
;;
*)
echo "Unknown argument received: '$argument_key'"
exit 1
;;
esac

shift
done

# Ensure release version is provided
if [ -z "$SONIC_VERSION" ]; then
echo "No Sonic release version was provided, please provide it using '--version'"

exit 1
fi

# Define release pipeline
function release_for_architecture {
final_tar="v$SONIC_VERSION-$1.tar.gz"

rm -rf ./sonic/ && \
RUSTFLAGS="-C target-feature=-crt-static -C link-arg=-s" cross build --target "$2" --release && \
mkdir ./sonic && \
cp -p "target/$2/release/sonic" ./sonic/ && \
cp -r ./config.cfg sonic/ && \
tar -czvf "$final_tar" ./sonic && \
rm -r ./sonic/
release_result=$?

if [ $release_result -eq 0 ]; then
echo "Result: Packed architecture: $1 to file: $final_tar"
fi

return $release_result
}

# Run release tasks
ABSPATH=$(cd "$(dirname "$0")"; pwd)
BASE_DIR="$ABSPATH/../"

rc=0

pushd "$BASE_DIR" > /dev/null
echo "Executing release steps for Sonic v$SONIC_VERSION..."

release_for_architecture "x86_64" "x86_64-unknown-linux-musl" && \
release_for_architecture "armv7" "armv7-unknown-linux-musleabihf"
rc=$?

if [ $rc -eq 0 ]; then
echo "Success: Done executing release steps for Sonic v$SONIC_VERSION"
else
echo "Error: Failed executing release steps for Sonic v$SONIC_VERSION"
fi
popd > /dev/null

exit $rc
4 changes: 4 additions & 0 deletions tools/cross/cross-armv7-unknown-linux-musleabihf/Dockerfile
@@ -0,0 +1,4 @@
FROM rustembedded/cross:armv7-unknown-linux-musleabihf-0.2.0

RUN apt-get update && \
apt-get install -y clang libclang-dev libc6-dev-i386
4 changes: 4 additions & 0 deletions tools/cross/cross-x86_64-unknown-linux-musl/Dockerfile
@@ -0,0 +1,4 @@
FROM rustembedded/cross:x86_64-unknown-linux-musl-0.2.0

RUN apt-get update && \
apt-get install -y clang libclang-dev libc6-dev-i386

0 comments on commit 961bab9

Please sign in to comment.