Dockerfile: extract scripts to separate files
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
# Docker Build Scripts
|
||||
|
||||
This directory contains scripts used by the Dockerfile to build SQLPage with cross-compilation support.
|
||||
|
||||
## Scripts
|
||||
|
||||
- **`setup-cross-compilation.sh`**: Sets up the cross-compilation environment based on target and build architectures. Handles system dependencies, cross-compiler installation, and libgcc extraction for runtime.
|
||||
- **`build-dependencies.sh`**: Builds only the project dependencies for Docker layer caching
|
||||
- **`build-project.sh`**: Builds the final SQLPage binary
|
||||
|
||||
## Usage
|
||||
|
||||
These scripts are automatically copied and executed by the Dockerfile during the build process. They handle:
|
||||
|
||||
- Cross-compilation setup for different architectures (amd64, arm64, arm)
|
||||
- System dependencies installation
|
||||
- Cargo build configuration with appropriate linkers
|
||||
- Library extraction for runtime
|
||||
|
||||
The scripts use temporary files in `/tmp/` to pass configuration between stages and export environment variables for use in subsequent build steps.
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#!/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)"
|
||||
|
||||
echo "Building dependencies for target: $TARGET"
|
||||
|
||||
# Build dependencies only (for Docker layer caching)
|
||||
cargo build \
|
||||
--target "$TARGET" \
|
||||
--config "target.$TARGET.linker=\"$LINKER\"" \
|
||||
--features odbc-static \
|
||||
--profile superoptimized
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
# Source the environment variables set by setup-cross-compilation.sh
|
||||
TARGET="$(cat /tmp/TARGET)"
|
||||
LINKER="$(cat /tmp/LINKER)"
|
||||
|
||||
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
|
||||
Executable
+55
@@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
TARGETARCH="$1"
|
||||
BUILDARCH="$2"
|
||||
|
||||
if [ "$TARGETARCH" = "$BUILDARCH" ]; then
|
||||
# Native build
|
||||
rustup target list --installed > /tmp/TARGET
|
||||
echo "gcc" > /tmp/LINKER
|
||||
apt-get install -y gcc libgcc-s1 cmake pkg-config
|
||||
|
||||
LIBDIR="/lib/$(gcc -print-multiarch)"
|
||||
|
||||
elif [ "$TARGETARCH" = "arm64" ]; then
|
||||
echo "aarch64-unknown-linux-gnu" > /tmp/TARGET
|
||||
echo "aarch64-linux-gnu-gcc" > /tmp/LINKER
|
||||
|
||||
apt-get update
|
||||
apt-get install -y gcc-aarch64-linux-gnu libgcc-s1-arm64-cross pkg-config
|
||||
|
||||
LIBDIR="/usr/aarch64-linux-gnu/lib"
|
||||
|
||||
# Also install gcc for aarch64 to get libgcc
|
||||
apt-get install -y gcc-aarch64-linux-gnu
|
||||
|
||||
elif [ "$TARGETARCH" = "arm" ]; then
|
||||
echo "armv7-unknown-linux-gnueabihf" > /tmp/TARGET
|
||||
echo "arm-linux-gnueabihf-gcc" > /tmp/LINKER
|
||||
|
||||
apt-get update
|
||||
apt-get install -y gcc-arm-linux-gnueabihf libgcc-s1-armhf-cross cmake libclang1 clang pkg-config
|
||||
|
||||
# Ensure gcc-arm-linux-gnueabihf is available
|
||||
apt-get install -y gcc-arm-linux-gnueabihf
|
||||
|
||||
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
|
||||
|
||||
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/
|
||||
|
||||
# Add the target
|
||||
rustup target add "$(cat /tmp/TARGET)"
|
||||
|
||||
Reference in New Issue
Block a user