From 9cc55d3ecd474aca6f754c23d9aacc238f029e31 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Thu, 20 Nov 2025 00:07:10 +0100 Subject: [PATCH 1/3] remove docker build cruft - Simplified environment variable sourcing in build scripts by using a single build-env.sh file. - Updated Dockerfile to streamline the build process and reduce unnecessary comments. - Enhanced setup-cross-compilation.sh to directly set target and linker variables without temporary files. - Improved clarity and maintainability of build scripts. --- Dockerfile | 6 ----- scripts/build-dependencies.sh | 6 +---- scripts/build-project.sh | 7 +----- scripts/setup-cross-compilation.sh | 37 ++++++++++++------------------ 4 files changed, 17 insertions(+), 39 deletions(-) diff --git a/Dockerfile b/Dockerfile index f3ea20f1..15fe9841 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,20 +4,14 @@ WORKDIR /usr/src/sqlpage ARG TARGETARCH ARG BUILDARCH -# Copy build scripts COPY scripts/ /usr/local/bin/ - -# Initialize cargo project RUN cargo init . -# Setup cross-compilation environment RUN /usr/local/bin/setup-cross-compilation.sh "$TARGETARCH" "$BUILDARCH" -# Build dependencies (creates a layer that avoids recompiling dependencies on every build) COPY Cargo.toml Cargo.lock ./ RUN /usr/local/bin/build-dependencies.sh -# Build the project COPY . . RUN /usr/local/bin/build-project.sh diff --git a/scripts/build-dependencies.sh b/scripts/build-dependencies.sh index e732125f..5a55754a 100755 --- a/scripts/build-dependencies.sh +++ b/scripts/build-dependencies.sh @@ -1,14 +1,10 @@ #!/bin/bash set -euo pipefail -# Source the environment variables set by setup-cross-compilation.sh -TARGET="$(cat /tmp/TARGET)" -LINKER="$(cat /tmp/LINKER)" -BINDGEN_EXTRA_CLANG_ARGS="$(cat /tmp/BINDGEN_EXTRA_CLANG_ARGS || true)" +source /tmp/build-env.sh echo "Building dependencies for target: $TARGET" -# Build dependencies only (for Docker layer caching) cargo build \ --target "$TARGET" \ --config "target.$TARGET.linker=\"$LINKER\"" \ diff --git a/scripts/build-project.sh b/scripts/build-project.sh index 6723fc17..ac595b61 100755 --- a/scripts/build-project.sh +++ b/scripts/build-project.sh @@ -1,19 +1,14 @@ #!/bin/bash set -euo pipefail -# Source the environment variables set by setup-cross-compilation.sh -TARGET="$(cat /tmp/TARGET)" -LINKER="$(cat /tmp/LINKER)" +source /tmp/build-env.sh echo "Building project for target: $TARGET" -# Build the project -touch src/main.rs cargo build \ --target "$TARGET" \ --config "target.$TARGET.linker=\"$LINKER\"" \ --features odbc-static \ --profile superoptimized -# Move the binary to the expected location mv "target/$TARGET/superoptimized/sqlpage" sqlpage.bin diff --git a/scripts/setup-cross-compilation.sh b/scripts/setup-cross-compilation.sh index 941c99b9..a43dccac 100755 --- a/scripts/setup-cross-compilation.sh +++ b/scripts/setup-cross-compilation.sh @@ -1,48 +1,41 @@ #!/bin/bash -set -euox pipefail +set -euo pipefail TARGETARCH="$1" BUILDARCH="$2" +BINDGEN_EXTRA_CLANG_ARGS="" apt-get update if [ "$TARGETARCH" = "$BUILDARCH" ]; then - # Native build - rustup target list --installed > /tmp/TARGET - echo "gcc" > /tmp/LINKER + TARGET="$(rustup target list --installed | head -n1)" + LINKER="gcc" apt-get install -y gcc libgcc-s1 make - LIBDIR="/lib/$(gcc -print-multiarch)" - elif [ "$TARGETARCH" = "arm64" ]; then - echo "aarch64-unknown-linux-gnu" > /tmp/TARGET - echo "aarch64-linux-gnu-gcc" > /tmp/LINKER - + TARGET="aarch64-unknown-linux-gnu" + LINKER="aarch64-linux-gnu-gcc" apt-get install -y gcc-aarch64-linux-gnu libgcc-s1-arm64-cross make - LIBDIR="/usr/aarch64-linux-gnu/lib" elif [ "$TARGETARCH" = "arm" ]; then - echo "armv7-unknown-linux-gnueabihf" > /tmp/TARGET - echo "arm-linux-gnueabihf-gcc" > /tmp/LINKER - + TARGET="armv7-unknown-linux-gnueabihf" + LINKER="arm-linux-gnueabihf-gcc" apt-get install -y gcc-arm-linux-gnueabihf libgcc-s1-armhf-cross make cmake libclang-dev - cargo install --force --locked bindgen-cli - SYSROOT=$(arm-linux-gnueabihf-gcc -print-sysroot) - echo "--sysroot=$SYSROOT -I$SYSROOT/usr/include -I$SYSROOT/usr/include/arm-linux-gnueabihf" > /tmp/BINDGEN_EXTRA_CLANG_ARGS - + BINDGEN_EXTRA_CLANG_ARGS="--sysroot=$SYSROOT -I$SYSROOT/usr/include -I$SYSROOT/usr/include/arm-linux-gnueabihf" LIBDIR="/usr/arm-linux-gnueabihf/lib" else echo "Unsupported cross compilation target: $TARGETARCH" exit 1 fi -# Copy libgcc_s.so.1 for runtime mkdir -p /tmp/sqlpage-libs - cp "$LIBDIR/libgcc_s.so.1" /tmp/sqlpage-libs/ +rustup target add "$TARGET" -# Add the target -rustup target add "$(cat /tmp/TARGET)" - +cat > /tmp/build-env.sh < Date: Thu, 20 Nov 2025 00:22:10 +0100 Subject: [PATCH 2/3] fix setup-cross-compilation.sh - Updated the script to use a more concise syntax for exporting environment variables. - Improved readability by using echo and conditional checks for BINDGEN_EXTRA_CLANG_ARGS. - This change simplifies the script while maintaining functionality. --- scripts/setup-cross-compilation.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/setup-cross-compilation.sh b/scripts/setup-cross-compilation.sh index a43dccac..4a49cc87 100755 --- a/scripts/setup-cross-compilation.sh +++ b/scripts/setup-cross-compilation.sh @@ -34,8 +34,8 @@ mkdir -p /tmp/sqlpage-libs cp "$LIBDIR/libgcc_s.so.1" /tmp/sqlpage-libs/ rustup target add "$TARGET" -cat > /tmp/build-env.sh < /tmp/build-env.sh From 9c79bc0ad4b4ed042eb9e723a59223a1d522739e Mon Sep 17 00:00:00 2001 From: lovasoa Date: Thu, 20 Nov 2025 00:23:07 +0100 Subject: [PATCH 3/3] Refactor setup-cross-compilation.sh for improved readability - Changed the syntax for checking BINDGEN_EXTRA_CLANG_ARGS to use a conditional statement for clarity. - This enhances the script's maintainability while preserving its functionality. --- scripts/setup-cross-compilation.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/setup-cross-compilation.sh b/scripts/setup-cross-compilation.sh index 4a49cc87..83531abb 100755 --- a/scripts/setup-cross-compilation.sh +++ b/scripts/setup-cross-compilation.sh @@ -37,5 +37,7 @@ rustup target add "$TARGET" { echo "export TARGET='$TARGET'" echo "export LINKER='$LINKER'" - [ -n "$BINDGEN_EXTRA_CLANG_ARGS" ] && printf "export BINDGEN_EXTRA_CLANG_ARGS=%q\n" "$BINDGEN_EXTRA_CLANG_ARGS" + if [ -n "$BINDGEN_EXTRA_CLANG_ARGS" ]; then + printf "export BINDGEN_EXTRA_CLANG_ARGS=%q\n" "$BINDGEN_EXTRA_CLANG_ARGS" + fi } > /tmp/build-env.sh