Skip to content

Commit 36c3303

Browse files
committed
Pivot to use vcpkg to build natives
* put into nuget package
1 parent c873ef4 commit 36c3303

12 files changed

Lines changed: 240 additions & 0 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "NetCord.Natives/vcpkg"]
2+
path = NetCord.Natives/vcpkg
3+
url = https://github.com/microsoft/vcpkg.git

NetCord.Natives/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.tlog
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<Description>Pre-built binaries for NetCord, $(Description)</Description>
5+
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
6+
7+
<VcpkgInstalledDir>bin\natives</VcpkgInstalledDir>
8+
<VcpkgMsbuildPath>vcpkg/scripts/buildsystems/msbuild/vcpkg</VcpkgMsbuildPath>
9+
<RepositoryRoot>$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\..'))</RepositoryRoot>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<Compile Remove="vcpkg\**" />
14+
<None Remove="vcpkg\**" />
15+
<None Include="$(VcpkgMsbuildPath).*">
16+
<Link>vcpkg\%(Filename)%(Extension)</Link>
17+
</None>
18+
</ItemGroup>
19+
20+
<Import Project="$(VcpkgMsbuildPath).props" Condition="Exists('$(VcpkgMsbuildPath).props')" />
21+
22+
<!-- Use vcpkg integration with MSBuild Platform (normalize AnyCPU to x64). -->
23+
<PropertyGroup>
24+
<VcpkgEnableManifest>true</VcpkgEnableManifest>
25+
26+
<VcpkgOSTarget Condition="'$(VcpkgOSTarget)' == ''">windows</VcpkgOSTarget>
27+
<VcpkgPlatformTarget Condition="'$(VcpkgPlatformTarget)' == '' and ('$(Platform)' == 'Any CPU' or '$(Platform)' == 'AnyCPU')">x64</VcpkgPlatformTarget>
28+
<VcpkgPlatformTarget Condition="'$(VcpkgPlatformTarget)' == ''">$(Platform)</VcpkgPlatformTarget>
29+
30+
<DebugDefinedDir Condition="'$(Configuration)' == 'Debug'">debug</DebugDefinedDir>
31+
<BuildNativeOutputPath>$(VcpkgInstalledDir)\$(VcpkgPlatformTarget)-$(VcpkgOSTarget)\$(DebugDefinedDir)</BuildNativeOutputPath>
32+
</PropertyGroup>
33+
34+
<ItemGroup>
35+
<None Include="$(BuildNativeOutputPath)\**">
36+
<Link>Built Natives $(DebugDefinedDir)\%(RecursiveDir)%(Filename)%(Extension)</Link>
37+
</None>
38+
</ItemGroup>
39+
40+
<Import Project="$(VcpkgMsbuildPath).targets" Condition="Exists('$(VcpkgMsbuildPath).targets')" />
41+
42+
<Target Name="_EnsureVcpkgSubmodule" BeforeTargets="PrepareForBuild" Condition="!Exists('$(VcpkgMsbuildPath).targets')">
43+
<Message Text="vcpkg submodule is missing. Initializing/updating submodule..." Importance="High" />
44+
<Exec Command="git -C &quot;$(RepositoryRoot)&quot; submodule update --init --recursive -- NetCord.Natives/vcpkg" />
45+
<Error Condition="!Exists('$(VcpkgMsbuildPath).targets')" Text="Failed to initialize the 'vcpkg' submodule. Ensure git is available and rerun the build." />
46+
<Warning Text="vcpkg submodule was initialized during this build. Run the build again so vcpkg MSBuild targets are imported." Condition="Exists('$(VcpkgMsbuildPath).targets')" />
47+
</Target>
48+
49+
<Target Name="_LogVcpkgSelection" BeforeTargets="VcpkgTripletSelection">
50+
<Message Text="Using VcpkgManifestRoot='$(VcpkgManifestRoot)', Platform='$(Platform)', VcpkgOSTarget='$(VcpkgOSTarget)', VcpkgPlatformTarget='$(VcpkgPlatformTarget)', VcpkgTriplet='$(VcpkgTriplet)'" Importance="High" />
51+
</Target>
52+
53+
<Target Name="ClCompile" BeforeTargets="Build" />
54+
55+
<Target Name="PackageNatives" BeforeTargets="_GetPackageFiles" DependsOnTargets="ClCompile">
56+
57+
<ItemGroup>
58+
<NativesBuilt Include="$(BuildNativeOutputPath)\bin\*;$(BuildNativeOutputPath)\lib\*" />
59+
<NativesBuilt Remove="**/pkgconf*.*" />
60+
61+
<Content Include="@(NativesBuilt)">
62+
<Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
63+
<Pack>true</Pack>
64+
<PackagePath>runtimes\$(VcpkgOSTarget)-$(VcpkgPlatformTarget)\$(DebugDefinedDir)\</PackagePath>
65+
</Content>
66+
67+
<None Include="$(MSBuildProjectName).props;$(MSBuildProjectName).targets">
68+
<Pack>true</Pack>
69+
<PackagePath>build\</PackagePath>
70+
</None>
71+
72+
</ItemGroup>
73+
74+
<Message Text="$(MSBuildProjectName) packaged items:" Importance="high" />
75+
<Message Text=" %(Content.Identity) -> [pkg].\%(Content.PackagePath)%(Filename)%(Extension)"
76+
Importance="high" Condition="'%(Content.Pack)' == 'true'" />
77+
78+
</Target>
79+
80+
</Project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
3+
<PropertyGroup>
4+
<NetCordNativesPath>$(MSBuildThisFileDirectory)..\runtimes\</NetCordNativesPath>
5+
</PropertyGroup>
6+
7+
</Project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
3+
<Target Name="ProcessNativeBinaries"
4+
BeforeTargets="GetCopyToOutputDirectoryItems;AssignTargetPaths">
5+
6+
<PropertyGroup>
7+
<IsTargetWindows Condition="$(RuntimeIdentifier.StartsWith('win'))">true</IsTargetWindows>
8+
<IsTargetLinux Condition="$(RuntimeIdentifier.StartsWith('linux'))">true</IsTargetLinux>
9+
<IsTargetOSX Condition="$(RuntimeIdentifier.StartsWith('osx'))">true</IsTargetOSX>
10+
11+
<IsTargetWindows Condition="'$(RuntimeIdentifier)' == '' AND '$([MSBuild]::IsOSPlatform('Windows'))'">true</IsTargetWindows>
12+
<IsTargetLinux Condition="'$(RuntimeIdentifier)' == '' AND '$([MSBuild]::IsOSPlatform('Linux'))'">true</IsTargetLinux>
13+
<IsTargetOSX Condition="'$(RuntimeIdentifier)' == '' AND '$([MSBuild]::IsOSPlatform('OSX'))'">true</IsTargetOSX>
14+
15+
<IsAotPublish Condition="'$(PublishAot)' == 'true' or '$(NativeCompilationDuringPublish)' == 'true'">true</IsAotPublish>
16+
17+
<_NetCordNativesPath>$(NetCordNativesPath)\$(RuntimeIdentifier)</_NetCordNativesPath>
18+
</PropertyGroup>
19+
20+
<ItemGroup Condition="'$(IsAotPublish)' != 'true'">
21+
22+
<NativeFilter Include="$(_NetCordNativesPath)\**\*.dll" Condition="'$(IsTargetWindows)' == 'true'" />
23+
<NativeFilter Include="$(_NetCordNativesPath)\**\*.so" Condition="'$(IsTargetLinux)' == 'true'" />
24+
<NativeFilter Include="$(_NetCordNativesPath)\**\*.dylib" Condition="'$(IsTargetOSX)' == 'true'" />
25+
26+
<AllItemsFullPathWithTargetPath Include="@(NativeFilter->'%(FullPath)')"
27+
Exclude="**\*.pdb;**\*.lib;**\*.exp">
28+
<TargetPath Condition="'%(NativeFilter.Link)' != ''">%(NativeFilter.Link)</TargetPath>
29+
<TargetPath Condition="'%(NativeFilter.Link)' == ''">%(Filename)%(Extension)</TargetPath>
30+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
31+
</AllItemsFullPathWithTargetPath>
32+
</ItemGroup>
33+
34+
<ItemGroup Condition="'$(IsAotPublish)' == 'true'">
35+
<NativeLibToLink Include="$(_NetCordNativesPath)\**\*.lib" Condition="'$(IsTargetWindows)' == 'true'" />
36+
<NativeLibToLink Include="$(_NetCordNativesPath)\**\*.a" Condition="'$(IsTargetLinux)' == 'true' or '$(IsTargetOSX)' == 'true'" />
37+
38+
<NativeLibrary Include="@(NativeLibToLink->'%(FullPath)')" />
39+
</ItemGroup>
40+
41+
</Target>
42+
</Project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
vcpkg_from_github(
2+
OUT_SOURCE_PATH SOURCE_PATH
3+
REPO discord/libdave
4+
REF "${VERSION}"
5+
SHA512 78b4e5b8ddc6397775d403465e0da770ec7905d7913546b3aec161baf4478443e554f0ae7bd012af8bfd308639be2601d46da22c02aff2b756ff91878f1fc843
6+
HEAD_REF main
7+
)
8+
9+
vcpkg_cmake_configure(
10+
SOURCE_PATH "${SOURCE_PATH}/cpp"
11+
OPTIONS
12+
-DTESTING=OFF
13+
-DBUILD_TESTING=OFF
14+
MAYBE_UNUSED_VARIABLES
15+
BUILD_TESTING
16+
)
17+
18+
vcpkg_cmake_build()
19+
20+
vcpkg_cmake_install()
21+
vcpkg_copy_pdbs()
22+
23+
# file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
24+
25+
# file(INSTALL
26+
# "${SOURCE_PATH}/LICENSE"
27+
# DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}"
28+
# RENAME LICENSE.txt
29+
# )
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "libdave",
3+
"version-string": "52cd56dc550f447fb354b3a06c9e2d2e2a4309c6",
4+
"license": "MIT",
5+
"dependencies": [
6+
"openssl",
7+
"mlspp",
8+
"nlohmann-json",
9+
{
10+
"name": "vcpkg-cmake",
11+
"host": true
12+
},
13+
{
14+
"name": "vcpkg-cmake-config",
15+
"host": true
16+
}
17+
]
18+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
vcpkg_from_github(
2+
OUT_SOURCE_PATH SOURCE_PATH
3+
REPO cisco/mlspp
4+
REF "${VERSION}"
5+
SHA512 5d37631e2c47daae1133ef074e60cc09ca2d395f9e11c416f829060e374051cf219d2d7fe98dae49d1d045292e07d6a09f4814a5f16e6cc05e67e7cd96f146c4
6+
)
7+
8+
if(VCPKG_TARGET_IS_OSX AND EXISTS "/usr/local/include/openssl/")
9+
set(VCPKG_INCLUDE_OVERRIDE "-DCMAKE_CXX_FLAGS=-I${CURRENT_INSTALLED_DIR}/include")
10+
endif()
11+
12+
set(VCPKG_LIBRARY_LINKAGE static)
13+
14+
vcpkg_cmake_configure(
15+
SOURCE_PATH "${SOURCE_PATH}"
16+
OPTIONS
17+
${VCPKG_INCLUDE_OVERRIDE}
18+
-DDISABLE_GREASE=ON
19+
-DTESTING=OFF
20+
-DBUILD_TESTING=OFF
21+
-DMLS_CXX_NAMESPACE="mlspp"
22+
MAYBE_UNUSED_VARIABLES
23+
BUILD_TESTING
24+
)
25+
26+
vcpkg_cmake_install()
27+
vcpkg_copy_pdbs()
28+
29+
vcpkg_cmake_config_fixup(PACKAGE_NAME "MLSPP" CONFIG_PATH "share/MLSPP")
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "mlspp",
3+
"version-string": "1cc50a124a3bc4e143a787ec934280dc70c1034d",
4+
"description": "Cisco MLS C++ library",
5+
"dependencies": [
6+
"openssl",
7+
"nlohmann-json",
8+
{
9+
"name": "vcpkg-cmake",
10+
"host": true
11+
},
12+
{
13+
"name": "vcpkg-cmake-config",
14+
"host": true
15+
}
16+
]
17+
}

NetCord.Natives/vcpkg

Submodule vcpkg added at 89dd0f4

0 commit comments

Comments
 (0)