Skip to content

Add native GLFW binary builds #792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jan 28, 2022
Merged
43 changes: 43 additions & 0 deletions .github/workflows/GLFW.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
62 changes: 61 additions & 1 deletion build/nuke/Build.Native.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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");
}
}
)
);

}
35 changes: 35 additions & 0 deletions build/nuke/Build.Support.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand All @@ -38,6 +43,36 @@ static int IndexOfOrThrow(string x, char y)
return idx;
}

Dictionary<string, string> CreateEnvVarDictionary()
=> Environment.GetEnvironmentVariables()
.Cast<DictionaryEntry>()
.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<DictionaryEntry>()
.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<AbsolutePath> 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";

Expand Down
1 change: 1 addition & 0 deletions build/submodules/GLFW
Submodule GLFW added at 7d5a16