Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions .github/workflows/build-libdave.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: Build Libdave.RID

on:
pull_request:
branches:
- stable
- alpha
- feature/e2ee-libdave
paths:
- 'NetCord/ThirdParty/Libdave/**'
- '.github/workflows/build-libdave.yml'
push:
branches:
- stable
- alpha
- feature/e2ee-libdave
paths:
- 'NetCord/ThirdParty/Libdave/**'
- '.github/workflows/build-libdave.yml'
workflow_dispatch:

jobs:
build-libdave:
strategy:
fail-fast: false
matrix:
include:
# Windows builds
- os: windows-2025-vs2026
rid: win-x86
arch: Win32
- os: windows-2025-vs2026
rid: win-x64
arch: x64
- os: windows-2025-vs2026
rid: win-arm64
arch: ARM64

# Linux builds
- os: ubuntu-latest
rid: linux-x64
- os: ubuntu-latest
rid: linux-arm64

# macOS builds
- os: macos-latest
rid: osx-arm64
- os: macos-latest-large
rid: osx-x64

runs-on: ${{ matrix.os }}

name: Build ${{ matrix.rid }}

steps:
- uses: actions/checkout@v6.0.2
with:
fetch-depth: 0
filter: tree:0
submodules: recursive

- name: Setup .NET
uses: actions/setup-dotnet@v5.1.0
with:
global-json-file: global.json

- name: Install Linux cross-compilation tools (ARM64)
if: matrix.os == 'ubuntu-latest' && matrix.rid == 'linux-arm64'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu

- name: Restore dependencies
run: dotnet restore NetCord/ThirdParty/Libdave/Libdave.RID/Libdave.RID.csproj -v normal -r ${{ matrix.rid }} /bl:restore-${{ matrix.rid }}.binlog

# /p:Configurations="RelWithDebInfo,MinSizeRel"
- id: install-nlohmann
name: Install nlohmann-json (vcpkg)
shell: pwsh
run: |
# Use vcpkg installed on the runner
$vcpkgPath = Join-Path $env:VCPKG_INSTALLATION_ROOT 'vcpkg'
if (Test-Path "$vcpkgPath.exe") { $vcpkgPath = "$vcpkgPath.exe" }
elseif (-not (Test-Path $vcpkgPath)) { Write-Error "vcpkg executable not found under $env:VCPKG_INSTALLATION_ROOT"; exit 1 }

switch ("${{ matrix.rid }}") {
'win-x86' { $triplet = 'x86-windows' }
'win-x64' { $triplet = 'x64-windows' }
'win-arm64' { $triplet = 'arm64-windows' }
'linux-x64' { $triplet = 'x64-linux' }
'linux-arm64'{ $triplet = 'arm64-linux' }
'osx-x64' { $triplet = 'x64-osx' }
'osx-arm64' { $triplet = 'arm64-osx' }
default { Write-Host "Unknown RID '${{ matrix.rid }}' for vcpkg triplet mapping; skipping vcpkg install"; exit 0 }
}

Write-Host "Installing nlohmann-json for triplet: $triplet"
# Export vcpkg settings as step outputs (do NOT persist to job env)
Add-Content -Path $env:GITHUB_OUTPUT -Value "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT"
Add-Content -Path $env:GITHUB_OUTPUT -Value "CMAKE_TOOLCHAIN_FILE=$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake"
Add-Content -Path $env:GITHUB_OUTPUT -Value "VCPKG_TARGET_TRIPLET=$triplet"

& $vcpkgPath install "nlohmann-json:$triplet"

- name: Build & Pack Libdave.RID (via <GeneratePackageOnBuild>)
shell: pwsh
run: |
# Use vcpkg settings exported by the install step
$env:CMAKE_TOOLCHAIN_FILE = '${{ steps.install-nlohmann.outputs.CMAKE_TOOLCHAIN_FILE }}'
$env:VCPKG_TARGET_TRIPLET = '${{ steps.install-nlohmann.outputs.VCPKG_TARGET_TRIPLET }}'
Write-Host "Using vcpkg toolchain: $env:CMAKE_TOOLCHAIN_FILE"
Write-Host "Using vcpkg triplet: $env:VCPKG_TARGET_TRIPLET"

if ("${{ matrix.arch }}" -ne "") { $env:CMAKE_GENERATOR_PLATFORM = "${{ matrix.arch }}" }

