Skip to content

Commit

Permalink
Native/wgpu-native: Build for linux-arm and linux-arm64.
Browse files Browse the repository at this point in the history
Also clean up the build script to be table-driven.
  • Loading branch information
alexrp committed Apr 13, 2024
1 parent 6871235 commit ba54689
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 34 deletions.
28 changes: 23 additions & 5 deletions .github/workflows/wgpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,35 @@ jobs:
fail-fast: false
matrix:
env:
- os: ubuntu-latest
- os: ubuntu-22.04
name: Linux
nuke_invoke: ./build.sh
extras: |
sudo apt-get update
sudo apt-get install -y gcc-multilib
- os: windows-latest
sudo tee /etc/apt/sources.list << EOF
deb [arch=amd64,i386] http://archive.ubuntu.com/ubuntu jammy main multiverse restricted universe
deb [arch=amd64,i386] http://archive.ubuntu.com/ubuntu jammy-backports main multiverse restricted universe
deb [arch=amd64,i386] http://archive.ubuntu.com/ubuntu jammy-security main multiverse restricted universe
deb [arch=amd64,i386] http://archive.ubuntu.com/ubuntu jammy-updates main multiverse restricted universe
deb [arch=arm64,armhf] http://ports.ubuntu.com jammy main multiverse restricted universe
deb [arch=arm64,armhf] http://ports.ubuntu.com jammy-backports main multiverse restricted universe
deb [arch=arm64,armhf] http://ports.ubuntu.com jammy-security main multiverse restricted universe
deb [arch=arm64,armhf] http://ports.ubuntu.com jammy-updates main multiverse restricted universe
deb [arch=amd64,i386] http://security.ubuntu.com/ubuntu jammy main multiverse restricted universe
deb [arch=amd64,i386] http://security.ubuntu.com/ubuntu jammy-backports main multiverse restricted universe
deb [arch=amd64,i386] http://security.ubuntu.com/ubuntu jammy-security main multiverse restricted universe
deb [arch=amd64,i386] http://security.ubuntu.com/ubuntu jammy-updates main multiverse restricted universe
EOF
sudo dpkg --add-architecture arm64
sudo dpkg --add-architecture armhf
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install -y gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf gcc-i686-linux-gnu
sudo apt install -y libgcc-11-dev libgcc-11-dev-arm64-cross libgcc-11-dev-armhf-cross libgcc-11-dev-i386-cross
- os: windows-2022
name: Windows
nuke_invoke: ./build.cmd
extras: ""
- os: macos-latest
- os: macos-14
name: Darwin
nuke_invoke: ./build.sh
extras: ""
Expand Down
72 changes: 47 additions & 25 deletions build/nuke/Native/Wgpu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,45 +36,67 @@ partial class Build {
(
() =>
{
var target = WgpuPath / "target";
var runtimes = RootDirectory / "src" / "Native" / "Silk.NET.WebGPU.Native.WGPU" / "runtimes";
var target = WgpuPath / "target";
EnsureCleanDirectory(target);
if(OperatingSystem.IsWindows())
{
//Compile Windows libraries
InheritedShell("cargo build --release --target=i686-pc-windows-msvc", WgpuPath).AssertZeroExitCode();
InheritedShell("cargo build --release --target=x86_64-pc-windows-msvc", WgpuPath).AssertZeroExitCode();
InheritedShell("cargo build --release --target=aarch64-pc-windows-msvc", WgpuPath).AssertZeroExitCode();
(string Triple, string Rid)[] targets;
string library;
CopyFile(target / "i686-pc-windows-msvc" / "release" / "wgpu_native.dll", runtimes / "win-x86" / "native" / "wgpu_native.dll", FileExistsPolicy.Overwrite);
CopyFile(target / "x86_64-pc-windows-msvc" / "release" / "wgpu_native.dll", runtimes / "win-x64" / "native" / "wgpu_native.dll", FileExistsPolicy.Overwrite);
CopyFile(target / "aarch64-pc-windows-msvc" / "release" / "wgpu_native.dll", runtimes / "win-arm64" / "native" / "wgpu_native.dll", FileExistsPolicy.Overwrite);
if (OperatingSystem.IsWindows())
{
targets = new[]
{
("i686-pc-windows-msvc", "win-x86"),
("x86_64-pc-windows-msvc", "win-x64"),
("aarch64-pc-windows-msvc", "win-arm64"),
};
library = "wgpu_native.dll";
}
if(OperatingSystem.IsLinux())
else if (OperatingSystem.IsLinux())
{
//Compile Linux libraries
InheritedShell("cargo build --release --target=i686-unknown-linux-gnu", WgpuPath).AssertZeroExitCode();
InheritedShell("cargo build --release --target=x86_64-unknown-linux-gnu", WgpuPath).AssertZeroExitCode();
CopyFile(target / "i686-unknown-linux-gnu" / "release" / "libwgpu_native.so", runtimes / "linux-x86" / "native" / "libwgpu_native.so", FileExistsPolicy.Overwrite);
CopyFile(target / "x86_64-unknown-linux-gnu" / "release" / "libwgpu_native.so", runtimes / "linux-x64" / "native" / "libwgpu_native.so", FileExistsPolicy.Overwrite);
targets = new[]
{
("i686-unknown-linux-gnu", "linux-x86"),
("x86_64-unknown-linux-gnu", "linux-x64"),
("arm-unknown-linux-gnueabihf", "linux-arm"),
("aarch64-unknown-linux-gnu", "linux-arm64"),
};
library = "libwgpu_native.so";
}
else if (OperatingSystem.IsMacOS())
{
targets = new[]
{
("x86_64-apple-darwin", "osx-x64"),
("aarch64-apple-darwin", "osx-arm64"),
};
library = "libwgpu_native.dylib";
}
else
throw new Exception("Unsupported OS!");
if(OperatingSystem.IsMacOS())
foreach (var (triple, rid) in targets)
{
//Compile MacOS libraries
InheritedShell("cargo build --release --target=aarch64-apple-darwin", WgpuPath).AssertZeroExitCode();
InheritedShell("cargo build --release --target=x86_64-apple-darwin", WgpuPath).AssertZeroExitCode();
// Cross-compiling to these targets on linux-x64 will fail if a proper linker is not set.
var linker = rid switch
{
"linux-arm" => "arm-linux-gnueabihf-gcc",
"linux-arm64" => "aarch64-linux-gnu-gcc",
_ => null,
};
if (linker != null)
linker = $" --config \"target.{triple}.linker = '{linker}'\"";
InheritedShell($"cargo build --release --target {triple}{linker}", WgpuPath).AssertZeroExitCode();
CopyFile(target / "x86_64-apple-darwin" / "release" / "libwgpu_native.dylib", runtimes / "osx-x64" / "native" / "libwgpu_native.dylib", FileExistsPolicy.Overwrite);
CopyFile(target / "aarch64-apple-darwin" / "release" / "libwgpu_native.dylib", runtimes / "osx-arm64" / "native" / "libwgpu_native.dylib", FileExistsPolicy.Overwrite);
CopyFile(target / triple / "release" / library, runtimes / rid / "native" / library, FileExistsPolicy.Overwrite);
}
PrUpdatedNativeBinary("Wgpu");
}
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@

<ItemGroup>
<Content Include="build\net461\$(PackageId).targets" PackagePath="build\net461\$(PackageId).targets" />
<Content Include="runtimes\linux-x86\native\libwgpu_native.so" PackagePath="runtimes\linux-x86\native\libwgpu_native.so" />
<Content Include="runtimes\linux-arm\native\libwgpu_native.so" PackagePath="runtimes\linux-arm\native\libwgpu_native.so" />
<Content Include="runtimes\linux-arm64\native\libwgpu_native.so" PackagePath="runtimes\linux-arm64\native\libwgpu_native.so" />
<Content Include="runtimes\linux-x64\native\libwgpu_native.so" PackagePath="runtimes\linux-x64\native\libwgpu_native.so" />
<Content Include="runtimes\osx-x64\native\libwgpu_native.dylib" PackagePath="runtimes\osx-x64\native\libwgpu_native.dylib" />
<Content Include="runtimes\linux-x86\native\libwgpu_native.so" PackagePath="runtimes\linux-x86\native\libwgpu_native.so" />
<Content Include="runtimes\osx-arm64\native\libwgpu_native.dylib" PackagePath="runtimes\osx-arm64\native\libwgpu_native.dylib" />
<Content Include="runtimes\win-x86\native\wgpu_native.dll" PackagePath="runtimes\win-x86\native\wgpu_native.dll" />
<Content Include="runtimes\win-x64\native\wgpu_native.dll" PackagePath="runtimes\win-x64\native\wgpu_native.dll" />
<Content Include="runtimes\osx-x64\native\libwgpu_native.dylib" PackagePath="runtimes\osx-x64\native\libwgpu_native.dylib" />
<Content Include="runtimes\win-arm64\native\wgpu_native.dll" PackagePath="runtimes\win-arm64\native\wgpu_native.dll" />
<Content Include="runtimes\win-x64\native\wgpu_native.dll" PackagePath="runtimes\win-x64\native\wgpu_native.dll" />
<Content Include="runtimes\win-x86\native\wgpu_native.dll" PackagePath="runtimes\win-x86\native\wgpu_native.dll" />
</ItemGroup>

</Project>

0 comments on commit ba54689

Please sign in to comment.