-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[actions] Move building release binary to a script
Make the script default to x86_64,aarch64, and s390x. Speed up toolchain installation by batching it in one command. Signed-off-by: Manu Bretelle <chantr4@gmail.com>
- Loading branch information
Showing
2 changed files
with
49 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
# | ||
# Build a release version of vmtest for a list of architectures. | ||
# The resulting binaries will be copied in the current directory and named vmtest-<arch>. | ||
# | ||
# This script assumes it is run on a Debian based system. | ||
# | ||
# Run this on your root host inside vmtest repository. | ||
# | ||
# Usage: | ||
# ./scripts/build_release.sh | ||
# ./scripts/build_kernel.sh x86_64 aarch64 | ||
|
||
set -eu | ||
|
||
|
||
function gnu_to_debian() { | ||
# Funtion to convert an architecture in Debian to its GNU equivalent, | ||
# e.g amd64 -> x86_64 | ||
# CPUTABLE contains a list of debian_arch\tgnu_arch per line | ||
# Compare of the first field matches and print the second one. | ||
awk -v gnu_arch="$1" '$2 ~ gnu_arch {print $1}' /usr/share/dpkg/cputable | ||
} | ||
|
||
ARCHS=(x86_64 aarch64 s390x) | ||
|
||
if [[ $# -gt 0 ]] | ||
then | ||
ARCHS=("$@") | ||
fi | ||
|
||
# Install the required toolchain for cross-compilation | ||
X_ARCHS=() | ||
for arch in "${ARCHS[@]}"; do | ||
if [[ "${arch}" == "$(uname -m)" ]]; then | ||
continue | ||
fi | ||
X_ARCHS+=("${arch}") | ||
done | ||
ARCHS_TO_EXPAND=$(IFS=, ; echo "${X_ARCHS[*]}") | ||
eval sudo apt install -y "gcc-{${ARCHS_TO_EXPAND//_/-}}-linux-gnu" | ||
eval rustup target add "{${ARCHS_TO_EXPAND}}-unknown-linux-gnu" | ||
|
||
for arch in "${ARCHS[@]}"; do | ||
# Compile the binary | ||
RUSTFLAGS="-C target-feature=+crt-static -C linker=/usr/bin/${arch}-linux-gnu-gcc" cargo build --release --target "${arch}-unknown-linux-gnu" | ||
cp "./target/${arch}-unknown-linux-gnu/release/vmtest" "./vmtest-$(gnu_to_debian "${arch}")" | ||
done |