if ("${{ matrix.rid }}" -eq "linux-arm64") {
$env:CMAKE_CXX_COMPILER = "aarch64-linux-gnu-g++"
$env:CMAKE_C_COMPILER = "aarch64-linux-gnu-gcc"
}

$env:CMakeArgs = "-DCMAKE_TOOLCHAIN_FILE=$env:CMAKE_TOOLCHAIN_FILE -DVCPKG_TARGET_TRIPLET=$env:VCPKG_TARGET_TRIPLET"

dotnet build NetCord/ThirdParty/Libdave/Libdave.RID/Libdave.RID.csproj --no-restore -v normal -c MinSizeRel -r ${{ matrix.rid }} /bl:build-${{ matrix.rid }}.binlog

- name: Upload Binary Log
if: always() && (hashFiles('restore-${{ matrix.rid }}.binlog','build-${{ matrix.rid }}.binlog') != '')
uses: actions/upload-artifact@v6.0.0
with:
name: BinLog-${{ matrix.rid }}
path: |
restore-${{ matrix.rid }}.binlog
build-${{ matrix.rid }}.binlog

- name: Upload NuGet Packages
uses: actions/upload-artifact@v6.0.0
with:
name: NuGet-Libdave-${{ matrix.rid }}
path: NetCord/ThirdParty/Libdave/Libdave.RID/bin/MinSizeRel/*.nupkg
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,6 @@ FodyWeavers.xsd

# Settings file
appsettings.json
!Documentation/**/appsettings.json
!Documentation/**/appsettings.json

/NetCord/ThirdParty/**/*_build*
7 changes: 7 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[submodule "NetCord/ThirdParty/Libdave/libdave"]
path = NetCord/ThirdParty/Libdave/libdave
url = https://github.com/discord/libdave/

[submodule "NetCord/ThirdParty/MLSpp/mlspp"]
path = NetCord/ThirdParty/MLSpp/mlspp
url = https://github.com/cisco/mlspp/
6 changes: 5 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<Project>

