Skip to content

Commit

Permalink
[actions] Move building release binary to a script
Browse files Browse the repository at this point in the history
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
chantra committed Jan 10, 2024
1 parent 6262fd6 commit 41e8467
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 18 deletions.
19 changes: 1 addition & 18 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,7 @@ jobs:

- name: Build statically linked vmtest
run: |
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)
for arch in "${ARCHS[@]}"; do
# Install the required toolchain
sudo apt install -y gcc-${arch//_/-}-linux-gnu
rustup target add "${arch}-unknown-linux-gnu"
# 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
./scripts/build_release.sh
- name: Create release
uses: softprops/action-gh-release@v1
Expand Down
48 changes: 48 additions & 0 deletions scripts/build_release.sh
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

0 comments on commit 41e8467

Please sign in to comment.