ci(artifacts): build and package demo app artifacts cross-target
Multi-Platform CI / test-platforms (ubuntu-22.04) (push) Successful in 22s
Multi-Platform CI / test-platforms (windows-latest) (push) Successful in 19s
Multi-Platform CI / Package for Linux x86_64 (push) Successful in 2m3s
Multi-Platform CI / Package for Windows x86_64 (push) Successful in 2m3s
Multi-Platform CI / Create GitHub Release (push) Successful in 29s

- cross-compile examples/demo_app with demo-monitor when
  upload-artifacts is true and a target is provided
- package demo binary as medicallib_demo_app-<version>-<triple> archive
  with bin/<demo_app> included
- add strict bash flags, ensure dist dir exists, and fail early if the
  demo binary is missing
- use platform linkers via env for linux/windows GNU targets
- keep existing library package; now upload both artifacts
This commit is contained in:
2025-09-24 03:09:19 -07:00
parent a7638c411a
commit 0e6365bf7f
+29 -1
View File
@@ -79,10 +79,19 @@ jobs:
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: Build demo app (Cross-Compile)
if: inputs.upload-artifacts && inputs.target != ''
run: cargo build --release --example demo_app --features demo-monitor --target=${{ inputs.target }}
env:
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
if: inputs.upload-artifacts
shell: bash
run: |
set -euo pipefail
VERSION=$(sed -n 's/^version\s*=\s*"\([^"]\+\)"/\1/p' Cargo.toml | head -n1)
TARGET_ARCH="x86_64"
TARGET_TRIPLE="${{ inputs.target }}"
@@ -90,17 +99,29 @@ jobs:
# 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"
DEMO_PKG_BASENAME="medicallib_demo_app-v${VERSION}-${TARGET_ARCH}-unknown-linux-gnu"
LIB_NAME="libmedicallib_rust.so"
DEMO_BINARY_NAME="demo_app"
ARCHIVE_TYPE="tar.gz"
elif [[ "$TARGET_TRIPLE" == "x86_64-pc-windows-gnu" ]]; then
PKG_BASENAME="medicallib_rust-v${VERSION}-${TARGET_ARCH}-pc-windows-gnu"
DEMO_PKG_BASENAME="medicallib_demo_app-v${VERSION}-${TARGET_ARCH}-pc-windows-gnu"
LIB_NAME="medicallib_rust.dll"
DEMO_BINARY_NAME="demo_app.exe"
ARCHIVE_TYPE="zip"
else
echo "::error::Unsupported target for packaging: $TARGET_TRIPLE"
exit 1
fi
DEMO_BINARY_SOURCE="target/${TARGET_TRIPLE}/release/examples/${DEMO_BINARY_NAME}"
if [[ ! -f "$DEMO_BINARY_SOURCE" ]]; then
echo "::error::Demo binary not found at $DEMO_BINARY_SOURCE"
exit 1
fi
mkdir -p dist
PKG_DIR="dist/${PKG_BASENAME}"
echo "Creating package ${PKG_BASENAME}..."
mkdir -p "${PKG_DIR}/include" "${PKG_DIR}/lib"
@@ -109,11 +130,18 @@ jobs:
cp ffi/medicallib.h "${PKG_DIR}/include/"
cp "target/${TARGET_TRIPLE}/release/${LIB_NAME}" "${PKG_DIR}/lib/"
DEMO_DIR="dist/${DEMO_PKG_BASENAME}"
echo "Creating demo package ${DEMO_PKG_BASENAME}..."
mkdir -p "${DEMO_DIR}/bin"
cp "$DEMO_BINARY_SOURCE" "${DEMO_DIR}/bin/${DEMO_BINARY_NAME}"
# Create the appropriate archive
if [[ "$ARCHIVE_TYPE" == "tar.gz" ]]; then
tar -C dist -czf "dist/${PKG_BASENAME}.tar.gz" "${PKG_BASENAME}"
tar -C dist -czf "dist/${DEMO_PKG_BASENAME}.tar.gz" "${DEMO_PKG_BASENAME}"
elif [[ "$ARCHIVE_TYPE" == "zip" ]]; then
(cd dist && zip -r9 "${PKG_BASENAME}.zip" "${PKG_BASENAME}")
(cd dist && zip -r9 "${DEMO_PKG_BASENAME}.zip" "${DEMO_PKG_BASENAME}")
fi
- name: Upload Artifact
@@ -123,4 +151,4 @@ jobs:
# 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/
if-no-files-found: error
if-no-files-found: error