<PropertyGroup>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" Condition="'' != $([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand All @@ -16,6 +18,7 @@
<PackageTags>bot;discord;discord-api</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Description>The modern and fully customizable C# Discord library.</Description>
<Authors>KubaZ2; NetCord Contributors</Authors>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>ICON.png</PackageIcon>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand All @@ -37,6 +40,7 @@
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)\Resources\NuGet\README.md" Pack="true" PackagePath="" />
<None Include="$(MSBuildThisFileDirectory)\Resources\NuGet\ICON.png" Pack="true" PackagePath="" />
<None Include="$(MSBuildThisFileDirectory)\LICENSE.md" Pack="true" PackagePath="" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<PropertyGroup>
<DefineConstants>$(DefineConstants);$([System.String]::Copy('$(AssemblyName)').Replace('.', '_'))</DefineConstants>
</PropertyGroup>

</Project>
12 changes: 12 additions & 0 deletions NetCord.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@
<Project Path="Hosting/NetCord.Hosting.Services/NetCord.Hosting.Services.csproj" />
<Project Path="Hosting/NetCord.Hosting/NetCord.Hosting.csproj" />
</Folder>
<Folder Name="/Native Libraries/">
<File Path="NetCord/ThirdParty/Directory.Build.props" />
<File Path="NetCord/ThirdParty/Directory.Build.targets" />
<Project Path="NetCord/ThirdParty/Libdave/Libdave.Manager/Libdave.Manager.csproj">
<BuildType Solution="Debug|*" Project="RelWithDebInfo" />
<BuildType Solution="Release|*" Project="MinSizeRel" />
</Project>
<Project Path="NetCord/ThirdParty/Libdave/Libdave.RID/Libdave.RID.csproj">
<BuildType Solution="Debug|*" Project="RelWithDebInfo" />
<BuildType Solution="Release|*" Project="MinSizeRel" />
</Project>
</Folder>
<Folder Name="/Solution Items/">
<File Path=".editorconfig" />
<File Path="Directory.Build.props" />
Expand Down
5 changes: 5 additions & 0 deletions NetCord/NetCord.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<None Remove="ThirdParty\**\*" />
<Compile Remove="ThirdParty\**\*" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SourceGenerators\MethodsForPropertiesGenerator\MethodsForPropertiesGenerator.csproj" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
<ProjectReference Include="..\SourceGenerators\UserAgentHeaderGenerator\UserAgentHeaderGenerator.csproj" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
Expand Down
71 changes: 71 additions & 0 deletions NetCord/ThirdParty/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" Condition="'' != $([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<PropertyGroup>
<CMakeStaticRT Condition="'$(CMakeStaticRT)' == ''">false</CMakeStaticRT>

<!-- Prebuilt library paths (customize these) -->
<!-- Use _ROOT to point to installation directory, or _DIR to point directly to CMake config directory -->
<CMakeOpenSSLRoot Condition="'$(CMakeOpenSSLRoot)' == ''"></CMakeOpenSSLRoot>
<CMakeOpenSSLDir Condition="'$(CMakeOpenSSLDir)' == ''"></CMakeOpenSSLDir>
<CMakeBoringSSLRoot Condition="'$(CMakeBoringSSLRoot)' == ''"></CMakeBoringSSLRoot>
<CMakeBoringSSLDir Condition="'$(CMakeBoringSSLDir)' == ''"></CMakeBoringSSLDir>
<CMakeNlohmannJsonRoot Condition="'$(CMakeNlohmannJsonRoot)' == ''"></CMakeNlohmannJsonRoot>
<CMakeNlohmannJsonDir Condition="'$(CMakeNlohmannJsonDir)' == ''"></CMakeNlohmannJsonDir>
<CMakeMlsppRoot Condition="'$(CMakeMlsppRoot)' == ''"></CMakeMlsppRoot>
<CMakeMlsppDir Condition="'$(CMakeMlsppDir)' == ''"></CMakeMlsppDir>
</PropertyGroup>

<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)\LICENSE.md" />
</ItemGroup>

<ItemGroup Condition="'@(CMakeConfiguration)' == ''">
<!--<CMakeConfiguration Include="RelWithDebInfo">
<MSBuildProperties></MSBuildProperties>
</CMakeConfiguration>-->
<CMakeConfiguration Include="MinSizeRel">
<MSBuildProperties></MSBuildProperties>
</CMakeConfiguration>
</ItemGroup>

<PropertyGroup>
<_BuildArch>$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)</_BuildArch>
<_BuildRuntime Condition="$([MSBuild]::IsOSPlatform('Windows'))">win</_BuildRuntime>
<_BuildRuntime Condition="$([MSBuild]::IsOSPlatform('Linux'))">linux</_BuildRuntime>
<_BuildRuntime Condition="$([MSBuild]::IsOSPlatform('OSX'))">osx</_BuildRuntime>
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">$(_BuildRuntime)-$(_BuildArch.ToLower())</RuntimeIdentifier>
</PropertyGroup>

<PropertyGroup>
<CMakeClearCache>true</CMakeClearCache>
<RestoreSources Condition="'$(PackageOutputPath)' != ''">$(PackageOutputPath);$(RestoreSources)</RestoreSources>

<RuntimeIdentifiers Condition="'$(RuntimeIdentifiers)' == ''">win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-arm64;osx-x64</RuntimeIdentifiers>

<!-- For UNIX PIC-compatible .a objects -->
<CMakeArgs Condition="'$(OS)' != 'Windows_NT'">$(CMakeArgs) -DCMAKE_POSITION_INDEPENDENT_CODE=ON</CMakeArgs>
</PropertyGroup>

<PropertyGroup Condition="'$(CMakeMlsppRoot)' == '' AND '$(CMakeMlsppDir)' == ''">
<MlsppDir>$(MSBuildThisFileDirectory)\MLSpp\</MlsppDir>
<Building_DependsOn>BuildMlsppNative;MlsppOutputs;$(Building_DependsOn)</Building_DependsOn>
<Installing_DependsOn>MlsppInstall;$(Installing_DependsOn)</Installing_DependsOn>
<Cleaning_DependsOn>CleanMlsppNative;$(Cleaning_DependsOn)</Cleaning_DependsOn>
<Packing_DependsOn>PackageMlsppLib;$(Packing_DependsOn)</Packing_DependsOn>
<AlsoCleanMlspp>true</AlsoCleanMlspp>
</PropertyGroup>

<Import Project="$(MlsppDir)\MLSpp.build.props" Condition="'$(MSBuildProjectName)' != 'Libdave.Manager' AND '$(CMakeMlsppRoot)' == '' AND '$(CMakeMlsppDir)' == ''"/>
<Import Project="$(MlsppDir)\MLSpp.build.targets" Condition="'$(MSBuildProjectName)' != 'Libdave.Manager' AND '$(CMakeMlsppRoot)' == '' AND '$(CMakeMlsppDir)' == ''"/>

<PropertyGroup Condition="'$(CMakeOpenSSLRoot)' == '' AND '$(CMakeOpenSSLDir)' == ''
AND '$(CMakeBoringSSLRoot)' == '' AND '$(CMakeBoringSSLDir)' == ''">
<Packing_DependsOn>PackageOpenSSLLib;$(Packing_DependsOn)</Packing_DependsOn>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)\FindOpenSSL.targets"
Condition="'$(CMakeOpenSSLRoot)' == '' AND '$(CMakeOpenSSLDir)' == ''
AND '$(CMakeBoringSSLRoot)' == '' AND '$(CMakeBoringSSLDir)' == ''" />

