Skip to content

Commit e24a863

Browse files
committed
Refactor to improve portability and robustness
This commit implements a small refactor to make the dev container setup more resilient and truly multi-platform. - Installs `aarch64` cross-compilation packages (`gcc-aarch64-linux-gnu`, `libc6-dev-arm64-cross`) in the `Dockerfile` to enable building for ARM64 on x86_64 hosts. - Updates `bin/build-arch` to use the correct `strip` binary (native or cross-compile) by checking both the host and target architectures. - Adds a 30-second timeout to the `postCreate` script to prevent it from hanging if the Docker daemon fails to start. - Adds a comment to `bin/test` clarifying why language runtime tests are now enabled for all architectures. - Merges the `update-alternatives` command into the main `RUN` layer, reducing the total number of image layers.
1 parent 808f771 commit e24a863

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

.devcontainer/Dockerfile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,32 @@ FROM mcr.microsoft.com/devcontainers/rust:2-1-bookworm
33
RUN apt-get update -y \
44
&& apt-get upgrade -y \
55
&& apt-get install -y --fix-missing --no-install-recommends \
6+
\
7+
# Zip for packaging
68
zip \
9+
\
10+
# QEMU for multi-architecture support
711
qemu-system \
812
binfmt-support \
913
qemu-user-static \
14+
\
15+
# Language runtimes for tests
1016
nodejs \
1117
ruby \
1218
php \
1319
php-common \
1420
python3-pip \
21+
\
22+
# Cross-compilation toolchains
1523
gcc-x86-64-linux-gnu \
1624
libc6-dev-amd64-cross \
25+
gcc-aarch64-linux-gnu \
26+
libc6-dev-arm64-cross \
27+
\
28+
# Clean up, enable QEMU, and set Python alternative in a single layer
1729
&& rm -rf /var/lib/apt/lists/* \
18-
&& update-binfmts --enable qemu-aarch64
19-
20-
# Easy way to install Python.
21-
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1
30+
&& update-binfmts --enable qemu-aarch64 \
31+
&& update-alternatives --install /usr/bin/python python /usr/bin/python3 1
2232

2333
# Switch to root to install rust targets and fix permissions
2434
USER root

.devcontainer/postCreate

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
set -e
33

44
# Wait for docker to be ready
5+
TIMEOUT=30
56
while ! docker info > /dev/null 2>&1; do
67
echo "Waiting for docker daemon..."
78
sleep 1
9+
TIMEOUT=$((TIMEOUT - 1))
10+
if [ $TIMEOUT -le 0 ]; then
11+
echo "Docker daemon failed to start"
12+
exit 1
13+
fi
814
done

bin/build-arch

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,25 @@ cp "./target/${CRYPTEIA_BUILD_TARGET}/release/crypteia" "./build/${BIN}"
1919
cp "./target/${CRYPTEIA_BUILD_TARGET}/release/libcrypteia.so" "./build/${LIB}"
2020

2121
cd ./build
22-
if [ "${CRYPTEIA_BUILD_TARGET}" = "aarch64-unknown-linux-gnu" ]; then
23-
strip "$BIN"
24-
else
25-
x86_64-linux-gnu-strip "$BIN"
26-
fi
22+
23+
# Use appropriate strip command based on target
24+
case "${CRYPTEIA_BUILD_TARGET}" in
25+
aarch64-unknown-linux-gnu)
26+
if [ "$(uname -m)" = "aarch64" ]; then
27+
strip "$BIN"
28+
else
29+
aarch64-linux-gnu-strip "$BIN" 2>/dev/null || strip "$BIN"
30+
fi
31+
;;
32+
x86_64-unknown-linux-gnu)
33+
if [ "$(uname -m)" = "x86_64" ]; then
34+
strip "$BIN"
35+
else
36+
x86_64-linux-gnu-strip "$BIN" 2>/dev/null || strip "$BIN"
37+
fi
38+
;;
39+
esac
40+
2741
chmod +x "$BIN"
2842
zip -r "${BIN}.zip" "$BIN"
2943
zip -r "libcrypteia-${CRYPTEIA_BUILD_OS}${CRYPTEIA_BUILD_SUFFIX}.zip" "$LIB"

bin/test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ if [ ! "${SKIP_CARGO_TEST}" = "1" ]; then
2828
cargo test --target "${CRYPTEIA_BUILD_TARGET}" --quiet
2929
fi
3030

31+
# Language runtime tests now work on both architectures thanks to proper
32+
# LD_PRELOAD path matching (CRYPTEIA_BUILD_SUFFIX) and installed runtimes
3133
TEST_LANG=node ./test/libcrypteia.sh
3234
TEST_LANG=ruby ./test/libcrypteia.sh
3335
TEST_LANG=php ./test/libcrypteia.sh

0 commit comments

Comments
 (0)