diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml index 4090c7e..b58c6f4 100644 --- a/.github/workflows/default.yml +++ b/.github/workflows/default.yml @@ -11,35 +11,179 @@ on: workflow_dispatch: env: + ARTIFACT_DIR: ${{ github.workspace }}/dist + CMAKE_TOOLCHAIN_FILE: ${{ github.workspace }}/cpp/vcpkg/scripts/buildsystems/vcpkg.cmake DOTNET_NOLOGO: true + LIBDAVE_VERSION: 1.1.1 NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages + VCPKG_BINARY_SOURCES: clear;files,${{ github.workspace }}/vcpkg_cache,readwrite + VCPKG_CACHE_DIR: ${{ github.workspace }}/vcpkg_cache jobs: build: - runs-on: ubuntu-latest + name: build (${{ matrix.rid }}) + runs-on: ${{ matrix.runner }} + defaults: + run: + working-directory: ./cpp + shell: bash + + strategy: + fail-fast: false + matrix: + include: + - rid: linux-x64 + runner: ubuntu-24.04 + vcpkg_rid: x64-linux + + - rid: linux-arm64 + runner: ubuntu-24.04-arm + vcpkg_rid: arm64-linux + + - rid: osx-arm64 + runner: macos-26 + vcpkg_rid: arm64-osx + + - rid: osx-x64 + runner: macos-26-intel + vcpkg_rid: x64-osx + + - rid: win-x64 + runner: windows-2025 + vcpkg_rid: x64-windows-static + steps: - name: checkout uses: actions/checkout@v6 with: - fetch-depth: 1 + repository: discord/libdave + ref: v${{ env.LIBDAVE_VERSION }}/cpp + submodules: recursive + fetch-depth: 0 - - name: setup dotnet - uses: actions/setup-dotnet@v5 + - name: setup vcpkg + run: git -C vcpkg rev-parse HEAD > vcpkg_commit.txt + + - name: cache vcpkg + id: cache-vcpkg-restore + uses: actions/cache/restore@v5 with: - cache: true - cache-dependency-path: ./**/packages.lock.json - global-json-file: global.json + path: ${{ env.VCPKG_CACHE_DIR }} + key: vcpkg-${{ matrix.runner }}-openssl-${{ hashFiles('cpp/vcpkg_commit.txt', 'cpp/vcpkg-alts/**') }} + restore-keys: vcpkg-${{ matrix.runner }}-openssl - - name: restore sample - run: dotnet restore sample/libdave.sample.csproj --locked-mode + - name: setup tools (Linux) + if: runner.os == 'Linux' + run: sudo apt-get install -y nasm - - name: build sample - run: dotnet build sample/libdave.sample.csproj --no-restore + - name: setup tools (macOS) + if: runner.os == 'macOS' + run: brew install go nasm - pack: - if: startsWith(github.ref, 'refs/heads/main') || startsWith(github.ref, 'refs/heads/develop') + - name: bootstrap vcpkg (linux/macOS) + if: runner.os != 'Windows' + run: ./vcpkg/bootstrap-vcpkg.sh -disableMetrics + + - name: bootstrap vcpkg (windows) + if: runner.os == 'Windows' + shell: cmd + run: .\vcpkg\bootstrap-vcpkg.bat -disableMetrics + + - name: setup build + run: echo "BUILD_DIR=${{ runner.temp }}/build" >> $GITHUB_ENV + + - name: configure (shared) + run: | + make "${{ env.BUILD_DIR }}-shared" \ + BUILD_DIR="${{ env.BUILD_DIR }}-shared" \ + BUILD_TYPE=Release \ + BUILD_SHARED_LIBS=ON \ + TESTING=OFF \ + INSTALL_VCPKG_LICENSES=ON \ + MSVC_RUNTIME_LIBRARY=MultiThreaded + + - name: configure (static) + run: | + make "${{ env.BUILD_DIR }}-static" \ + BUILD_DIR="${{ env.BUILD_DIR }}-static" \ + BUILD_TYPE=Release \ + BUILD_SHARED_LIBS=OFF \ + TESTING=OFF \ + INSTALL_VCPKG_LICENSES=ON \ + MSVC_RUNTIME_LIBRARY=MultiThreaded + + - name: build (shared) + run: | + make all \ + BUILD_DIR="${{ env.BUILD_DIR }}-shared" \ + BUILD_TYPE=Release + + - name: build (static) + run: | + make all \ + BUILD_DIR="${{ env.BUILD_DIR }}-static" \ + BUILD_TYPE=Release + + - name: prepare artifact (linux) + if: runner.os == 'Linux' + run: | + mkdir -p "${{ env.ARTIFACT_DIR }}/bin" "${{ env.ARTIFACT_DIR }}/lib" + cp "${{ env.BUILD_DIR }}-shared/libdave.so" "${{ env.ARTIFACT_DIR }}/bin/libdave.so" + cp "${{ env.BUILD_DIR }}-static/libdave.a" "${{ env.ARTIFACT_DIR }}/lib/libdave.a" + + VCPKG_INSTALLED="${{ env.BUILD_DIR }}-static/vcpkg_installed/${{ matrix.vcpkg_rid }}" + cp ${VCPKG_INSTALLED}/lib/libbytes.a ${{ env.ARTIFACT_DIR }}/lib/libbytes.a + cp ${VCPKG_INSTALLED}/lib/libhpke.a ${{ env.ARTIFACT_DIR }}/lib/libhpke.a + cp ${VCPKG_INSTALLED}/lib/libmlspp.a ${{ env.ARTIFACT_DIR }}/lib/libmlspp.a + cp ${VCPKG_INSTALLED}/lib/libtls_syntax.a ${{ env.ARTIFACT_DIR }}/lib/libtls_syntax.a + + - name: prepare artifact (macOS) + if: runner.os == 'macOS' + run: | + mkdir -p "${{ env.ARTIFACT_DIR }}/bin" "${{ env.ARTIFACT_DIR }}/lib" + cp "${{ env.BUILD_DIR }}-shared/libdave.dylib" "${{ env.ARTIFACT_DIR }}/bin/libdave.dylib" + cp "${{ env.BUILD_DIR }}-static/libdave.a" "${{ env.ARTIFACT_DIR }}/lib/libdave.a" + VCPKG_INSTALLED="${{ env.BUILD_DIR }}-static/vcpkg_installed/${{ matrix.vcpkg_rid }}" + cp ${VCPKG_INSTALLED}/lib/libbytes.a ${{ env.ARTIFACT_DIR }}/lib/libbytes.a + cp ${VCPKG_INSTALLED}/lib/libhpke.a ${{ env.ARTIFACT_DIR }}/lib/libhpke.a + cp ${VCPKG_INSTALLED}/lib/libmlspp.a ${{ env.ARTIFACT_DIR }}/lib/libmlspp.a + cp ${VCPKG_INSTALLED}/lib/libtls_syntax.a ${{ env.ARTIFACT_DIR }}/lib/libtls_syntax.a + + - name: prepare artifact (windows) + if: runner.os == 'Windows' + run: | + mkdir -p "${{ env.ARTIFACT_DIR }}/bin" "${{ env.ARTIFACT_DIR }}/lib" + cp "${{ env.BUILD_DIR }}-shared/Release/libdave.dll" "${{ env.ARTIFACT_DIR }}/bin/libdave.dll" + cp "${{ env.BUILD_DIR }}-static/Release/libdave.lib" "${{ env.ARTIFACT_DIR }}/lib/libdave.lib" + + VCPKG_INSTALLED="${{ env.BUILD_DIR }}-static/vcpkg_installed/${{ matrix.vcpkg_rid }}" + cp "${VCPKG_INSTALLED}/lib/bytes.lib" "${{ env.ARTIFACT_DIR }}/lib/libbytes.lib" + cp "${VCPKG_INSTALLED}/lib/hpke.lib" "${{ env.ARTIFACT_DIR }}/lib/libhpke.lib" + cp "${VCPKG_INSTALLED}/lib/mlspp.lib" "${{ env.ARTIFACT_DIR }}/lib/libmlspp.lib" + cp "${VCPKG_INSTALLED}/lib/tls_syntax.lib" "${{ env.ARTIFACT_DIR }}/lib/libtls_syntax.lib" + + - name: upload artifact + uses: actions/upload-artifact@v7 + with: + name: libdave-${{ matrix.rid }} + path: ${{ env.ARTIFACT_DIR }} + + - name: Post cache vcpkg + if: steps.cache-vcpkg-restore.outputs.cache-hit != 'true' + uses: actions/cache/save@v5 + with: + key: ${{ steps.cache-vcpkg-restore.outputs.cache-primary-key }} + path: ${{ env.VCPKG_CACHE_DIR }} + + pack: + needs: [build] runs-on: ubuntu-latest + + permissions: + checks: write + contents: read + steps: - name: checkout uses: actions/checkout@v6 @@ -54,23 +198,58 @@ jobs: cache-dependency-path: ./**/packages.lock.json global-json-file: global.json + - name: download artifacts + uses: actions/download-artifact@v8 + with: + pattern: libdave-* + merge-multiple: false + path: artifact + - name: restore - run: dotnet restore --locked-mode + shell: pwsh + run: | + dotnet restore --locked-mode + + $artifact = Join-Path ${{ github.workspace }} "artifact" + $output = Join-Path ${{ github.workspace }} "src" + + foreach ($runtime in @("linux-arm64", "linux-x64", "osx-arm64", "osx-x64", "win-x64")) { + foreach ($file in Get-ChildItem -Path ([System.IO.Path]::Combine($artifact, "libdave-$runtime", "lib")) -Recurse -File) { + New-Item -ItemType Directory -Path ([System.IO.Path]::Combine($output, "static", $runtime, "native")) -Force | Out-Null + + $destination = [System.IO.Path]::Combine($output, "static", $runtime, "native", $file.Name) + Move-Item -Path $file.FullName -Destination $destination -Force + + Write-Host "[!] Moved ${file.FullName} to '$destination'" + } + + foreach ($file in Get-ChildItem -Path ([System.IO.Path]::Combine($artifact, "libdave-$runtime", "bin")) -Recurse -File) { + New-Item -ItemType Directory -Path ([System.IO.Path]::Combine($output, "shared", $runtime, "native")) -Force | Out-Null + + $destination = [System.IO.Path]::Combine($output, "shared", $runtime, "native", $file.Name) + Move-Item -Path $file.FullName -Destination $destination -Force + + Write-Host "[!] Moved ${file.FullName} to '$destination'" + } + } - name: pack - run: dotnet build src/libdave.csproj -c Release && dotnet pack src/libdave.csproj -c Release -o dist --no-build + run: dotnet build src/libdave.csproj -c Release -p:LibDaveVersion="${{ env.LIBDAVE_VERSION }}" && dotnet pack src/libdave.csproj -c Release -o dist --no-build -p:LibDaveVersion="${{ env.LIBDAVE_VERSION }}" - name: upload artifact uses: actions/upload-artifact@v7 with: - name: libdave + name: libdave-nuget path: dist publish: + if: startsWith(github.ref, 'refs/heads/main') || startsWith(github.ref, 'refs/heads/develop') + needs: [pack] runs-on: ubuntu-latest permissions: + contents: read id-token: write steps: @@ -93,7 +272,7 @@ jobs: - name: download artifact uses: actions/download-artifact@v8 with: - name: libdave + name: libdave-nuget - name: push run: dotnet nuget push "*.nupkg" --api-key ${{steps.login.outputs.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json --skip-duplicate diff --git a/Directory.Build.props b/Directory.Build.props index 7259b3b..c8db074 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -13,6 +13,7 @@ false strict true + true true true latest @@ -30,7 +31,7 @@ - 1.1.1 + 1.1.1 @@ -54,6 +55,7 @@ + diff --git a/README.md b/README.md index f7c296f..9c77bce 100644 --- a/README.md +++ b/README.md @@ -8,5 +8,5 @@ Native library assets for [libdave](https://github.com/discord/libdave). | Property | Default | Description | | -------------------------------- | -------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | -| `$(LibDaveEnableRuntimeLinking)` | `true` | Toggle whether shared libraries are copied to the output directory. | -| `$(LibDaveEnableStaticLinking)` | `$(PublishAot) == 'true' AND $(RuntimeIdentifier) != ''` | Toggle whether `DirectPInvoke`+`NativeLibrary` items are included in the project (for Static Linking) | \ No newline at end of file +| `$(LibDaveRuntimeLinking)` | `true` | Toggle whether shared libraries are copied to the output directory. | +| `$(LibDaveStaticLinking)` | `$(PublishAot) == 'true' AND $(RuntimeIdentifier) != ''` | Toggle whether `DirectPInvoke`+`NativeLibrary` items are included in the project (for Static Linking) | \ No newline at end of file diff --git a/sample/libdave.sample.csproj b/sample/libdave.sample.csproj index 0b336e7..4ef4b47 100644 --- a/sample/libdave.sample.csproj +++ b/sample/libdave.sample.csproj @@ -3,6 +3,8 @@ Exe + true + linux-x64;win-x64 net10.0 diff --git a/sample/packages.lock.json b/sample/packages.lock.json index 3c59e45..a6de1e1 100644 --- a/sample/packages.lock.json +++ b/sample/packages.lock.json @@ -8,6 +8,24 @@ "resolved": "10.0.201", "contentHash": "MTE+F0fj0N8dtfkEGIcX3/rEycMbOf54DXq/n6n8cE6ZfDIPEElY8lc4X5BpZ+c7DBoQDGLG0iBY/W0YZ3nhtw==" }, + "Microsoft.DotNet.ILCompiler": { + "type": "Direct", + "requested": "[10.0.5, )", + "resolved": "10.0.5", + "contentHash": "yadTZIkStCVsG8nGwvfroSfBApPsgjQbodQyaIfp53dgayE0qhZpywixiCB6lx57JYQ+KVg1m1AFLrj54pxpZg==" + }, + "Microsoft.NET.ILLink.Tasks": { + "type": "Direct", + "requested": "[10.0.5, )", + "resolved": "10.0.5", + "contentHash": "A+5ZuQ0f449tM+MQrhf6R9ZX7lYpjk/ODEwLYKrnF6111rtARx8fVsm4YznUnQiKnnXfaXNBqgxmil6RW3L3SA==" + }, + "Microsoft.Sbom.Targets": { + "type": "Direct", + "requested": "[4.1.5, )", + "resolved": "4.1.5", + "contentHash": "i5z+cNu/cOcdO0AgFB8aXk8w6In2H+haaDfSgd9ImvQIK+rSHavHZIogVoAZLL8jLwYx4bAcs5b7EyuMMG4mQQ==" + }, "Microsoft.SourceLink.GitHub": { "type": "Direct", "requested": "[10.0.201, )", @@ -46,6 +64,38 @@ "libdave": { "type": "Project" } + }, + "net10.0/linux-x64": { + "Microsoft.DotNet.ILCompiler": { + "type": "Direct", + "requested": "[10.0.5, )", + "resolved": "10.0.5", + "contentHash": "yadTZIkStCVsG8nGwvfroSfBApPsgjQbodQyaIfp53dgayE0qhZpywixiCB6lx57JYQ+KVg1m1AFLrj54pxpZg==", + "dependencies": { + "runtime.linux-x64.Microsoft.DotNet.ILCompiler": "10.0.5" + } + }, + "runtime.linux-x64.Microsoft.DotNet.ILCompiler": { + "type": "Transitive", + "resolved": "10.0.5", + "contentHash": "QYAggijHfk8FpLrPVhaESEOCYGWzEjA9JLapzg6XMFK5TGmwQ2HIqEprFv28MwvB5GdPGaZVLXE5icnkgLUfSA==" + } + }, + "net10.0/win-x64": { + "Microsoft.DotNet.ILCompiler": { + "type": "Direct", + "requested": "[10.0.5, )", + "resolved": "10.0.5", + "contentHash": "yadTZIkStCVsG8nGwvfroSfBApPsgjQbodQyaIfp53dgayE0qhZpywixiCB6lx57JYQ+KVg1m1AFLrj54pxpZg==", + "dependencies": { + "runtime.win-x64.Microsoft.DotNet.ILCompiler": "10.0.5" + } + }, + "runtime.win-x64.Microsoft.DotNet.ILCompiler": { + "type": "Transitive", + "resolved": "10.0.5", + "contentHash": "vblLkpVhSDYOmrEW0jypX7YVtLg7idU1QzUyx45ZdZ2sFUSSf3mYFCr0FW3+KZgXWpN1ve9ZPrxNywvHISF4bA==" + } } } } \ No newline at end of file diff --git a/src/build/libdave.props b/src/build/libdave.props index fe80bb3..a2a247e 100644 --- a/src/build/libdave.props +++ b/src/build/libdave.props @@ -2,9 +2,11 @@ $([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\..')) - true - true + false + true + auto + true \ No newline at end of file diff --git a/src/build/libdave.targets b/src/build/libdave.targets index 293469e..e5e066a 100644 --- a/src/build/libdave.targets +++ b/src/build/libdave.targets @@ -2,17 +2,17 @@ - false + false - true + true - false + false - - + + PreserveNewest PreserveNewest runtimes\%(RecursiveDir)\%(Filename)%(Extension) @@ -27,13 +27,24 @@ - - - + + true + true + + + + + + + + + + - - + + + \ No newline at end of file diff --git a/src/libdave.csproj b/src/libdave.csproj index 06a0f51..055b51f 100644 --- a/src/libdave.csproj +++ b/src/libdave.csproj @@ -1,11 +1,11 @@ - Native library assets for libdave. true $(NoWarn);NU5100;NU5128; README.md + linux-arm64;linux-x64;osx-arm64;osx-x64;win-x64 netstandard2.1 @@ -16,4 +16,5 @@ + \ No newline at end of file diff --git a/src/libdave.targets b/src/libdave.targets deleted file mode 100644 index 46f9844..0000000 --- a/src/libdave.targets +++ /dev/null @@ -1,90 +0,0 @@ - - - - 3 - $(BaseIntermediateOutputPath)\libdave - - $(BaseIntermediateOutputPath)\libdave.assets - $(LibDaveOutput)\assets - - $(BaseIntermediateOutputPath)\libdave.packages - $(LibDaveOutput)\packages - - - - - - - - - - - - - - - - - - - - - - <_LibDaveDownloadBaseUrl>https://github.com/discord/libdave/releases/download/ - <_LibDaveReleaseTag>$([System.Uri]::EscapeDataString('v$(LibDaveVersion)/cpp')) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <_LibDaveAsset Include="$(LibDaveAssetsOutput)\**\*.*" /> - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/packages.lock.json b/src/packages.lock.json index 06b9587..c43f79c 100644 --- a/src/packages.lock.json +++ b/src/packages.lock.json @@ -8,6 +8,12 @@ "resolved": "10.0.201", "contentHash": "MTE+F0fj0N8dtfkEGIcX3/rEycMbOf54DXq/n6n8cE6ZfDIPEElY8lc4X5BpZ+c7DBoQDGLG0iBY/W0YZ3nhtw==" }, + "Microsoft.Sbom.Targets": { + "type": "Direct", + "requested": "[4.1.5, )", + "resolved": "4.1.5", + "contentHash": "i5z+cNu/cOcdO0AgFB8aXk8w6In2H+haaDfSgd9ImvQIK+rSHavHZIogVoAZLL8jLwYx4bAcs5b7EyuMMG4mQQ==" + }, "Microsoft.SourceLink.GitHub": { "type": "Direct", "requested": "[10.0.201, )", @@ -57,6 +63,11 @@ "resolved": "4.6.3", "contentHash": "qdcDOgnFZY40+Q9876JUHnlHu7bosOHX8XISRoH94fwk6hgaeQGSgfZd8srWRZNt5bV9ZW2TljcegDNxsf+96A==" } - } + }, + ".NETStandard,Version=v2.1/linux-arm64": {}, + ".NETStandard,Version=v2.1/linux-x64": {}, + ".NETStandard,Version=v2.1/osx-arm64": {}, + ".NETStandard,Version=v2.1/osx-x64": {}, + ".NETStandard,Version=v2.1/win-x64": {} } } \ No newline at end of file diff --git a/tool/download.ps1 b/tool/download.ps1 deleted file mode 100644 index 1b469ae..0000000 --- a/tool/download.ps1 +++ /dev/null @@ -1,70 +0,0 @@ -[CmdletBinding()] -param( - [Parameter(Mandatory)] - [string]$Version, - - [Parameter(Mandatory)] - [string]$OutputDir -) - -function Get-NetCoreRuntime { - param([string]$runtime) - - if ($runtime -eq "windows-x64") { return "win-x64" } - return $runtime -} - -$runtimes = @("linux-arm64", "linux-x64", "macos-arm64", "macos-x64", "windows-x64") -$cache = ([System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), [System.IO.Path]::GetRandomFileName())) - -New-Item -ItemType Directory -Path $cache | Out-Null -Write-Host "[!] Downloading Packages $Version to '$cache'..." - -$version = "v$Version/cpp" -foreach ($runtime in $runtimes) { - $package = "libdave-$runtime-boringssl.zip" - $url = "https://github.com/discord/libdave/releases/download/$([Uri]::EscapeDataString($version))/$package" - - $destination = [System.IO.Path]::Combine($cache, $package) - Invoke-WebRequest -Uri $url -OutFile $destination - - Write-Host "[!] Downloaded $package to '$destination'" -} - -$obj = ([System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), [System.IO.Path]::GetRandomFileName())) - -Write-Host "[!] Extracting Packages to '$obj'..." -foreach ($runtime in $runtimes) { - $package = "libdave-$runtime-boringssl.zip" - - $destination = [System.IO.Path]::Combine($obj, $runtime) - Expand-Archive -Path ([System.IO.Path]::Combine($cache, $package)) -DestinationPath $destination - - Write-Host "[!] Extracted $package to '$destination'" -} - - -Write-Host "[!] Moving Assets to '$OutputDir'..." -foreach ($runtime in $runtimes) { - $rid = $(Get-NetCoreRuntime $runtime) - - foreach ($file in Get-ChildItem -Path ([System.IO.Path]::Combine($obj, $runtime, "lib")) -Recurse -File) { - New-Item -ItemType Directory -Path ([System.IO.Path]::Combine($OutputDir, "static", $rid, "native")) -Force | Out-Null - - $destination = [System.IO.Path]::Combine($OutputDir, "static", $rid, "native", $file.Name) - Move-Item -Path $file.FullName -Destination $destination -Force - - Write-Host "[!] Moved ${file.FullName} to '$destination'" - } - - foreach ($file in Get-ChildItem -Path ([System.IO.Path]::Combine($obj, $runtime, "bin")) -Recurse -File) { - New-Item -ItemType Directory -Path ([System.IO.Path]::Combine($OutputDir, "runtimes", $rid, "native")) -Force | Out-Null - - $destination = [System.IO.Path]::Combine($OutputDir, "runtimes", $rid, "native", $file.Name) - Move-Item -Path $file.FullName -Destination $destination -Force - - Write-Host "[!] Moved ${file.FullName} to '$destination'" - } - - Write-Host "[!] Moved Assets for runtime '$runtime'" -} \ No newline at end of file