Skip to content

Commit a52b20c

Browse files
authored
remove docker build cruft (#1115)
* 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. * 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. * 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.
1 parent 25fe2e6 commit a52b20c

File tree

4 files changed

+20
-40
lines changed

4 files changed

+20
-40
lines changed

Dockerfile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,14 @@ WORKDIR /usr/src/sqlpage
44
ARG TARGETARCH
55
ARG BUILDARCH
66

7-
# Copy build scripts
87
COPY scripts/ /usr/local/bin/
9-
10-
# Initialize cargo project
118
RUN cargo init .
129

13-
# Setup cross-compilation environment
1410
RUN /usr/local/bin/setup-cross-compilation.sh "$TARGETARCH" "$BUILDARCH"
1511

16-
# Build dependencies (creates a layer that avoids recompiling dependencies on every build)
1712
COPY Cargo.toml Cargo.lock ./
1813
RUN /usr/local/bin/build-dependencies.sh
1914

20-
# Build the project
2115
COPY . .
2216
RUN /usr/local/bin/build-project.sh
2317

scripts/build-dependencies.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
# Source the environment variables set by setup-cross-compilation.sh
5-
TARGET="$(cat /tmp/TARGET)"
6-
LINKER="$(cat /tmp/LINKER)"
7-
BINDGEN_EXTRA_CLANG_ARGS="$(cat /tmp/BINDGEN_EXTRA_CLANG_ARGS || true)"
4+
source /tmp/build-env.sh
85

96
echo "Building dependencies for target: $TARGET"
107

11-
# Build dependencies only (for Docker layer caching)
128
cargo build \
139
--target "$TARGET" \
1410
--config "target.$TARGET.linker=\"$LINKER\"" \

scripts/build-project.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
# Source the environment variables set by setup-cross-compilation.sh
5-
TARGET="$(cat /tmp/TARGET)"
6-
LINKER="$(cat /tmp/LINKER)"
4+
source /tmp/build-env.sh
75

86
echo "Building project for target: $TARGET"
97

10-
# Build the project
11-
touch src/main.rs
128
cargo build \
139
--target "$TARGET" \
1410
--config "target.$TARGET.linker=\"$LINKER\"" \
1511
--features odbc-static \
1612
--profile superoptimized
1713

18-
# Move the binary to the expected location
1914
mv "target/$TARGET/superoptimized/sqlpage" sqlpage.bin

scripts/setup-cross-compilation.sh

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,43 @@
11
#!/bin/bash
2-
set -euox pipefail
2+
set -euo pipefail
33

44
TARGETARCH="$1"
55
BUILDARCH="$2"
6+
BINDGEN_EXTRA_CLANG_ARGS=""
67

78
apt-get update
89

910
if [ "$TARGETARCH" = "$BUILDARCH" ]; then
10-
# Native build
11-
rustup target list --installed > /tmp/TARGET
12-
echo "gcc" > /tmp/LINKER
11+
TARGET="$(rustup target list --installed | head -n1)"
12+
LINKER="gcc"
1313
apt-get install -y gcc libgcc-s1 make
14-
1514
LIBDIR="/lib/$(gcc -print-multiarch)"
16-
1715
elif [ "$TARGETARCH" = "arm64" ]; then
18-
echo "aarch64-unknown-linux-gnu" > /tmp/TARGET
19-
echo "aarch64-linux-gnu-gcc" > /tmp/LINKER
20-
16+
TARGET="aarch64-unknown-linux-gnu"
17+
LINKER="aarch64-linux-gnu-gcc"
2118
apt-get install -y gcc-aarch64-linux-gnu libgcc-s1-arm64-cross make
22-
2319
LIBDIR="/usr/aarch64-linux-gnu/lib"
2420
elif [ "$TARGETARCH" = "arm" ]; then
25-
echo "armv7-unknown-linux-gnueabihf" > /tmp/TARGET
26-
echo "arm-linux-gnueabihf-gcc" > /tmp/LINKER
27-
21+
TARGET="armv7-unknown-linux-gnueabihf"
22+
LINKER="arm-linux-gnueabihf-gcc"
2823
apt-get install -y gcc-arm-linux-gnueabihf libgcc-s1-armhf-cross make cmake libclang-dev
29-
3024
cargo install --force --locked bindgen-cli
31-
3225
SYSROOT=$(arm-linux-gnueabihf-gcc -print-sysroot)
33-
echo "--sysroot=$SYSROOT -I$SYSROOT/usr/include -I$SYSROOT/usr/include/arm-linux-gnueabihf" > /tmp/BINDGEN_EXTRA_CLANG_ARGS
34-
26+
BINDGEN_EXTRA_CLANG_ARGS="--sysroot=$SYSROOT -I$SYSROOT/usr/include -I$SYSROOT/usr/include/arm-linux-gnueabihf"
3527
LIBDIR="/usr/arm-linux-gnueabihf/lib"
3628
else
3729
echo "Unsupported cross compilation target: $TARGETARCH"
3830
exit 1
3931
fi
4032

41-
# Copy libgcc_s.so.1 for runtime
4233
mkdir -p /tmp/sqlpage-libs
43-
4434
cp "$LIBDIR/libgcc_s.so.1" /tmp/sqlpage-libs/
45-
46-
# Add the target
47-
rustup target add "$(cat /tmp/TARGET)"
48-
35+
rustup target add "$TARGET"
36+
37+
{
38+
echo "export TARGET='$TARGET'"
39+
echo "export LINKER='$LINKER'"
40+
if [ -n "$BINDGEN_EXTRA_CLANG_ARGS" ]; then
41+
printf "export BINDGEN_EXTRA_CLANG_ARGS=%q\n" "$BINDGEN_EXTRA_CLANG_ARGS"
42+
fi
43+
} > /tmp/build-env.sh

0 commit comments

Comments
 (0)