-
-
Notifications
You must be signed in to change notification settings - Fork 39
Provide prebuilt native libraries by NuGet Packages. #257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ha-ves
wants to merge
12
commits into
NetCordDev:alpha
Choose a base branch
from
ha-ves:feature/prebuilt-natives
base: alpha
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4b3d111
Pivot to use vcpkg to build natives
ha-ves 48bfd5b
* Add NetCord.Natives project and vcpkg support
ha-ves f0030a5
feat: native library support and testing
ha-ves 247d363
* Refactor NetCord.Natives.csproj for improved build configuration
ha-ves aa317d0
* Refactor native library handling and packaging
ha-ves da37fff
CI finished & fix typos & guarding
ha-ves a883480
solution build fix
ha-ves 498226a
separate solution for natives
ha-ves ee00a64
refactor native build/test pipeline
ha-ves a748fa6
Clean up & atomize CI workflows
ha-ves d93ced7
Apply typos and internals fixes
ha-ves d6fd84e
Merge branch 'alpha' into feature/prebuilt-natives
KubaZ2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| name: Setup vcpkg | ||
| description: Setup vcpkg with fallback to submodule checkout | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Resolve or checkout vcpkg | ||
| shell: pwsh | ||
| run: | | ||
| # Ensure vcpkg cache and downloads directories exist | ||
| New-Item -ItemType Directory -Path $env:VCPKG_BINARY_SOURCES.Split(',')[1] -Force | Out-Null | ||
| New-Item -ItemType Directory -Path $env:VCPKG_DOWNLOADS -Force | Out-Null | ||
|
|
||
| $vcpkgRoot = $env:VCPKG_INSTALLATION_ROOT | ||
| if (-not $vcpkgRoot) { | ||
| $vcpkgCommand = Get-Command vcpkg -ErrorAction SilentlyContinue | ||
| if ($vcpkgCommand) { | ||
| $vcpkgRoot = Split-Path -Parent $vcpkgCommand.Source | ||
| } | ||
| } | ||
|
|
||
| if (-not $vcpkgRoot -or -not (Test-Path $vcpkgRoot)) { | ||
| Write-Host "vcpkg not found in runner image, checking out from submodule..." | ||
| git config --file .gitmodules --get-regexp path | while-object { $_.Split()[-1] | where-object { $_ -match 'vcpkg' } } | ForEach-Object { | ||
| git submodule update --init --recursive $_ | ||
| } | ||
| $vcpkgRoot = Join-Path $env:GITHUB_WORKSPACE "vcpkg" | ||
| if (-not (Test-Path $vcpkgRoot)) { | ||
| Write-Error "vcpkg submodule not found and vcpkg executable not available" | ||
| exit 1 | ||
| } | ||
| } | ||
|
|
||
| if (Test-Path $vcpkgRoot) { | ||
| Write-Host "Bootstrapping vcpkg from: $vcpkgRoot" | ||
| if ($IsWindows) { | ||
| & "$vcpkgRoot/bootstrap-vcpkg.bat" -disableMetrics | ||
| } else { | ||
| & "$vcpkgRoot/bootstrap-vcpkg.sh" -disableMetrics | ||
| } | ||
| } | ||
|
|
||
| "VCPKG_ROOT=$vcpkgRoot" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8 |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| name: Build, Test, and Package NetCord.Natives | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| paths: | ||
| - 'NetCord.Natives/**' | ||
| - '.github/workflows/build-natives.yml' | ||
| tags: | ||
| - "[0-9]+.[0-9]+.[0-9]+" | ||
| - "[0-9]+.[0-9]+.[0-9]+-*" | ||
|
|
||
| jobs: | ||
| build-test-natives: | ||
| runs-on: ${{ matrix.runs-on }} | ||
| env: | ||
| CI: true | ||
| VCPKG_BINARY_SOURCES: clear;files,${{ github.workspace }}/.vcpkg-cache,readwrite | ||
| VCPKG_DOWNLOADS: ${{ github.workspace }}/.vcpkg-downloads | ||
| VcpkgOSTarget: ${{ matrix.vcpkg-os-target }} | ||
| VcpkgPlatformTarget: ${{ matrix.vcpkg-platform-target }} | ||
| Configuration: Release | ||
| RuntimeIdentifier: ${{ matrix.rid }} | ||
| DotnetVerbose: minimal | ||
|
|
||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - rid: win-x64 | ||
| runs-on: windows-latest | ||
| vcpkg-os-target: windows | ||
| vcpkg-platform-target: x64 | ||
| - rid: win-arm64 | ||
| runs-on: windows-11-arm | ||
| vcpkg-os-target: windows | ||
| vcpkg-platform-target: arm64 | ||
| - rid: osx-x64 | ||
| runs-on: macos-15-intel | ||
| vcpkg-os-target: osx | ||
| vcpkg-platform-target: x64 | ||
| - rid: osx-arm64 | ||
| runs-on: macos-15 | ||
| vcpkg-os-target: osx | ||
| vcpkg-platform-target: arm64 | ||
| - rid: linux-x64 | ||
| runs-on: ubuntu-latest | ||
| vcpkg-os-target: linux | ||
| vcpkg-platform-target: x64 | ||
| - rid: linux-arm64 | ||
| runs-on: ubuntu-24.04-arm | ||
| vcpkg-os-target: linux | ||
| vcpkg-platform-target: arm64 | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6.0.2 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Restore vcpkg cache | ||
| uses: actions/cache/restore@v5.0.5 | ||
| with: | ||
| path: | | ||
| .vcpkg-cache | ||
| .vcpkg-downloads | ||
| key: vcpkg-${{ runner.os }}-${{ matrix.rid }}-${{ hashFiles('NetCord.Natives/vcpkg.json', 'NetCord.Natives/natives-ports/**') }} | ||
| restore-keys: | | ||
| vcpkg-${{ runner.os }}-${{ matrix.rid }}- | ||
| vcpkg-${{ runner.os }}- | ||
|
|
||
| - name: Setup vcpkg | ||
| uses: ./.github/actions/setup-vcpkg | ||
|
|
||
| - name: Setup .NET Core SDK | ||
| uses: actions/setup-dotnet@v5.2.0 | ||
| with: | ||
| global-json-file: global.json | ||
|
|
||
| - name: Install native build tools (macOS) | ||
| if: runner.os == 'macOS' | ||
| shell: bash | ||
| run: | | ||
| brew update | ||
| brew install autoconf automake libtool | ||
|
|
||
| - name: Restore | ||
| shell: pwsh | ||
| run: | | ||
| dotnet restore Tests/NetCord.Natives.Tests/NetCord.Natives.Tests.csproj -v normal | ||
|
|
||
| - name: Build natives projects for ${{ matrix.rid }} | ||
| shell: pwsh | ||
| run: > # Building tests will build dependencies including the native libraries | ||
| dotnet build Tests/NetCord.Natives.Tests/NetCord.Natives.Tests.csproj --no-restore -v ${{ env.DotnetVerbose }} | ||
| -p:AppendNativeAotAppProps="RuntimeIdentifier=${{ env.RuntimeIdentifier }}" | ||
| -p:GeneratePackageOnBuild=false | ||
|
|
||
| - name: Test natives outputs for ${{ matrix.rid }} | ||
| shell: pwsh | ||
| run: > | ||
| dotnet test Tests/NetCord.Natives.Tests/NetCord.Natives.Tests.csproj --no-restore --no-build -v ${{ env.DotnetVerbose }} | ||
| --logger GitHubActions | ||
|
|
||
| - name: List built for ${{ matrix.rid }} | ||
| if: ${{ always() }} | ||
| shell: pwsh | ||
| run: | | ||
| $rid = '${{ matrix.rid }}' | ||
| $tripletBase = '${{ matrix.vcpkg-platform-target }}-${{ matrix.vcpkg-os-target }}' | ||
| $suffix = if ($IsWindows) { 'static' } else { 'dynamic' } | ||
| $triplets = @("$tripletBase", "$tripletBase-$suffix") | ||
|
|
||
| foreach ($variant in @('natives','natives-static')) { | ||
| foreach ($triplet in @($triplets)) { | ||
| foreach ($folder in @('bin','lib')) { | ||
| $path = "NetCord.Natives/bin/$rid/$variant/$triplet/$folder" | ||
| if (Test-Path $path) { | ||
| Get-ChildItem -Path $path -Recurse | ||
| } else { | ||
| Write-Host "[Info] Not found: $path" | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| - name: Pack NuGet Package for ${{ matrix.rid }} | ||
| shell: pwsh | ||
| run: > | ||
| dotnet pack NetCord.Natives/NetCord.Natives.csproj --no-restore --no-build -v ${{ env.DotnetVerbose }} | ||
| -o NetCord.Natives/bin/${{ matrix.rid }} | ||
| -p:CI=false | ||
|
|
||
| - name: Upload NuGet Package Artifact | ||
| uses: actions/upload-artifact@v7.0.1 | ||
| with: | ||
| name: NetCord.Natives.${{ matrix.rid }}.nupkg | ||
| path: NetCord.Natives/bin/${{ matrix.rid }}/*.nupkg | ||
|
|
||
| - name: Save vcpkg cache | ||
| if: ${{ always() }} | ||
| uses: actions/cache/save@v5.0.5 | ||
| with: | ||
| path: | | ||
| .vcpkg-cache | ||
| .vcpkg-downloads | ||
| key: vcpkg-${{ runner.os }}-${{ matrix.rid }}-${{ hashFiles('NetCord.Natives/vcpkg.json', 'NetCord.Natives/natives-ports/**') }} | ||
|
|
||
| publish: | ||
| needs: [build-test-natives] | ||
| if: startsWith(github.ref, 'refs/tags/') | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Download All NuGet Package Artifacts | ||
| uses: actions/download-artifact@v8.0.1 | ||
| with: | ||
| path: artifacts/pkgs | ||
| pattern: NetCord.Natives*.nupkg | ||
|
|
||
| - name: Publish packages | ||
| env: | ||
| KEY: ${{ secrets.NUGET_API_KEY }} | ||
| run: | | ||
| dotnet nuget push artifacts/pkgs/*.nupkg -k $KEY -s https://api.nuget.org/v3/index.json --skip-duplicate |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [submodule "NetCord.Natives/vcpkg"] | ||
| path = NetCord.Natives/vcpkg | ||
| url = https://github.com/microsoft/vcpkg.git |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.