diff --git a/.gitea/workflows/ci-reusable.yml b/.gitea/workflows/ci-reusable.yml index 01c8cb4..94d3c74 100644 --- a/.gitea/workflows/ci-reusable.yml +++ b/.gitea/workflows/ci-reusable.yml @@ -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 @@ -39,7 +39,7 @@ jobs: - name: Test if: ${{ !inputs.package-only }} run: cargo test --all-features - + - name: Clippy if: ${{ !inputs.package-only }} run: cargo clippy --all-targets --all-features -- -D warnings @@ -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" + + # Copy header and the compiled library from the correct target-specific directory cp ffi/medicallib.h "${PKG_DIR}/include/" - cp "target/release/libmedicallib_rust.so" "${PKG_DIR}/lib/" + cp "target/${TARGET_TRIPLE}/release/${LIB_NAME}" "${PKG_DIR}/lib/" - tar -C dist -czf "dist/${PKG_BASENAME}.tar.gz" "${PKG_BASENAME}" - (cd dist && zip -r9 "${PKG_BASENAME}.zip" "${PKG_BASENAME}") + # 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 \ No newline at end of file diff --git a/.gitea/workflows/multi-platform.yml b/.gitea/workflows/multi-platform.yml index 3b25dc8..0930bb1 100644 --- a/.gitea/workflows/multi-platform.yml +++ b/.gitea/workflows/multi-platform.yml @@ -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 }}