diff --git a/.github/workflows/GLFW.yml b/.github/workflows/GLFW.yml new file mode 100644 index 0000000000..613f2521f0 --- /dev/null +++ b/.github/workflows/GLFW.yml @@ -0,0 +1,43 @@ +name: GLFW +on: + push: + branches-ignore: + - "ci/*" + - "develop/*" + - "main" +jobs: + Build: + strategy: + fail-fast: false + matrix: + env: + - os: ubuntu-latest + name: Linux + nuke_invoke: ./build.sh + extras: | + sudo apt-get install -y xorg-dev + - os: windows-latest + name: Windows + nuke_invoke: ./build.cmd + extras: "" + - os: macos-latest + name: Darwin + nuke_invoke: ./build.sh + extras: "" + name: ${{ matrix.env.name }} Build + runs-on: ${{ matrix.env.os }} + steps: + - uses: actions/checkout@v2 + - name: Checkout submodules + run: | + git -c submodule.third_party/git-hooks.update=none submodule update --init --recursive + - name: Extra prerequisites + run: | + echo running extras + ${{ matrix.env.extras }} + - name: Setup .NET 6.0 + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 6.0.100 + - name: Build GLFW + run: ${{ matrix.env.nuke_invoke }} glfw diff --git a/.gitmodules b/.gitmodules index a916c433be..8cc8960770 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "build/submodules/Vulkan-Headers"] path = build/submodules/Vulkan-Headers url = https://github.com/KhronosGroup/Vulkan-Headers +[submodule "build/submodules/GLFW"] + path = build/submodules/GLFW + url = https://github.com/glfw/glfw.git diff --git a/build/nuke/Build.Native.cs b/build/nuke/Build.Native.cs index 64682d5f3a..50587effba 100644 --- a/build/nuke/Build.Native.cs +++ b/build/nuke/Build.Native.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System; @@ -99,4 +99,64 @@ string AndroidHome } ) ); + + AbsolutePath GLFWPath => RootDirectory / "build" / "submodules" / "GLFW"; + Target GLFW => CommonTarget + ( + x => x.Before(Compile) + .Executes + ( + () => + { + var @out = GLFWPath / "build"; + var prepare = "cmake -S. -B build -D BUILD_SHARED_LIBS=ON"; + var build = "cmake --build build --config Release"; + EnsureCleanDirectory(@out); + 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); + + InheritedShell($"{prepare} -A Win32", GLFWPath) + .AssertZeroExitCode(); + InheritedShell(build, GLFWPath) + .AssertZeroExitCode(); + + CopyAll(@out.GlobFiles("src/Release/glfw3.dll"), runtimes / "win-x86" / "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"); + } + 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); + + InheritedShell($"{prepare} -DCMAKE_OSX_ARCHITECTURES=arm64", GLFWPath) + .AssertZeroExitCode(); + InheritedShell(build, GLFWPath) + .AssertZeroExitCode(); + + CopyAll(@out.GlobFiles("src/libglfw.3.dylib"), runtimes / "osx-arm64" / "native"); + } + } + ) + ); + } diff --git a/build/nuke/Build.Support.cs b/build/nuke/Build.Support.cs index b4b58af330..f90458c91b 100644 --- a/build/nuke/Build.Support.cs +++ b/build/nuke/Build.Support.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; @@ -14,8 +15,12 @@ using Nuke.Common.CI.GitHubActions; using Nuke.Common.IO; using Nuke.Common.ProjectModel; +using Nuke.Common.Tooling; +using Nuke.Common.Utilities; using Octokit; using Octokit.Internal; +using static Nuke.Common.IO.FileSystemTasks; +using static Nuke.Common.Tooling.ProcessTasks; partial class Build { @@ -38,6 +43,36 @@ static int IndexOfOrThrow(string x, char y) return idx; } + Dictionary CreateEnvVarDictionary() + => Environment.GetEnvironmentVariables() + .Cast() + .ToDictionary(x => (string) x.Key, x => (string) x.Value); + + IProcess InheritedShell(string cmd, [CanBeNull] string workDir = null) + => OperatingSystem.IsWindows() + ? StartProcess("powershell", $"-Command {cmd.DoubleQuote()}", workDir, CreateEnvVarDictionary()) + : StartProcess("bash", $"-c {cmd.DoubleQuote()}", workDir, CreateEnvVarDictionary()); + + void AddToPath(string dir) + { + var pathVar = Environment.GetEnvironmentVariables() + .Cast() + .First(x => ((string) x.Key).Equals("PATH", StringComparison.OrdinalIgnoreCase)); + Environment.SetEnvironmentVariable + ( + (string) pathVar.Key, + (string) pathVar.Value + (OperatingSystem.IsWindows() ? $";{dir}" : $":{dir}") + ); + } + + static void CopyAll(IEnumerable paths, AbsolutePath dir) + { + foreach (var path in paths) + { + CopyFile(path, dir / Path.GetFileName(path), FileExistsPolicy.Overwrite); + } + } + [Nuke.Common.Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] readonly string Configuration = IsLocalBuild ? "Debug" : "Release"; diff --git a/build/submodules/GLFW b/build/submodules/GLFW new file mode 160000 index 0000000000..7d5a16ce71 --- /dev/null +++ b/build/submodules/GLFW @@ -0,0 +1 @@ +Subproject commit 7d5a16ce714f0b5f4efa3262de22e4d948851525