|
19 | 19 | <PropertyGroup> |
20 | 20 | <DebugDefinedDir Condition="'$(Configuration)' == 'Debug'">debug</DebugDefinedDir> |
21 | 21 |
|
22 | | - <VcpkgMsbuildPath>vcpkg/scripts/buildsystems/msbuild/vcpkg</VcpkgMsbuildPath> |
| 22 | + <VcpkgArtifactsRoot Condition="'$(VcpkgArtifactsRoot)' == ''">bin</VcpkgArtifactsRoot> |
| 23 | + |
| 24 | + <VcpkgRoot Condition="'$(VcpkgRoot)' == ''">$(VCPKG_ROOT)</VcpkgRoot> |
| 25 | + <VcpkgMsbuildPath>$(VcpkgRoot)\scripts\buildsystems\msbuild\vcpkg</VcpkgMsbuildPath> |
| 26 | + |
| 27 | + <VcpkgConfiguration>Release</VcpkgConfiguration> |
23 | 28 | <VcpkgEnableManifest>true</VcpkgEnableManifest> |
24 | 29 |
|
25 | 30 | <VcpkgOSTarget Condition="'$(VcpkgOSTarget)' == '' and '$(OS)' == 'Windows_NT'">windows</VcpkgOSTarget> |
|
28 | 33 |
|
29 | 34 | <VcpkgBuildOS>$(VcpkgOSTarget)</VcpkgBuildOS> |
30 | 35 | <VcpkgBuildOS Condition="'$(VcpkgOSTarget)' == 'windows'">win</VcpkgBuildOS> |
31 | | - |
| 36 | + |
| 37 | + <!-- Prevent vcpkg msbuild target from installing packages. We do our own Exec --> |
| 38 | + <VcpkgManifestInstall Condition="'$(VcpkgBuildOS)' != 'win'">false</VcpkgManifestInstall> |
| 39 | + |
32 | 40 | <VcpkgPlatformTarget Condition="'$(VcpkgPlatformTarget)' == '' and |
33 | 41 | ('$(Platform)' == 'Any CPU' or '$(Platform)' == 'AnyCPU')">x64</VcpkgPlatformTarget> |
34 | 42 | <VcpkgPlatformTarget Condition="'$(VcpkgPlatformTarget)' == ''">$(Platform)</VcpkgPlatformTarget> |
35 | 43 |
|
36 | | - <NativeArtifactsRoot Condition="'$(NativeArtifactsRoot)' == ''">bin</NativeArtifactsRoot> |
37 | | - |
38 | | - <VcpkgInstalledDir>$(NativeArtifactsRoot)\$(VcpkgBuildOS)-$(VcpkgPlatformTarget)\natives</VcpkgInstalledDir> |
| 44 | + <VcpkgInstalledDirBase>$(VcpkgArtifactsRoot)\$(VcpkgBuildOS)-$(VcpkgPlatformTarget)\natives</VcpkgInstalledDirBase> |
| 45 | + <VcpkgInstalledDir>$(VcpkgInstalledDirBase)</VcpkgInstalledDir> |
39 | 46 | <VcpkgInstalledDir Condition="'$(VcpkgUseStatic)' == 'true'">$(VcpkgInstalledDir)-static</VcpkgInstalledDir> |
40 | 47 |
|
41 | | - <BuildNativeOutputPath>$(VcpkgInstalledDir)\$(VcpkgPlatformTarget)-$(VcpkgOSTarget)</BuildNativeOutputPath> |
42 | | - <BuildNativeOutputPath Condition="'$(VcpkgUseStatic)' == 'true'" |
43 | | - >$(VcpkgInstalledDir)\$(VcpkgPlatformTarget)-$(VcpkgOSTarget)-static</BuildNativeOutputPath> |
44 | | - |
45 | | - <_BuildNativeStaticOutputPath>$(VcpkgInstalledDir)\$(VcpkgPlatformTarget)-$(VcpkgOSTarget)-static</_BuildNativeStaticOutputPath> |
| 48 | + <VcpkgOutputPath_Static>$(VcpkgInstalledDirBase)-static\$(VcpkgPlatformTarget)-$(VcpkgOSTarget)</VcpkgOutputPath_Static> |
| 49 | + <VcpkgOutputPath_Static Condition="'$(VcpkgBuildOS)' == 'win'">$(VcpkgOutputPath_Static)-static</VcpkgOutputPath_Static> |
46 | 50 | <_VcpkgStatusFile>$(VcpkgInstalledDir)\vcpkg\status</_VcpkgStatusFile> |
47 | 51 | </PropertyGroup> |
48 | 52 |
|
49 | 53 | <ItemGroup> |
50 | | - <AllowedNativeLibrary Include="libdave" /> |
51 | | - <AllowedNativeLibrary Include="mlspp;bytes;tls_syntax;hpke" /> |
52 | | - <AllowedNativeLibrary Include="openssl;libcrypto" /> |
53 | | - <AllowedNativeLibrary Include="libsodium;opus;zstd" /> |
| 54 | + <NativeLibSet Include="libdave;dave" /> |
| 55 | + <NativeLibSet Include="mlspp;bytes;tls_syntax;hpke" /> |
| 56 | + <NativeLibSet Include="libcrypto;crypto" /> |
| 57 | + <NativeLibSet Include="libsodium;sodium" /> |
| 58 | + <NativeLibSet Include="libsodium;sodium;opus;zstd" /> |
54 | 59 |
|
55 | | - <AllowedNativesLicenses Include="libdave;libsodium;opus;zstd" /> |
| 60 | + <NativeLibLic Include="libdave;openssl;libsodium;opus;zstd" /> |
| 61 | + |
| 62 | + <_VcpkgRelatedFile Include="native-ports\**" /> |
56 | 63 | </ItemGroup> |
57 | 64 |
|
58 | | - <Target Name="GetStaticBuildDir" Returns="@(_NetCordStaticFullPath)"> |
| 65 | + <Target Name="GetStaticBuildDir" Returns="@(_StaticFullPath)"> |
59 | 66 | <ItemGroup> |
60 | | - <_NetCordStaticFullPath Include="$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\$(_BuildNativeStaticOutputPath)'))" /> |
| 67 | + <_StaticFullPath Include="$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\$(VcpkgOutputPath_Static)'))" /> |
61 | 68 | </ItemGroup> |
62 | | - <Message Text="Static build output path: @(_NetCordStaticFullPath)" Importance="high" /> |
| 69 | + <Message Text="Static build output path: @(_StaticFullPath)" Importance="high" /> |
63 | 70 | </Target> |
64 | 71 |
|
65 | 72 | <Import Project="$(VcpkgMsbuildPath).props" Condition="Exists('$(VcpkgMsbuildPath).props')" /> |
66 | 73 | <Import Project="$(VcpkgMsbuildPath).targets" Condition="Exists('$(VcpkgMsbuildPath).targets')" /> |
| 74 | + <!-- When not on Windows, refer to this file --> |
| 75 | + <Import Project="vcpkg-non-windows.targets" |
| 76 | + Condition="'$(VcpkgBuildOS)' != 'win' and Exists('vcpkg-non-windows.targets')" /> |
| 77 | + |
| 78 | + <Target Name="PrepareVcpkg" BeforeTargets="VcpkgTripletSelection"> |
| 79 | + <PropertyGroup Condition="'$(VcpkgBuildOS)' != 'win'"> |
| 80 | + <VcpkgTriplet>$(VcpkgPlatformTarget)-$(VcpkgOSTarget)</VcpkgTriplet> |
| 81 | + <VcpkgTriplet Condition="'$(VcpkgUseStatic)' != 'true'">$(VcpkgTriplet)-dynamic</VcpkgTriplet> |
| 82 | + |
| 83 | + <_ZVcpkgMSBuildStampFile>$(_ZVcpkgInstalledDir).msbuildstamp-$(VcpkgTriplet).$(_ZVcpkgHostTripletSuffix)stamp</_ZVcpkgMSBuildStampFile> |
| 84 | + </PropertyGroup> |
| 85 | + <PropertyGroup> |
| 86 | + <VcpkgOutputPath>$(VcpkgInstalledDir)\$(VcpkgTriplet)</VcpkgOutputPath> |
| 87 | + </PropertyGroup> |
67 | 88 |
|
68 | | - <Target Name="_EnsureVcpkgSubmodule" BeforeTargets="PrepareForBuild" Condition="!Exists('$(VcpkgMsbuildPath).targets') and '$(CI)' != 'true'"> |
69 | | - <Message Text="vcpkg submodule is missing. Initializing/updating submodule..." Importance="High" /> |
70 | | - <Exec Command="git -C "$(RepositoryRoot)" submodule update --init --recursive -- NetCord.Natives/vcpkg" /> |
71 | | - <Error Condition="!Exists('$(VcpkgMsbuildPath).targets')" Text="Failed to initialize the 'vcpkg' submodule. Ensure git is available and rerun the build." /> |
72 | | - <Warning Text="vcpkg submodule was initialized during this build. Run the build again so vcpkg MSBuild targets are imported." Condition="Exists('$(VcpkgMsbuildPath).targets')" /> |
73 | | - </Target> |
74 | | - |
75 | | - <Target Name="_LogVcpkgSelection" BeforeTargets="VcpkgTripletSelection"> |
76 | | - <Message Text="Using VcpkgManifestRoot='$(VcpkgManifestRoot)', Platform='$(Platform)', VcpkgTriplet='$(VcpkgTriplet)', 'BuildNativeOutputPath'='$(BuildNativeOutputPath)'" Importance="High" /> |
| 89 | + <ItemGroup> |
| 90 | + <_LibArchs Include="x64;arm64"> |
| 91 | + <LibName>%(NativeLibSet.Identity)</LibName> |
| 92 | + </_LibArchs> |
| 93 | + <_BuiltRid Include="win-%(_LibArchs.Identity)"> |
| 94 | + <BinPath>%(_LibArchs.Identity)-windows\bin\%(_LibArchs.LibName)</BinPath> |
| 95 | + <LibPath>%(_LibArchs.Identity)-windows-static\lib\%(_LibArchs.LibName)</LibPath> |
| 96 | + <Ext>dll</Ext> |
| 97 | + </_BuiltRid> |
| 98 | + <_BuiltRid Include="linux-%(_LibArchs.Identity)"> |
| 99 | + <BinPath>%(_LibArchs.Identity)-linux-dynamic\lib\lib%(_LibArchs.LibName)</BinPath> |
| 100 | + <LibPath>%(_LibArchs.Identity)-linux\lib\lib%(_LibArchs.LibName)</LibPath> |
| 101 | + <Ext>so</Ext> |
| 102 | + </_BuiltRid> |
| 103 | + <_BuiltRid Include="osx-%(_LibArchs.Identity)"> |
| 104 | + <BinPath>%(_LibArchs.Identity)-osx-dynamic\lib\lib%(_LibArchs.LibName)</BinPath> |
| 105 | + <LibPath>%(_LibArchs.Identity)-osx\lib\lib%(_LibArchs.LibName)</LibPath> |
| 106 | + <Ext>dylib</Ext> |
| 107 | + </_BuiltRid> |
| 108 | + <_BuiltRid Remove="%(Identity)" Condition="'$(CI)' != 'true' and '%(Identity)' != '$(VcpkgBuildOS)-$(VcpkgPlatformTarget)'" /> |
| 109 | + </ItemGroup> |
77 | 110 | </Target> |
78 | 111 |
|
79 | | - <Target Name="ClCompile" BeforeTargets="GetDynamicVcpkgVersions" Condition="'$(NoBuild)' != 'true'"> |
80 | | - <Message Text="Building static native libraries..." Importance="High" Condition="'$(VcpkgUseStatic)' == 'false'" /> |
| 112 | + <Target Name="ClCompile" BeforeTargets="BeforeBuild" DependsOnTargets="PrepareVcpkg" |
| 113 | + Condition="'$(NoBuild)' != 'true' and Exists('$(VcpkgMsbuildPath).targets')"> |
| 114 | + |
| 115 | + <Message Text="Building static native libraries..." Importance="High" |
| 116 | + Condition="'$(VcpkgUseStatic)' != 'true'" /> |
81 | 117 | <MSBuild Projects="$(MSBuildProjectFullPath)" Targets="ClCompile" |
82 | | - Properties="VcpkgUseStatic=true;GeneratePackageOnBuild=false" Condition="'$(VcpkgUseStatic)' == 'false'" /> |
83 | | - |
84 | | - <ItemGroup> |
85 | | - <_NativeLicenseSource Include="$(BuildNativeOutputPath)\share\%(AllowedNativesLicenses.Identity)\copyright" |
86 | | - Condition="Exists('$(BuildNativeOutputPath)\share\%(AllowedNativesLicenses.Identity)\copyright')"> |
87 | | - <TargetPath>$(BuildNativeOutputPath)\licenses\%(AllowedNativesLicenses.Identity)_LICENSE.txt</TargetPath> |
| 118 | + Properties="VcpkgUseStatic=true;GeneratePackageOnBuild=false" |
| 119 | + Condition="'$(VcpkgUseStatic)' != 'true'" /> |
| 120 | + |
| 121 | + <ItemGroup Condition="'$(VcpkgUseStatic)' != 'true'"> |
| 122 | + <_NativeLicenseSource Include="$(VcpkgOutputPath)\share\%(NativeLibLic.Identity)\copyright" |
| 123 | + Condition="Exists('$(VcpkgOutputPath)\share\%(NativeLibLic.Identity)\copyright')"> |
| 124 | + <TargetPath>$(VcpkgOutputPath)\licenses\%(NativeLibLic.Identity)_LICENSE.txt</TargetPath> |
88 | 125 | </_NativeLicenseSource> |
89 | 126 | </ItemGroup> |
90 | 127 |
|
91 | 128 | <Copy SourceFiles="@(_NativeLicenseSource)" DestinationFiles="@(_NativeLicenseSource->'%(TargetPath)')" |
92 | | - SkipUnchangedFiles="true" /> |
| 129 | + SkipUnchangedFiles="true" Condition="'$(VcpkgUseStatic)' != 'true'" /> |
93 | 130 | </Target> |
94 | 131 |
|
95 | | - <Target Name="GetDynamicVcpkgVersions" BeforeTargets="PrepareForBuild"> |
| 132 | + <Target Name="GetDynamicVcpkgVersions" BeforeTargets="GetAssemblyAttributes" |
| 133 | + Condition="Exists('$(_VcpkgStatusFile)')"> |
96 | 134 |
|
97 | 135 | <!-- 1. Read the entire status file into a property --> |
98 | 136 | <ReadLinesFromFile File="$(_VcpkgStatusFile)"> |
|
106 | 144 |
|
107 | 145 | <!-- 2. Use Item Transformation to find the version for each library --> |
108 | 146 | <ItemGroup> |
109 | | - <PackageWithVersion Include="@(AllowedNativesLicenses)"> |
| 147 | + <_VcpkgPkg Include="@(NativeLibLic)"> |
110 | 148 | <!-- This Regex looks for 'Package: [name]' then skips lines until 'Version: [value]' --> |
111 | 149 | <Version>$([System.Text.RegularExpressions.Regex]::Match('$(StatusText)', 'Package: %(Identity)\n(?:.*\n)*?Version: (.*?)\n').Groups[1].Value)</Version> |
112 | | - </PackageWithVersion> |
| 150 | + </_VcpkgPkg> |
113 | 151 | </ItemGroup> |
114 | 152 |
|
115 | 153 | <!-- 3. Inject them into the Assembly Metadata --> |
116 | 154 | <ItemGroup> |
117 | | - <AssemblyAttribute Include="NetCord.Natives.NativeLibraryVersion" Condition="'%(PackageWithVersion.Version)' != ''"> |
118 | | - <_Parameter1>%(PackageWithVersion.Identity)</_Parameter1> |
119 | | - <_Parameter2>%(PackageWithVersion.Version)</_Parameter2> |
| 155 | + <AssemblyAttribute Include="NetCord.Natives.NativeLibraryVersion" Condition="'%(_VcpkgPkg.Version)' != ''"> |
| 156 | + <_Parameter1>%(_VcpkgPkg.Identity)</_Parameter1> |
| 157 | + <_Parameter2>%(_VcpkgPkg.Version)</_Parameter2> |
120 | 158 | </AssemblyAttribute> |
121 | 159 | </ItemGroup> |
122 | 160 |
|
123 | 161 | <!-- Optional: Debugging message to see it working in the build log --> |
124 | | - <Message Importance="high" Text="Vcpkg Sync: %(PackageWithVersion.Identity) version is [%(PackageWithVersion.Version)]" /> |
| 162 | + <Message Importance="high" Text="Vcpkg Sync: %(_VcpkgPkg.Identity) version is [%(_VcpkgPkg.Version)]" /> |
125 | 163 | </Target> |
126 | 164 |
|
127 | | - <Target Name="_AddNativeRuntimeCopyItems" BeforeTargets="AssignTargetPaths"> |
| 165 | + <Target Name="_AddNativeRuntimeCopyItems" BeforeTargets="AssignTargetPaths" DependsOnTargets="PrepareVcpkg"> |
128 | 166 | <ItemGroup> |
129 | | - <NativesRuntime Include="$(BuildNativeOutputPath)\bin\%(AllowedNativeLibrary.Identity).*" /> |
| 167 | + <NativesRuntime Include="$(VcpkgArtifactsRoot)\%(_BuiltRid.Identity)\natives\%(_BuiltRid.BinPath)*.%(_BuiltRid.Ext)" /> |
130 | 168 | <Content Include="@(NativesRuntime)" Condition="Exists('%(NativesRuntime.Identity)')"> |
131 | 169 | <!-- <TargetPath>natives\runtimes\%(Filename)%(Extension)</TargetPath> --> |
132 | 170 | <TargetPath>%(Filename)%(Extension)</TargetPath> |
|
136 | 174 | </ItemGroup> |
137 | 175 | </Target> |
138 | 176 |
|
139 | | - <Target Name="PackageNatives" BeforeTargets="_GetPackageFiles" AfterTargets="Build"> |
| 177 | + <Target Name="PackageNatives" BeforeTargets="_GetPackageFiles" DependsOnTargets="PrepareVcpkg"> |
140 | 178 |
|
141 | 179 | <PropertyGroup Condition="'$(CI)' != 'true'"> |
142 | 180 | <PackageId>$(PackageId).$(VcpkgBuildOS)-$(VcpkgPlatformTarget)</PackageId> |
143 | 181 | </PropertyGroup> |
144 | 182 |
|
145 | | - <ItemGroup Condition="'$(CI)' != 'true'"> |
146 | | - <NativesBuilt Include="$(BuildNativeOutputPath)\bin\%(AllowedNativeLibrary.Identity).*"> |
147 | | - <PackagePath>runtimes\$(VcpkgBuildOS)-$(VcpkgPlatformTarget)\native\</PackagePath> |
148 | | - </NativesBuilt> |
149 | | - <NativesBuilt Include="$(_BuildNativeStaticOutputPath)\lib\%(AllowedNativeLibrary.Identity).*"> |
150 | | - <PackagePath>staticlibs\$(VcpkgBuildOS)-$(VcpkgPlatformTarget)\</PackagePath> |
151 | | - </NativesBuilt> |
152 | | - </ItemGroup> |
153 | | - |
154 | | - <ItemGroup Condition="'$(CI)' == 'true'"> |
155 | | - <_BuiltTriplets Include="x64-windows"> |
156 | | - <RuntimeId>win-x64</RuntimeId> |
157 | | - <RuntimeBinPath>x64-windows\bin\%(AllowedNativeLibrary.Identity)</RuntimeBinPath> |
158 | | - <StaticLibPath>x64-windows-static\lib\%(AllowedNativeLibrary.Identity)</StaticLibPath> |
159 | | - </_BuiltTriplets> |
160 | | - <_BuiltTriplets Include="arm64-windows"> |
161 | | - <RuntimeId>win-arm64</RuntimeId> |
162 | | - <RuntimeBinPath>arm64-windows\bin\%(AllowedNativeLibrary.Identity)</RuntimeBinPath> |
163 | | - <StaticLibPath>arm64-windows-static\lib\%(AllowedNativeLibrary.Identity)</StaticLibPath> |
164 | | - </_BuiltTriplets> |
165 | | - <_BuiltTriplets Include="x64-linux"> |
166 | | - <RuntimeId>linux-x64</RuntimeId> |
167 | | - <RuntimeBinPath>x64-linux\bin\%(AllowedNativeLibrary.Identity)</RuntimeBinPath> |
168 | | - <StaticLibPath>x64-linux-static\lib\%(AllowedNativeLibrary.Identity)</StaticLibPath> |
169 | | - </_BuiltTriplets> |
170 | | - <_BuiltTriplets Include="arm64-linux"> |
171 | | - <RuntimeId>linux-arm64</RuntimeId> |
172 | | - <RuntimeBinPath>arm64-linux\bin\%(AllowedNativeLibrary.Identity)</RuntimeBinPath> |
173 | | - <StaticLibPath>arm64-linux-static\lib\%(AllowedNativeLibrary.Identity)</StaticLibPath> |
174 | | - </_BuiltTriplets> |
175 | | - <_BuiltTriplets Include="x64-osx"> |
176 | | - <RuntimeId>osx-x64</RuntimeId> |
177 | | - <RuntimeBinPath>x64-osx\bin\%(AllowedNativeLibrary.Identity)</RuntimeBinPath> |
178 | | - <StaticLibPath>x64-osx-static\lib\%(AllowedNativeLibrary.Identity)</StaticLibPath> |
179 | | - </_BuiltTriplets> |
180 | | - <_BuiltTriplets Include="arm64-osx"> |
181 | | - <RuntimeId>osx-arm64</RuntimeId> |
182 | | - <RuntimeBinPath>arm64-osx\bin\%(AllowedNativeLibrary.Identity)</RuntimeBinPath> |
183 | | - <StaticLibPath>arm64-osx-static\lib\%(AllowedNativeLibrary.Identity)</StaticLibPath> |
184 | | - </_BuiltTriplets> |
185 | | - |
186 | | - <NativesBuilt Include="$(NativeArtifactsRoot)\%(_BuiltTriplets.RuntimeId)\natives\%(_BuiltTriplets.RuntimeBinPath).*"> |
187 | | - <PackagePath>runtimes\%(_BuiltTriplets.RuntimeId)\native\</PackagePath> |
| 183 | + <ItemGroup> |
| 184 | + <NativesBuilt Include="$(VcpkgArtifactsRoot)\%(_BuiltRid.Identity)\natives\%(_BuiltRid.BinPath)*.%(_BuiltRid.Ext)"> |
| 185 | + <PackagePath>runtimes\%(_BuiltRid.Identity)\native\</PackagePath> |
188 | 186 | </NativesBuilt> |
189 | | - <NativesBuilt Include="$(NativeArtifactsRoot)\%(_BuiltTriplets.RuntimeId)\natives-static\%(_BuiltTriplets.StaticLibPath).*"> |
190 | | - <PackagePath>staticlibs\%(_BuiltTriplets.RuntimeId)\</PackagePath> |
| 187 | + <NativesBuilt Include="$(VcpkgArtifactsRoot)\%(_BuiltRid.Identity)\natives-static\%(_BuiltRid.LibPath).*"> |
| 188 | + <PackagePath>staticlibs\%(_BuiltRid.Identity)\</PackagePath> |
191 | 189 | </NativesBuilt> |
192 | | - </ItemGroup> |
193 | | - |
194 | | - <ItemGroup> |
| 190 | + |
195 | 191 | <Content Include="@(NativesBuilt)" Condition="Exists('%(NativesBuilt.Identity)')"> |
196 | 192 | <Pack>true</Pack> |
197 | 193 | </Content> |
198 | 194 |
|
199 | | - <Content Include="$(NativeArtifactsRoot)\$(VcpkgBuildOS)-$(VcpkgPlatformTarget)\natives\$(VcpkgPlatformTarget)-$(VcpkgOSTarget)\licenses\%(AllowedNativesLicenses.Identity)_LICENSE.txt"> |
| 195 | + <Content Include="$(VcpkgOutputPath)\licenses\%(NativeLibLic.Identity)_LICENSE.txt"> |
200 | 196 | <Pack>true</Pack> |
201 | 197 | <PackagePath>licenses\</PackagePath> |
202 | 198 | </Content> |
|
0 commit comments