Build sodium #18
This file contains hidden or 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 sodium | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - master | |
| paths: | |
| - '.github/workflows/sodium.yml' | |
| jobs: | |
| build: | |
| name: Build sodium | |
| runs-on: ${{ matrix.os }} | |
| outputs: | |
| version: ${{ steps.print-version.outputs.version }} | |
| strategy: | |
| fail-fast: false # Run the other two OSs even if one fails | |
| matrix: | |
| os: [ windows-latest, ubuntu-latest, macos-latest ] | |
| steps: | |
| - name: Clone sodium repo | |
| uses: actions/checkout@v4.2.2 | |
| with: | |
| repository: jedisct1/libsodium | |
| 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: Install Visual Studio 2022 Build Tools | |
| if: matrix.os == 'windows-latest' | |
| shell: pwsh | |
| run: | | |
| choco install visualstudio2022buildtools --package-parameters "--add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.VC.Tools.ARM64 --includeRecommended --includeOptional" | |
| - name: Setup MSBuild | |
| uses: microsoft/setup-msbuild@v2 | |
| if: matrix.os == 'windows-latest' | |
| - name: Build sodium on Windows | |
| if: matrix.os == 'windows-latest' | |
| shell: pwsh | |
| 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 | |
| } | |
| - name: Build sodium | |
| if: matrix.os != 'windows-latest' | |
| 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 | |
| uses: actions/upload-artifact@v4.4.3 | |
| with: | |
| name: sodium-${{ matrix.os }} | |
| path: output | |
| compression-level: 9 # Prefer smaller downloads over a shorter workflow runtime | |
| 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 | |
| steps: | |
| - name: Clone sodium repo | |
| uses: actions/checkout@v4.2.2 | |
| with: | |
| repository: jedisct1/libsodium | |
| submodules: recursive | |
| - name: Checkout latest Tag | |
| 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 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 | |
| uses: actions/upload-artifact@v4.4.3 | |
| with: | |
| name: sodium-alpine-latest | |
| path: output | |
| compression-level: 9 # Prefer smaller downloads over a shorter workflow runtime | |
| publish-nuget: | |
| needs: [build, build-musl] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout CSPROJ files | |
| uses: actions/checkout@v4.2.2 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: 9 | |
| - name: Download Artifacts | |
| uses: actions/download-artifact@v4 | |
| 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: Pack DSharpPlus.Natives.Sodium | |
| shell: bash | |
| env: | |
| NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} | |
| VERSION: ${{ needs.build.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 |