Provide prebuilt native libraries by NuGet Packages.#257
Draft
ha-ves wants to merge 10 commits intoNetCordDev:alphafrom
Draft
Provide prebuilt native libraries by NuGet Packages.#257ha-ves wants to merge 10 commits intoNetCordDev:alphafrom
ha-ves wants to merge 10 commits intoNetCordDev:alphafrom
Conversation
dd93de7 to
7ab57a9
Compare
* put into nuget package
* Add native ports for libdave and mlspp * Update build workflows for native packaging * Add local targets and CI helpers for natives * Update README
- GitHub Actions tag triggers, NuGet publish job - NativesHelper, NativeLibraryVersionAttribute - vcpkg integration, static linking - zstd support - native library tests, import checks - Native AOT test app - NetCordNativesDir assembly metadata
* Add MSVC builtin add overflow patch for libdave * Add vcpkg-non-windows.targets for cross-platform support * Update libdave and mlspp portfiles with build fixes * Update build-natives workflow and vcpkg.json versions * Fix vcpkg dependency resolution for multi-platform builds
* Add dynamic library exclusion for AOT builds * Add NativeAotApp test project
1c05c69 to
6565a35
Compare
* natives conditionals fix * fix nativeaot test structure * add natives tests to build workflow
|
The documentation preview is available at https://preview.netcord.dev/257. |
|
I feel like the best option is to do something like: |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Continues from #245. Implements CI-driven distribution of prebuilt native binary dependencies.
Supported Platforms & Build Variants
win-x64win-arm64linux-x64linux-arm64osx-x64osx-arm64Overview
This PR provides prebuilt native libraries via NuGet. The primary, provided distribution is a top-level package (
NetCord.Natives) that includes prebuilt artifacts; per-RID packages are an option produced when building from source (local or CI) for users who prefer minimal per-platform artifacts. Each package bundles:.dll,.so,.dylib) for standard .NET consumptionPackages are published automatically on successful CI builds to the configured NuGet feed.
Structure & Packaging Model
Dual Distribution Model:
Top-Level Package (
NetCord.Natives): Bundles all RID variants in a single packagePer-RID Targeted Packages: Produced when building from source (local or CI builds). These are not required for consumers who install the provided top-level package.
NetCord.Natives.{win|linux|osx}-{x64|arm64}NetCord.Natives.linux-x64,NetCord.Natives.win-arm64Package Contents (both top-level and per-RID):
What Changed
Core Build & Packaging
libdave/portfile.cmake— builds from discord/libdave with MSVC patchmlspp/portfile.cmake— provides static build for libdave's cryptographic dependenciesMSBuild Integration
$(RuntimeIdentifier)Runtime Metadata
NativeLibraryVersionAttributefor runtime version discovery of bundled native libsHow to Use
Option 1: Top-Level Package (Simplest)
Add a single package reference for all platforms:
MSBuild automatically selects the correct RID variant at build time. Note: this package includes static libraries for all 6 RIDs, resulting in a larger download/installation footprint.
Option 2: Per-RID Targeted Package (Minimal Footprint)
If you build natives from source or use CI-produced per-RID artifacts, add only the package for your target platform:
Smaller download and disk usage; useful when you or your CI produces per-RID packages from source.
NativeAOT Trimmed Deployments
Use the top-level or per-RID package (static libraries are automatically linked, runtime binaries excluded for AOT):
Multi-Target Build with Per-RID Packages
For projects targeting multiple platforms with minimal per-platform size:
Alternatively, use the top-level package and MSBuild handles RID selection automatically.
Maintainer Notes: vcpkg Baseline & Dependency Pinning
All native dependencies are pinned to a specific vcpkg baseline (vcpkg.json) to ensure reproducible builds.
When upgrading native library versions:
vcpkg.jsonKnown build constraints:
gcc-aarch64-linux-gnucross-compiler toolchainVCPKG_CONCURRENCY=4to avoid OOM on resource-constrained runnersTesting
Comprehensive native library validation via Tests/NetCord.Natives.Tests/:
Unit Tests (NativesBuildTests.cs)
Framework: MSTest with method-level parallelization
Target: .NET 10.0
Three independent test methods validate the entire native stack:
NativeLoaded — Runtime Library Resolution
NativeLibrary.Load()RuntimeIdentifier)AllLibraryImportsExistInBinary — P/Invoke Symbol Verification
[LibraryImport]entry pointsNativeLibrary.TryGetExport()NativeAotStaticLinking — NativeAOT Full Integration
dotnet publish -c Releaseon NativeAotApp with NativeAOT enabledwin-x64,linux-x64,osx-arm64)NativeAOT Test Application (Assets/NativeAotApp/)
Standalone console app configured for AOT compilation (
PublishAot=true,IsAotCompatible=true):Validation Logic (Program.cs):
libdave:daveMaxSupportedProtocolVersion()libsodium:sodium_init()opus:opus_get_version_string()zstd:ZSTD_versionNumber()Coverage: All 6 supported RIDs tested implicitly (test framework builds and runs for current platform)
Test Execution Workflow
dotnet test NetCord.Natives.Tests.csprojNativeAotStaticLinkingtest; uses current platform's runtimeScope & Follow-Up Work
Included in This PR
✓ CI-driven multi-platform native package build and publish
✓ Dual distribution: top-level package + per-RID targeted packages
✓ NativeAOT static library support and MSBuild integration
✓ Custom vcpkg overlay ports for libdave and mlspp
Package Size Note
The top-level
NetCord.Nativespackage bundles static libraries for all 6 RIDs, resulting in a significantly larger footprint compared to per-RID packages:Choose based on your deployment scenario:
Out of Scope (Follow-Up Issues)