</Project>
46 changes: 46 additions & 0 deletions NetCord/ThirdParty/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" Condition="'' != $([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />

<!-- Check MSBuild and CMake version compatibility -->
<Target Name="CheckCMakeVersionCompatibility"
BeforeTargets="$(CheckCMakeVersionCompatibility_BeforeTargets)"
Condition="'$(CMakeGenerator)' == '' AND '$(OS)' == 'Windows_NT'">

<!-- Get MSBuild version -->
<PropertyGroup>
<MSBuildVersionMajor>$([System.Version]::Parse('$(MSBuildVersion)').Major)</MSBuildVersionMajor>
</PropertyGroup>

<!-- Get CMake version -->
<Exec Command="cmake --version"
ConsoleToMSBuild="true"
IgnoreExitCode="true"
EchoOff="true"
StandardOutputImportance="low">
<Output TaskParameter="ConsoleOutput" PropertyName="CMakeVersionOutput" />
<Output TaskParameter="ExitCode" PropertyName="CMakeExitCode" />
</Exec>

<!-- Parse CMake version (format: "cmake version X.Y.Z") -->
<PropertyGroup Condition="'$(CMakeExitCode)' == '0'">
<CMakeVersionString>$([System.Text.RegularExpressions.Regex]::Match($(CMakeVersionOutput), 'cmake version (\d+\.\d+\.\d+)').Groups[1].Value)</CMakeVersionString>
<CMakeVersionMajor Condition="'$(CMakeVersionString)' != ''">$([System.Version]::Parse('$(CMakeVersionString)').Major)</CMakeVersionMajor>
<CMakeVersionMinor Condition="'$(CMakeVersionString)' != ''">$([System.Version]::Parse('$(CMakeVersionString)').Minor)</CMakeVersionMinor>
</PropertyGroup>

<Message Text="MSBuild Version: $(MSBuildVersion) (Major: $(MSBuildVersionMajor))" Importance="high" />
<Message Text="CMake Version: $(CMakeVersionString)" Importance="high" Condition="'$(CMakeVersionString)' != ''" />

<!-- Warn if Visual Studio 2026+ (MSBuild 18+) with CMake < 4.2 -->
<Warning Text="CMake version $(CMakeVersionString) may not be compatible with Visual Studio 2026 (MSBuild $(MSBuildVersionMajor)). CMake 4.2 or later is recommended for Visual Studio 2026 and newer versions. Please upgrade CMake to version 4.2 or later."
Condition="'$(MSBuildVersionMajor)' != '' AND '$(CMakeVersionMajor)' != '' AND
$([System.Convert]::ToInt32($(MSBuildVersionMajor))) >= 18 AND
($([System.Convert]::ToInt32($(CMakeVersionMajor))) &lt; 4 OR
($([System.Convert]::ToInt32($(CMakeVersionMajor))) == 4 AND $([System.Convert]::ToInt32($(CMakeVersionMinor))) &lt; 2))" />

<!-- Warn if CMake is not found -->
<Warning Text="CMake not found or failed to execute. Please ensure CMake is installed and available in PATH."
Condition="'$(CMakeExitCode)' != '0'" />
</Target>

</Project>
Loading