diff --git a/.github/workflows/wgpu.yml b/.github/workflows/wgpu.yml index b0569cc96e..0642a28fe2 100644 --- a/.github/workflows/wgpu.yml +++ b/.github/workflows/wgpu.yml @@ -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: "" diff --git a/build/nuke/Native/Wgpu.cs b/build/nuke/Native/Wgpu.cs index 29f4e185bb..48cc289ca5 100644 --- a/build/nuke/Native/Wgpu.cs +++ b/build/nuke/Native/Wgpu.cs @@ -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"); } ) ); -} \ No newline at end of file +} diff --git a/src/Native/Silk.NET.WebGPU.Native.WGPU/Silk.NET.WebGPU.Native.WGPU.csproj b/src/Native/Silk.NET.WebGPU.Native.WGPU/Silk.NET.WebGPU.Native.WGPU.csproj index 1da340b171..fb538f23cc 100644 --- a/src/Native/Silk.NET.WebGPU.Native.WGPU/Silk.NET.WebGPU.Native.WGPU.csproj +++ b/src/Native/Silk.NET.WebGPU.Native.WGPU/Silk.NET.WebGPU.Native.WGPU.csproj @@ -22,13 +22,15 @@ - + + - + - - + + +