From 55339ae93faa908149a1af3d0a974327cc95c996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sat, 6 Apr 2024 01:39:08 +0200 Subject: [PATCH 01/20] Native/Assimp: Build for linux-arm, linux-arm64, and win-arm64. Also clean up the build script. --- .github/workflows/assimp.yml | 29 +++++-- build/nuke/Native/Assimp.cs | 76 ++++++++++--------- build/nuke/Native/Core.cs | 5 ++ .../Silk.NET.Assimp.Native.csproj | 7 +- 4 files changed, 75 insertions(+), 42 deletions(-) diff --git a/.github/workflows/assimp.yml b/.github/workflows/assimp.yml index 95c560dec3..9863c61790 100644 --- a/.github/workflows/assimp.yml +++ b/.github/workflows/assimp.yml @@ -17,17 +17,34 @@ 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 xorg-dev - - os: windows-latest + sudo tee /etc/apt/sources.list << EOF + deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy main universe + deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy-backports main universe + deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy-security main universe + deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy-updates main universe + deb [arch=arm64,armhf] http://ports.ubuntu.com jammy main universe + deb [arch=arm64,armhf] http://ports.ubuntu.com jammy-backports main universe + deb [arch=arm64,armhf] http://ports.ubuntu.com jammy-security main universe + deb [arch=arm64,armhf] http://ports.ubuntu.com jammy-updates main universe + deb [arch=amd64] http://security.ubuntu.com/ubuntu jammy main universe + deb [arch=amd64] http://security.ubuntu.com/ubuntu jammy-backports main universe + deb [arch=amd64] http://security.ubuntu.com/ubuntu jammy-security main universe + deb [arch=amd64] http://security.ubuntu.com/ubuntu jammy-updates main universe + EOF + sudo dpkg --add-architecture arm64 + sudo dpkg --add-architecture armhf + sudo apt update + sudo apt install -y gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf + sudo apt install -y g++-aarch64-linux-gnu g++-arm-linux-gnueabihf + - os: windows-2022 name: Windows nuke_invoke: ./build.cmd extras: "" - - os: macos-latest + - os: macos-14 name: Darwin nuke_invoke: ./build.sh extras: "" @@ -41,7 +58,7 @@ jobs: run: | git -c submodule.third_party/git-hooks.update=none submodule update --init --recursive --depth 0 build/submodules/Assimp git config --local user.email "9011267+dotnet-bot@users.noreply.github.com" - git config --local user.name "The Silk.NET Automaton" + git config --local user.name "The Silk.NET Automaton" - name: Extra prerequisites run: | echo running extras diff --git a/build/nuke/Native/Assimp.cs b/build/nuke/Native/Assimp.cs index 15d92957d2..bd3818ee69 100644 --- a/build/nuke/Native/Assimp.cs +++ b/build/nuke/Native/Assimp.cs @@ -36,57 +36,65 @@ partial class Build { ( () => { - var @out = AssimpPath / "build"; - var prepare = "cmake -S. -B build -D BUILD_SHARED_LIBS=ON -DASSIMP_WARNINGS_AS_ERRORS=OFF"; - var build = $"cmake --build build --config Release{JobsArg}"; - EnsureCleanDirectory(@out); + var buildDir = AssimpPath / "build"; var runtimes = RootDirectory / "src" / "Native" / "Silk.NET.Assimp.Native" / "runtimes"; + + var prepare = "cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DASSIMP_WARNINGS_AS_ERRORS=OFF"; + var build = $"cmake --build . --config Release{JobsArg}"; + if (OperatingSystem.IsWindows()) { - InheritedShell($"{prepare} -A X64", AssimpPath) - .AssertZeroExitCode(); - InheritedShell(build, AssimpPath) - .AssertZeroExitCode(); - - CopyAs(@out, "bin/Release/assimp-*-mt.dll", runtimes / "win-x64" / "native" / "Assimp64.dll"); - EnsureCleanDirectory(@out); + foreach (var (platform, rid) in new[] + { + ("Win32", "win-x86"), + ("x64", "win-x64"), + ("ARM64", "win-arm64"), + }) + { + EnsureCleanDirectory(buildDir); - InheritedShell($"{prepare} -A Win32", AssimpPath) - .AssertZeroExitCode(); - InheritedShell(build, AssimpPath) - .AssertZeroExitCode(); + InheritedShell($"{prepare} -A {platform}", buildDir).AssertZeroExitCode(); + InheritedShell(build, buildDir).AssertZeroExitCode(); - CopyAs(@out, "bin/Release/assimp-*-mt.dll", runtimes / "win-x86" / "native" / "Assimp32.dll"); + CopyAs(buildDir / "bin" / "Release", "assimp-*-mt.dll", runtimes / rid / "native" / $"Assimp{(rid.Contains("64") ? 64 : 32)}.dll"); + } } else if (OperatingSystem.IsLinux()) { - InheritedShell($"{prepare} -DCMAKE_SYSTEM_PROCESSOR=x86_64", AssimpPath) - .AssertZeroExitCode(); - InheritedShell(build, AssimpPath) - .AssertZeroExitCode(); + foreach (var (triple, rid) in new[] + { + ("x86_64-linux-gnu", "linux-x64"), + ("arm-linux-gnueabihf", "linux-arm"), + ("aarch64-linux-gnu", "linux-arm64"), + }) + { + EnsureCleanDirectory(buildDir); - CopyAll(@out.GlobFiles("bin/libassimp.so.5"), runtimes / "linux-x64" / "native"); + InheritedShell($"{prepare} {GetCMakeToolchainFlag(triple)}", buildDir).AssertZeroExitCode(); + InheritedShell(build, buildDir).AssertZeroExitCode(); + + CopyAll((buildDir / "bin").GlobFiles("libassimp.so.5"), runtimes / rid / "native"); + } } else if (OperatingSystem.IsMacOS()) { - InheritedShell($"{prepare} -DCMAKE_OSX_ARCHITECTURES=x86_64", AssimpPath) - .AssertZeroExitCode(); - InheritedShell(build, AssimpPath) - .AssertZeroExitCode(); - CopyAll(@out.GlobFiles("bin/libassimp.5.dylib"), runtimes / "osx-x64" / "native"); - - EnsureCleanDirectory(@out); + foreach (var (arch, rid) in new[] + { + ("x86_64", "osx-x64"), + ("arm64", "osx-arm64"), + }) + { + EnsureCleanDirectory(buildDir); - InheritedShell($"{prepare} -DCMAKE_OSX_ARCHITECTURES=arm64", AssimpPath) - .AssertZeroExitCode(); - InheritedShell(build, AssimpPath) - .AssertZeroExitCode(); + InheritedShell($"{prepare} -DCMAKE_OSX_ARCHITECTURES={arch}", buildDir).AssertZeroExitCode(); + InheritedShell(build, buildDir).AssertZeroExitCode(); - CopyAll(@out.GlobFiles("bin/libassimp.5.dylib"), runtimes / "osx-arm64" / "native"); + CopyAll((buildDir / "bin").GlobFiles("libassimp.5.dylib"), runtimes / rid / "native"); + } } PrUpdatedNativeBinary("Assimp"); } ) ); -} \ No newline at end of file +} diff --git a/build/nuke/Native/Core.cs b/build/nuke/Native/Core.cs index 3544ad290f..30d9223eb3 100644 --- a/build/nuke/Native/Core.cs +++ b/build/nuke/Native/Core.cs @@ -39,6 +39,11 @@ partial class Build { ? Environment.ProcessorCount - 1 : 1; + public string GetCMakeToolchainFlag(string target) + { + return $"-DCMAKE_TOOLCHAIN_FILE={RootDirectory / "build" / "cmake" / target}.cmake"; + } + public void CopyAs(AbsolutePath @out, string from, string to) { var file = @out.GlobFiles(from).First(); diff --git a/src/Native/Silk.NET.Assimp.Native/Silk.NET.Assimp.Native.csproj b/src/Native/Silk.NET.Assimp.Native/Silk.NET.Assimp.Native.csproj index 52195a9276..d19cbd65b4 100644 --- a/src/Native/Silk.NET.Assimp.Native/Silk.NET.Assimp.Native.csproj +++ b/src/Native/Silk.NET.Assimp.Native/Silk.NET.Assimp.Native.csproj @@ -20,12 +20,15 @@ false true - + + + - + + From 5f579bdc8da5f562f9b3ca4e8a4ea333ee887a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 8 Apr 2024 08:16:01 +0200 Subject: [PATCH 02/20] Native/Assimp: Don't build tests. --- build/nuke/Native/Assimp.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/nuke/Native/Assimp.cs b/build/nuke/Native/Assimp.cs index bd3818ee69..3162e304e8 100644 --- a/build/nuke/Native/Assimp.cs +++ b/build/nuke/Native/Assimp.cs @@ -39,7 +39,7 @@ partial class Build { var buildDir = AssimpPath / "build"; var runtimes = RootDirectory / "src" / "Native" / "Silk.NET.Assimp.Native" / "runtimes"; - var prepare = "cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DASSIMP_WARNINGS_AS_ERRORS=OFF"; + var prepare = "cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DASSIMP_WARNINGS_AS_ERRORS=OFF -DASSIMP_BUILD_TESTS=OFF"; var build = $"cmake --build . --config Release{JobsArg}"; if (OperatingSystem.IsWindows()) From b8d1c2f40e43289345113d1c9f9e5aebad52348d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 7 Apr 2024 00:29:27 +0200 Subject: [PATCH 03/20] Native/Assimp: Strip Linux/macOS binaries after build. --- build/nuke/Native/Assimp.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build/nuke/Native/Assimp.cs b/build/nuke/Native/Assimp.cs index 3162e304e8..ed1fb21d95 100644 --- a/build/nuke/Native/Assimp.cs +++ b/build/nuke/Native/Assimp.cs @@ -73,6 +73,8 @@ partial class Build { InheritedShell($"{prepare} {GetCMakeToolchainFlag(triple)}", buildDir).AssertZeroExitCode(); InheritedShell(build, buildDir).AssertZeroExitCode(); + InheritedShell($"{triple}-strip bin/libassimp.so.5", buildDir).AssertZeroExitCode(); + CopyAll((buildDir / "bin").GlobFiles("libassimp.so.5"), runtimes / rid / "native"); } } @@ -89,6 +91,8 @@ partial class Build { InheritedShell($"{prepare} -DCMAKE_OSX_ARCHITECTURES={arch}", buildDir).AssertZeroExitCode(); InheritedShell(build, buildDir).AssertZeroExitCode(); + InheritedShell($"strip bin/libassimp.5.dylib", buildDir).AssertZeroExitCode(); + CopyAll((buildDir / "bin").GlobFiles("libassimp.5.dylib"), runtimes / rid / "native"); } } From b22bf966eb8559b312a4197759be9f0b142e4342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sat, 6 Apr 2024 01:40:04 +0200 Subject: [PATCH 04/20] Native/GLFW: Build for linux-arm and linux-arm64. Also clean up the build script. --- .github/workflows/glfw.yml | 33 +++++-- build/nuke/Native/GLFW.cs | 87 +++++++++---------- .../Silk.NET.GLFW.Native.csproj | 6 +- 3 files changed, 74 insertions(+), 52 deletions(-) diff --git a/.github/workflows/glfw.yml b/.github/workflows/glfw.yml index b05d8871c5..e005f86566 100644 --- a/.github/workflows/glfw.yml +++ b/.github/workflows/glfw.yml @@ -17,17 +17,38 @@ 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 xorg-dev libwayland-dev libxkbcommon-dev - - 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 apt update + sudo apt install -y gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf + sudo apt install -y extra-cmake-modules wayland-protocols + for arch in amd64 arm64 armhf; do + sudo apt install -y libwayland-dev:$arch libxcursor-dev:$arch libxi-dev:$arch + sudo apt install -y libxinerama-dev:$arch libxrandr-dev:$arch libxkbcommon-dev:$arch + done + - os: windows-2022 name: Windows nuke_invoke: ./build.cmd extras: "" - - os: macos-latest + - os: macos-14 name: Darwin nuke_invoke: ./build.sh extras: "" @@ -41,7 +62,7 @@ jobs: run: | git -c submodule.third_party/git-hooks.update=none submodule update --init --recursive --depth 0 build/submodules/GLFW git config --local user.email "9011267+dotnet-bot@users.noreply.github.com" - git config --local user.name "The Silk.NET Automaton" + git config --local user.name "The Silk.NET Automaton" - name: Extra prerequisites run: | echo running extras diff --git a/build/nuke/Native/GLFW.cs b/build/nuke/Native/GLFW.cs index 57b472de5e..c0131aecc1 100644 --- a/build/nuke/Native/GLFW.cs +++ b/build/nuke/Native/GLFW.cs @@ -36,66 +36,65 @@ partial class Build { ( () => { - var @out = GLFWPath / "build"; - var prepare = "cmake -S. -B build -D BUILD_SHARED_LIBS=ON"; - var build = $"cmake --build build --config Release{JobsArg}"; - EnsureCleanDirectory(@out); + var buildDir = GLFWPath / "build"; var runtimes = RootDirectory / "src" / "Native" / "Silk.NET.GLFW.Native" / "runtimes"; - if (OperatingSystem.IsWindows()) - { - InheritedShell($"{prepare} -A X64", GLFWPath) - .AssertZeroExitCode(); - InheritedShell(build, GLFWPath) - .AssertZeroExitCode(); - - CopyAll(@out.GlobFiles("src/Release/glfw3.dll"), runtimes / "win-x64" / "native"); - EnsureCleanDirectory(@out); + var prepare = "cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON"; + var build = $"cmake --build . --config Release{JobsArg}"; - InheritedShell($"{prepare} -A Win32", GLFWPath) - .AssertZeroExitCode(); - InheritedShell(build, GLFWPath) - .AssertZeroExitCode(); + if (OperatingSystem.IsWindows()) + { + foreach (var (platform, rid) in new[] + { + ("Win32", "win-x86"), + ("x64", "win-x64"), + ("ARM64", "win-arm64"), + }) + { + EnsureCleanDirectory(buildDir); - CopyAll(@out.GlobFiles("src/Release/glfw3.dll"), runtimes / "win-x86" / "native"); - - EnsureCleanDirectory(@out); - - InheritedShell($"{prepare} -A arm64", GLFWPath) - .AssertZeroExitCode(); - InheritedShell(build, GLFWPath) - .AssertZeroExitCode(); + InheritedShell($"{prepare} -A {platform}", buildDir).AssertZeroExitCode(); + InheritedShell(build, buildDir).AssertZeroExitCode(); - CopyAll(@out.GlobFiles("src/Release/glfw3.dll"), runtimes / "win-arm64" / "native"); + CopyAll((buildDir / "src" / "Release").GlobFiles("glfw3.dll"), runtimes / rid / "native"); + } } else if (OperatingSystem.IsLinux()) { - InheritedShell($"{prepare} -DCMAKE_SYSTEM_PROCESSOR=x86_64", GLFWPath) - .AssertZeroExitCode(); - InheritedShell(build, GLFWPath) - .AssertZeroExitCode(); - CopyAll(@out.GlobFiles("src/libglfw.so"), runtimes / "linux-x64" / "native"); + foreach (var (triple, rid) in new[] + { + ("x86_64-linux-gnu", "linux-x64"), + ("arm-linux-gnueabihf", "linux-arm"), + ("aarch64-linux-gnu", "linux-arm64"), + }) + { + EnsureCleanDirectory(buildDir); + + InheritedShell($"{prepare} {GetCMakeToolchainFlag(triple)}", buildDir).AssertZeroExitCode(); + InheritedShell(build, buildDir).AssertZeroExitCode(); + + CopyAll((buildDir / "src").GlobFiles("libglfw.so"), runtimes / rid / "native"); + } } else if (OperatingSystem.IsMacOS()) { - InheritedShell($"{prepare} -DCMAKE_OSX_ARCHITECTURES=x86_64", GLFWPath) - .AssertZeroExitCode(); - InheritedShell(build, GLFWPath) - .AssertZeroExitCode(); - CopyAll(@out.GlobFiles("src/libglfw.3.dylib"), runtimes / "osx-x64" / "native"); - - EnsureCleanDirectory(@out); + foreach (var (arch, rid) in new[] + { + ("x86_64", "osx-x64"), + ("arm64", "osx-arm64"), + }) + { + EnsureCleanDirectory(buildDir); - InheritedShell($"{prepare} -DCMAKE_OSX_ARCHITECTURES=arm64", GLFWPath) - .AssertZeroExitCode(); - InheritedShell(build, GLFWPath) - .AssertZeroExitCode(); + InheritedShell($"{prepare} -DCMAKE_OSX_ARCHITECTURES={arch}", buildDir).AssertZeroExitCode(); + InheritedShell(build, buildDir).AssertZeroExitCode(); - CopyAll(@out.GlobFiles("src/libglfw.3.dylib"), runtimes / "osx-arm64" / "native"); + CopyAll((buildDir / "src").GlobFiles("libglfw.3.dylib"), runtimes / rid / "native"); + } } PrUpdatedNativeBinary("GLFW"); } ) ); -} \ No newline at end of file +} diff --git a/src/Native/Silk.NET.GLFW.Native/Silk.NET.GLFW.Native.csproj b/src/Native/Silk.NET.GLFW.Native/Silk.NET.GLFW.Native.csproj index 1f89567c9d..0e29cc5055 100644 --- a/src/Native/Silk.NET.GLFW.Native/Silk.NET.GLFW.Native.csproj +++ b/src/Native/Silk.NET.GLFW.Native/Silk.NET.GLFW.Native.csproj @@ -23,11 +23,13 @@ + + - - + + From 05fc8978eef653bfed3e91a37e3f0a4d22e2a00f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 8 Apr 2024 08:16:17 +0200 Subject: [PATCH 05/20] Native/GLFW: Don't build examples, tests, and docs. --- build/nuke/Native/GLFW.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/nuke/Native/GLFW.cs b/build/nuke/Native/GLFW.cs index c0131aecc1..d28933e77e 100644 --- a/build/nuke/Native/GLFW.cs +++ b/build/nuke/Native/GLFW.cs @@ -39,7 +39,7 @@ partial class Build { var buildDir = GLFWPath / "build"; var runtimes = RootDirectory / "src" / "Native" / "Silk.NET.GLFW.Native" / "runtimes"; - var prepare = "cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON"; + var prepare = "cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DGLFW_BUILD_EXAMPLES=OFF -DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_DOCS=OFF"; var build = $"cmake --build . --config Release{JobsArg}"; if (OperatingSystem.IsWindows()) From f2405d48bd7881fc13b404c434d3b35b9ef9179b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 7 Apr 2024 00:06:32 +0200 Subject: [PATCH 06/20] Native/GLFW: Strip Linux/macOS binaries after build. --- build/nuke/Native/GLFW.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build/nuke/Native/GLFW.cs b/build/nuke/Native/GLFW.cs index d28933e77e..5086b92215 100644 --- a/build/nuke/Native/GLFW.cs +++ b/build/nuke/Native/GLFW.cs @@ -73,6 +73,8 @@ partial class Build { InheritedShell($"{prepare} {GetCMakeToolchainFlag(triple)}", buildDir).AssertZeroExitCode(); InheritedShell(build, buildDir).AssertZeroExitCode(); + InheritedShell($"{triple}-strip src/libglfw.so", buildDir).AssertZeroExitCode(); + CopyAll((buildDir / "src").GlobFiles("libglfw.so"), runtimes / rid / "native"); } } @@ -89,6 +91,8 @@ partial class Build { InheritedShell($"{prepare} -DCMAKE_OSX_ARCHITECTURES={arch}", buildDir).AssertZeroExitCode(); InheritedShell(build, buildDir).AssertZeroExitCode(); + InheritedShell($"strip src/libglfw.3.dylib", buildDir).AssertZeroExitCode(); + CopyAll((buildDir / "src").GlobFiles("libglfw.3.dylib"), runtimes / rid / "native"); } } From d06e508549693e15b603875d340ba655c437c533 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 7 Apr 2024 04:13:57 +0200 Subject: [PATCH 07/20] Native/OpenAL Soft: Add submodule tracking 1.23.1. --- .gitmodules | 3 +++ build/submodules/openal-soft | 1 + 2 files changed, 4 insertions(+) create mode 160000 build/submodules/openal-soft diff --git a/.gitmodules b/.gitmodules index de5272891d..1489f22dd3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -52,3 +52,6 @@ [submodule "build/submodules/MoltenVK"] path = build/submodules/MoltenVK url = https://github.com/KhronosGroup/MoltenVK +[submodule "build/submodules/openal-soft"] + path = build/submodules/openal-soft + url = https://github.com/kcat/openal-soft diff --git a/build/submodules/openal-soft b/build/submodules/openal-soft new file mode 160000 index 0000000000..d3875f333f --- /dev/null +++ b/build/submodules/openal-soft @@ -0,0 +1 @@ +Subproject commit d3875f333fb6abe2f39d82caca329414871ae53b From cd67863e2b4db15bfa20485f74b97c3c53ddcb83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 7 Apr 2024 05:01:24 +0200 Subject: [PATCH 08/20] Native/OpenAL Soft: Add build script and workflow. --- .github/workflows/openal-soft.yml | 80 +++++++++++++ .nuke/build.schema.json | 2 + build/nuke/Native/OpenALSoft.cs | 106 ++++++++++++++++++ .../Silk.NET.OpenAL.Soft.Native.csproj | 4 + 4 files changed, 192 insertions(+) create mode 100644 .github/workflows/openal-soft.yml create mode 100644 build/nuke/Native/OpenALSoft.cs diff --git a/.github/workflows/openal-soft.yml b/.github/workflows/openal-soft.yml new file mode 100644 index 0000000000..625ad52db9 --- /dev/null +++ b/.github/workflows/openal-soft.yml @@ -0,0 +1,80 @@ +name: OpenAL Soft +on: + push: + branches-ignore: + - "ci/*" + - "develop/*" + - "main" + paths: + - build/submodules/openal-soft + - build/nuke/Native/Core.cs + - build/nuke/Native/OpenALSoft.cs + - .github/workflows/openal-soft.yml +jobs: + Build: + if: github.repository == 'dotnet/Silk.NET' + strategy: + fail-fast: false + matrix: + env: + - os: ubuntu-22.04 + name: Linux + nuke_invoke: ./build.sh + extras: | + sudo tee /etc/apt/sources.list << EOF + deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy main multiverse restricted universe + deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy-backports main multiverse restricted universe + deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy-security main multiverse restricted universe + deb [arch=amd64] 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] http://security.ubuntu.com/ubuntu jammy main multiverse restricted universe + deb [arch=amd64] http://security.ubuntu.com/ubuntu jammy-backports main multiverse restricted universe + deb [arch=amd64] http://security.ubuntu.com/ubuntu jammy-security main multiverse restricted universe + deb [arch=amd64] http://security.ubuntu.com/ubuntu jammy-updates main multiverse restricted universe + EOF + sudo dpkg --add-architecture arm64 + sudo dpkg --add-architecture armhf + sudo apt update + sudo apt install -y gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf + sudo apt install -y g++-aarch64-linux-gnu g++-arm-linux-gnueabihf + for arch in amd64 arm64 armhf; do + sudo apt install -y libasound2-dev:$arch libpulse-dev:$arch libjack-dev:$arch libsoundio-dev:$arch + sudo apt install -y portaudio19-dev:$arch libsndfile1-dev:$arch libmysofa-dev:$arch qtbase5-dev:$arch + done + - os: windows-2022 + name: Windows + nuke_invoke: ./build.cmd + extras: "" + - os: macos-14 + name: Darwin + nuke_invoke: ./build.sh + extras: "" + name: ${{ matrix.env.name }} Build + runs-on: ${{ matrix.env.os }} + steps: + - uses: actions/checkout@v2 + with: + token: ${{ secrets.PUSHABLE_GITHUB_TOKEN }} + - name: Checkout submodules, configure git. + run: | + git -c submodule.third_party/git-hooks.update=none submodule update --init --recursive --depth 0 build/submodules/openal-soft + git config --local user.email "9011267+dotnet-bot@users.noreply.github.com" + git config --local user.name "The Silk.NET Automaton" + - name: Extra prerequisites + run: | + echo running extras + ${{ matrix.env.extras }} + - name: Setup .NET 6.0 and .NET 7.0 + uses: actions/setup-dotnet@v1 + with: + dotnet-version: | + 6.0.201 + 7.0.* + - name: Build OpenAL Soft + run: ${{ matrix.env.nuke_invoke }} openalsoft + env: + PUSHABLE_GITHUB_TOKEN: ${{ secrets.PUSHABLE_GITHUB_TOKEN }} + diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index e18f4e81b8..09c66fc913 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -154,6 +154,7 @@ "FullPushToNuGet", "GLFW", "MoltenVK", + "OpenALSoft", "Pack", "Prerequisites", "PushToNuGet", @@ -197,6 +198,7 @@ "FullPushToNuGet", "GLFW", "MoltenVK", + "OpenALSoft", "Pack", "Prerequisites", "PushToNuGet", diff --git a/build/nuke/Native/OpenALSoft.cs b/build/nuke/Native/OpenALSoft.cs new file mode 100644 index 0000000000..164e7139cd --- /dev/null +++ b/build/nuke/Native/OpenALSoft.cs @@ -0,0 +1,106 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using JetBrains.Annotations; +using Nuke.Common; +using Nuke.Common.CI.GitHubActions; +using Nuke.Common.Git; +using Nuke.Common.IO; +using Nuke.Common.Tooling; +using Nuke.Common.Tools.DotNet; +using Nuke.Common.Tools.Git; +using Octokit; +using Octokit.Internal; +using static Nuke.Common.IO.CompressionTasks; +using static Nuke.Common.IO.FileSystemTasks; +using static Nuke.Common.IO.HttpTasks; +using static Nuke.Common.Tooling.ProcessTasks; +using static Nuke.Common.Tools.DotNet.DotNetTasks; +using static Nuke.Common.Tools.Git.GitTasks; +using static Nuke.Common.Tools.GitHub.GitHubTasks; + +partial class Build { + AbsolutePath OpenALSoftPath => RootDirectory / "build" / "submodules" / "openal-soft"; + + Target OpenALSoft => CommonTarget + ( + x => x.Before(Compile) + .After(Clean) + .Executes + ( + () => + { + var buildDir = OpenALSoftPath / "build"; + var runtimes = RootDirectory / "src" / "Native" / "Silk.NET.OpenAL.Soft.Native" / "runtimes"; + + var prepare = "cmake .. -DCMAKE_BUILD_TYPE=Release -DALSOFT_UTILS=OFF -DALSOFT_NO_CONFIG_UTIL=ON -DALSOFT_EXAMPLES=OFF"; + var build = $"cmake --build . --config Release{JobsArg}"; + + if (OperatingSystem.IsWindows()) + { + foreach (var (platform, rid) in new[] + { + ("Win32", "win-x86"), + ("x64", "win-x64"), + ("ARM64", "win-arm64"), + }) + { + EnsureCleanDirectory(buildDir); + + InheritedShell($"{prepare} -A {platform}", buildDir).AssertZeroExitCode(); + InheritedShell(build, buildDir).AssertZeroExitCode(); + + CopyFile(buildDir / "Release" / "openal.dll", runtimes / rid / "native" / "soft_oal.dll", FileExistsPolicy.Overwrite); + } + } + else if (OperatingSystem.IsLinux()) + { + foreach (var (triple, rid) in new[] + { + ("x86_64-linux-gnu", "linux-x64"), + ("arm-linux-gnueabihf", "linux-arm"), + ("aarch64-linux-gnu", "linux-arm64"), + }) + { + EnsureCleanDirectory(buildDir); + + InheritedShell($"{prepare} {GetCMakeToolchainFlag(triple)}", buildDir).AssertZeroExitCode(); + InheritedShell(build, buildDir).AssertZeroExitCode(); + + InheritedShell($"{triple}-strip libopenal.so", buildDir).AssertZeroExitCode(); + + CopyFile(buildDir / "libopenal.so", runtimes / rid / "native" / "libopenal.so", FileExistsPolicy.Overwrite); + } + } + else if (OperatingSystem.IsMacOS()) + { + foreach (var (arch, rid) in new[] + { + ("x86_64", "osx-x64"), + ("arm64", "osx-arm64"), + }) + { + EnsureCleanDirectory(buildDir); + + InheritedShell($"{prepare} -DCMAKE_OSX_ARCHITECTURES={arch}", buildDir).AssertZeroExitCode(); + InheritedShell(build, buildDir).AssertZeroExitCode(); + + InheritedShell($"strip libopenal.dylib", buildDir).AssertZeroExitCode(); + + CopyFile(buildDir / "libopenal.dylib", runtimes / rid / "native" / "libopenal.dylib", FileExistsPolicy.Overwrite); + } + } + + Git("checkout HEAD build/", OpenALSoftPath); + + PrUpdatedNativeBinary("GLFW"); + } + ) + ); +} diff --git a/src/Native/Silk.NET.OpenAL.Soft.Native/Silk.NET.OpenAL.Soft.Native.csproj b/src/Native/Silk.NET.OpenAL.Soft.Native/Silk.NET.OpenAL.Soft.Native.csproj index 9c47a4aba0..f04889ff0f 100644 --- a/src/Native/Silk.NET.OpenAL.Soft.Native/Silk.NET.OpenAL.Soft.Native.csproj +++ b/src/Native/Silk.NET.OpenAL.Soft.Native/Silk.NET.OpenAL.Soft.Native.csproj @@ -22,8 +22,12 @@ + + + + From d63b98bed2d99225f8013dc44def5e73b33332e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sat, 6 Apr 2024 22:03:15 +0200 Subject: [PATCH 09/20] Native/SDL: Build for linux-arm and linux-arm64. Also clean up the Linux/Windows build script logic. --- .github/workflows/sdl2.yml | 37 +++++- build/nuke/Native/SDL2.cs | 121 ++++++++---------- .../Silk.NET.SDL.Native.csproj | 12 +- 3 files changed, 91 insertions(+), 79 deletions(-) diff --git a/.github/workflows/sdl2.yml b/.github/workflows/sdl2.yml index 2c3321efde..25c3e0af05 100644 --- a/.github/workflows/sdl2.yml +++ b/.github/workflows/sdl2.yml @@ -17,15 +17,15 @@ jobs: fail-fast: false matrix: env: - - os: ubuntu-latest + - os: ubuntu-22.04 name: Linux nuke_invoke: ./build.sh - - os: windows-latest + - os: windows-2022 name: Windows nuke_invoke: ./build.cmd extras: | pwsh build\Install-WindowsSDK.ps1 - - os: macos-latest + - os: macos-14 name: Darwin nuke_invoke: ./build.sh extras: "" @@ -56,8 +56,35 @@ jobs: uses: Beyley/run-as-1804@239b211a2ca687388b6251d6dab22cb90ac0391d with: command: | + tee /etc/apt/sources.list << EOF + deb [arch=amd64,i386] http://archive.ubuntu.com/ubuntu bionic main multiverse restricted universe + deb [arch=amd64,i386] http://archive.ubuntu.com/ubuntu bionic-backports main multiverse restricted universe + deb [arch=amd64,i386] http://archive.ubuntu.com/ubuntu bionic-security main multiverse restricted universe + deb [arch=amd64,i386] http://archive.ubuntu.com/ubuntu bionic-updates main multiverse restricted universe + deb [arch=arm64,armhf] http://ports.ubuntu.com bionic main multiverse restricted universe + deb [arch=arm64,armhf] http://ports.ubuntu.com bionic-backports main multiverse restricted universe + deb [arch=arm64,armhf] http://ports.ubuntu.com bionic-security main multiverse restricted universe + deb [arch=arm64,armhf] http://ports.ubuntu.com bionic-updates main multiverse restricted universe + deb [arch=amd64,i386] http://security.ubuntu.com/ubuntu bionic main multiverse restricted universe + deb [arch=amd64,i386] http://security.ubuntu.com/ubuntu bionic-backports main multiverse restricted universe + deb [arch=amd64,i386] http://security.ubuntu.com/ubuntu bionic-security main multiverse restricted universe + deb [arch=amd64,i386] http://security.ubuntu.com/ubuntu bionic-updates main multiverse restricted universe + EOF + dpkg --add-architecture arm64 + dpkg --add-architecture armhf + dpkg --add-architecture i386 apt update - apt install -y python3 curl wget build-essential git make autoconf gcc-multilib g++-multilib automake libtool pkg-config ninja-build gnome-desktop-testing libasound2-dev libpulse-dev libaudio-dev libjack-dev libsndio-dev libsamplerate0-dev libx11-dev libxext-dev libxrandr-dev libxcursor-dev libxfixes-dev libxi-dev libxss-dev libwayland-dev libxkbcommon-dev libdrm-dev libgbm-dev libgl1-mesa-dev libgles2-mesa-dev libegl1-mesa-dev libdbus-1-dev libibus-1.0-dev libudev-dev fcitx-libs-dev + apt install -y gcc gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf gcc-i686-linux-gnu + apt install -y g++ g++-aarch64-linux-gnu g++-arm-linux-gnueabihf gcc-i686-linux-gnu + apt install -y automake build-essential curl git libtool pkg-config python3 wget + for arch in amd64 arm64 armhf i386; do + apt install -y libasound2-dev:$arch libpulse-dev:$arch libaudio-dev:$arch libjack-dev:$arch + apt install -y libsndio-dev:$arch libsamplerate0-dev:$arch libx11-dev:$arch libxext-dev:$arch + apt install -y libxrandr-dev:$arch libxcursor-dev:$arch libxfixes-dev:$arch libxi-dev:$arch + apt install -y libxss-dev:$arch libwayland-dev:$arch libxkbcommon-dev:$arch libdrm-dev:$arch + apt install -y libgbm-dev:$arch libgl1-mesa-dev:$arch libgles2-mesa-dev:$arch libegl1-mesa-dev:$arch + apt install -y libdbus-1-dev:$arch libibus-1.0-dev:$arch libudev-dev:$arch + done wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh chmod +x ./dotnet-install.sh @@ -82,5 +109,5 @@ jobs: run: ${{ matrix.env.nuke_invoke }} SDL2 env: PUSHABLE_GITHUB_TOKEN: ${{ secrets.PUSHABLE_GITHUB_TOKEN }} - + diff --git a/build/nuke/Native/SDL2.cs b/build/nuke/Native/SDL2.cs index 1f6b50b152..0c1e294fd4 100644 --- a/build/nuke/Native/SDL2.cs +++ b/build/nuke/Native/SDL2.cs @@ -58,100 +58,83 @@ static readonly (string Sdk, string Arch, string Rid, string Args)[] iPhoneConfi { var runtimes = RootDirectory / "src" / "Native" / "Silk.NET.SDL.Native" / "runtimes"; - var x86BuildDir = SDL2Path / "buildx86"; - var x64BuildDir = SDL2Path / "buildx64"; - var ARM64BuildDir = SDL2Path / "buildARM64"; - EnsureCleanDirectory(x86BuildDir); - EnsureCleanDirectory(x64BuildDir); - EnsureCleanDirectory(ARM64BuildDir); - if (OperatingSystem.IsWindows()) { - var prepare = "cmake .. -DBUILD_SHARED_LIBS=ON"; - var build = $"cmake --build . --config Release{JobsArg}"; - - InheritedShell($"{prepare} -A Win32", x86BuildDir).AssertZeroExitCode(); - InheritedShell(build, x86BuildDir).AssertZeroExitCode(); + foreach (var (platform, rid) in new[] + { + ("Win32", "win-x86"), + ("x64", "win-x64"), + ("ARM64", "win-arm64"), + }) + { + var buildDir = SDL2Path / "build"; - InheritedShell($"{prepare} -A X64", x64BuildDir).AssertZeroExitCode(); - InheritedShell(build, x64BuildDir).AssertZeroExitCode(); + EnsureCleanDirectory(buildDir); - InheritedShell($"{prepare} -A arm64", ARM64BuildDir).AssertZeroExitCode(); - InheritedShell(build, ARM64BuildDir).AssertZeroExitCode(); + InheritedShell($"cmake .. -A {platform} -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON", buildDir).AssertZeroExitCode(); + InheritedShell($"cmake --build . --config Release{JobsArg}", buildDir).AssertZeroExitCode(); - CopyFile(x86BuildDir / "Release" / "SDL2.dll", runtimes / "win-x86" / "native" / "SDL2.dll", FileExistsPolicy.Overwrite); - CopyFile(x64BuildDir / "Release" / "SDL2.dll", runtimes / "win-x64" / "native" / "SDL2.dll", FileExistsPolicy.Overwrite); - CopyFile(ARM64BuildDir / "Release" / "SDL2.dll", runtimes / "win-arm64" / "native" / "SDL2.dll", FileExistsPolicy.Overwrite); + CopyFile(buildDir / "Release" / "SDL2.dll", runtimes / rid / "native" / "SDL2.dll", FileExistsPolicy.Overwrite); + } } - - if (OperatingSystem.IsLinux()) + else if (OperatingSystem.IsLinux()) { - if (RuntimeInformation.OSArchitecture == Architecture.Arm64) + foreach (var (triple, rid) in new[] { - InheritedShell("cmake ..", x86BuildDir).AssertZeroExitCode(); - InheritedShell("cmake --build .", x86BuildDir).AssertZeroExitCode(); - - CopyFile(ARM64BuildDir.GlobFiles("libSDL2-2.0.so*").First(), runtimes / "linux-arm64" / "native" / "libSDL2-2.0.so", FileExistsPolicy.Overwrite); - } - else if (RuntimeInformation.OSArchitecture == Architecture.X64) + ("i686-linux-gnu", "linux-x86"), + ("x86_64-linux-gnu", "linux-x64"), + ("arm-linux-gnueabihf", "linux-arm"), + ("aarch64-linux-gnu", "linux-arm64"), + }) { - var envVars32bit = "CFLAGS='-m32 -O2' CXXFLAGS='-m32 -O2' LDFLAGS=-m32"; - var envVars64bit = "CFLAGS=-O2 CXXFLAGS=-O2"; + var buildDir = SDL2Path / "build"; - InheritedShell($"{envVars32bit} ./configure --prefix={x86BuildDir}", SDL2Path).AssertZeroExitCode(); - InheritedShell($"{envVars32bit} make {JobsArg}", SDL2Path).AssertZeroExitCode(); - InheritedShell($"make install", SDL2Path).AssertZeroExitCode(); + EnsureCleanDirectory(buildDir); - InheritedShell($"{envVars64bit} ./configure --prefix={x64BuildDir}", SDL2Path).AssertZeroExitCode(); - InheritedShell($"{envVars64bit} make {JobsArg}", SDL2Path).AssertZeroExitCode(); + InheritedShell($"./configure --prefix={buildDir} --host={triple}", SDL2Path).AssertZeroExitCode(); + InheritedShell($"make {JobsArg}", SDL2Path).AssertZeroExitCode(); InheritedShell($"make install", SDL2Path).AssertZeroExitCode(); - //Strip the libraries - InheritedShell($"strip {x86BuildDir / "lib" / "libSDL2-2.0.so*"}", SDL2Path).AssertZeroExitCode(); - InheritedShell($"strip {x64BuildDir / "lib" / "libSDL2-2.0.so*"}", SDL2Path).AssertZeroExitCode(); + InheritedShell($"{triple}-strip lib/libSDL2-2.0.so*", buildDir).AssertZeroExitCode(); - CopyFile((x86BuildDir / "lib").GlobFiles("libSDL2-2.0.so*").First(), runtimes / "linux-x86" / "native" / "libSDL2-2.0.so", FileExistsPolicy.Overwrite); - CopyFile((x64BuildDir / "lib").GlobFiles("libSDL2-2.0.so*").First(), runtimes / "linux-x64" / "native" / "libSDL2-2.0.so", FileExistsPolicy.Overwrite); - } - else - { - throw new Exception($"Unable to build SDL libs on your architecture ({RuntimeInformation.OSArchitecture})."); + CopyFile((buildDir / "lib").GlobFiles("libSDL2-2.0.so*").First(), runtimes / rid / "native" / "libSDL2-2.0.so", FileExistsPolicy.Overwrite); } } - - if (OperatingSystem.IsMacOS()) + else if (OperatingSystem.IsMacOS()) { // iOS build/hackery ported from https://github.com/Ultz/SDL-Xamarin.iOS - var mainH = File.ReadAllText(SDL2Path / "include" / "SDL_main.h"); - try + + File.WriteAllText( + SDL2Path / "include" / "SDL_main.h", + $"#define SDL_MAIN_HANDLED\n{File.ReadAllText(SDL2Path / "include" / "SDL_main.h")}"); + + EnsureCleanDirectory(SDL2Path / "allbuild"); + + foreach (var (sdk, arch, rid, args) in iPhoneConfigs) { - File.WriteAllText(SDL2Path / "include" / "SDL_main.h", $"#define SDL_MAIN_HANDLED\n{mainH}"); - EnsureCleanDirectory(SDL2Path / "allbuild"); - foreach (var (sdk, arch, rid, args) in iPhoneConfigs) - { - InheritedShell($"xcodebuild -project SDL.xcodeproj {args} -sdk {sdk} -arch {arch} -configuration Release clean build -jobs {Jobs}", SDL2Path / "XCode" / "SDL") - .AssertZeroExitCode(); - var ext = rid is "maccatalyst" or "osx" ? "dylib" : "a"; - var cfg = rid is "maccatalyst" or "osx" ? "Release" : $"Release-{sdk}"; - CopyFile(SDL2Path / "XCode" / "SDL" / "build" / cfg / $"libSDL2.{ext}", SDL2Path / "allbuild" / $"libSDL2.{sdk}.{arch}.{rid}.{ext}"); - } - foreach (var rid in iPhoneConfigs.GroupBy(x => x.Rid)) - { - var ext = rid.Key is "maccatalyst" or "osx" ? "dylib" : "a"; - var @in = string.Join("\" \"", rid.Select(x => SDL2Path / "allbuild" / $"libSDL2.{x.Sdk}.{x.Arch}.{rid.Key}.{ext}")); - var @out = runtimes / rid.Key / "native" / (ext is "dylib" ? "libSDL2-2.0.dylib" : "libSDL2.a"); - EnsureCleanDirectory(Path.GetDirectoryName(@out)); - InheritedShell($"lipo -create -output \"{@out}\" \"{@in}\"").AssertZeroExitCode(); - } + InheritedShell($"xcodebuild -project SDL.xcodeproj {args} -sdk {sdk} -arch {arch} -configuration Release clean build -jobs {Jobs}", SDL2Path / "XCode" / "SDL").AssertZeroExitCode(); + + var ext = rid is "maccatalyst" or "osx" ? "dylib" : "a"; + var cfg = rid is "maccatalyst" or "osx" ? "Release" : $"Release-{sdk}"; + + CopyFile(SDL2Path / "XCode" / "SDL" / "build" / cfg / $"libSDL2.{ext}", SDL2Path / "allbuild" / $"libSDL2.{sdk}.{arch}.{rid}.{ext}"); } - finally + + foreach (var rid in iPhoneConfigs.GroupBy(x => x.Rid)) { - File.WriteAllText(SDL2Path / "include" / "SDL_main.h", mainH); + var ext = rid.Key is "maccatalyst" or "osx" ? "dylib" : "a"; + var @in = string.Join("\" \"", rid.Select(x => SDL2Path / "allbuild" / $"libSDL2.{x.Sdk}.{x.Arch}.{rid.Key}.{ext}")); + var @out = runtimes / rid.Key / "native" / (ext is "dylib" ? "libSDL2-2.0.dylib" : "libSDL2.a"); + + EnsureCleanDirectory(Path.GetDirectoryName(@out)); + InheritedShell($"lipo -create -output \"{@out}\" \"{@in}\"").AssertZeroExitCode(); } } + Git("checkout HEAD include/", SDL2Path); + PrUpdatedNativeBinary("SDL2"); } ) ); -} \ No newline at end of file +} diff --git a/src/Native/Silk.NET.SDL.Native/Silk.NET.SDL.Native.csproj b/src/Native/Silk.NET.SDL.Native/Silk.NET.SDL.Native.csproj index 38b06f2a05..8aea8e6cb9 100644 --- a/src/Native/Silk.NET.SDL.Native/Silk.NET.SDL.Native.csproj +++ b/src/Native/Silk.NET.SDL.Native/Silk.NET.SDL.Native.csproj @@ -24,16 +24,18 @@ + - + + + - - - + - + + From 8d04fb8d1cbddec22fb548654d89a5301f4dece3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 8 Apr 2024 08:56:22 +0200 Subject: [PATCH 10/20] Native/SDL: Build with dynamically-loaded Wayland and X11 support. --- build/nuke/Native/SDL2.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/nuke/Native/SDL2.cs b/build/nuke/Native/SDL2.cs index 0c1e294fd4..4baae91ea5 100644 --- a/build/nuke/Native/SDL2.cs +++ b/build/nuke/Native/SDL2.cs @@ -91,7 +91,7 @@ static readonly (string Sdk, string Arch, string Rid, string Args)[] iPhoneConfi EnsureCleanDirectory(buildDir); - InheritedShell($"./configure --prefix={buildDir} --host={triple}", SDL2Path).AssertZeroExitCode(); + InheritedShell($"./configure --prefix={buildDir} --host={triple} --enable-wayland-shared --enable-x11-shared", SDL2Path).AssertZeroExitCode(); InheritedShell($"make {JobsArg}", SDL2Path).AssertZeroExitCode(); InheritedShell($"make install", SDL2Path).AssertZeroExitCode(); From b5bd0568bf6f4879e01cde6e97fdd9fa66dc0d74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 8 Apr 2024 08:07:05 +0200 Subject: [PATCH 11/20] Native/SDL: Disable assertions when building on Windows/Linux. --- build/nuke/Native/SDL2.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/nuke/Native/SDL2.cs b/build/nuke/Native/SDL2.cs index 4baae91ea5..5bd4c04663 100644 --- a/build/nuke/Native/SDL2.cs +++ b/build/nuke/Native/SDL2.cs @@ -71,7 +71,7 @@ static readonly (string Sdk, string Arch, string Rid, string Args)[] iPhoneConfi EnsureCleanDirectory(buildDir); - InheritedShell($"cmake .. -A {platform} -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON", buildDir).AssertZeroExitCode(); + InheritedShell($"cmake .. -A {platform} -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DSDL_ASSERTIONS=disabled", buildDir).AssertZeroExitCode(); InheritedShell($"cmake --build . --config Release{JobsArg}", buildDir).AssertZeroExitCode(); CopyFile(buildDir / "Release" / "SDL2.dll", runtimes / rid / "native" / "SDL2.dll", FileExistsPolicy.Overwrite); @@ -91,7 +91,7 @@ static readonly (string Sdk, string Arch, string Rid, string Args)[] iPhoneConfi EnsureCleanDirectory(buildDir); - InheritedShell($"./configure --prefix={buildDir} --host={triple} --enable-wayland-shared --enable-x11-shared", SDL2Path).AssertZeroExitCode(); + InheritedShell($"./configure --prefix={buildDir} --host={triple} --enable-assertions=disabled --enable-wayland-shared --enable-x11-shared", SDL2Path).AssertZeroExitCode(); InheritedShell($"make {JobsArg}", SDL2Path).AssertZeroExitCode(); InheritedShell($"make install", SDL2Path).AssertZeroExitCode(); From c203fa92b373a62c9b6ce578541b71e9f916b6bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Tue, 9 Apr 2024 11:43:57 +0200 Subject: [PATCH 12/20] Native/SDL: Don't build static libraries on Linux. --- build/nuke/Native/SDL2.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/nuke/Native/SDL2.cs b/build/nuke/Native/SDL2.cs index 5bd4c04663..3d170e8687 100644 --- a/build/nuke/Native/SDL2.cs +++ b/build/nuke/Native/SDL2.cs @@ -91,7 +91,7 @@ static readonly (string Sdk, string Arch, string Rid, string Args)[] iPhoneConfi EnsureCleanDirectory(buildDir); - InheritedShell($"./configure --prefix={buildDir} --host={triple} --enable-assertions=disabled --enable-wayland-shared --enable-x11-shared", SDL2Path).AssertZeroExitCode(); + InheritedShell($"./configure --prefix={buildDir} --disable-static --host={triple} --enable-assertions=disabled --enable-wayland-shared --enable-x11-shared", SDL2Path).AssertZeroExitCode(); InheritedShell($"make {JobsArg}", SDL2Path).AssertZeroExitCode(); InheritedShell($"make install", SDL2Path).AssertZeroExitCode(); From 04ac4f951ea8b2f0761474191ce344527db0c19a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 7 Apr 2024 01:02:57 +0200 Subject: [PATCH 13/20] Native/SDL: Strip macOS binaries after build. --- build/nuke/Native/SDL2.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/build/nuke/Native/SDL2.cs b/build/nuke/Native/SDL2.cs index 3d170e8687..e32599d331 100644 --- a/build/nuke/Native/SDL2.cs +++ b/build/nuke/Native/SDL2.cs @@ -128,6 +128,7 @@ static readonly (string Sdk, string Arch, string Rid, string Args)[] iPhoneConfi EnsureCleanDirectory(Path.GetDirectoryName(@out)); InheritedShell($"lipo -create -output \"{@out}\" \"{@in}\"").AssertZeroExitCode(); + InheritedShell($"strip \"{@out}\"").AssertZeroExitCode(); } } From a444bf14ec5b5a71a44f9c8ade4d44f06902493b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Tue, 9 Apr 2024 12:50:34 +0200 Subject: [PATCH 14/20] Native/SwiftShader: Build for linux-arm, linux-arm64, osx-arm64, win-arm64, and win-x86. Also clean up the build script. --- .github/workflows/swiftshader.yml | 32 ++++++-- build/nuke/Native/SwiftShader.cs | 120 +++++++++++++++--------------- 2 files changed, 85 insertions(+), 67 deletions(-) diff --git a/.github/workflows/swiftshader.yml b/.github/workflows/swiftshader.yml index 2f0a416105..625308daca 100644 --- a/.github/workflows/swiftshader.yml +++ b/.github/workflows/swiftshader.yml @@ -17,17 +17,37 @@ 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 libx11-xcb-dev - - os: windows-latest + sudo tee /etc/apt/sources.list << EOF + deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy main multiverse restricted universe + deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy-backports main multiverse restricted universe + deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy-security main multiverse restricted universe + deb [arch=amd64] 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] http://security.ubuntu.com/ubuntu jammy main multiverse restricted universe + deb [arch=amd64] http://security.ubuntu.com/ubuntu jammy-backports main multiverse restricted universe + deb [arch=amd64] http://security.ubuntu.com/ubuntu jammy-security main multiverse restricted universe + deb [arch=amd64] http://security.ubuntu.com/ubuntu jammy-updates main multiverse restricted universe + EOF + sudo dpkg --add-architecture arm64 + sudo dpkg --add-architecture armhf + sudo apt update + sudo apt install -y gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf + sudo apt install -y g++-aarch64-linux-gnu g++-arm-linux-gnueabihf + for arch in amd64 arm64 armhf; do + sudo apt install -y libx11-xcb-dev:$arch + done + - os: windows-2022 name: Windows nuke_invoke: ./build.cmd extras: "" - - os: macos-latest + - os: macos-14 name: Darwin nuke_invoke: ./build.sh extras: "" @@ -41,7 +61,7 @@ jobs: run: | git -c submodule.third_party/git-hooks.update=none submodule update --init --recursive --depth 0 build/submodules/SwiftShader git config --local user.email "9011267+dotnet-bot@users.noreply.github.com" - git config --local user.name "The Silk.NET Automaton" + git config --local user.name "The Silk.NET Automaton" - name: Extra prerequisites run: | echo running extras diff --git a/build/nuke/Native/SwiftShader.cs b/build/nuke/Native/SwiftShader.cs index 2874904ce6..1ea3b91345 100644 --- a/build/nuke/Native/SwiftShader.cs +++ b/build/nuke/Native/SwiftShader.cs @@ -26,7 +26,7 @@ using static Nuke.Common.Tools.GitHub.GitHubTasks; partial class Build { - AbsolutePath SwiftShaderBuildPath => RootDirectory / "build" / "submodules" / "SwiftShader" / "build"; + AbsolutePath SwiftShaderPath => RootDirectory / "build" / "submodules" / "SwiftShader"; Target SwiftShader => CommonTarget ( @@ -36,78 +36,76 @@ partial class Build { ( () => { - var sysName = OperatingSystem.IsLinux() ? "Linux" : - OperatingSystem.IsWindows() ? "Windows" : - OperatingSystem.IsMacOS() ? "Darwin" : throw new PlatformNotSupportedException(); - DeleteDirectory(SwiftShaderBuildPath); - Git("checkout HEAD build/", SwiftShaderBuildPath / ".."); - StartProcess("cmake", ".. -DCMAKE_BUILD_TYPE=Release", SwiftShaderBuildPath) - .AssertZeroExitCode(); - StartProcess("cmake", $"--build .{JobsArg} --config Release", SwiftShaderBuildPath) - .AssertWaitForExit(); // might fail... as long as the output exists we're happy - var fname = sysName switch - { - "Linux" => "libvk_swiftshader.so", - "Windows" => "vk_swiftshader.dll", - "Darwin" => "libvk_swiftshader.dylib", - _ => throw new("what") - }; - + var buildDir = SwiftShaderPath / "build"; var runtimes = RootDirectory / "src" / "Native" / "Silk.NET.Vulkan.SwiftShader.Native" / "runtimes"; - var outputPath = SwiftShaderBuildPath / sysName; - const string icd = "vk_swiftshader_icd.json"; + + var prepare = "cmake .. -DSWIFTSHADER_WARNINGS_AS_ERRORS=FALSE"; + var build = $"cmake --build . --config Release{JobsArg}"; + + // Work around SwiftShader's silly Git hook installation logic that fails as a submodule. + File.WriteAllText( + SwiftShaderPath / "CMakeLists.txt", + File.ReadAllText(SwiftShaderPath / "CMakeLists.txt") + .Replace("if(NOT EXISTS ${CMAKE_SOURCE_DIR}/.git/hooks/commit-msg)", "if(FALSE)")); + if (OperatingSystem.IsWindows()) { - CopyFile - ( - outputPath / fname, runtimes / "win-x64" / "native" / fname, - FileExistsPolicy.Overwrite - ); // we'll use WOW64 - CopyFile - ( - outputPath / fname, runtimes / "win-x86" / "native" / fname, - FileExistsPolicy.Overwrite - ); - CopyFile - ( - outputPath / icd, runtimes / "win-x64" / "native" / icd, - FileExistsPolicy.Overwrite - ); - CopyFile - ( - outputPath / icd, runtimes / "win-x86" / "native" / icd, - FileExistsPolicy.Overwrite - ); + foreach (var (platform, rid) in new[] + { + ("Win32", "win-x86"), + ("x64", "win-x64"), + ("ARM64", "win-arm64"), + }) + { + EnsureCleanDirectory(buildDir); + + InheritedShell($"{prepare} -A {platform}", buildDir).AssertZeroExitCode(); + InheritedShell(build, buildDir).AssertZeroExitCode(); + + CopyFile(buildDir / "Windows" / "vk_swiftshader.dll", runtimes / rid / "native" / "vk_swiftshader.dll", FileExistsPolicy.Overwrite); + CopyFile(buildDir / "Windows" / "vk_swiftshader_icd.json", runtimes / rid / "native" / "vk_swiftshader_icd.json", FileExistsPolicy.Overwrite); + } } else if (OperatingSystem.IsLinux()) { - CopyFile - ( - outputPath / fname, runtimes / "linux-x64" / "native" / fname, - FileExistsPolicy.Overwrite - ); - CopyFile - ( - outputPath / icd, runtimes / "linux-x64" / "native" / icd, - FileExistsPolicy.Overwrite - ); + foreach (var (triple, rid) in new[] + { + ("x86_64-linux-gnu", "linux-x64"), + ("arm-linux-gnueabihf", "linux-arm"), + ("aarch64-linux-gnu", "linux-arm64"), + }) + { + EnsureCleanDirectory(buildDir); + + InheritedShell($"{prepare} {GetCMakeToolchainFlag(triple)}", buildDir).AssertZeroExitCode(); + InheritedShell(build, buildDir).AssertZeroExitCode(); + + CopyFile(buildDir / "Linux" / "libvk_swiftshader.so", runtimes / rid / "native" / "libvk_swiftshader.so", FileExistsPolicy.Overwrite); + CopyFile(buildDir / "Linux" / "vk_swiftshader_icd.json", runtimes / rid / "native" / "vk_swiftshader_icd.json", FileExistsPolicy.Overwrite); + } } else if (OperatingSystem.IsMacOS()) { - CopyFile - ( - outputPath / fname, runtimes / "osx-x64" / "native" / fname, - FileExistsPolicy.Overwrite - ); - CopyFile - ( - outputPath / icd, runtimes / "osx-x64" / "native" / icd, - FileExistsPolicy.Overwrite - ); + foreach (var (arch, rid) in new[] + { + ("x86_64", "osx-x64"), + ("arm64", "osx-arm64"), + }) + { + EnsureCleanDirectory(buildDir); + + InheritedShell($"{prepare} -DCMAKE_OSX_ARCHITECTURES={arch}", buildDir).AssertZeroExitCode(); + InheritedShell(build, buildDir).AssertZeroExitCode(); + + CopyFile(buildDir / "Darwin" / "libvk_swiftshader.dylib", runtimes / rid / "native" / "libvk_swiftshader.dylib", FileExistsPolicy.Overwrite); + CopyFile(buildDir / "Darwin" / "vk_swiftshader_icd.json", runtimes / rid / "native" / "vk_swiftshader_icd.json", FileExistsPolicy.Overwrite); + } } + Git("checkout HEAD CMakeLists.txt build/", SwiftShaderPath); + PrUpdatedNativeBinary("SwiftShader"); } ) ); -} \ No newline at end of file +} From 99fc3ff19dd9dfbc7e18f2ac5fba4b67ba51cd36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Tue, 9 Apr 2024 12:58:03 +0200 Subject: [PATCH 15/20] Native/SwiftShader: Don't build tests. --- build/nuke/Native/SwiftShader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/nuke/Native/SwiftShader.cs b/build/nuke/Native/SwiftShader.cs index 1ea3b91345..1adf1f57bb 100644 --- a/build/nuke/Native/SwiftShader.cs +++ b/build/nuke/Native/SwiftShader.cs @@ -39,7 +39,7 @@ partial class Build { var buildDir = SwiftShaderPath / "build"; var runtimes = RootDirectory / "src" / "Native" / "Silk.NET.Vulkan.SwiftShader.Native" / "runtimes"; - var prepare = "cmake .. -DSWIFTSHADER_WARNINGS_AS_ERRORS=FALSE"; + var prepare = "cmake .. -DSWIFTSHADER_WARNINGS_AS_ERRORS=FALSE -DSWIFTSHADER_BUILD_TESTS=FALSE"; var build = $"cmake --build . --config Release{JobsArg}"; // Work around SwiftShader's silly Git hook installation logic that fails as a submodule. From 15d84c8a3bfe4e896dff00b2dff1500774f29f88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Tue, 9 Apr 2024 13:01:23 +0200 Subject: [PATCH 16/20] Native/SwiftShader: Strip Linux/macOS binaries after build. --- build/nuke/Native/SwiftShader.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build/nuke/Native/SwiftShader.cs b/build/nuke/Native/SwiftShader.cs index 1adf1f57bb..0ff770777d 100644 --- a/build/nuke/Native/SwiftShader.cs +++ b/build/nuke/Native/SwiftShader.cs @@ -80,6 +80,8 @@ partial class Build { InheritedShell($"{prepare} {GetCMakeToolchainFlag(triple)}", buildDir).AssertZeroExitCode(); InheritedShell(build, buildDir).AssertZeroExitCode(); + InheritedShell($"{triple}-strip Linux/libvk_swiftshader.so", buildDir).AssertZeroExitCode(); + CopyFile(buildDir / "Linux" / "libvk_swiftshader.so", runtimes / rid / "native" / "libvk_swiftshader.so", FileExistsPolicy.Overwrite); CopyFile(buildDir / "Linux" / "vk_swiftshader_icd.json", runtimes / rid / "native" / "vk_swiftshader_icd.json", FileExistsPolicy.Overwrite); } @@ -97,6 +99,8 @@ partial class Build { InheritedShell($"{prepare} -DCMAKE_OSX_ARCHITECTURES={arch}", buildDir).AssertZeroExitCode(); InheritedShell(build, buildDir).AssertZeroExitCode(); + InheritedShell($"-strip Darwin/libvk_swiftshader.dylib", buildDir).AssertZeroExitCode(); + CopyFile(buildDir / "Darwin" / "libvk_swiftshader.dylib", runtimes / rid / "native" / "libvk_swiftshader.dylib", FileExistsPolicy.Overwrite); CopyFile(buildDir / "Darwin" / "vk_swiftshader_icd.json", runtimes / rid / "native" / "vk_swiftshader_icd.json", FileExistsPolicy.Overwrite); } From f98f3f41dd73cd924f46793f0f0bff816e6f935d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Tue, 9 Apr 2024 12:15:44 +0200 Subject: [PATCH 17/20] Native/Vulkan Loader: Build for linux-arm64, osx-arm64, and win-x86. Also clean up the build script. --- .github/workflows/vulkan-loader.yml | 32 ++++-- build/nuke/Native/VulkanLoader.cs | 98 ++++++++++++------- .../Silk.NET.Vulkan.Loader.Native.csproj | 2 + 3 files changed, 92 insertions(+), 40 deletions(-) diff --git a/.github/workflows/vulkan-loader.yml b/.github/workflows/vulkan-loader.yml index 8c48f00d2a..d1ea6cd4f4 100644 --- a/.github/workflows/vulkan-loader.yml +++ b/.github/workflows/vulkan-loader.yml @@ -17,17 +17,37 @@ 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 build-essential libx11-xcb-dev libxkbcommon-dev libwayland-dev libxrandr-dev - - os: windows-latest + sudo tee /etc/apt/sources.list << EOF + deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy main multiverse restricted universe + deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy-backports main multiverse restricted universe + deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy-security main multiverse restricted universe + deb [arch=amd64] 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] http://security.ubuntu.com/ubuntu jammy main multiverse restricted universe + deb [arch=amd64] http://security.ubuntu.com/ubuntu jammy-backports main multiverse restricted universe + deb [arch=amd64] http://security.ubuntu.com/ubuntu jammy-security main multiverse restricted universe + deb [arch=amd64] http://security.ubuntu.com/ubuntu jammy-updates main multiverse restricted universe + EOF + sudo dpkg --add-architecture arm64 + sudo dpkg --add-architecture armhf + sudo apt update + sudo apt install -y gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf + for arch in amd64 arm64 armhf; do + sudo apt install -y pkg-config:$arch + sudo apt install -y libx11-xcb-dev:$arch libxkbcommon-dev:$arch libwayland-dev:$arch libxrandr-dev:$arch + done + - os: windows-2022 name: Windows nuke_invoke: ./build.cmd extras: "" - - os: macos-latest + - os: macos-14 name: Darwin nuke_invoke: ./build.sh extras: "" @@ -41,7 +61,7 @@ jobs: run: | git -c submodule.third_party/git-hooks.update=none submodule update --init --recursive --depth 0 build/submodules/Vulkan-Loader git config --local user.email "9011267+dotnet-bot@users.noreply.github.com" - git config --local user.name "The Silk.NET Automaton" + git config --local user.name "The Silk.NET Automaton" - name: Extra prerequisites run: | echo running extras diff --git a/build/nuke/Native/VulkanLoader.cs b/build/nuke/Native/VulkanLoader.cs index eb589de50d..4573843b7b 100644 --- a/build/nuke/Native/VulkanLoader.cs +++ b/build/nuke/Native/VulkanLoader.cs @@ -31,39 +31,69 @@ partial class Build { Target VulkanLoader => CommonTarget ( x => x.Before(Compile) - .After(Clean) - .Executes - ( - () => - { - var @out = VulkanLoaderPath / "build"; - EnsureCleanDirectory(@out); - var abi = OperatingSystem.IsWindows() ? " -DCMAKE_GENERATOR_PLATFORM=Win32" : string.Empty; - InheritedShell - ( - $"cmake -S. -Bbuild -DUPDATE_DEPS=On -DCMAKE_BUILD_TYPE=Release{abi}", - VulkanLoaderPath - ) - .AssertZeroExitCode(); - InheritedShell($"cmake --build build --config Release{JobsArg}", VulkanLoaderPath) - .AssertZeroExitCode(); - var runtimes = RootDirectory / "src" / "Native" / "Silk.NET.Vulkan.Loader.Native" / "runtimes"; - if (OperatingSystem.IsWindows()) - { - CopyAll(@out.GlobFiles("loader/Release/vulkan-1.dll"), runtimes / "win-x64" / "native"); - CopyAll(@out.GlobFiles("loader/Release/vulkan-1.dll"), runtimes / "win-x86" / "native"); - } - else - { - CopyAll - ( - @out.GlobFiles("loader/libvulkan.so", "loader/libvulkan.dylib"), - runtimes / (OperatingSystem.IsMacOS() ? "osx-x64" : "linux-x64") / "native" - ); - } + .After(Clean) + .Executes + ( + () => + { + var buildDir = VulkanLoaderPath / "build"; + var runtimes = RootDirectory / "src" / "Native" / "Silk.NET.Vulkan.Loader.Native" / "runtimes"; - PrUpdatedNativeBinary("Vulkan Loader"); - } - ) + var prepare = "cmake .. -DCMAKE_BUILD_TYPE=Release -DUPDATE_DEPS=ON"; + var build = $"cmake --build . --config Release{JobsArg}"; + + if (OperatingSystem.IsWindows()) + { + foreach (var (platform, rid) in new[] + { + ("Win32", "win-x86"), + ("x64", "win-x64"), + }) + { + EnsureCleanDirectory(buildDir); + + InheritedShell($"{prepare} -A {platform}", buildDir).AssertZeroExitCode(); + InheritedShell(build, buildDir).AssertZeroExitCode(); + + CopyAll((buildDir / "loader" / "Release").GlobFiles("vulkan-1.dll"), runtimes / rid / "native"); + } + } + else if (OperatingSystem.IsLinux()) + { + + foreach (var (triple, rid) in new[] + { + ("x86_64-linux-gnu", "linux-x64"), + ("aarch64-linux-gnu", "linux-arm64"), + }) + { + EnsureCleanDirectory(buildDir); + + InheritedShell($"{prepare} {GetCMakeToolchainFlag(triple)}", buildDir).AssertZeroExitCode(); + InheritedShell(build, buildDir).AssertZeroExitCode(); + + CopyAll((buildDir / "loader").GlobFiles("libvulkan.so"), runtimes / rid / "native"); + } + } + else if (OperatingSystem.IsMacOS()) + { + foreach (var (arch, rid) in new[] + { + ("x86_64", "osx-x64"), + ("arm64", "osx-arm64"), + }) + { + EnsureCleanDirectory(buildDir); + + InheritedShell($"{prepare} -DCMAKE_OSX_ARCHITECTURES={arch}", buildDir).AssertZeroExitCode(); + InheritedShell(build, buildDir).AssertZeroExitCode(); + + CopyAll((buildDir / "loader").GlobFiles("libvulkan.dylib"), runtimes / rid / "native"); + } + } + + PrUpdatedNativeBinary("Vulkan Loader"); + } + ) ); -} \ No newline at end of file +} diff --git a/src/Native/Silk.NET.Vulkan.Loader.Native/Silk.NET.Vulkan.Loader.Native.csproj b/src/Native/Silk.NET.Vulkan.Loader.Native/Silk.NET.Vulkan.Loader.Native.csproj index c65e2e3cbd..4ab9b2f9bd 100644 --- a/src/Native/Silk.NET.Vulkan.Loader.Native/Silk.NET.Vulkan.Loader.Native.csproj +++ b/src/Native/Silk.NET.Vulkan.Loader.Native/Silk.NET.Vulkan.Loader.Native.csproj @@ -18,7 +18,9 @@ + + From 94c7454ac1e51ce2531fceea51dfc95edc1f24e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Tue, 9 Apr 2024 12:17:02 +0200 Subject: [PATCH 18/20] Native/Vulkan Loader: Strip Linux/macOS binaries after build. --- build/nuke/Native/VulkanLoader.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build/nuke/Native/VulkanLoader.cs b/build/nuke/Native/VulkanLoader.cs index 4573843b7b..b91286bcc5 100644 --- a/build/nuke/Native/VulkanLoader.cs +++ b/build/nuke/Native/VulkanLoader.cs @@ -72,6 +72,8 @@ partial class Build { InheritedShell($"{prepare} {GetCMakeToolchainFlag(triple)}", buildDir).AssertZeroExitCode(); InheritedShell(build, buildDir).AssertZeroExitCode(); + InheritedShell($"{triple}-strip loader/libvulkan.so", buildDir).AssertZeroExitCode(); + CopyAll((buildDir / "loader").GlobFiles("libvulkan.so"), runtimes / rid / "native"); } } @@ -88,6 +90,8 @@ partial class Build { InheritedShell($"{prepare} -DCMAKE_OSX_ARCHITECTURES={arch}", buildDir).AssertZeroExitCode(); InheritedShell(build, buildDir).AssertZeroExitCode(); + InheritedShell($"strip loader/libvulkan.dylib", buildDir).AssertZeroExitCode(); + CopyAll((buildDir / "loader").GlobFiles("libvulkan.dylib"), runtimes / rid / "native"); } } From 0446db0191d672aabc2ef881f3a9ea188538e583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 7 Apr 2024 03:51:14 +0200 Subject: [PATCH 19/20] Native/wgpu-native: Build for linux-arm and linux-arm64. Also clean up the build script to be table-driven. --- .github/workflows/wgpu.yml | 27 +++++-- build/nuke/Native/Wgpu.cs | 72 ++++++++++++------- .../Silk.NET.WebGPU.Native.WGPU.csproj | 10 +-- 3 files changed, 75 insertions(+), 34 deletions(-) diff --git a/.github/workflows/wgpu.yml b/.github/workflows/wgpu.yml index 82188b4f46..4d018c2891 100644 --- a/.github/workflows/wgpu.yml +++ b/.github/workflows/wgpu.yml @@ -17,17 +17,34 @@ 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 + - 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 @@ - + + - + - - + + + From 32c0d3677655ea01155a03b258d647e225fd2950 Mon Sep 17 00:00:00 2001 From: "The Silk.NET Automaton" <9011267+dotnet-bot@users.noreply.github.com> Date: Sat, 13 Apr 2024 17:26:49 +0000 Subject: [PATCH 20/20] New binaries for SPIRV-Cross on Linux 6.5.0-1017-azure #17~22.04.1-Ubuntu SMP Sat Mar 9 04:50:38 UTC 2024 --- .../runtimes/win-arm64/native/spirv-cross.dll | Bin 2175488 -> 2175488 bytes .../runtimes/win-x64/native/spirv-cross.dll | Bin 2309632 -> 2309632 bytes .../runtimes/win-x86/native/spirv-cross.dll | Bin 2734080 -> 2734080 bytes 3 files changed, 0 insertions(+), 0 deletions(-) diff --git a/src/Native/Silk.NET.SPIRV.Cross.Native/runtimes/win-arm64/native/spirv-cross.dll b/src/Native/Silk.NET.SPIRV.Cross.Native/runtimes/win-arm64/native/spirv-cross.dll index 71cf2cd2e1b5d918ccf4051fc44c638f74070a63..3d848eef19def8bc7ff70497642cca80bab81839 100755 GIT binary patch delta 117 zcmWN=$qj-~06@VYA}WHoq2Njh7D)2RnIml5?Qps5^QcELOxyfA~@|4#|+r9s1X)IR& delta 117 zcmWN=$qj-~06@VYiVLW?p(vn~U^8@M^2zhvX~q-nScpzC;roul{}AG_D|;l8iNrFM tnItlog)C(ysbsR2jcg^Co$TcxM>$C$XSqlzSGh?gwKQ^<$A|Xy`~g**EGqy2 diff --git a/src/Native/Silk.NET.SPIRV.Cross.Native/runtimes/win-x64/native/spirv-cross.dll b/src/Native/Silk.NET.SPIRV.Cross.Native/runtimes/win-x64/native/spirv-cross.dll index 17b8679004697edb2e20f1eae49960a72e27d455..bc40dd691e51f43754d9d1499a8cfda37f8f3fa2 100755 GIT binary patch delta 123 zcmWN=$qj-~06@VYDsC+92=3NlX(pe%yqgD`@k&h=-~lF?@P9|4{|WK0tr{effy6SD wk&GpgiA-fCb6H3#ndDN)QdY8-jcjEndnx50mDF;Slbq!uSGmdk%j5Oz0Lj8HY5)KL delta 123 zcmWN=$qj-~06@X8skk758}3Ui!#3!KHxNHv$r1Fx3EyWF{vRQ}eeydJNkw9* zN=@q0kfyYxEs1obD?RDUK!!4su}owtsbn&fx#Y5trL1Hv8!2QfJK4)Yj&hQ-TwYwu F_YV~KHedh% delta 141 zcmWN=*9pQ<06