diff --git a/.github/workflows/koana.yml b/.github/workflows/koana.yml index 1e126c1..11544b7 100644 --- a/.github/workflows/koana.yml +++ b/.github/workflows/koana.yml @@ -1,4 +1,5 @@ name: Build koana + on: workflow_dispatch: push: @@ -6,421 +7,500 @@ on: - master paths: - '.github/workflows/koana.yml' + pull_request: + branches: + - master + paths: + - '.github/workflows/koana.yml' + +env: + UPSTREAM_REPO: DSharpPlus/libkoana + OPENSSL_VERSION: openssl-3.6.2 + MACOSX_DEPLOYMENT_TARGET: "11.0" + ALPINE_VERSION: "3.24.1" + CFLAGS_LIN_X64: "-march=x86-64-v2" + CFLAGS_LIN_ARM: "-march=armv8-a" + CFLAGS_MAC_X64: "-march=x86-64-v2" + CFLAGS_MAC_ARM: "-mcpu=apple-m1" + CFLAGS_WIN_X64: "/arch:SSE4.2" + CFLAGS_WIN_ARM: "/arch:armv8.0" jobs: version: - runs-on: ubuntu-latest + runs-on: ubuntu-26.04 outputs: - version: ${{ steps.print-version.outputs.version }} + tag: ${{ steps.detect.outputs.tag }} + version: ${{ steps.detect.outputs.version }} steps: - - name: Clone koana repo + - name: Clone upstream uses: actions/checkout@v6 with: - repository: DSharpPlus/libkoana - - - name: Print version - id: print-version + repository: ${{ env.UPSTREAM_REPO }} + + - name: Detect latest tag + id: detect shell: bash run: | git fetch --tags - LATEST_TAG=$(git tag | grep -E ^v[0-9]+.[0-9]+.[0-9]+$ | tail -1) - git checkout "$LATEST_TAG" - echo "version=$LATEST_TAG" >> $GITHUB_OUTPUT + TAG=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -1) + echo "tag=$TAG" >> "$GITHUB_OUTPUT" + echo "version=${TAG#v}" >> "$GITHUB_OUTPUT" build-windows-x64: - runs-on: windows-latest + runs-on: windows-2025-vs2026 needs: version steps: - - name: Clone koana repo + - name: Clone koana uses: actions/checkout@v6 with: - repository: DSharpPlus/libkoana - ref: ${{needs.version.outputs.version}} + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} - - name: Setup VS build tools - uses: seanmiddleditch/gha-setup-vsdevenv@v5 - with: - host_arch: amd64 - arch: amd64 - - - name: Install nasm + - name: Install nasm and jom shell: pwsh - run: | - choco install nasm - + run: choco install nasm jom + - name: Build openssl shell: pwsh + env: + CL: ${{ env.CFLAGS_WIN_X64 }} run: | + $vsPath = & "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -property installationPath + Import-Module (Join-Path $vsPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll") + Enter-VsDevShell -VsInstallPath $vsPath -SkipAutomaticLocation -Arch amd64 -HostArch amd64 git clone https://github.com/openssl/openssl cd openssl - git checkout openssl-3.6.2 + git checkout $env:OPENSSL_VERSION $env:PATH += ";C:\Program Files\NASM" - C:\Strawberry\perl\bin\perl.exe Configure no-makedepend VC-WIN64A - nmake - + C:\Strawberry\perl\bin\perl.exe Configure no-makedepend VC-WIN64A /FS + jom + - name: Build koana shell: pwsh + env: + CL: ${{ env.CFLAGS_WIN_X64 }} run: | - cmake -B build -A x64 -DOPENSSL_ROOT_DIR=".\openssl\" -DOPENSSL_CRYPTO_LIBRARY=".\openssl\libcrypto_static.lib" -DOPENSSL_SSL_LIBRARY=".\openssl\libssl_static.lib" -DOPENSSL_INCLUDE_DIR=".\openssl\include\" + cmake -B build -A x64 ` + -DOPENSSL_ROOT_DIR=".\openssl\" ` + -DOPENSSL_CRYPTO_LIBRARY=".\openssl\libcrypto_static.lib" ` + -DOPENSSL_SSL_LIBRARY=".\openssl\libssl_static.lib" ` + -DOPENSSL_INCLUDE_DIR=".\openssl\include\" cmake --build build --config Release --parallel - - name: Rename native + - name: Stage artifact shell: bash - run: mv build/Release/koana.dll build/Release/koana-win-x64.dll - - - name: Publish Artifacts + run: | + mkdir artifact + cp build/Release/koana.dll artifact/koana.dll + + - name: Upload artifact uses: actions/upload-artifact@v7 with: - name: koana-windows-x64 - path: build/Release/koana-win-x64.dll + name: koana-win-x64 + path: artifact + compression-level: 9 build-windows-arm64: - runs-on: windows-11-arm + runs-on: windows-11-vs2026-arm needs: version steps: - - name: Clone koana repo + - name: Clone koana uses: actions/checkout@v6 with: - repository: DSharpPlus/libkoana - ref: ${{needs.version.outputs.version}} + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} - - name: Setup VS build tools - uses: seanmiddleditch/gha-setup-vsdevenv@v5 - with: - host_arch: arm64 - arch: arm64 - - - name: Install nasm + - name: Install nasm and jom shell: pwsh - run: | - choco install nasm - + run: choco install nasm jom + - name: Build openssl shell: pwsh + env: + CL: ${{ env.CFLAGS_WIN_ARM }} run: | + $vsPath = & "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -property installationPath + Import-Module (Join-Path $vsPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll") + Enter-VsDevShell -VsInstallPath $vsPath -SkipAutomaticLocation -Arch arm64 -HostArch arm64 git clone https://github.com/openssl/openssl cd openssl - git checkout openssl-3.6.2 + git checkout $env:OPENSSL_VERSION $env:PATH += ";C:\Program Files\NASM" - C:\Strawberry\perl\bin\perl.exe Configure no-makedepend VC-WIN64-ARM - nmake - + C:\Strawberry\perl\bin\perl.exe Configure no-makedepend VC-WIN64-ARM /FS + jom + - name: Build koana shell: pwsh + env: + CL: ${{ env.CFLAGS_WIN_ARM }} run: | - cmake -B build -A ARM64 -DOPENSSL_ROOT_DIR=".\openssl\" -DOPENSSL_CRYPTO_LIBRARY=".\openssl\libcrypto_static.lib" -DOPENSSL_SSL_LIBRARY=".\openssl\libssl_static.lib" -DOPENSSL_INCLUDE_DIR=".\openssl\include\" + cmake -B build -A ARM64 ` + -DOPENSSL_ROOT_DIR=".\openssl\" ` + -DOPENSSL_CRYPTO_LIBRARY=".\openssl\libcrypto_static.lib" ` + -DOPENSSL_SSL_LIBRARY=".\openssl\libssl_static.lib" ` + -DOPENSSL_INCLUDE_DIR=".\openssl\include\" cmake --build build --config Release --parallel - - name: Rename native + - name: Stage artifact shell: bash - run: mv build/Release/koana.dll build/Release/koana-win-arm64.dll - - - name: Publish Artifacts + run: | + mkdir artifact + cp build/Release/koana.dll artifact/koana.dll + + - name: Upload artifact uses: actions/upload-artifact@v7 with: - name: koana-windows-arm64 - path: build/Release/koana-win-arm64.dll + name: koana-win-arm64 + path: artifact + compression-level: 9 build-linux-x64: - runs-on: ubuntu-latest + runs-on: ubuntu-26.04 needs: version steps: - - name: Clone koana repo + - name: Clone koana uses: actions/checkout@v6 with: - repository: DSharpPlus/libkoana - ref: ${{needs.version.outputs.version}} - + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + - name: Install build tools shell: bash run: | sudo apt update - sudo apt install cmake - + sudo apt install -y cmake + - name: Build openssl shell: bash + env: + CFLAGS: ${{ env.CFLAGS_LIN_X64 }} + CXXFLAGS: ${{ env.CFLAGS_LIN_X64 }} run: | git clone https://github.com/openssl/openssl cd openssl - git checkout openssl-3.6.2 + git checkout "$OPENSSL_VERSION" ./Configure no-makedepend linux-x86_64 - make -j4 - + make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu) + - name: Build koana shell: bash + env: + CFLAGS: ${{ env.CFLAGS_LIN_X64 }} + CXXFLAGS: ${{ env.CFLAGS_LIN_X64 }} run: | - cmake -B build -DCMAKE_BUILD_TYPE=Release -DOPENSSL_ROOT_DIR="./openssl/" -DOPENSSL_CRYPTO_LIBRARY="./openssl/libcrypto.so" -DOPENSSL_SSL_LIBRARY="./openssl/libssl.so" -DOPENSSL_INCLUDE_DIR="./openssl/include/" + cmake -B build -DCMAKE_BUILD_TYPE=Release \ + -DOPENSSL_ROOT_DIR="./openssl/" \ + -DOPENSSL_CRYPTO_LIBRARY="./openssl/libcrypto.so" \ + -DOPENSSL_SSL_LIBRARY="./openssl/libssl.so" \ + -DOPENSSL_INCLUDE_DIR="./openssl/include/" cmake --build build --parallel - - name: Rename native + - name: Stage artifact shell: bash - run: mv build/libkoana.so build/libkoana-linux-x64.so - - - name: Publish Artifacts + run: | + mkdir artifact + cp build/libkoana.so artifact/libkoana.so + + - name: Upload artifact uses: actions/upload-artifact@v7 with: name: koana-linux-x64 - path: build/libkoana-linux-x64.so + path: artifact + compression-level: 9 build-linux-arm64: - runs-on: ubuntu-24.04-arm + runs-on: ubuntu-26.04-arm needs: version steps: - - name: Clone koana repo + - name: Clone koana uses: actions/checkout@v6 with: - repository: DSharpPlus/libkoana - ref: ${{needs.version.outputs.version}} - + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + - name: Install build tools shell: bash run: | sudo apt update - sudo apt install cmake - + sudo apt install -y cmake + - name: Build openssl shell: bash + env: + CFLAGS: ${{ env.CFLAGS_LIN_ARM }} + CXXFLAGS: ${{ env.CFLAGS_LIN_ARM }} run: | git clone https://github.com/openssl/openssl cd openssl - git checkout openssl-3.6.2 + git checkout "$OPENSSL_VERSION" ./Configure no-makedepend linux-aarch64 - make -j4 - + make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu) + - name: Build koana shell: bash + env: + CFLAGS: ${{ env.CFLAGS_LIN_ARM }} + CXXFLAGS: ${{ env.CFLAGS_LIN_ARM }} run: | - cmake -B build -DCMAKE_BUILD_TYPE=Release -DOPENSSL_ROOT_DIR="./openssl/" -DOPENSSL_CRYPTO_LIBRARY="./openssl/libcrypto.so" -DOPENSSL_SSL_LIBRARY="./openssl/libssl.so" -DOPENSSL_INCLUDE_DIR="./openssl/include/" + cmake -B build -DCMAKE_BUILD_TYPE=Release \ + -DOPENSSL_ROOT_DIR="./openssl/" \ + -DOPENSSL_CRYPTO_LIBRARY="./openssl/libcrypto.so" \ + -DOPENSSL_SSL_LIBRARY="./openssl/libssl.so" \ + -DOPENSSL_INCLUDE_DIR="./openssl/include/" cmake --build build --parallel - - name: Rename native + - name: Stage artifact shell: bash - run: mv build/libkoana.so build/libkoana-linux-arm64.so - - - name: Publish Artifacts + run: | + mkdir artifact + cp build/libkoana.so artifact/libkoana.so + + - name: Upload artifact uses: actions/upload-artifact@v7 with: name: koana-linux-arm64 - path: build/libkoana-linux-arm64.so + path: artifact + compression-level: 9 build-macos-x64: - runs-on: macos-latest + runs-on: macos-26-intel needs: version steps: - - name: Clone koana repo + - name: Clone koana uses: actions/checkout@v6 with: - repository: DSharpPlus/libkoana - ref: ${{needs.version.outputs.version}} - + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + - name: Install nasm shell: bash + # aws/tap prints some warnings, we don't use it, yeet it run: | + brew untap aws/tap || true brew install nasm - + - name: Build openssl shell: bash + env: + CFLAGS: ${{ env.CFLAGS_MAC_X64 }} + CXXFLAGS: ${{ env.CFLAGS_MAC_X64 }} run: | git clone https://github.com/openssl/openssl cd openssl - git checkout openssl-3.6.2 + git checkout "$OPENSSL_VERSION" ./Configure no-makedepend no-shared darwin64-x86_64-cc - make -j4 - + make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu) + - name: Build koana shell: bash + env: + CFLAGS: ${{ env.CFLAGS_MAC_X64 }} + CXXFLAGS: ${{ env.CFLAGS_MAC_X64 }} run: | - cmake -B build -DOPENSSL_ROOT_DIR="./openssl/" -DOPENSSL_CRYPTO_LIBRARY="./openssl/libcrypto.a" -DOPENSSL_SSL_LIBRARY="./openssl/libssl.a" -DOPENSSL_INCLUDE_DIR="./openssl/include/" -DCMAKE_OSX_ARCHITECTURES=x86_64 + cmake -B build -DCMAKE_OSX_ARCHITECTURES=x86_64 \ + -DOPENSSL_ROOT_DIR="./openssl/" \ + -DOPENSSL_CRYPTO_LIBRARY="./openssl/libcrypto.a" \ + -DOPENSSL_SSL_LIBRARY="./openssl/libssl.a" \ + -DOPENSSL_INCLUDE_DIR="./openssl/include/" cmake --build build --config Release --parallel - - name: Rename native + - name: Stage artifact shell: bash - run: mv build/libkoana.dylib build/libkoana-osx-x64.dylib - - - name: Publish Artifacts + run: | + mkdir artifact + cp build/libkoana.dylib artifact/libkoana.dylib + + - name: Upload artifact uses: actions/upload-artifact@v7 with: - name: koana-macos-x64 - path: build/libkoana-osx-x64.dylib + name: koana-osx-x64 + path: artifact + compression-level: 9 build-macos-arm64: - runs-on: macos-latest + runs-on: macos-26 needs: version steps: - - name: Clone koana repo + - name: Clone koana uses: actions/checkout@v6 with: - repository: DSharpPlus/libkoana - ref: ${{needs.version.outputs.version}} - + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + - name: Install nasm shell: bash + # aws/tap prints some warnings, we don't use it, yeet it run: | + brew untap aws/tap || true brew install nasm - + - name: Build openssl shell: bash + env: + CFLAGS: ${{ env.CFLAGS_MAC_ARM }} + CXXFLAGS: ${{ env.CFLAGS_MAC_ARM }} run: | git clone https://github.com/openssl/openssl cd openssl - git checkout openssl-3.6.2 + git checkout "$OPENSSL_VERSION" ./Configure no-makedepend no-shared darwin64-arm64-cc - make -j4 - + make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu) + - name: Build koana shell: bash + env: + CFLAGS: ${{ env.CFLAGS_MAC_ARM }} + CXXFLAGS: ${{ env.CFLAGS_MAC_ARM }} run: | - cmake -B build -DOPENSSL_ROOT_DIR="./openssl/" -DOPENSSL_CRYPTO_LIBRARY="./openssl/libcrypto.a" -DOPENSSL_SSL_LIBRARY="./openssl/libssl.a" -DOPENSSL_INCLUDE_DIR="./openssl/include/" -DCMAKE_OSX_ARCHITECTURES=arm64 + cmake -B build -DCMAKE_OSX_ARCHITECTURES=arm64 \ + -DOPENSSL_ROOT_DIR="./openssl/" \ + -DOPENSSL_CRYPTO_LIBRARY="./openssl/libcrypto.a" \ + -DOPENSSL_SSL_LIBRARY="./openssl/libssl.a" \ + -DOPENSSL_INCLUDE_DIR="./openssl/include/" cmake --build build --config Release --parallel - - name: Rename native + - name: Stage artifact shell: bash - run: mv build/libkoana.dylib build/libkoana-osx-arm64.dylib - - - name: Publish Artifacts + run: | + mkdir artifact + cp build/libkoana.dylib artifact/libkoana.dylib + + - name: Upload artifact uses: actions/upload-artifact@v7 with: - name: koana-macos-arm64 - path: build/libkoana-osx-arm64.dylib + name: koana-osx-arm64 + path: artifact + compression-level: 9 build-musl-x64: - runs-on: ubuntu-latest + runs-on: ubuntu-26.04 needs: version steps: - - name: Clone koana repo + - name: Clone koana uses: actions/checkout@v6 with: - repository: DSharpPlus/libkoana - ref: ${{needs.version.outputs.version}} - - - name: Setup Alpine Linux - uses: jirutka/setup-alpine@v1 - with: - packages: > - build-base - cmake - git - make - gcc - g++ - nasm - perl - linux-headers - - - name: Build openssl - shell: alpine.sh {0} - run: | - git clone https://github.com/openssl/openssl - cd openssl - git checkout openssl-3.6.2 - ./Configure no-makedepend linux-x86_64 - make -j4 - - - name: Build koana - shell: alpine.sh {0} + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + + - name: Build koana in Alpine + env: + CFLAGS: ${{ env.CFLAGS_LIN_X64 }} + CXXFLAGS: ${{ env.CFLAGS_LIN_X64 }} run: | - cmake -B build -DCMAKE_BUILD_TYPE=Release -DOPENSSL_ROOT_DIR="./openssl/" -DOPENSSL_CRYPTO_LIBRARY="./openssl/libcrypto.so" -DOPENSSL_SSL_LIBRARY="./openssl/libssl.so" -DOPENSSL_INCLUDE_DIR="./openssl/include/" - cmake --build build --parallel + docker run --rm -v "$PWD:/src" -w /src \ + -e CFLAGS -e CXXFLAGS -e OPENSSL_VERSION \ + alpine:$ALPINE_VERSION sh -ec ' + apk add --no-cache build-base cmake git make gcc g++ nasm perl linux-headers + git clone https://github.com/openssl/openssl + cd openssl + git checkout "$OPENSSL_VERSION" + ./Configure no-makedepend linux-x86_64 + make -j"$(nproc)" + cd .. + cmake -B build -DCMAKE_BUILD_TYPE=Release \ + -DOPENSSL_ROOT_DIR="./openssl/" \ + -DOPENSSL_CRYPTO_LIBRARY="./openssl/libcrypto.so" \ + -DOPENSSL_SSL_LIBRARY="./openssl/libssl.so" \ + -DOPENSSL_INCLUDE_DIR="./openssl/include/" + cmake --build build --parallel + ' - - name: Rename native + - name: Stage artifact shell: bash - run: mv build/libkoana.so build/libkoana-musl-x64.so - - - name: Publish Artifacts + run: | + mkdir artifact + cp build/libkoana.so artifact/libkoana.so + + - name: Upload artifact uses: actions/upload-artifact@v7 with: - name: koana-musl-x64 - path: build/libkoana-musl-x64.so + name: koana-linux-musl-x64 + path: artifact + compression-level: 9 build-musl-arm64: - runs-on: ubuntu-latest + runs-on: ubuntu-26.04-arm needs: version steps: - - name: Clone koana repo + - name: Clone koana uses: actions/checkout@v6 with: - repository: DSharpPlus/libkoana - ref: ${{needs.version.outputs.version}} - - - name: Setup Alpine Linux - uses: jirutka/setup-alpine@v1 - with: - arch: aarch64 - packages: > - build-base - cmake - git - make - gcc - g++ - nasm - perl - linux-headers - - - name: Build openssl - shell: alpine.sh {0} - run: | - git clone https://github.com/openssl/openssl - cd openssl - git checkout openssl-3.6.2 - ./Configure no-makedepend linux-aarch64 - make -j4 - - - name: Build koana - shell: alpine.sh {0} + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + + - name: Build koana in Alpine + env: + CFLAGS: ${{ env.CFLAGS_LIN_ARM }} + CXXFLAGS: ${{ env.CFLAGS_LIN_ARM }} run: | - cmake -B build -DCMAKE_BUILD_TYPE=Release -DOPENSSL_ROOT_DIR="./openssl/" -DOPENSSL_CRYPTO_LIBRARY="./openssl/libcrypto.so" -DOPENSSL_SSL_LIBRARY="./openssl/libssl.so" -DOPENSSL_INCLUDE_DIR="./openssl/include/" - cmake --build build --parallel - - - name: Rename native + docker run --rm -v "$PWD:/src" -w /src \ + -e CFLAGS -e CXXFLAGS -e OPENSSL_VERSION \ + alpine:$ALPINE_VERSION sh -ec ' + apk add --no-cache build-base cmake git make gcc g++ nasm perl linux-headers + git clone https://github.com/openssl/openssl + cd openssl + git checkout "$OPENSSL_VERSION" + ./Configure no-makedepend linux-aarch64 + make -j"$(nproc)" + cd .. + cmake -B build -DCMAKE_BUILD_TYPE=Release \ + -DOPENSSL_ROOT_DIR="./openssl/" \ + -DOPENSSL_CRYPTO_LIBRARY="./openssl/libcrypto.so" \ + -DOPENSSL_SSL_LIBRARY="./openssl/libssl.so" \ + -DOPENSSL_INCLUDE_DIR="./openssl/include/" + cmake --build build --parallel + ' + + - name: Stage artifact shell: bash - run: mv build/libkoana.so build/libkoana-musl-arm64.so - - - name: Publish Artifacts + run: | + mkdir artifact + cp build/libkoana.so artifact/libkoana.so + + - name: Upload artifact uses: actions/upload-artifact@v7 with: - name: koana-musl-arm64 - path: build/libkoana-musl-arm64.so + name: koana-linux-musl-arm64 + path: artifact + compression-level: 9 publish-nuget: - runs-on: ubuntu-latest - needs: [version, build-windows-x64, build-windows-arm64, build-linux-x64, build-linux-arm64, build-macos-x64, build-macos-arm64, build-musl-x64, build-musl-arm64] + runs-on: ubuntu-26.04 + if: github.event_name != 'pull_request' permissions: id-token: write + needs: + - version + - build-windows-x64 + - build-windows-arm64 + - build-linux-x64 + - build-linux-arm64 + - build-macos-x64 + - build-macos-arm64 + - build-musl-x64 + - build-musl-arm64 steps: - - name: Checkout CSPROJ files + - name: Checkout Natives repo uses: actions/checkout@v6 - name: Setup .NET - uses: actions/setup-dotnet@v4 + uses: actions/setup-dotnet@v5 with: dotnet-version: 9 - - name: Download Artifacts - uses: actions/download-artifact@v4 + - name: Download artifacts + uses: actions/download-artifact@v8 with: path: temp pattern: koana-* - merge-multiple: true - - name: Move Artifacts + - name: Assemble runtime tree + shell: bash run: | - mkdir -p lib/koana/win-x64/native - mkdir -p lib/koana/linux-x64/native - mkdir -p lib/koana/win-arm64/native - mkdir -p lib/koana/linux-arm64/native - mkdir -p lib/koana/osx-x64/native - mkdir -p lib/koana/osx-arm64/native - mkdir -p lib/koana/linux-musl-x64/native - mkdir -p lib/koana/linux-musl-arm64/native - cp temp/koana-win-x64.dll lib/koana/win-x64/native/koana.dll - cp temp/libkoana-linux-x64.so lib/koana/linux-x64/native/libkoana.so - cp temp/koana-win-arm64.dll lib/koana/win-arm64/native/koana.dll - cp temp/libkoana-linux-arm64.so lib/koana/linux-arm64/native/libkoana.so - cp temp/libkoana-osx-x64.dylib lib/koana/osx-x64/native/libkoana.dylib - cp temp/libkoana-osx-arm64.dylib lib/koana/osx-arm64/native/libkoana.dylib - cp temp/libkoana-musl-x64.so lib/koana/linux-musl-x64/native/libkoana.so - cp temp/libkoana-musl-arm64.so lib/koana/linux-musl-arm64/native/libkoana.so + for rid in win-x64 win-arm64 linux-x64 linux-arm64 osx-x64 osx-arm64 linux-musl-x64 linux-musl-arm64; do + mkdir -p "lib/koana/$rid/native" + cp "temp/koana-$rid"/* "lib/koana/$rid/native/" + done - name: Login to NuGet id: nuget-login @@ -428,12 +508,11 @@ jobs: with: user: ${{ secrets.NUGET_USER }} - - name: Pack DSharpPlus.Natives.Koana + - name: Pack and push shell: bash env: NUGET_API_KEY: ${{ steps.nuget-login.outputs.NUGET_API_KEY }} VERSION: ${{ needs.version.outputs.version }} run: | - VERSION="${VERSION:1}" dotnet pack ./build/DSharpPlus.Natives.Koana.csproj -c Release -p:Version="$VERSION.${{ github.run_number }}" dotnet nuget push "artifacts/**" --skip-duplicate -k "$NUGET_API_KEY" -s https://api.nuget.org/v3/index.json diff --git a/.github/workflows/opus.yml b/.github/workflows/opus.yml index c781d65..6d245da 100644 --- a/.github/workflows/opus.yml +++ b/.github/workflows/opus.yml @@ -1,4 +1,5 @@ name: Build opus + on: workflow_dispatch: push: @@ -6,184 +7,353 @@ on: - master paths: - '.github/workflows/opus.yml' + pull_request: + branches: + - master + paths: + - '.github/workflows/opus.yml' env: - COMMON_CMAKE_FLAGS: "-DOPUS_BUILD_SHARED_LIBRARY=ON -DCMAKE_BUILD_TYPE=Release" + UPSTREAM_REPO: DSharpPlus/opus + CMAKE_FLAGS: -DOPUS_BUILD_SHARED_LIBRARY=ON -DCMAKE_BUILD_TYPE=Release + MACOSX_DEPLOYMENT_TARGET: "11.0" + ALPINE_VERSION: "3.24.1" + CFLAGS_LIN_X64: "-march=x86-64-v2" + CFLAGS_LIN_ARM: "-march=armv8-a" + CFLAGS_MAC_X64: "-march=x86-64-v2" + CFLAGS_MAC_ARM: "-mcpu=apple-m1" + CFLAGS_WIN_X64: "/arch:SSE4.2" + CFLAGS_WIN_ARM: "/arch:armv8.0" jobs: - build: - name: Build opus - runs-on: ${{ matrix.os }} - + version: + runs-on: ubuntu-26.04 outputs: - version: ${{ steps.print-version.outputs.version }} + tag: ${{ steps.detect.outputs.tag }} + version: ${{ steps.detect.outputs.version }} + steps: + - name: Clone upstream + uses: actions/checkout@v6 + with: + repository: ${{ env.UPSTREAM_REPO }} + + - name: Detect latest tag + id: detect + shell: bash + run: | + git fetch --tags + TAG=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+(\.[0-9]+)?$' | head -1) + echo "tag=$TAG" >> "$GITHUB_OUTPUT" + echo "version=${TAG#v}" >> "$GITHUB_OUTPUT" - strategy: - fail-fast: false # Run the other two OSs even if one fails - matrix: - os: [ windows-latest, ubuntu-latest, macos-latest ] - + build-windows-x64: + runs-on: windows-2025-vs2026 + needs: version steps: - - name: Clone opus repo + - name: Clone opus uses: actions/checkout@v6 with: - repository: DSharpPlus/opus + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} submodules: recursive - - name: Checkout latest Tag - id: print-version + - name: Build opus shell: bash + env: + CL: ${{ env.CFLAGS_WIN_X64 }} run: | - git fetch --tags - LATEST_TAG=$(git tag | grep -E ^v[0-9]+.[0-9]+.[0-9]+$ | tail -1) - echo "version=$LATEST_TAG" >> $GITHUB_OUTPUT - + cmake -B build -A x64 $CMAKE_FLAGS + cmake --build build --config Release --parallel + + - name: Stage artifact + shell: bash + run: | + mkdir artifact + cp build/Release/opus.dll artifact/opus.dll + + - name: Upload artifact + uses: actions/upload-artifact@v7 + with: + name: opus-win-x64 + path: artifact + compression-level: 9 + + build-windows-arm64: + runs-on: windows-11-vs2026-arm + needs: version + steps: + - name: Clone opus + uses: actions/checkout@v6 + with: + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + submodules: recursive + + - name: Build opus + shell: bash + env: + CL: ${{ env.CFLAGS_WIN_ARM }} + # disable run-time NEON detection, see xiph/opus#340 + run: | + cmake -B build -A ARM64 $CMAKE_FLAGS -DOPUS_PRESUME_NEON=ON -DOPUS_MAY_HAVE_NEON=OFF + cmake --build build --config Release --parallel + + - name: Stage artifact + shell: bash + run: | + mkdir artifact + cp build/Release/opus.dll artifact/opus.dll + + - name: Upload artifact + uses: actions/upload-artifact@v7 + with: + name: opus-win-arm64 + path: artifact + compression-level: 9 + + build-linux-x64: + runs-on: ubuntu-26.04 + needs: version + steps: + - name: Clone opus + uses: actions/checkout@v6 + with: + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + submodules: recursive + + - name: Build opus + shell: bash + env: + CFLAGS: ${{ env.CFLAGS_LIN_X64 }} + CXXFLAGS: ${{ env.CFLAGS_LIN_X64 }} + run: | + cmake -B build $CMAKE_FLAGS + cmake --build build --parallel + + - name: Stage artifact + shell: bash + run: | + mkdir artifact + cp build/libopus.so artifact/libopus.so + + - name: Upload artifact + uses: actions/upload-artifact@v7 + with: + name: opus-linux-x64 + path: artifact + compression-level: 9 + + build-linux-arm64: + runs-on: ubuntu-26.04-arm + needs: version + steps: + - name: Clone opus + uses: actions/checkout@v6 + with: + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + submodules: recursive + + - name: Build opus + shell: bash + env: + CFLAGS: ${{ env.CFLAGS_LIN_ARM }} + CXXFLAGS: ${{ env.CFLAGS_LIN_ARM }} + run: | + cmake -B build $CMAKE_FLAGS + cmake --build build --parallel + + - name: Stage artifact + shell: bash + run: | + mkdir artifact + cp build/libopus.so artifact/libopus.so + + - name: Upload artifact + uses: actions/upload-artifact@v7 + with: + name: opus-linux-arm64 + path: artifact + compression-level: 9 + + build-macos-x64: + runs-on: macos-26-intel + needs: version + steps: + - name: Clone opus + uses: actions/checkout@v6 + with: + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + submodules: recursive + - name: Build opus shell: bash + env: + CFLAGS: ${{ env.CFLAGS_MAC_X64 }} + CXXFLAGS: ${{ env.CFLAGS_MAC_X64 }} run: | - if [[ "${{ matrix.os }}" == "windows-latest" ]]; then - for arch in x64 ARM64; do # We dont want Win32 - mkdir -p output/$arch - mkdir build-$arch - cd build-$arch - cmake $COMMON_CMAKE_FLAGS -A $arch .. - cmake --build . -j 4 --config Release - cp Release/opus.dll ../output/$arch/libopus.dll - cd .. - done - elif [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then - for arch in x64 ARM64; do - mkdir -p output/$arch - mkdir build-$arch - cd build-$arch - if [[ "$arch" == "ARM64" ]]; then - sudo apt update - sudo apt install cmake gcc-aarch64-linux-gnu g++-aarch64-linux-gnu - cmake $COMMON_CMAKE_FLAGS -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ .. - else - cmake $COMMON_CMAKE_FLAGS .. - fi - cmake --build . -j 4 - cp libopus.so ../output/$arch/libopus.so - cd .. - done - elif [[ "${{ matrix.os }}" == "macos-latest" ]]; then - mkdir build output - cd build - cmake $COMMON_CMAKE_FLAGS "-DCMAKE_OSX_ARCHITECTURES=arm64;arm64e;x86_64;x86_64h" .. - cmake --build . -j 4 --config Release - cp libopus.dylib ../output/libopus.dylib - cd .. - fi - - - name: Publish Artifacts + cmake -B build $CMAKE_FLAGS -DCMAKE_OSX_ARCHITECTURES=x86_64 + cmake --build build --config Release --parallel + + - name: Stage artifact + shell: bash + run: | + mkdir artifact + cp build/libopus.dylib artifact/libopus.dylib + + - name: Upload artifact uses: actions/upload-artifact@v7 with: - name: opus-${{ matrix.os }} - path: output - compression-level: 9 # Prefer smaller downloads over a shorter workflow runtime + name: opus-osx-x64 + path: artifact + compression-level: 9 - build-musl: - name: Build opus (alpine-musl) - runs-on: ubuntu-latest - - # We sadly cant use a matrix to run x64 and ARM64, because it would give use 2 artifacts + build-macos-arm64: + runs-on: macos-26 + needs: version steps: - - name: Clone opus repo + - name: Clone opus uses: actions/checkout@v6 with: - repository: DSharpPlus/opus + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} submodules: recursive - - - name: Setup Alpine Linux for x64 - uses: jirutka/setup-alpine@v1 - with: - packages: > - build-base - cmake - git - make - gcc - g++ - - - name: Build opus for x64 (musl) - shell: alpine.sh {0} - run: | - mkdir -p output/x64 - mkdir build-x64 - cd build-x64 - cmake $COMMON_CMAKE_FLAGS .. - cmake --build . -j 4 - cp libopus.so ../output/x64/libopus.musl.so - cd .. - - - name: Setup Alpine Linux for ARM64 - uses: jirutka/setup-alpine@v1 - with: - arch: aarch64 - packages: > - build-base - cmake - git - make - gcc - g++ - - - name: Build opus for ARM64 (musl) - shell: alpine.sh {0} - run: | - mkdir -p output/ARM64 - mkdir build-ARM64 - cd build-ARM64 - cmake $COMMON_CMAKE_FLAGS .. - cmake --build . -j 4 - cp libopus.so ../output/ARM64/libopus.musl.so - cd .. - - - name: Publish Artifacts + + - name: Build opus + shell: bash + env: + CFLAGS: ${{ env.CFLAGS_MAC_ARM }} + CXXFLAGS: ${{ env.CFLAGS_MAC_ARM }} + run: | + cmake -B build $CMAKE_FLAGS -DCMAKE_OSX_ARCHITECTURES=arm64 + cmake --build build --config Release --parallel + + - name: Stage artifact + shell: bash + run: | + mkdir artifact + cp build/libopus.dylib artifact/libopus.dylib + + - name: Upload artifact uses: actions/upload-artifact@v7 with: - name: opus-alpine-latest - path: output - compression-level: 9 # Prefer smaller downloads over a shorter workflow runtime - + name: opus-osx-arm64 + path: artifact + compression-level: 9 + + build-musl-x64: + runs-on: ubuntu-26.04 + needs: version + steps: + - name: Clone opus + uses: actions/checkout@v6 + with: + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + submodules: recursive + + - name: Build opus in Alpine + env: + CFLAGS: ${{ env.CFLAGS_LIN_X64 }} + CXXFLAGS: ${{ env.CFLAGS_LIN_X64 }} + run: | + docker run --rm -v "$PWD:/src" -w /src \ + -e CFLAGS -e CXXFLAGS -e CMAKE_FLAGS \ + alpine:$ALPINE_VERSION sh -ec ' + apk add --no-cache build-base cmake git make gcc g++ + cmake -B build $CMAKE_FLAGS + cmake --build build --parallel + ' + + - name: Stage artifact + shell: bash + run: | + mkdir artifact + cp build/libopus.so artifact/libopus.so + + - name: Upload artifact + uses: actions/upload-artifact@v7 + with: + name: opus-linux-musl-x64 + path: artifact + compression-level: 9 + + build-musl-arm64: + runs-on: ubuntu-26.04-arm + needs: version + steps: + - name: Clone opus + uses: actions/checkout@v6 + with: + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + submodules: recursive + + - name: Build opus in Alpine + env: + CFLAGS: ${{ env.CFLAGS_LIN_ARM }} + CXXFLAGS: ${{ env.CFLAGS_LIN_ARM }} + run: | + docker run --rm -v "$PWD:/src" -w /src \ + -e CFLAGS -e CXXFLAGS -e CMAKE_FLAGS \ + alpine:$ALPINE_VERSION sh -ec ' + apk add --no-cache build-base cmake git make gcc g++ + cmake -B build $CMAKE_FLAGS + cmake --build build --parallel + ' + + - name: Stage artifact + shell: bash + run: | + mkdir artifact + cp build/libopus.so artifact/libopus.so + + - name: Upload artifact + uses: actions/upload-artifact@v7 + with: + name: opus-linux-musl-arm64 + path: artifact + compression-level: 9 + publish-nuget: - needs: [build, build-musl] - runs-on: ubuntu-latest + runs-on: ubuntu-26.04 + if: github.event_name != 'pull_request' permissions: id-token: write + needs: + - version + - build-windows-x64 + - build-windows-arm64 + - build-linux-x64 + - build-linux-arm64 + - build-macos-x64 + - build-macos-arm64 + - build-musl-x64 + - build-musl-arm64 steps: - - name: Checkout CSPROJ files + - name: Checkout Natives repo uses: actions/checkout@v6 - name: Setup .NET - uses: actions/setup-dotnet@v4 + uses: actions/setup-dotnet@v5 with: dotnet-version: 9 - - name: Download Artifacts - uses: actions/download-artifact@v4 + - name: Download artifacts + uses: actions/download-artifact@v8 with: path: temp pattern: opus-* - merge-multiple: true - - - name: Move Artifacts - run: | - mkdir -p lib/opus/win-x64/native - mkdir -p lib/opus/linux-x64/native - mkdir -p lib/opus/win-arm64/native - mkdir -p lib/opus/linux-arm64/native - mkdir -p lib/opus/osx/native - mkdir -p lib/opus/linux-musl-x64/native - mkdir -p lib/opus/linux-musl-arm64/native - cp temp/x64/libopus.dll lib/opus/win-x64/native/opus.dll - cp temp/x64/libopus.so lib/opus/linux-x64/native/libopus.so - cp temp/ARM64/libopus.dll lib/opus/win-arm64/native/opus.dll - cp temp/ARM64/libopus.so lib/opus/linux-arm64/native/libopus.so - cp temp/libopus.dylib lib/opus/osx/native/libopus.dylib - cp temp/x64/libopus.musl.so lib/opus/linux-musl-x64/native/libopus.so - cp temp/ARM64/libopus.musl.so lib/opus/linux-musl-arm64/native/libopus.so + + - name: Assemble runtime tree + shell: bash + run: | + for rid in win-x64 win-arm64 linux-x64 linux-arm64 osx-x64 osx-arm64 linux-musl-x64 linux-musl-arm64; do + mkdir -p "lib/opus/$rid/native" + cp "temp/opus-$rid"/* "lib/opus/$rid/native/" + done - name: Login to NuGet id: nuget-login @@ -191,12 +361,11 @@ jobs: with: user: ${{ secrets.NUGET_USER }} - - name: Pack DSharpPlus.Natives.Opus + - name: Pack and push shell: bash env: NUGET_API_KEY: ${{ steps.nuget-login.outputs.NUGET_API_KEY }} - VERSION: ${{ needs.build.outputs.version }} + VERSION: ${{ needs.version.outputs.version }} run: | - VERSION="${VERSION:1}" dotnet pack ./build/DSharpPlus.Natives.Opus.csproj -c Release -p:Version="$VERSION.${{ github.run_number }}" dotnet nuget push "artifacts/**" --skip-duplicate -k "$NUGET_API_KEY" -s https://api.nuget.org/v3/index.json diff --git a/.github/workflows/sodium.yml b/.github/workflows/sodium.yml index 4e068db..a797fc5 100644 --- a/.github/workflows/sodium.yml +++ b/.github/workflows/sodium.yml @@ -1,4 +1,5 @@ name: Build sodium + on: workflow_dispatch: push: @@ -6,205 +7,357 @@ on: - master paths: - '.github/workflows/sodium.yml' + pull_request: + branches: + - master + paths: + - '.github/workflows/sodium.yml' -jobs: - build: - name: Build sodium - runs-on: ${{ matrix.os }} +env: + UPSTREAM_REPO: jedisct1/libsodium + MACOSX_DEPLOYMENT_TARGET: "11.0" + ALPINE_VERSION: "3.24.1" + CFLAGS_LIN_X64: "-march=x86-64-v2" + CFLAGS_LIN_ARM: "-march=armv8-a" + CFLAGS_MAC_X64: "-march=x86-64-v2" + CFLAGS_MAC_ARM: "-mcpu=apple-m1" + CFLAGS_WIN_X64: "/arch:SSE4.2" + CFLAGS_WIN_ARM: "/arch:armv8.0" +jobs: + version: + runs-on: ubuntu-26.04 outputs: - version: ${{ steps.print-version.outputs.version }} + tag: ${{ steps.detect.outputs.tag }} + version: ${{ steps.detect.outputs.version }} + steps: + - name: Clone upstream + uses: actions/checkout@v6 + with: + repository: ${{ env.UPSTREAM_REPO }} - strategy: - fail-fast: false # Run the other two OSs even if one fails - matrix: - os: [ windows-latest, ubuntu-latest, macos-latest ] + - name: Detect latest tag + id: detect + shell: bash + run: | + git fetch --tags + TAG=$(git tag --sort=-v:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+(-RELEASE|-FINAL)?$' | head -1) + VERSION="${TAG%-RELEASE}" + VERSION="${VERSION%-FINAL}" + echo "tag=$TAG" >> "$GITHUB_OUTPUT" + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + build-windows-x64: + runs-on: windows-2025-vs2026 + needs: version steps: - - name: Clone sodium repo + - name: Clone sodium uses: actions/checkout@v6 with: - repository: jedisct1/libsodium + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} submodules: recursive - - name: Checkout latest Tag - id: print-version - shell: bash - run: | - git fetch --tags - LATEST_TAG=$(git tag --sort=-v:refname | head -1) - git checkout "$LATEST_TAG" - VERSION="${LATEST_TAG%-RELEASE}" - VERSION="${VERSION%-FINAL}" - echo "version=$VERSION" >> $GITHUB_OUTPUT + - name: Setup MSBuild + uses: microsoft/setup-msbuild@v2 - - name: Install Visual Studio 2022 Build Tools - if: matrix.os == 'windows-latest' + - name: Build sodium shell: pwsh + env: + CL: ${{ env.CFLAGS_WIN_X64 }} run: | - choco install visualstudio2022buildtools --package-parameters "--add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.VC.Tools.ARM64 --includeRecommended --includeOptional" + msbuild builds/msvc/vs2022/libsodium.sln /m /p:Configuration=DynRelease /p:Platform=x64 /t:Clean,Build + + - name: Stage artifact + shell: bash + run: | + mkdir artifact + cp bin/x64/Release/v*/dynamic/libsodium.dll artifact/libsodium.dll + + - name: Upload artifact + uses: actions/upload-artifact@v7 + with: + name: sodium-win-x64 + path: artifact + compression-level: 9 + + build-windows-arm64: + runs-on: windows-11-vs2026-arm + needs: version + steps: + - name: Clone sodium + uses: actions/checkout@v6 + with: + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + submodules: recursive - name: Setup MSBuild uses: microsoft/setup-msbuild@v2 - if: matrix.os == 'windows-latest' - - name: Build sodium on Windows - if: matrix.os == 'windows-latest' + - name: Build sodium shell: pwsh + env: + CL: ${{ env.CFLAGS_WIN_ARM }} + run: | + msbuild builds/msvc/vs2022/libsodium.sln /m /p:Configuration=DynRelease /p:Platform=ARM64 /t:Clean,Build + + - name: Stage artifact + shell: bash run: | - foreach ($arch in "x64", "ARM64") { - New-Item -ItemType Directory -Name output/$arch - msbuild builds/msvc/vs2022/libsodium.sln /p:Configuration=DynRelease /p:Platform=$arch /t:Clean,Build # Clean between builds - cp bin/$arch/Release/v143/dynamic/libsodium.dll output/$arch/libsodium.dll # TODO: Figure out if we can detect the version part (v143) when it changes - } + mkdir artifact + cp bin/ARM64/Release/v*/dynamic/libsodium.dll artifact/libsodium.dll + + - name: Upload artifact + uses: actions/upload-artifact@v7 + with: + name: sodium-win-arm64 + path: artifact + compression-level: 9 + + build-linux-x64: + runs-on: ubuntu-26.04 + needs: version + steps: + - name: Clone sodium + uses: actions/checkout@v6 + with: + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + submodules: recursive - name: Build sodium - if: matrix.os != 'windows-latest' + shell: bash + env: + CFLAGS: ${{ env.CFLAGS_LIN_X64 }} + CXXFLAGS: ${{ env.CFLAGS_LIN_X64 }} + run: | + ./configure --enable-static=off --host=x86_64-linux-gnu + make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu) + + - name: Stage artifact shell: bash run: | - if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then - for arch in x64 ARM64; do - mkdir -p output/$arch - if [[ "$arch" == "ARM64" ]]; then - sudo apt update - sudo apt install cmake gcc-aarch64-linux-gnu g++-aarch64-linux-gnu - ./configure --enable-static=off --host=aarch64-linux-gnu - else - ./configure --enable-static=off --host=x86_64-linux-gnu - fi - make -j4 - cp src/libsodium/.libs/libsodium.so output/$arch/libsodium.so - make clean # Clean between builds - done - else - for arch in x64 ARM64; do - mkdir -p output/$arch - if [[ "$arch" == "ARM64" ]]; then - ./configure --enable-static=off --host=arm-apple-darwin - else - ./configure --enable-static=off --host=x86_64-apple-darwin - fi - make -j4 - cp src/libsodium/.libs/libsodium.dylib output/$arch/libsodium.dylib - make clean # Clean between builds - done - fi - - - name: Publish Artifacts + mkdir artifact + cp src/libsodium/.libs/libsodium.so artifact/libsodium.so + + - name: Upload artifact uses: actions/upload-artifact@v7 with: - name: sodium-${{ matrix.os }} - path: output - compression-level: 9 # Prefer smaller downloads over a shorter workflow runtime + name: sodium-linux-x64 + path: artifact + compression-level: 9 - build-musl: - name: Build sodium (alpine-musl) - runs-on: ubuntu-latest - - # We sadly cant use a matrix to run x64 and ARM64, because it would give use 2 artifacts + build-linux-arm64: + runs-on: ubuntu-26.04-arm + needs: version steps: - - name: Clone sodium repo + - name: Clone sodium uses: actions/checkout@v6 with: - repository: jedisct1/libsodium + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} submodules: recursive - - - name: Checkout latest Tag + + - name: Build sodium shell: bash + env: + CFLAGS: ${{ env.CFLAGS_LIN_ARM }} + CXXFLAGS: ${{ env.CFLAGS_LIN_ARM }} run: | - git fetch --tags - LATEST_TAG=$(git tag --sort=-v:refname | head -1) - git checkout "$LATEST_TAG" - VERSION="${LATEST_TAG%-RELEASE}" - VERSION="${VERSION%-FINAL}" - echo "version=$VERSION" >> $GITHUB_OUTPUT - - - name: Setup Alpine Linux for x64 - uses: jirutka/setup-alpine@v1 - with: - packages: > - build-base - cmake - git - make - gcc - g++ - - - name: Build sodium for x64 (musl) - shell: alpine.sh {0} - run: | - mkdir -p output/x64 - ./configure --enable-static=off - make -j4 - cp src/libsodium/.libs/libsodium.so output/x64/libsodium.musl.so - make clean # Clean between builds - - - name: Setup Alpine Linux for ARM64 - uses: jirutka/setup-alpine@v1 - with: - arch: aarch64 - packages: > - build-base - cmake - git - make - gcc - g++ - - - name: Build sodium for ARM64 (musl) - shell: alpine.sh {0} - run: | - mkdir -p output/ARM64 - ./configure --enable-static=off - make -j4 - cp src/libsodium/.libs/libsodium.so output/ARM64/libsodium.musl.so - - - name: Publish Artifacts + ./configure --enable-static=off --host=aarch64-linux-gnu + make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu) + + - name: Stage artifact + shell: bash + run: | + mkdir artifact + cp src/libsodium/.libs/libsodium.so artifact/libsodium.so + + - name: Upload artifact + uses: actions/upload-artifact@v7 + with: + name: sodium-linux-arm64 + path: artifact + compression-level: 9 + + build-macos-x64: + runs-on: macos-26-intel + needs: version + steps: + - name: Clone sodium + uses: actions/checkout@v6 + with: + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + submodules: recursive + + - name: Build sodium + shell: bash + env: + CFLAGS: ${{ env.CFLAGS_MAC_X64 }} + CXXFLAGS: ${{ env.CFLAGS_MAC_X64 }} + run: | + ./configure --enable-static=off --host=x86_64-apple-darwin + make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu) + + - name: Stage artifact + shell: bash + run: | + mkdir artifact + cp src/libsodium/.libs/libsodium.dylib artifact/libsodium.dylib + + - name: Upload artifact uses: actions/upload-artifact@v7 with: - name: sodium-alpine-latest - path: output - compression-level: 9 # Prefer smaller downloads over a shorter workflow runtime - + name: sodium-osx-x64 + path: artifact + compression-level: 9 + + build-macos-arm64: + runs-on: macos-26 + needs: version + steps: + - name: Clone sodium + uses: actions/checkout@v6 + with: + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + submodules: recursive + + - name: Build sodium + shell: bash + env: + CFLAGS: ${{ env.CFLAGS_MAC_ARM }} + CXXFLAGS: ${{ env.CFLAGS_MAC_ARM }} + run: | + ./configure --enable-static=off --host=arm-apple-darwin + make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu) + + - name: Stage artifact + shell: bash + run: | + mkdir artifact + cp src/libsodium/.libs/libsodium.dylib artifact/libsodium.dylib + + - name: Upload artifact + uses: actions/upload-artifact@v7 + with: + name: sodium-osx-arm64 + path: artifact + compression-level: 9 + + build-musl-x64: + runs-on: ubuntu-26.04 + needs: version + steps: + - name: Clone sodium + uses: actions/checkout@v6 + with: + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + submodules: recursive + + - name: Build sodium in Alpine + env: + CFLAGS: ${{ env.CFLAGS_LIN_X64 }} + CXXFLAGS: ${{ env.CFLAGS_LIN_X64 }} + run: | + docker run --rm -v "$PWD:/src" -w /src \ + -e CFLAGS -e CXXFLAGS \ + alpine:$ALPINE_VERSION sh -ec ' + apk add --no-cache build-base cmake git make gcc g++ + ./configure --enable-static=off + make -j"$(nproc)" + ' + + - name: Stage artifact + shell: bash + run: | + mkdir artifact + cp src/libsodium/.libs/libsodium.so artifact/libsodium.so + + - name: Upload artifact + uses: actions/upload-artifact@v7 + with: + name: sodium-linux-musl-x64 + path: artifact + compression-level: 9 + + build-musl-arm64: + runs-on: ubuntu-26.04-arm + needs: version + steps: + - name: Clone sodium + uses: actions/checkout@v6 + with: + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + submodules: recursive + + - name: Build sodium in Alpine + env: + CFLAGS: ${{ env.CFLAGS_LIN_ARM }} + CXXFLAGS: ${{ env.CFLAGS_LIN_ARM }} + run: | + docker run --rm -v "$PWD:/src" -w /src \ + -e CFLAGS -e CXXFLAGS \ + alpine:$ALPINE_VERSION sh -ec ' + apk add --no-cache build-base cmake git make gcc g++ + ./configure --enable-static=off + make -j"$(nproc)" + ' + + - name: Stage artifact + shell: bash + run: | + mkdir artifact + cp src/libsodium/.libs/libsodium.so artifact/libsodium.so + + - name: Upload artifact + uses: actions/upload-artifact@v7 + with: + name: sodium-linux-musl-arm64 + path: artifact + compression-level: 9 + publish-nuget: - needs: [build, build-musl] - runs-on: ubuntu-latest + runs-on: ubuntu-26.04 + if: github.event_name != 'pull_request' permissions: id-token: write + needs: + - version + - build-windows-x64 + - build-windows-arm64 + - build-linux-x64 + - build-linux-arm64 + - build-macos-x64 + - build-macos-arm64 + - build-musl-x64 + - build-musl-arm64 steps: - - name: Checkout CSPROJ files + - name: Checkout Natives repo uses: actions/checkout@v6 - name: Setup .NET - uses: actions/setup-dotnet@v4 + uses: actions/setup-dotnet@v5 with: dotnet-version: 9 - - name: Download Artifacts - uses: actions/download-artifact@v4 + - name: Download artifacts + uses: actions/download-artifact@v8 with: path: temp pattern: sodium-* - merge-multiple: true - - - name: Move Artifacts - run: | - mkdir -p lib/sodium/win-x64/native - mkdir -p lib/sodium/linux-x64/native - mkdir -p lib/sodium/osx-x64/native - mkdir -p lib/sodium/win-arm64/native - mkdir -p lib/sodium/linux-arm64/native - mkdir -p lib/sodium/osx-arm64/native - mkdir -p lib/sodium/linux-musl-x64/native - mkdir -p lib/sodium/linux-musl-arm64/native - cp temp/x64/libsodium.dll lib/sodium/win-x64/native/libsodium.dll - cp temp/x64/libsodium.so lib/sodium/linux-x64/native/libsodium.so - cp temp/x64/libsodium.dylib lib/sodium/osx-x64/native/libsodium.dylib - cp temp/ARM64/libsodium.dll lib/sodium/win-arm64/native/libsodium.dll - cp temp/ARM64/libsodium.so lib/sodium/linux-arm64/native/libsodium.so - cp temp/ARM64/libsodium.dylib lib/sodium/osx-arm64/native/libsodium.dylib - cp temp/x64/libsodium.musl.so lib/sodium/linux-musl-x64/native/libsodium.so - cp temp/ARM64/libsodium.musl.so lib/sodium/linux-musl-arm64/native/libsodium.so + + - name: Assemble runtime tree + shell: bash + run: | + for rid in win-x64 win-arm64 linux-x64 linux-arm64 osx-x64 osx-arm64 linux-musl-x64 linux-musl-arm64; do + mkdir -p "lib/sodium/$rid/native" + cp "temp/sodium-$rid"/* "lib/sodium/$rid/native/" + done - name: Login to NuGet id: nuget-login @@ -212,12 +365,11 @@ jobs: with: user: ${{ secrets.NUGET_USER }} - - name: Pack DSharpPlus.Natives.Sodium + - name: Pack and push shell: bash env: NUGET_API_KEY: ${{ steps.nuget-login.outputs.NUGET_API_KEY }} - VERSION: ${{ needs.build.outputs.version }} + VERSION: ${{ needs.version.outputs.version }} run: | - VERSION="${VERSION%%-*}" dotnet pack ./build/DSharpPlus.Natives.Sodium.csproj -c Release -p:Version="$VERSION.${{ github.run_number }}" dotnet nuget push "artifacts/**" --skip-duplicate -k "$NUGET_API_KEY" -s https://api.nuget.org/v3/index.json diff --git a/.github/workflows/speexdsp.yml b/.github/workflows/speexdsp.yml index 04931f6..e74b10b 100644 --- a/.github/workflows/speexdsp.yml +++ b/.github/workflows/speexdsp.yml @@ -1,4 +1,5 @@ name: Build speexdsp + on: workflow_dispatch: push: @@ -7,361 +8,392 @@ on: paths: - '.github/workflows/speexdsp.yml' - 'build/SpeexDSP_CMakeLists.txt' + pull_request: + branches: + - master + paths: + - '.github/workflows/speexdsp.yml' + - 'build/SpeexDSP_CMakeLists.txt' + +env: + UPSTREAM_REPO: xiph/speexdsp + MACOSX_DEPLOYMENT_TARGET: "11.0" + ALPINE_VERSION: "3.24.1" + CFLAGS_LIN_X64: "-march=x86-64-v2" + CFLAGS_LIN_ARM: "-march=armv8-a" + CFLAGS_MAC_X64: "-march=x86-64-v2" + CFLAGS_MAC_ARM: "-mcpu=apple-m1" + CFLAGS_WIN_X64: "/arch:SSE4.2" + CFLAGS_WIN_ARM: "/arch:armv8.0" jobs: version: - runs-on: ubuntu-latest + runs-on: ubuntu-26.04 outputs: - version: ${{ steps.print-version.outputs.version }} + tag: ${{ steps.detect.outputs.tag }} + version: ${{ steps.detect.outputs.version }} steps: - - name: Clone speexdsp repo + - name: Clone upstream uses: actions/checkout@v6 with: - repository: xiph/speexdsp - - - name: Print version - id: print-version + repository: ${{ env.UPSTREAM_REPO }} + + - name: Detect latest tag + id: detect shell: bash run: | git fetch --tags - LATEST_TAG=$(git tag | grep -E ^SpeexDSP-[0-9]+.[0-9]+.[0-9]+$ | tail -1) - git checkout "$LATEST_TAG" - echo "version=$LATEST_TAG" >> $GITHUB_OUTPUT + TAG=$(git tag --sort=-v:refname | grep -E '^SpeexDSP-[0-9]+\.[0-9]+\.[0-9]+$' | head -1) + echo "tag=$TAG" >> "$GITHUB_OUTPUT" + echo "version=${TAG#SpeexDSP-}" >> "$GITHUB_OUTPUT" build-windows-x64: - runs-on: windows-latest + runs-on: windows-2025-vs2026 needs: version steps: - - name: Clone speexdsp repo + - name: Clone speexdsp uses: actions/checkout@v6 with: - repository: xiph/speexdsp - ref: ${{needs.version.outputs.version}} + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} - name: Clone Natives repo uses: actions/checkout@v6 with: path: natives - - name: Setup VS build tools - uses: seanmiddleditch/gha-setup-vsdevenv@v5 - with: - host_arch: amd64 - arch: amd64 - - name: Build speexdsp - shell: pwsh + shell: bash + env: + CL: ${{ env.CFLAGS_WIN_X64 }} run: | cp natives/build/SpeexDSP_CMakeLists.txt CMakeLists.txt cmake -B build -A x64 -DSPEEX_USE_SSE=ON cmake --build build --config Release --parallel - - name: Rename native + - name: Stage artifact shell: bash - run: mv build/Release/speexdsp.dll build/Release/speexdsp-win-x64.dll - - - name: Publish Artifacts + run: | + mkdir artifact + cp build/Release/speexdsp.dll artifact/speexdsp.dll + + - name: Upload artifact uses: actions/upload-artifact@v7 with: - name: speexdsp-windows-x64 - path: build\Release\speexdsp-win-x64.dll + name: speexdsp-win-x64 + path: artifact + compression-level: 9 build-windows-arm64: - runs-on: windows-11-arm + runs-on: windows-11-vs2026-arm needs: version steps: - - name: Clone speexdsp repo + - name: Clone speexdsp uses: actions/checkout@v6 with: - repository: xiph/speexdsp - ref: ${{needs.version.outputs.version}} + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} - name: Clone Natives repo uses: actions/checkout@v6 with: path: natives - - name: Setup VS build tools - uses: seanmiddleditch/gha-setup-vsdevenv@v5 - with: - host_arch: arm64 - arch: arm64 - - name: Build speexdsp - shell: pwsh + shell: bash + env: + CL: ${{ env.CFLAGS_WIN_ARM }} run: | cp natives/build/SpeexDSP_CMakeLists.txt CMakeLists.txt cmake -B build -A ARM64 cmake --build build --config Release --parallel - - name: Rename native + - name: Stage artifact shell: bash - run: mv build/Release/speexdsp.dll build/Release/speexdsp-win-arm64.dll - - - name: Publish Artifacts + run: | + mkdir artifact + cp build/Release/speexdsp.dll artifact/speexdsp.dll + + - name: Upload artifact uses: actions/upload-artifact@v7 with: - name: speexdsp-windows-arm64 - path: build\Release\speexdsp-win-arm64.dll + name: speexdsp-win-arm64 + path: artifact + compression-level: 9 build-linux-x64: - runs-on: ubuntu-latest + runs-on: ubuntu-26.04 needs: version steps: - - name: Clone speexdsp repo + - name: Clone speexdsp uses: actions/checkout@v6 with: - repository: xiph/speexdsp - ref: ${{needs.version.outputs.version}} + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} - name: Clone Natives repo uses: actions/checkout@v6 with: path: natives - + - name: Build speexdsp shell: bash + env: + CFLAGS: ${{ env.CFLAGS_LIN_X64 }} + CXXFLAGS: ${{ env.CFLAGS_LIN_X64 }} run: | cp natives/build/SpeexDSP_CMakeLists.txt CMakeLists.txt cmake -B build -DSPEEX_USE_SSE=ON cmake --build build --config Release --parallel - - name: Rename native + - name: Stage artifact shell: bash - run: mv build/libspeexdsp.so build/libspeexdsp-linux-x64.so - - - name: Publish Artifacts + run: | + mkdir artifact + cp build/libspeexdsp.so artifact/libspeexdsp.so + + - name: Upload artifact uses: actions/upload-artifact@v7 with: name: speexdsp-linux-x64 - path: build/libspeexdsp-linux-x64.so + path: artifact + compression-level: 9 build-linux-arm64: - runs-on: ubuntu-24.04-arm + runs-on: ubuntu-26.04-arm needs: version steps: - - name: Clone speexdsp repo + - name: Clone speexdsp uses: actions/checkout@v6 with: - repository: xiph/speexdsp - ref: ${{needs.version.outputs.version}} + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} - name: Clone Natives repo uses: actions/checkout@v6 with: path: natives - + - name: Build speexdsp shell: bash + env: + CFLAGS: ${{ env.CFLAGS_LIN_ARM }} + CXXFLAGS: ${{ env.CFLAGS_LIN_ARM }} run: | cp natives/build/SpeexDSP_CMakeLists.txt CMakeLists.txt cmake -B build cmake --build build --config Release --parallel - - name: Rename native + - name: Stage artifact shell: bash - run: mv build/libspeexdsp.so build/libspeexdsp-linux-arm64.so - - - name: Publish Artifacts + run: | + mkdir artifact + cp build/libspeexdsp.so artifact/libspeexdsp.so + + - name: Upload artifact uses: actions/upload-artifact@v7 with: name: speexdsp-linux-arm64 - path: build/libspeexdsp-linux-arm64.so + path: artifact + compression-level: 9 build-macos-x64: - runs-on: macos-latest + runs-on: macos-26-intel needs: version steps: - - name: Clone speexdsp repo + - name: Clone speexdsp uses: actions/checkout@v6 with: - repository: xiph/speexdsp - ref: ${{needs.version.outputs.version}} + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} - name: Clone Natives repo uses: actions/checkout@v6 with: path: natives - + - name: Build speexdsp shell: bash + env: + CFLAGS: ${{ env.CFLAGS_MAC_X64 }} + CXXFLAGS: ${{ env.CFLAGS_MAC_X64 }} run: | cp natives/build/SpeexDSP_CMakeLists.txt CMakeLists.txt - cmake -B build + cmake -B build -DCMAKE_OSX_ARCHITECTURES=x86_64 cmake --build build --config Release --parallel - - name: Rename native + - name: Stage artifact shell: bash - run: mv build/libspeexdsp.dylib build/libspeexdsp-osx-x64.dylib - - - name: Publish Artifacts + run: | + mkdir artifact + cp build/libspeexdsp.dylib artifact/libspeexdsp.dylib + + - name: Upload artifact uses: actions/upload-artifact@v7 with: - name: speexdsp-macos-x64 - path: build/libspeexdsp-osx-x64.dylib + name: speexdsp-osx-x64 + path: artifact + compression-level: 9 build-macos-arm64: - runs-on: macos-latest + runs-on: macos-26 needs: version steps: - - name: Clone speexdsp repo + - name: Clone speexdsp uses: actions/checkout@v6 with: - repository: xiph/speexdsp - ref: ${{needs.version.outputs.version}} - + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + - name: Clone Natives repo uses: actions/checkout@v6 with: path: natives - + - name: Build speexdsp shell: bash + env: + CFLAGS: ${{ env.CFLAGS_MAC_ARM }} + CXXFLAGS: ${{ env.CFLAGS_MAC_ARM }} run: | cp natives/build/SpeexDSP_CMakeLists.txt CMakeLists.txt - cmake -B build + cmake -B build -DCMAKE_OSX_ARCHITECTURES=arm64 cmake --build build --config Release --parallel - - name: Rename native + - name: Stage artifact shell: bash - run: mv build/libspeexdsp.dylib build/libspeexdsp-osx-arm64.dylib - - - name: Publish Artifacts + run: | + mkdir artifact + cp build/libspeexdsp.dylib artifact/libspeexdsp.dylib + + - name: Upload artifact uses: actions/upload-artifact@v7 with: - name: speexdsp-macos-arm64 - path: build/libspeexdsp-osx-arm64.dylib + name: speexdsp-osx-arm64 + path: artifact + compression-level: 9 build-musl-x64: - runs-on: ubuntu-latest + runs-on: ubuntu-26.04 needs: version steps: - - name: Clone speexdsp repo + - name: Clone speexdsp uses: actions/checkout@v6 with: - repository: xiph/speexdsp - ref: ${{needs.version.outputs.version}} + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} - name: Clone Natives repo uses: actions/checkout@v6 with: path: natives - - - name: Setup Alpine Linux - uses: jirutka/setup-alpine@v1 - with: - packages: > - build-base - cmake - git - make - gcc - g++ - nasm - linux-headers - - - name: Build speexdsp - shell: alpine.sh {0} - run: | - cp natives/build/SpeexDSP_CMakeLists.txt CMakeLists.txt - cmake -B build -DSPEEX_USE_SSE=ON - cmake --build build --config Release --parallel - - name: Rename native + - name: Build speexdsp in Alpine + env: + CFLAGS: ${{ env.CFLAGS_LIN_X64 }} + CXXFLAGS: ${{ env.CFLAGS_LIN_X64 }} + run: | + docker run --rm -v "$PWD:/src" -w /src \ + -e CFLAGS -e CXXFLAGS \ + alpine:$ALPINE_VERSION sh -ec ' + apk add --no-cache build-base cmake git make gcc g++ nasm linux-headers + cp natives/build/SpeexDSP_CMakeLists.txt CMakeLists.txt + cmake -B build -DSPEEX_USE_SSE=ON + cmake --build build --config Release --parallel + ' + + - name: Stage artifact shell: bash - run: mv build/libspeexdsp.so build/libspeexdsp-musl-x64.so - - - name: Publish Artifacts + run: | + mkdir artifact + cp build/libspeexdsp.so artifact/libspeexdsp.so + + - name: Upload artifact uses: actions/upload-artifact@v7 with: - name: speexdsp-musl-x64 - path: build/libspeexdsp-musl-x64.so + name: speexdsp-linux-musl-x64 + path: artifact + compression-level: 9 build-musl-arm64: - runs-on: ubuntu-latest + runs-on: ubuntu-26.04-arm needs: version steps: - - name: Clone speexdsp repo + - name: Clone speexdsp uses: actions/checkout@v6 with: - repository: xiph/speexdsp - ref: ${{needs.version.outputs.version}} + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} - name: Clone Natives repo uses: actions/checkout@v6 with: path: natives - - - name: Setup Alpine Linux - uses: jirutka/setup-alpine@v1 - with: - arch: aarch64 - packages: > - build-base - cmake - git - make - gcc - g++ - nasm - linux-headers - - name: Build speexdsp - shell: alpine.sh {0} + - name: Build speexdsp in Alpine + env: + CFLAGS: ${{ env.CFLAGS_LIN_ARM }} + CXXFLAGS: ${{ env.CFLAGS_LIN_ARM }} run: | - cp natives/build/SpeexDSP_CMakeLists.txt CMakeLists.txt - cmake -B build - cmake --build build --config Release --parallel - - - name: Rename native + docker run --rm -v "$PWD:/src" -w /src \ + -e CFLAGS -e CXXFLAGS \ + alpine:$ALPINE_VERSION sh -ec ' + apk add --no-cache build-base cmake git make gcc g++ nasm linux-headers + cp natives/build/SpeexDSP_CMakeLists.txt CMakeLists.txt + cmake -B build + cmake --build build --config Release --parallel + ' + + - name: Stage artifact shell: bash - run: mv build/libspeexdsp.so build/libspeexdsp-musl-arm64.so - - - name: Publish Artifacts + run: | + mkdir artifact + cp build/libspeexdsp.so artifact/libspeexdsp.so + + - name: Upload artifact uses: actions/upload-artifact@v7 with: - name: speexdsp-musl-arm64 - path: build/libspeexdsp-musl-arm64.so + name: speexdsp-linux-musl-arm64 + path: artifact + compression-level: 9 publish-nuget: - runs-on: ubuntu-latest - needs: [version, build-windows-x64, build-windows-arm64, build-linux-x64, build-linux-arm64, build-macos-x64, build-macos-arm64, build-musl-x64, build-musl-arm64] + runs-on: ubuntu-26.04 + if: github.event_name != 'pull_request' permissions: id-token: write + needs: + - version + - build-windows-x64 + - build-windows-arm64 + - build-linux-x64 + - build-linux-arm64 + - build-macos-x64 + - build-macos-arm64 + - build-musl-x64 + - build-musl-arm64 steps: - - name: Checkout CSPROJ files + - name: Checkout Natives repo uses: actions/checkout@v6 - name: Setup .NET - uses: actions/setup-dotnet@v4 + uses: actions/setup-dotnet@v5 with: dotnet-version: 9 - - name: Download Artifacts - uses: actions/download-artifact@v4 + - name: Download artifacts + uses: actions/download-artifact@v8 with: path: temp pattern: speexdsp-* - merge-multiple: true - - name: Move Artifacts + - name: Assemble runtime tree + shell: bash run: | - mkdir -p lib/speex/win-x64/native - mkdir -p lib/speex/linux-x64/native - mkdir -p lib/speex/win-arm64/native - mkdir -p lib/speex/linux-arm64/native - mkdir -p lib/speex/osx-x64/native - mkdir -p lib/speex/osx-arm64/native - mkdir -p lib/speex/linux-musl-x64/native - mkdir -p lib/speex/linux-musl-arm64/native - cp temp/speexdsp-win-x64.dll lib/speex/win-x64/native/speexdsp.dll - cp temp/libspeexdsp-linux-x64.so lib/speex/linux-x64/native/libspeexdsp.so - cp temp/speexdsp-win-arm64.dll lib/speex/win-arm64/native/speexdsp.dll - cp temp/libspeexdsp-linux-arm64.so lib/speex/linux-arm64/native/libspeexdsp.so - cp temp/libspeexdsp-osx-x64.dylib lib/speex/osx-x64/native/libspeexdsp.dylib - cp temp/libspeexdsp-osx-arm64.dylib lib/speex/osx-arm64/native/libspeexdsp.dylib - cp temp/libspeexdsp-musl-x64.so lib/speex/linux-musl-x64/native/libspeexdsp.so - cp temp/libspeexdsp-musl-arm64.so lib/speex/linux-musl-arm64/native/libspeexdsp.so + for rid in win-x64 win-arm64 linux-x64 linux-arm64 osx-x64 osx-arm64 linux-musl-x64 linux-musl-arm64; do + mkdir -p "lib/speex/$rid/native" + cp "temp/speexdsp-$rid"/* "lib/speex/$rid/native/" + done - name: Login to NuGet id: nuget-login @@ -369,12 +401,11 @@ jobs: with: user: ${{ secrets.NUGET_USER }} - - name: Pack DSharpPlus.Natives.Speex + - name: Pack and push shell: bash env: NUGET_API_KEY: ${{ steps.nuget-login.outputs.NUGET_API_KEY }} VERSION: ${{ needs.version.outputs.version }} run: | - VERSION="${VERSION:9}" dotnet pack ./build/DSharpPlus.Natives.Speex.csproj -c Release -p:Version="$VERSION.${{ github.run_number }}" dotnet nuget push "artifacts/**" --skip-duplicate -k "$NUGET_API_KEY" -s https://api.nuget.org/v3/index.json diff --git a/.github/workflows/zstd.yml b/.github/workflows/zstd.yml index 71a9e89..245f1be 100644 --- a/.github/workflows/zstd.yml +++ b/.github/workflows/zstd.yml @@ -1,4 +1,5 @@ name: Build zstd + on: workflow_dispatch: push: @@ -6,196 +7,358 @@ on: - master paths: - '.github/workflows/zstd.yml' + pull_request: + branches: + - master + paths: + - '.github/workflows/zstd.yml' env: - COMMON_CMAKE_FLAGS: "-DZSTD_MULTITHREAD_SUPPORT=ON -DZSTD_LEGACY_SUPPORT=OFF -DZSTD_BUILD_PROGRAMS=OFF -DZSTD_BUILD_STATIC=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release" + UPSTREAM_REPO: facebook/zstd + CMAKE_FLAGS: >- + -DZSTD_MULTITHREAD_SUPPORT=ON + -DZSTD_LEGACY_SUPPORT=OFF + -DZSTD_BUILD_PROGRAMS=OFF + -DZSTD_BUILD_STATIC=OFF + -DBUILD_SHARED_LIBS=ON + -DCMAKE_BUILD_TYPE=Release + MACOSX_DEPLOYMENT_TARGET: "11.0" + ALPINE_VERSION: "3.24.1" + CFLAGS_LIN_X64: "-march=x86-64-v2" + CFLAGS_LIN_ARM: "-march=armv8-a" + CFLAGS_MAC_X64: "-march=x86-64-v2" + CFLAGS_MAC_ARM: "-mcpu=apple-m1" + CFLAGS_WIN_X64: "/arch:SSE4.2" + CFLAGS_WIN_ARM: "/arch:armv8.0" jobs: - build: - name: Build zstd - runs-on: ${{ matrix.os }} - + version: + runs-on: ubuntu-26.04 outputs: - version: ${{ steps.print-version.outputs.version }} + tag: ${{ steps.detect.outputs.tag }} + version: ${{ steps.detect.outputs.version }} + steps: + - name: Clone upstream + uses: actions/checkout@v6 + with: + repository: ${{ env.UPSTREAM_REPO }} - strategy: - fail-fast: false # Run the other two OSs even if one fails - matrix: - os: [ windows-latest, ubuntu-latest, macos-latest ] - + - name: Detect latest tag + id: detect + shell: bash + run: | + git fetch --tags + TAG=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -1) + echo "tag=$TAG" >> "$GITHUB_OUTPUT" + echo "version=${TAG#v}" >> "$GITHUB_OUTPUT" + + build-windows-x64: + runs-on: windows-2025-vs2026 + needs: version steps: - - name: Clone zstd repo + - name: Clone zstd uses: actions/checkout@v6 with: - repository: facebook/zstd + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} submodules: recursive - - name: Checkout latest Tag - id: print-version + - name: Build zstd + shell: bash + env: + CL: ${{ env.CFLAGS_WIN_X64 }} + run: | + cmake -S build/cmake -B cmake-build -A x64 $CMAKE_FLAGS + cmake --build cmake-build --config Release --parallel + + - name: Stage artifact shell: bash run: | - git fetch --tags - LATEST_TAG=$(git tag | grep -E ^v[0-9]+.[0-9]+.[0-9]+$ | tail -1) - git checkout "$LATEST_TAG" - echo "version=$LATEST_TAG" >> $GITHUB_OUTPUT + mkdir artifact + cp cmake-build/lib/Release/zstd.dll artifact/libzstd.dll + + - name: Upload artifact + uses: actions/upload-artifact@v7 + with: + name: zstd-win-x64 + path: artifact + compression-level: 9 + + build-windows-arm64: + runs-on: windows-11-vs2026-arm + needs: version + steps: + - name: Clone zstd + uses: actions/checkout@v6 + with: + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + submodules: recursive - name: Build zstd shell: bash + env: + CL: ${{ env.CFLAGS_WIN_ARM }} run: | - cd build/cmake - if [[ "${{ matrix.os }}" == "windows-latest" ]]; then - for arch in x64 ARM64; do # We dont want Win32 - mkdir -p ../../output/$arch - mkdir build-$arch - cd build-$arch - cmake $COMMON_CMAKE_FLAGS -A $arch .. - cmake --build . -j 4 --config Release - cp lib/Release/zstd.dll ../../../output/$arch/libzstd.dll - cd .. - done - elif [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then - for arch in x64 ARM64; do - mkdir -p ../../output/$arch - mkdir build-$arch - cd build-$arch - if [[ "$arch" == "ARM64" ]]; then - sudo apt update - sudo apt install cmake gcc-aarch64-linux-gnu g++-aarch64-linux-gnu - cmake $COMMON_CMAKE_FLAGS -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ .. - else - cmake $COMMON_CMAKE_FLAGS .. - fi - cmake --build . -j 4 - cp lib/libzstd.so ../../../output/$arch/libzstd.so - cd .. - done - elif [[ "${{ matrix.os }}" == "macos-latest" ]]; then - mkdir build ../../output - cd build - cmake $COMMON_CMAKE_FLAGS "-DCMAKE_OSX_ARCHITECTURES=arm64;arm64e;x86_64;x86_64h" .. - cmake --build . -j 4 --config Release - cp lib/libzstd.dylib ../../../output/libzstd.dylib - cd .. - fi - - - name: Publish Artifacts + cmake -S build/cmake -B cmake-build -A ARM64 $CMAKE_FLAGS + cmake --build cmake-build --config Release --parallel + + - name: Stage artifact + shell: bash + run: | + mkdir artifact + cp cmake-build/lib/Release/zstd.dll artifact/libzstd.dll + + - name: Upload artifact uses: actions/upload-artifact@v7 with: - name: zstd-${{ matrix.os }} - path: output - compression-level: 9 # Prefer smaller downloads over a shorter workflow runtime + name: zstd-win-arm64 + path: artifact + compression-level: 9 - build-musl: - name: Build zstd (alpine-musl) - runs-on: ubuntu-latest - - # We sadly cant use a matrix to run x64 and ARM64, because it would give use 2 artifacts + build-linux-x64: + runs-on: ubuntu-26.04 + needs: version steps: - - name: Clone zstd repo + - name: Clone zstd uses: actions/checkout@v6 with: - repository: facebook/zstd + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} submodules: recursive - - name: Checkout latest Tag + - name: Build zstd + shell: bash + env: + CFLAGS: ${{ env.CFLAGS_LIN_X64 }} + CXXFLAGS: ${{ env.CFLAGS_LIN_X64 }} + run: | + cmake -S build/cmake -B cmake-build $CMAKE_FLAGS + cmake --build cmake-build --parallel + + - name: Stage artifact shell: bash run: | - git fetch --tags - LATEST_TAG=$(git tag | grep -E ^v[0-9]+.[0-9]+.[0-9]+$ | tail -1) - git checkout "$LATEST_TAG" - - - name: Setup Alpine Linux for x64 - uses: jirutka/setup-alpine@v1 - with: - packages: > - build-base - cmake - git - make - gcc - g++ - - - name: Build zstd for x64 (musl) - shell: alpine.sh {0} - run: | - cd build/cmake - mkdir -p ../../output/x64 - mkdir -p build-x64 - cd build-x64 - cmake $COMMON_CMAKE_FLAGS .. - cmake --build . -j 4 - cp lib/libzstd.so ../../../output/x64/libzstd.musl.so - cd .. - - - name: Setup Alpine Linux for ARM64 - uses: jirutka/setup-alpine@v1 - with: - arch: aarch64 - packages: > - build-base - cmake - git - make - gcc - g++ - - - name: Build zstd for ARM64 (musl) - shell: alpine.sh {0} - run: | - cd build/cmake - mkdir -p ../../output/ARM64 - mkdir -p build-ARM64 - cd build-ARM64 - cmake $COMMON_CMAKE_FLAGS .. - cmake --build . -j 4 - cp lib/libzstd.so ../../../output/ARM64/libzstd.musl.so - cd .. - - - name: Publish Artifacts + mkdir artifact + cp cmake-build/lib/libzstd.so artifact/libzstd.so + + - name: Upload artifact + uses: actions/upload-artifact@v7 + with: + name: zstd-linux-x64 + path: artifact + compression-level: 9 + + build-linux-arm64: + runs-on: ubuntu-26.04-arm + needs: version + steps: + - name: Clone zstd + uses: actions/checkout@v6 + with: + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + submodules: recursive + + - name: Build zstd + shell: bash + env: + CFLAGS: ${{ env.CFLAGS_LIN_ARM }} + CXXFLAGS: ${{ env.CFLAGS_LIN_ARM }} + run: | + cmake -S build/cmake -B cmake-build $CMAKE_FLAGS + cmake --build cmake-build --parallel + + - name: Stage artifact + shell: bash + run: | + mkdir artifact + cp cmake-build/lib/libzstd.so artifact/libzstd.so + + - name: Upload artifact + uses: actions/upload-artifact@v7 + with: + name: zstd-linux-arm64 + path: artifact + compression-level: 9 + + build-macos-x64: + runs-on: macos-26-intel + needs: version + steps: + - name: Clone zstd + uses: actions/checkout@v6 + with: + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + submodules: recursive + + - name: Build zstd + shell: bash + env: + CFLAGS: ${{ env.CFLAGS_MAC_X64 }} + CXXFLAGS: ${{ env.CFLAGS_MAC_X64 }} + run: | + cmake -S build/cmake -B cmake-build $CMAKE_FLAGS -DCMAKE_OSX_ARCHITECTURES=x86_64 + cmake --build cmake-build --config Release --parallel + + - name: Stage artifact + shell: bash + run: | + mkdir artifact + cp cmake-build/lib/libzstd.dylib artifact/libzstd.dylib + + - name: Upload artifact + uses: actions/upload-artifact@v7 + with: + name: zstd-osx-x64 + path: artifact + compression-level: 9 + + build-macos-arm64: + runs-on: macos-26 + needs: version + steps: + - name: Clone zstd + uses: actions/checkout@v6 + with: + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + submodules: recursive + + - name: Build zstd + shell: bash + env: + CFLAGS: ${{ env.CFLAGS_MAC_ARM }} + CXXFLAGS: ${{ env.CFLAGS_MAC_ARM }} + run: | + cmake -S build/cmake -B cmake-build $CMAKE_FLAGS -DCMAKE_OSX_ARCHITECTURES=arm64 + cmake --build cmake-build --config Release --parallel + + - name: Stage artifact + shell: bash + run: | + mkdir artifact + cp cmake-build/lib/libzstd.dylib artifact/libzstd.dylib + + - name: Upload artifact uses: actions/upload-artifact@v7 with: - name: zstd-alpine-latest - path: output - compression-level: 9 # Prefer smaller downloads over a shorter workflow runtime + name: zstd-osx-arm64 + path: artifact + compression-level: 9 + + build-musl-x64: + runs-on: ubuntu-26.04 + needs: version + steps: + - name: Clone zstd + uses: actions/checkout@v6 + with: + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + submodules: recursive + + - name: Build zstd in Alpine + env: + CFLAGS: ${{ env.CFLAGS_LIN_X64 }} + CXXFLAGS: ${{ env.CFLAGS_LIN_X64 }} + run: | + docker run --rm -v "$PWD:/src" -w /src \ + -e CFLAGS -e CXXFLAGS -e CMAKE_FLAGS \ + alpine:$ALPINE_VERSION sh -ec ' + apk add --no-cache build-base cmake git make gcc g++ + cmake -S build/cmake -B cmake-build $CMAKE_FLAGS + cmake --build cmake-build --parallel + ' + + - name: Stage artifact + shell: bash + run: | + mkdir artifact + cp cmake-build/lib/libzstd.so artifact/libzstd.so + + - name: Upload artifact + uses: actions/upload-artifact@v7 + with: + name: zstd-linux-musl-x64 + path: artifact + compression-level: 9 + + build-musl-arm64: + runs-on: ubuntu-26.04-arm + needs: version + steps: + - name: Clone zstd + uses: actions/checkout@v6 + with: + repository: ${{ env.UPSTREAM_REPO }} + ref: ${{ needs.version.outputs.tag }} + submodules: recursive + + - name: Build zstd in Alpine + env: + CFLAGS: ${{ env.CFLAGS_LIN_ARM }} + CXXFLAGS: ${{ env.CFLAGS_LIN_ARM }} + run: | + docker run --rm -v "$PWD:/src" -w /src \ + -e CFLAGS -e CXXFLAGS -e CMAKE_FLAGS \ + alpine:$ALPINE_VERSION sh -ec ' + apk add --no-cache build-base cmake git make gcc g++ + cmake -S build/cmake -B cmake-build $CMAKE_FLAGS + cmake --build cmake-build --parallel + ' + + - name: Stage artifact + shell: bash + run: | + mkdir artifact + cp cmake-build/lib/libzstd.so artifact/libzstd.so + + - name: Upload artifact + uses: actions/upload-artifact@v7 + with: + name: zstd-linux-musl-arm64 + path: artifact + compression-level: 9 publish-nuget: - needs: [build, build-musl] - runs-on: ubuntu-latest + runs-on: ubuntu-26.04 + if: github.event_name != 'pull_request' permissions: id-token: write - + needs: + - version + - build-windows-x64 + - build-windows-arm64 + - build-linux-x64 + - build-linux-arm64 + - build-macos-x64 + - build-macos-arm64 + - build-musl-x64 + - build-musl-arm64 steps: - - name: Checkout CSPROJ files + - name: Checkout Natives repo uses: actions/checkout@v6 - name: Setup .NET - uses: actions/setup-dotnet@v4 + uses: actions/setup-dotnet@v5 with: dotnet-version: 9 - - name: Download Artifacts - uses: actions/download-artifact@v4 + - name: Download artifacts + uses: actions/download-artifact@v8 with: path: temp pattern: zstd-* - merge-multiple: true - - - name: Move Artifacts - run: | - mkdir -p lib/zstd/win-x64/native - mkdir -p lib/zstd/linux-x64/native - mkdir -p lib/zstd/win-arm64/native - mkdir -p lib/zstd/linux-arm64/native - mkdir -p lib/zstd/osx/native - mkdir -p lib/zstd/linux-musl-x64/native - mkdir -p lib/zstd/linux-musl-arm64/native - cp temp/x64/libzstd.dll lib/zstd/win-x64/native/libzstd.dll - cp temp/x64/libzstd.so lib/zstd/linux-x64/native/libzstd.so - cp temp/ARM64/libzstd.dll lib/zstd/win-arm64/native/libzstd.dll - cp temp/ARM64/libzstd.so lib/zstd/linux-arm64/native/libzstd.so - cp temp/libzstd.dylib lib/zstd/osx/native/libzstd.dylib - cp temp/x64/libzstd.musl.so lib/zstd/linux-musl-x64/native/libzstd.so - cp temp/ARM64/libzstd.musl.so lib/zstd/linux-musl-arm64/native/libzstd.so + + - name: Assemble runtime tree + shell: bash + run: | + for rid in win-x64 win-arm64 linux-x64 linux-arm64 osx-x64 osx-arm64 linux-musl-x64 linux-musl-arm64; do + mkdir -p "lib/zstd/$rid/native" + cp "temp/zstd-$rid"/* "lib/zstd/$rid/native/" + done - name: Login to NuGet id: nuget-login @@ -203,12 +366,11 @@ jobs: with: user: ${{ secrets.NUGET_USER }} - - name: Pack DSharpPlus.Natives.Zstd + - name: Pack and push shell: bash env: NUGET_API_KEY: ${{ steps.nuget-login.outputs.NUGET_API_KEY }} - VERSION: ${{ needs.build.outputs.version }} + VERSION: ${{ needs.version.outputs.version }} run: | - VERSION="${VERSION:1}" dotnet pack ./build/DSharpPlus.Natives.Zstd.csproj -c Release -p:Version="$VERSION.${{ github.run_number }}" - dotnet nuget push "artifacts/**" --skip-duplicate -k "$NUGET_API_KEY" -s https://api.nuget.org/v3/index.json \ No newline at end of file + dotnet nuget push "artifacts/**" --skip-duplicate -k "$NUGET_API_KEY" -s https://api.nuget.org/v3/index.json