Build Native Libs #62
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Native Libs | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
type: string | |
required: true | |
description: Version number (package) | |
nuget: | |
type: boolean | |
description: Publish Package to NuGet | |
permissions: | |
packages: write | |
contents: read | |
jobs: | |
build-platforms: | |
name: Build ${{ matrix.targetname }}-${{ matrix.arch }} | |
runs-on: ${{ matrix.buildos }} | |
env: | |
CMAKE_BUILD_TYPE: Release | |
TRIPLETS_DIR: ${{ github.workspace }}/native/build/triplets | |
ARCHIVE_DIR: ${{ github.workspace }}/archive-${{ matrix.targetname }} | |
BUILD_DIR: ${{ github.workspace }}/build-${{ matrix.arch }} | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- { targetname: osx, buildos: macos-latest, arch: x64, triplet: release-osx-x64 } | |
- { targetname: osx, buildos: macos-latest, arch: arm64, triplet: release-osx-arm64 } | |
- { targetname: linux, buildos: ubuntu-20.04, arch: x64, triplet: release-linux-x64 } | |
- { targetname: linux, buildos: ubuntu-20.04, arch: arm64, triplet: release-linux-arm64 } | |
- { targetname: windows, buildos: windows-latest, arch: x64, triplet: x64-windows-release } | |
- { targetname: windows, buildos: windows-latest, arch: arm64, triplet: release-windows-arm64 } | |
- { targetname: android, buildos: ubuntu-20.04, arch: arm, triplet: release-android-arm } | |
- { targetname: android, buildos: ubuntu-20.04, arch: arm64, triplet: release-android-arm64 } | |
- { targetname: android, buildos: ubuntu-20.04, arch: x86_64, triplet: release-android-x86_64 } | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: 'recursive' | |
fetch-depth: 0 | |
- name: Prepare Environment (Ubuntu/arm64) | |
if: matrix.buildos == 'ubuntu-20.04' && matrix.arch == 'arm64' | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y binutils-aarch64-linux-gnu g++-aarch64-linux-gnu gcc-aarch64-linux-gnu | |
- name: Prepare Environment (Android) | |
if: matrix.targetname == 'android' | |
uses: nttld/setup-ndk@v1 | |
id: setup-ndk | |
with: | |
ndk-version: r27b | |
add-to-path: false | |
- name: Prepare Environment (macOS) | |
if: matrix.buildos == 'macos-latest' | |
run: brew install ninja | |
- name: Setup VCPKG | |
uses: lukka/run-vcpkg@v11 | |
- name: Setup CMake (Linux) | |
if: matrix.targetname == 'linux' | |
run: cmake -B ${{ env.BUILD_DIR }} -S . -DVCPKG_OVERLAY_TRIPLETS=${{ env.TRIPLETS_DIR }} -DVCPKG_TARGET_TRIPLET=${{ matrix.triplet }} | |
env: | |
CMAKE_TOOLCHAIN_FILE: ${{ github.workspace }}/native/build/linux-${{ matrix.arch }}.cmake | |
- name: Setup CMake (Android) | |
if: matrix.targetname == 'android' | |
run: cmake -B ${{ env.BUILD_DIR }} -S . -DVCPKG_OVERLAY_TRIPLETS=${{ env.TRIPLETS_DIR }} -DVCPKG_TARGET_TRIPLET=${{ matrix.triplet }} | |
env: | |
CMAKE_TOOLCHAIN_FILE: ${{ github.workspace }}/native/build/android-${{ matrix.arch }}.cmake | |
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} | |
- name: Setup CMake (Windows) | |
if: matrix.targetname == 'windows' | |
run: cmake -B ${{ env.BUILD_DIR }} -G "Visual Studio 17 2022" -A ${{ matrix.arch == 'arm64' && 'ARM64' || 'x64' }} -S . -DVCPKG_OVERLAY_TRIPLETS=${{ env.TRIPLETS_DIR }} -DVCPKG_TARGET_TRIPLET=${{ matrix.triplet }} | |
env: | |
CMAKE_TOOLCHAIN_FILE: ${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake | |
- name: Setup CMake (macOS) | |
if: matrix.targetname == 'osx' | |
run: cmake -B ${{ env.BUILD_DIR }} -G "Xcode" -S . -DVCPKG_OVERLAY_TRIPLETS=${{ env.TRIPLETS_DIR }} -DVCPKG_TARGET_TRIPLET=${{ matrix.triplet }} | |
env: | |
CMAKE_TOOLCHAIN_FILE: ${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake | |
CMAKE_OSX_ARCHITECTURES: ${{ matrix.arch == 'arm64' && 'arm64' || 'x86_64' }} | |
- name: Build | |
run: cmake --build ${{ env.BUILD_DIR }} --config Release | |
- name: Prepare Directory | |
run: mkdir ${{ env.ARCHIVE_DIR }} | |
- name: Prepare Files (Linux) | |
if: matrix.targetname == 'linux' | |
run: | | |
cp ${{ env.BUILD_DIR }}/libcsdl.so ${{ env.ARCHIVE_DIR }} | |
cp ${{ env.BUILD_DIR }}/vcpkg_installed/${{ matrix.triplet }}/lib/libtorrent-rasterbar.so ${{ env.ARCHIVE_DIR }}/libtorrent-rasterbar.so.2.0 | |
- name: Prepare Files (Android) | |
if: matrix.targetname == 'android' | |
run: | | |
${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip --strip-unneeded -x ${{ env.BUILD_DIR }}/libcsdl.so | |
cp ${{ env.BUILD_DIR }}/libcsdl.so ${{ env.ARCHIVE_DIR }} | |
- name: Prepare Files (macOS) | |
if: matrix.targetname == 'osx' | |
run: | | |
cp ${{ env.BUILD_DIR }}/Release/libcsdl.dylib ${{ env.ARCHIVE_DIR }} | |
cp ${{ env.BUILD_DIR }}/vcpkg_installed/${{ matrix.triplet }}/lib/libtorrent-rasterbar.dylib ${{ env.ARCHIVE_DIR }}/libtorrent-rasterbar.2.0.dylib | |
- name: Prepare Files (Windows) | |
if: matrix.targetname == 'windows' | |
run: cp ${{ env.BUILD_DIR }}/Release/*.dll ${{ env.ARCHIVE_DIR }} | |
- name: Upload | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.targetname }}-${{ matrix.arch }} | |
path: ${{ env.ARCHIVE_DIR }}/* | |
package: | |
name: Build Package | |
runs-on: ubuntu-latest | |
needs: [build-platforms] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: osx-x64 | |
path: native/nuget/runtimes/osx-x64/native | |
- uses: actions/download-artifact@v4 | |
with: | |
name: osx-arm64 | |
path: native/nuget/runtimes/osx-arm64/native | |
- uses: actions/download-artifact@v4 | |
with: | |
name: windows-x64 | |
path: native/nuget/runtimes/win-x64/native | |
- uses: actions/download-artifact@v4 | |
with: | |
name: windows-arm64 | |
path: native/nuget/runtimes/win-arm64/native | |
- uses: actions/download-artifact@v4 | |
with: | |
name: linux-x64 | |
path: native/nuget/runtimes/linux-x64/native | |
- uses: actions/download-artifact@v4 | |
with: | |
name: linux-arm64 | |
path: native/nuget/runtimes/linux-arm64/native | |
- name: Build Package | |
run: dotnet pack -c Release -p:Version=${{ github.event.inputs.version }} -o ./packages native/nuget | |
- name: Publish Package (NuGet) | |
if: github.event.inputs.nuget == 'true' | |
run: dotnet nuget push -s https://api.nuget.org/v3/index.json --skip-duplicate -k ${{ secrets.NUGET_KEY }} ./packages/*.nupkg | |
- name: Publish Package (GitHub) | |
if: github.event.inputs.nuget != 'true' | |
run: dotnet nuget push -s https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json --skip-duplicate -k ${{ github.token }} ./packages/*.nupkg | |
package-android: | |
name: Build Package (Android) | |
runs-on: ubuntu-latest | |
needs: [build-platforms] | |
steps: | |
- name: Install Android workload | |
run: sudo dotnet workload install android | |
- name: Install JDK | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '21' | |
distribution: 'microsoft' | |
- name: Install Android SDK | |
uses: android-actions/setup-android@v3 | |
- uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: android-x86_64 | |
path: native/nuget-android/runtimes/android-x64/native | |
- uses: actions/download-artifact@v4 | |
with: | |
name: android-arm | |
path: native/nuget-android/runtimes/android-arm/native | |
- uses: actions/download-artifact@v4 | |
with: | |
name: android-arm64 | |
path: native/nuget-android/runtimes/android-arm64/native | |
- name: Build Package | |
run: dotnet pack -c Release -p:Version=${{ github.event.inputs.version }} -o ./packages native/nuget-android | |
- name: Publish Package (NuGet) | |
if: github.event.inputs.nuget == 'true' | |
run: dotnet nuget push -s https://api.nuget.org/v3/index.json --skip-duplicate -k ${{ secrets.NUGET_KEY }} ./packages/*.nupkg | |
- name: Publish Package (GitHub) | |
if: github.event.inputs.nuget != 'true' | |
run: dotnet nuget push -s https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json --skip-duplicate -k ${{ github.token }} ./packages/*.nupkg |