wee
Multi-Platform CI / test-platforms (ubuntu-22.04) (push) Successful in 22s
Multi-Platform CI / test-platforms (windows-latest) (push) Successful in 18s
Multi-Platform CI / Package for Linux x86_64 (push) Successful in 58s
Multi-Platform CI / Package for Windows x86_64 (push) Successful in 54s

This commit is contained in:
2025-09-23 20:53:25 -07:00
parent 8785546403
commit b1be9d63dc
2 changed files with 51 additions and 57 deletions
+46 -52
View File
@@ -7,7 +7,7 @@ on:
required: true
type: string
target:
description: "The Rust compilation target (e.g., x86_64-pc-windows-gnu). Empty for native."
description: "The Rust compilation target. Empty for native test builds."
required: false
type: string
default: ''
@@ -31,7 +31,7 @@ jobs:
with:
components: clippy, rustfmt
# Steps for linting, testing, etc. These are skipped in 'package-only' mode.
# Normal tests and lints (these will run on the runner's native ARM architecture)
- name: Build
if: ${{ !inputs.package-only }}
run: cargo build --all-features
@@ -54,81 +54,75 @@ jobs:
cargo install cargo-audit
cargo audit
# --- Build & Package Logic ---
- name: Set up Windows cross-compilation environment
- name: Set up Linux x86_64 cross-compilation
if: inputs.target == 'x86_64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y g++-x86-64-linux-gnu
rustup target add x86_64-unknown-linux-gnu
- name: Set up Windows x86_64 cross-compilation
if: inputs.target == 'x86_64-pc-windows-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-mingw-w64-x86-64
rustup target add x86_64-pc-windows-gnu
- name: Build FFI library (Native)
if: inputs.upload-artifacts && inputs.target == ''
run: cargo build --release --features ffi
- name: Build FFI library (Cross-compile for Windows)
if: inputs.upload-artifacts && inputs.target == 'x86_64-pc-windows-gnu'
- name: Build FFI library (Cross-Compile)
if: inputs.upload-artifacts
run: cargo build --release --features ffi --target=${{ inputs.target }}
env:
# Set the correct linker for each target
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER: x86_64-linux-gnu-g++
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER: x86_64-w64-mingw32-gcc
- name: Extract version and create package (Linux)
if: inputs.upload-artifacts && inputs.target == ''
- name: Extract version and create package
if: inputs.upload-artifacts
shell: bash
run: |
VERSION=$(sed -n 's/^version\s*=\s*"\([^"]\+\)"/\1/p' Cargo.toml | head -n1)
# Map runner.arch to Rust target arch
case "${{ runner.arch }}" in
ARM64) ARCH_TRIPLE="aarch64" ;;
X64) ARCH_TRIPLE="x86_64" ;;
*) ARCH_TRIPLE="unknown" ;;
esac
PKG_BASENAME="medicallib_rust-v${VERSION}-${ARCH_TRIPLE}-unknown-linux-gnu"
PKG_DIR="dist/${PKG_BASENAME}"
TARGET_ARCH="x86_64"
TARGET_TRIPLE="${{ inputs.target }}"
# Determine package name and library extension based on target
if [[ "$TARGET_TRIPLE" == "x86_64-unknown-linux-gnu" ]]; then
PKG_BASENAME="medicallib_rust-v${VERSION}-${TARGET_ARCH}-unknown-linux-gnu"
LIB_NAME="libmedicallib_rust.so"
ARCHIVE_TYPE="tar.gz"
elif [[ "$TARGET_TRIPLE" == "x86_64-pc-windows-gnu" ]]; then
PKG_BASENAME="medicallib_rust-v${VERSION}-${TARGET_ARCH}-pc-windows-gnu"
LIB_NAME="medicallib_rust.dll"
ARCHIVE_TYPE="zip"
else
echo "::error::Unsupported target for packaging: $TARGET_TRIPLE"
exit 1
fi
PKG_DIR="dist/${PKG_BASENAME}"
echo "Creating package ${PKG_BASENAME}..."
mkdir -p "${PKG_DIR}/include" "${PKG_DIR}/lib"
cp ffi/medicallib.h "${PKG_DIR}/include/"
cp "target/release/libmedicallib_rust.so" "${PKG_DIR}/lib/"
# Copy header and the compiled library from the correct target-specific directory
cp ffi/medicallib.h "${PKG_DIR}/include/"
cp "target/${TARGET_TRIPLE}/release/${LIB_NAME}" "${PKG_DIR}/lib/"
# Create the appropriate archive
if [[ "$ARCHIVE_TYPE" == "tar.gz" ]]; then
tar -C dist -czf "dist/${PKG_BASENAME}.tar.gz" "${PKG_BASENAME}"
elif [[ "$ARCHIVE_TYPE" == "zip" ]]; then
(cd dist && zip -r9 "${PKG_BASENAME}.zip" "${PKG_BASENAME}")
fi
- name: Extract version and create package (Cross-compiled Windows)
if: inputs.upload-artifacts && inputs.target == 'x86_64-pc-windows-gnu'
shell: bash
run: |
VERSION=$(sed -n 's/^version\s*=\s*"\([^"]\+\)"/\1/p' Cargo.toml | head -n1)
ARCH_TRIPLE="x86_64"
PKG_BASENAME="medicallib_rust-v${VERSION}-${ARCH_TRIPLE}-pc-windows-gnu"
PKG_DIR="dist/${PKG_BASENAME}"
echo "Creating package ${PKG_BASENAME}..."
mkdir -p "${PKG_DIR}/include" "${PKG_DIR}/lib"
cp ffi/medicallib.h "${PKG_DIR}/include/"
# The output path is different for cross-compilation
cp "target/x86_64-pc-windows-gnu/release/medicallib_rust.dll" "${PKG_DIR}/lib/"
(cd dist && zip -r9 "${PKG_BASENAME}.zip" "${PKG_BASENAME}")
# --- Artifact Upload Logic ---
- name: Upload Linux Artifact
if: inputs.upload-artifacts && inputs.target == ''
- name: Upload Artifact
if: inputs.upload-artifacts
uses: https://github.com/christopherHX/gitea-upload-artifact@v4
with:
name: medicallib-rust-Linux-${{ runner.arch }}-${{ github.run_number }}
# Create a unique name based on the target OS
name: medicallib-rust-${{ contains(inputs.target, 'windows') && 'Windows' || 'Linux' }}-x86_64-${{ github.run_number }}
path: |
dist/*.tar.gz
dist/*.zip
if-no-files-found: error
- name: Upload Windows Artifact
if: inputs.upload-artifacts && inputs.target == 'x86_64-pc-windows-gnu'
uses: https://github.com/christopherHX/gitea-upload-artifact@v4
with:
name: medicallib-rust-Windows-x86_64-${{ github.run_number }}
path: dist/*.zip
if-no-files-found: error
+3 -3
View File
@@ -33,11 +33,11 @@ jobs:
matrix:
include:
# Configuration for the native Linux build
- name: Linux
target: '' # An empty target means native build
- name: Linux x86_64
target: 'x86_64-unknown-linux-gnu' # An empty target means native build
# Configuration for the Windows cross-compile build
- name: Windows (Cross-Compiled)
- name: Windows x86_64
target: 'x86_64-pc-windows-gnu'
name: Package for ${{ matrix.name }}