Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ jobs:
- name: Checkout code
uses: actions/checkout@v6

- name: Install build tools
run: |
sudo apt-get update
sudo apt-get install -y build-essential

- name: Set up Python
id: setup-python
uses: actions/setup-python@v6
Expand Down Expand Up @@ -51,11 +46,24 @@ jobs:
restore-keys: |
rust-build-${{ runner.os }}-

- name: Compile C code
run: make compile_c
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver: docker-container

- name: Compile Rust code (Linux Lambda target)
run: cargo build --release --target x86_64-unknown-linux-gnu --manifest-path smartscore/Rust/make_predictions/Cargo.toml
- name: Build compiler environment image
uses: docker/build-push-action@v6
with:
context: .
file: build_scripts/Dockerfile
push: false
load: true
tags: smartscore-build-env:latest
cache-from: type=gha,scope=smartscore-build-env
cache-to: type=gha,mode=max,scope=smartscore-build-env

- name: Compile C and Rust code (Linux Lambda target)
run: sh build_scripts/build.sh

- name: Install compiled Rust module into venv
run: |
Expand Down
18 changes: 18 additions & 0 deletions build_scripts/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Compiler environment for SmartScore's C and Rust extensions.
#
# Built on manylinux_2_28 so the produced artifacts link against glibc 2.28,
# making them safe to run on the Amazon Linux 2023 Lambda runtime. The image
# provides gcc/g++/make (for the C extension) plus a pinned Rust toolchain
# (for the pyo3 extension).
#
# The image layers (base + Rust toolchain) are cached in CI via Docker BuildKit
# so the toolchain install only happens once instead of on every run.
FROM quay.io/pypa/manylinux_2_28_x86_64

# Install a pinned Rust toolchain via rustup. "minimal" profile keeps it small.
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \
-y --profile minimal --default-toolchain 1.85.0

ENV PATH="/root/.cargo/bin:${PATH}"

WORKDIR /project
38 changes: 38 additions & 0 deletions build_scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

# Compiles SmartScore's C and Rust extensions inside a single manylinux
# container (see build_scripts/Dockerfile).
#
# In CI the compiler image is built and cached with Docker BuildKit before
# this script runs; if it is missing (e.g. first local use), it is built here.
#
# Outputs (written into the mounted workspace, matching the layout the rest of
# the build/deploy expects):
# smartscore/compiled_code.so
# smartscore/Rust/make_predictions/target/x86_64-unknown-linux-gnu/release/libmake_predictions_rust.so

SCRIPT_DIR=$(dirname "$(realpath "$0")")
PROJECT_PATH=$(dirname "$SCRIPT_DIR")

# Convert to Windows path only when cygpath is available (Git Bash on Windows).
if command -v cygpath.exe >/dev/null 2>&1; then
PROJECT_PATH="$(cygpath.exe -C ANSI -w -p "${PROJECT_PATH}")"
fi

IMAGE=${BUILD_IMAGE:-smartscore-build-env:latest}

# Build the compiler image on first use (local machines).
if ! docker image inspect "$IMAGE" >/dev/null 2>&1; then
echo "Building compiler environment image $IMAGE..."
docker build -t "$IMAGE" -f "$SCRIPT_DIR/Dockerfile" "$PROJECT_PATH"
fi

echo "Compiling C and Rust code in $IMAGE..."
docker run --rm -v "$PROJECT_PATH:/project" "$IMAGE" sh -c "
cd /project
make compile_c
cd /project/smartscore/Rust/make_predictions
cargo build --release --target x86_64-unknown-linux-gnu
"

echo "Compilation completed. Check the artifacts in $PROJECT_PATH/smartscore/"
30 changes: 0 additions & 30 deletions build_scripts/compile.sh

This file was deleted.

14 changes: 3 additions & 11 deletions build_scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,9 @@ if [ "${DEPLOY_SKIP_BUILD:-0}" = "1" ]; then
fi
echo "Skipping C/Rust compilation (reusing artifacts from CI setup job)..."
else
# compile C code
echo "Compiling C code..."
sh build_scripts/compile.sh
if [ $? -ne 0 ]; then
echo "Error: Compilation failed. Ensure docker is running."
exit 1
fi

# compile Rust code
echo "Compiling Rust code..."
sh build_scripts/rust_compile.sh
# compile C and Rust code
echo "Compiling C and Rust code..."
sh build_scripts/build.sh
if [ $? -ne 0 ]; then
echo "Error: Compilation failed. Ensure docker is running."
exit 1
Expand Down
33 changes: 0 additions & 33 deletions build_scripts/rust_compile.sh

This file was deleted.

Loading