Skip to content

Commit 614c48c

Browse files
Beyleysilkdotnet
andauthored
WGPU native libs (#1348)
* Add wgpu native binary workflow * Add compiled WGPU native libs (#1345) * SDL -> WGPU in WGPU native package props * WGPU native libs: .props -> .targets for net461 --------- Co-authored-by: silkdotnet <[email protected]>
1 parent d8a7b6a commit 614c48c

File tree

14 files changed

+223
-1
lines changed

14 files changed

+223
-1
lines changed

.github/workflows/wgpu.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: WGPU
2+
on:
3+
push:
4+
branches-ignore:
5+
- "ci/*"
6+
- "develop/*"
7+
- "main"
8+
paths:
9+
- "build/submodules/wgpu-native"
10+
- "build/nuke/Build.Native.cs"
11+
- ".github/workflows/wgpu.yml"
12+
jobs:
13+
Build:
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
env:
18+
- os: ubuntu-latest
19+
name: Linux
20+
nuke_invoke: ./build.sh
21+
extras: |
22+
sudo apt-get update
23+
sudo apt-get install -y gcc-multilib
24+
- os: windows-latest
25+
name: Windows
26+
nuke_invoke: ./build.cmd
27+
extras: ""
28+
- os: macos-latest
29+
name: Darwin
30+
nuke_invoke: ./build.sh
31+
extras: ""
32+
name: ${{ matrix.env.name }} Build
33+
runs-on: ${{ matrix.env.os }}
34+
steps:
35+
- uses: dtolnay/rust-toolchain@nightly
36+
if: runner.os == 'Windows'
37+
with:
38+
toolchain: nightly-x86_64-pc-windows-msvc
39+
40+
- uses: dtolnay/rust-toolchain@nightly
41+
if: runner.os == 'Linux'
42+
with:
43+
toolchain: nightly-x86_64-unknown-linux-gnu
44+
45+
- uses: dtolnay/rust-toolchain@nightly
46+
if: runner.os == 'macOS'
47+
with:
48+
toolchain: nightly-x86_64-apple-darwin
49+
50+
- name: Add targets
51+
if: runner.os == 'Windows'
52+
run: |
53+
rustup target add i686-pc-windows-msvc
54+
rustup target add aarch64-pc-windows-msvc
55+
56+
- name: Add targets
57+
if: runner.os == 'Linux'
58+
run: |
59+
rustup target add i686-unknown-linux-gnu
60+
61+
- name: Add targets
62+
if: runner.os == 'macOS'
63+
run: |
64+
rustup target add aarch64-apple-darwin
65+
66+
- uses: actions/checkout@v2
67+
with:
68+
token: ${{ secrets.PUSHABLE_GITHUB_TOKEN }}
69+
- name: Checkout submodules, configure git
70+
run: |
71+
git -c submodule.third_party/git-hooks.update=none submodule update --init --recursive build/submodules/wgpu-native
72+
git config --local user.email "[email protected]"
73+
git config --local user.name "The Silk.NET Automaton"
74+
- name: Extra prerequisites
75+
run: |
76+
echo running extras
77+
${{ matrix.env.extras }}
78+
- name: Setup .NET 6.0
79+
uses: actions/setup-dotnet@v1
80+
with:
81+
dotnet-version: 6.0.201
82+
- name: Setup .NET 7.0.102
83+
uses: actions/setup-dotnet@v1
84+
with:
85+
dotnet-version: 7.0.102
86+
- name: Build WGPU
87+
run: ${{ matrix.env.nuke_invoke }} Wgpu
88+
env:
89+
PUSHABLE_GITHUB_TOKEN: ${{ secrets.PUSHABLE_GITHUB_TOKEN }}
90+

Silk.NET.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.Direct3D11.Extensi
560560
EndProject
561561
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.DirectComposition", "src\Microsoft\Silk.NET.DirectComposition\Silk.NET.DirectComposition.csproj", "{8773396C-5EDF-498C-97D7-1D2728CB969B}"
562562
EndProject
563+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.WebGPU.Native.WGPU", "src\Native\Silk.NET.WebGPU.Native.WGPU\Silk.NET.WebGPU.Native.WGPU.csproj", "{4031A5EB-820B-478D-A656-85C93210054E}"
564+
EndProject
563565
Global
564566
GlobalSection(SolutionConfigurationPlatforms) = preSolution
565567
Debug|Any CPU = Debug|Any CPU
@@ -3389,6 +3391,18 @@ Global
33893391
{8773396C-5EDF-498C-97D7-1D2728CB969B}.Release|x64.Build.0 = Release|Any CPU
33903392
{8773396C-5EDF-498C-97D7-1D2728CB969B}.Release|x86.ActiveCfg = Release|Any CPU
33913393
{8773396C-5EDF-498C-97D7-1D2728CB969B}.Release|x86.Build.0 = Release|Any CPU
3394+
{4031A5EB-820B-478D-A656-85C93210054E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3395+
{4031A5EB-820B-478D-A656-85C93210054E}.Debug|Any CPU.Build.0 = Debug|Any CPU
3396+
{4031A5EB-820B-478D-A656-85C93210054E}.Debug|x64.ActiveCfg = Debug|Any CPU
3397+
{4031A5EB-820B-478D-A656-85C93210054E}.Debug|x64.Build.0 = Debug|Any CPU
3398+
{4031A5EB-820B-478D-A656-85C93210054E}.Debug|x86.ActiveCfg = Debug|Any CPU
3399+
{4031A5EB-820B-478D-A656-85C93210054E}.Debug|x86.Build.0 = Debug|Any CPU
3400+
{4031A5EB-820B-478D-A656-85C93210054E}.Release|Any CPU.ActiveCfg = Release|Any CPU
3401+
{4031A5EB-820B-478D-A656-85C93210054E}.Release|Any CPU.Build.0 = Release|Any CPU
3402+
{4031A5EB-820B-478D-A656-85C93210054E}.Release|x64.ActiveCfg = Release|Any CPU
3403+
{4031A5EB-820B-478D-A656-85C93210054E}.Release|x64.Build.0 = Release|Any CPU
3404+
{4031A5EB-820B-478D-A656-85C93210054E}.Release|x86.ActiveCfg = Release|Any CPU
3405+
{4031A5EB-820B-478D-A656-85C93210054E}.Release|x86.Build.0 = Release|Any CPU
33923406
EndGlobalSection
33933407
GlobalSection(SolutionProperties) = preSolution
33943408
HideSolutionNode = FALSE
@@ -3661,6 +3675,7 @@ Global
36613675
{58FECE86-7530-4E6F-BA61-512BE44DEA83} = {F2CF5D32-4B41-425E-B229-8FFC48F88063}
36623676
{82626916-C5F3-46E7-B0EC-1D38191450C7} = {58FECE86-7530-4E6F-BA61-512BE44DEA83}
36633677
{8773396C-5EDF-498C-97D7-1D2728CB969B} = {F2CF5D32-4B41-425E-B229-8FFC48F88063}
3678+
{4031A5EB-820B-478D-A656-85C93210054E} = {72E7FA64-5B1E-477D-BD30-63B7F206B3C4}
36643679
EndGlobalSection
36653680
GlobalSection(ExtensibilityGlobals) = postSolution
36663681
SolutionGuid = {F5273D7F-3334-48DF-94E3-41AE6816CD4D}

build/nuke/Build.Native.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,59 @@ string AndroidHome
277277
)
278278
);
279279

280+
281+
AbsolutePath WgpuPath => RootDirectory / "build" / "submodules" / "wgpu-native";
282+
283+
Target Wgpu => CommonTarget
284+
(
285+
x => x.Before(Compile)
286+
.After(Clean)
287+
.Executes
288+
(
289+
() =>
290+
{
291+
var runtimes = RootDirectory / "src" / "Native" / "Silk.NET.WebGPU.Native.WGPU" / "runtimes";
292+
293+
var target = WgpuPath / "target";
294+
EnsureCleanDirectory(target);
295+
296+
if(OperatingSystem.IsWindows())
297+
{
298+
//Compile Windows libraries
299+
InheritedShell("cargo build --release --target=i686-pc-windows-msvc", WgpuPath).AssertZeroExitCode();
300+
InheritedShell("cargo build --release --target=x86_64-pc-windows-msvc", WgpuPath).AssertZeroExitCode();
301+
InheritedShell("cargo build --release --target=aarch64-pc-windows-msvc", WgpuPath).AssertZeroExitCode();
302+
303+
CopyFile(target / "i686-pc-windows-msvc" / "release" / "wgpu_native.dll", runtimes / "win-x86" / "native" / "wgpu_native.dll", FileExistsPolicy.Overwrite);
304+
CopyFile(target / "x86_64-pc-windows-msvc" / "release" / "wgpu_native.dll", runtimes / "win-x64" / "native" / "wgpu_native.dll", FileExistsPolicy.Overwrite);
305+
CopyFile(target / "aarch64-pc-windows-msvc" / "release" / "wgpu_native.dll", runtimes / "win-arm64" / "native" / "wgpu_native.dll", FileExistsPolicy.Overwrite);
306+
}
307+
308+
if(OperatingSystem.IsLinux())
309+
{
310+
//Compile Linux libraries
311+
InheritedShell("cargo build --release --target=i686-unknown-linux-gnu", WgpuPath).AssertZeroExitCode();
312+
InheritedShell("cargo build --release --target=x86_64-unknown-linux-gnu", WgpuPath).AssertZeroExitCode();
313+
314+
CopyFile(target / "i686-unknown-linux-gnu" / "release" / "libwgpu_native.so", runtimes / "linux-x86" / "native" / "libwgpu_native.so", FileExistsPolicy.Overwrite);
315+
CopyFile(target / "x86_64-unknown-linux-gnu" / "release" / "libwgpu_native.so", runtimes / "linux-x64" / "native" / "libwgpu_native.so", FileExistsPolicy.Overwrite);
316+
}
317+
318+
if(OperatingSystem.IsMacOS())
319+
{
320+
//Compile MacOS libraries
321+
InheritedShell("cargo build --release --target=aarch64-apple-darwin", WgpuPath).AssertZeroExitCode();
322+
InheritedShell("cargo build --release --target=x86_64-apple-darwin", WgpuPath).AssertZeroExitCode();
323+
324+
CopyFile(target / "x86_64-apple-darwin" / "release" / "libwgpu_native.dylib", runtimes / "osx-x64" / "native" / "libwgpu_native.dylib", FileExistsPolicy.Overwrite);
325+
CopyFile(target / "aarch64-apple-darwin" / "release" / "libwgpu_native.dylib", runtimes / "osx-arm64" / "native" / "libwgpu_native.dylib", FileExistsPolicy.Overwrite);
326+
}
327+
328+
PrUpdatedNativeBinary("Wgpu");
329+
}
330+
)
331+
);
332+
280333
AbsolutePath GLFWPath => RootDirectory / "build" / "submodules" / "GLFW";
281334

282335
Target GLFW => CommonTarget

src/Native/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ compatibility with the rest of your solution:
1616
- Silk.NET.Assimp.Native: BSD-3-Clause
1717
- Silk.NET.SDL.Native and Silk.NET.GLFW.Native: Zlib
1818
- Silk.NET.OpenAL.Soft.Native: LGPL-2.0-or-later
19+
- Silk.NET.WebGPU.Native.WGPU: MIT/Apache-2.0
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<SilkNativePackage>true</SilkNativePackage>
5+
</PropertyGroup>
6+
7+
<Import Project="..\..\..\build\props\common.props" />
8+
9+
<PropertyGroup>
10+
<TargetFrameworks>netstandard2.0;net4.6.1</TargetFrameworks>
11+
<PackageId>Silk.NET.WebGPU.Native.WGPU</PackageId>
12+
<Authors>.NET Foundation and Contributors</Authors>
13+
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
14+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
15+
<PackageProjectUrl>https://github.com/dotnet/Silk.NET</PackageProjectUrl>
16+
<Description>Multi-platform native library for WGPU.</Description>
17+
<RepositoryType>git</RepositoryType>
18+
<RepositoryUrl>https://github.com/gfx-rs/wgpu-native</RepositoryUrl>
19+
<IncludeBuildOutput>false</IncludeBuildOutput>
20+
<IncludeContentInPack>true</IncludeContentInPack>
21+
</PropertyGroup>
22+
23+
<ItemGroup>
24+
<Content Include="build\net461\$(PackageId).targets" PackagePath="build\net461\$(PackageId).targets" />
25+
<Content Include="runtimes\linux-x86\native\libwgpu_native.so" PackagePath="runtimes\linux-x86\native\libwgpu_native.so" />
26+
<Content Include="runtimes\linux-x64\native\libwgpu_native.so" PackagePath="runtimes\linux-x64\native\libwgpu_native.so" />
27+
<Content Include="runtimes\osx-x64\native\libwgpu_native.dylib" PackagePath="runtimes\osx-x64\native\libwgpu_native.dylib" />
28+
<Content Include="runtimes\osx-arm64\native\libwgpu_native.dylib" PackagePath="runtimes\osx-arm64\native\libwgpu_native.dylib" />
29+
<Content Include="runtimes\win-x86\native\wgpu_native.dll" PackagePath="runtimes\win-x86\native\wgpu_native.dll" />
30+
<Content Include="runtimes\win-x64\native\wgpu_native.dll" PackagePath="runtimes\win-x64\native\wgpu_native.dll" />
31+
<Content Include="runtimes\win-arm64\native\wgpu_native.dll" PackagePath="runtimes\win-arm64\native\wgpu_native.dll" />
32+
</ItemGroup>
33+
34+
</Project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<_Silk_NET_WebGPU_Native_WGPU_IsWindows Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</_Silk_NET_WebGPU_Native_WGPU_IsWindows>
5+
<_Silk_NET_WebGPU_Native_WGPU_IsMacOS Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</_Silk_NET_WebGPU_Native_WGPU_IsMacOS>
6+
<_Silk_NET_WebGPU_Native_WGPU_IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</_Silk_NET_WebGPU_Native_WGPU_IsLinux>
7+
8+
<_Silk_NET_WebGPU_Native_WGPU_NativeRuntime Condition=" '$(_Silk_NET_WebGPU_Native_WGPU_NativeRuntime)' == '' And '$(_Silk_NET_WebGPU_Native_WGPU_IsMacOS)' == 'true' And ('$(Prefer32Bit)' == 'false' Or '$(PlatformTarget)' == 'x64')">osx-x64</_Silk_NET_WebGPU_Native_WGPU_NativeRuntime>
9+
<_Silk_NET_WebGPU_Native_WGPU_NativeRuntime Condition=" '$(_Silk_NET_WebGPU_Native_WGPU_NativeRuntime)' == '' And '$(_Silk_NET_WebGPU_Native_WGPU_IsLinux)' == 'true' And ('$(Prefer32Bit)' == 'false' Or '$(PlatformTarget)' == 'x64')">linux-x64</_Silk_NET_WebGPU_Native_WGPU_NativeRuntime>
10+
<_Silk_NET_WebGPU_Native_WGPU_NativeRuntime Condition=" '$(_Silk_NET_WebGPU_Native_WGPU_NativeRuntime)' == '' And '$(_Silk_NET_WebGPU_Native_WGPU_IsWindows)' == 'true' And ('$(Prefer32Bit)' == 'true' Or '$(PlatformTarget)' == 'x86')">win-x86</_Silk_NET_WebGPU_Native_WGPU_NativeRuntime>
11+
<_Silk_NET_WebGPU_Native_WGPU_NativeRuntime Condition=" '$(_Silk_NET_WebGPU_Native_WGPU_NativeRuntime)' == '' And '$(_Silk_NET_WebGPU_Native_WGPU_IsWindows)' == 'true' And ('$(Prefer32Bit)' == 'false' Or '$(PlatformTarget)' == 'x64')">win-x64</_Silk_NET_WebGPU_Native_WGPU_NativeRuntime>
12+
<_Silk_NET_WebGPU_Native_WGPU_NativeRuntime Condition=" '$(_Silk_NET_WebGPU_Native_WGPU_NativeRuntime)' == '' And '$(_Silk_NET_WebGPU_Native_WGPU_IsWindows)' == 'true' And '$(PlatformTarget)' == 'arm64'">win-arm64</_Silk_NET_WebGPU_Native_WGPU_NativeRuntime>
13+
14+
<_Silk_NET_WebGPU_Native_WGPU_NativeLibName Condition="'$(_Silk_NET_WebGPU_Native_WGPU_NativeRuntime)' == 'win-x86'">wgpu_native.dll</_Silk_NET_WebGPU_Native_WGPU_NativeLibName>
15+
<_Silk_NET_WebGPU_Native_WGPU_NativeLibName Condition="'$(_Silk_NET_WebGPU_Native_WGPU_NativeRuntime)' == 'win-x64'">wgpu_native.dll</_Silk_NET_WebGPU_Native_WGPU_NativeLibName>
16+
<_Silk_NET_WebGPU_Native_WGPU_NativeLibName Condition="'$(_Silk_NET_WebGPU_Native_WGPU_NativeRuntime)' == 'win-arm64'">wgpu_native.dll</_Silk_NET_WebGPU_Native_WGPU_NativeLibName>
17+
<_Silk_NET_WebGPU_Native_WGPU_NativeLibName Condition="'$(_Silk_NET_WebGPU_Native_WGPU_NativeRuntime)' == 'osx-x64'">libwgpu_native.dylib</_Silk_NET_WebGPU_Native_WGPU_NativeLibName>
18+
<_Silk_NET_WebGPU_Native_WGPU_NativeLibName Condition="'$(_Silk_NET_WebGPU_Native_WGPU_NativeRuntime)' == 'osx-arm64'">libwgpu_native.dylib</_Silk_NET_WebGPU_Native_WGPU_NativeLibName>
19+
<_Silk_NET_WebGPU_Native_WGPU_NativeLibName Condition="'$(_Silk_NET_WebGPU_Native_WGPU_NativeRuntime)' == 'linux-x86'">libwgpu_native.so</_Silk_NET_WebGPU_Native_WGPU_NativeLibName>
20+
<_Silk_NET_WebGPU_Native_WGPU_NativeLibName Condition="'$(_Silk_NET_WebGPU_Native_WGPU_NativeRuntime)' == 'linux-x64'">libwgpu_native.so</_Silk_NET_WebGPU_Native_WGPU_NativeLibName>
21+
</PropertyGroup>
22+
<ItemGroup>
23+
<Content Condition="'$(_Silk_NET_WebGPU_Native_WGPU_NativeRuntime)' != ''" Include="$(MSBuildThisFileDirectory)..\..\runtimes\$(_Silk_NET_WebGPU_Native_WGPU_NativeRuntime)\native\$(_Silk_NET_WebGPU_Native_WGPU_NativeLibName)">
24+
<Link>%(Filename)%(Extension)</Link>
25+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
26+
<Visible>False</Visible>
27+
</Content>
28+
</ItemGroup>
29+
</Project>

0 commit comments

Comments
 (0)