Skip to content

Commit c31124e

Browse files
roeyskoePerksey
andauthored
Add native GLFW binary builds (#792)
* Start working with native builds * gh actions now? * now? * Actually get the submodules... * It now actually kinda does something * Save artifacts for testing * Not the prettiest, but may actually work * Maybe now I actually get the artifacts * Typo * What about now * Now lets put files in the right place * Maybe this is a bit nicer now * Apply suggestions from code review Co-authored-by: Dylan Perks <[email protected]> * Lock glfw to latest release Co-authored-by: Dylan Perks <[email protected]>
1 parent cbd8d5c commit c31124e

File tree

5 files changed

+143
-1
lines changed

5 files changed

+143
-1
lines changed

.github/workflows/GLFW.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: GLFW
2+
on:
3+
push:
4+
branches-ignore:
5+
- "ci/*"
6+
- "develop/*"
7+
- "main"
8+
jobs:
9+
Build:
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
env:
14+
- os: ubuntu-latest
15+
name: Linux
16+
nuke_invoke: ./build.sh
17+
extras: |
18+
sudo apt-get install -y xorg-dev
19+
- os: windows-latest
20+
name: Windows
21+
nuke_invoke: ./build.cmd
22+
extras: ""
23+
- os: macos-latest
24+
name: Darwin
25+
nuke_invoke: ./build.sh
26+
extras: ""
27+
name: ${{ matrix.env.name }} Build
28+
runs-on: ${{ matrix.env.os }}
29+
steps:
30+
- uses: actions/checkout@v2
31+
- name: Checkout submodules
32+
run: |
33+
git -c submodule.third_party/git-hooks.update=none submodule update --init --recursive
34+
- name: Extra prerequisites
35+
run: |
36+
echo running extras
37+
${{ matrix.env.extras }}
38+
- name: Setup .NET 6.0
39+
uses: actions/setup-dotnet@v1
40+
with:
41+
dotnet-version: 6.0.100
42+
- name: Build GLFW
43+
run: ${{ matrix.env.nuke_invoke }} glfw

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "build/submodules/Vulkan-Headers"]
55
path = build/submodules/Vulkan-Headers
66
url = https://github.com/KhronosGroup/Vulkan-Headers
7+
[submodule "build/submodules/GLFW"]
8+
path = build/submodules/GLFW
9+
url = https://github.com/glfw/glfw.git

build/nuke/Build.Native.cs

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
@@ -99,4 +99,64 @@ string AndroidHome
9999
}
100100
)
101101
);
102+
103+
AbsolutePath GLFWPath => RootDirectory / "build" / "submodules" / "GLFW";
104+
Target GLFW => CommonTarget
105+
(
106+
x => x.Before(Compile)
107+
.Executes
108+
(
109+
() =>
110+
{
111+
var @out = GLFWPath / "build";
112+
var prepare = "cmake -S. -B build -D BUILD_SHARED_LIBS=ON";
113+
var build = "cmake --build build --config Release";
114+
EnsureCleanDirectory(@out);
115+
var runtimes = RootDirectory / "src" / "Native" / "Silk.NET.GLFW.Native" / "runtimes";
116+
if (OperatingSystem.IsWindows())
117+
{
118+
InheritedShell($"{prepare} -A X64", GLFWPath)
119+
.AssertZeroExitCode();
120+
InheritedShell(build, GLFWPath)
121+
.AssertZeroExitCode();
122+
CopyAll(@out.GlobFiles("src/Release/glfw3.dll"), runtimes / "win-x64" / "native");
123+
124+
EnsureCleanDirectory(@out);
125+
126+
InheritedShell($"{prepare} -A Win32", GLFWPath)
127+
.AssertZeroExitCode();
128+
InheritedShell(build, GLFWPath)
129+
.AssertZeroExitCode();
130+
131+
CopyAll(@out.GlobFiles("src/Release/glfw3.dll"), runtimes / "win-x86" / "native");
132+
}
133+
else if (OperatingSystem.IsLinux())
134+
{
135+
InheritedShell($"{prepare} -DCMAKE_SYSTEM_PROCESSOR=x86_64", GLFWPath)
136+
.AssertZeroExitCode();
137+
InheritedShell(build, GLFWPath)
138+
.AssertZeroExitCode();
139+
CopyAll(@out.GlobFiles("src/libglfw.so"), runtimes / "linux-x64" / "native");
140+
}
141+
else if (OperatingSystem.IsMacOS())
142+
{
143+
InheritedShell($"{prepare} -DCMAKE_OSX_ARCHITECTURES=x86_64", GLFWPath)
144+
.AssertZeroExitCode();
145+
InheritedShell(build, GLFWPath)
146+
.AssertZeroExitCode();
147+
CopyAll(@out.GlobFiles("src/libglfw.3.dylib"), runtimes / "osx-x64" / "native");
148+
149+
EnsureCleanDirectory(@out);
150+
151+
InheritedShell($"{prepare} -DCMAKE_OSX_ARCHITECTURES=arm64", GLFWPath)
152+
.AssertZeroExitCode();
153+
InheritedShell(build, GLFWPath)
154+
.AssertZeroExitCode();
155+
156+
CopyAll(@out.GlobFiles("src/libglfw.3.dylib"), runtimes / "osx-arm64" / "native");
157+
}
158+
}
159+
)
160+
);
161+
102162
}

build/nuke/Build.Support.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
5+
using System.Collections;
56
using System.Collections.Concurrent;
67
using System.Collections.Generic;
78
using System.IO;
@@ -14,8 +15,12 @@
1415
using Nuke.Common.CI.GitHubActions;
1516
using Nuke.Common.IO;
1617
using Nuke.Common.ProjectModel;
18+
using Nuke.Common.Tooling;
19+
using Nuke.Common.Utilities;
1720
using Octokit;
1821
using Octokit.Internal;
22+
using static Nuke.Common.IO.FileSystemTasks;
23+
using static Nuke.Common.Tooling.ProcessTasks;
1924

2025
partial class Build
2126
{
@@ -38,6 +43,36 @@ static int IndexOfOrThrow(string x, char y)
3843
return idx;
3944
}
4045

46+
Dictionary<string, string> CreateEnvVarDictionary()
47+
=> Environment.GetEnvironmentVariables()
48+
.Cast<DictionaryEntry>()
49+
.ToDictionary(x => (string) x.Key, x => (string) x.Value);
50+
51+
IProcess InheritedShell(string cmd, [CanBeNull] string workDir = null)
52+
=> OperatingSystem.IsWindows()
53+
? StartProcess("powershell", $"-Command {cmd.DoubleQuote()}", workDir, CreateEnvVarDictionary())
54+
: StartProcess("bash", $"-c {cmd.DoubleQuote()}", workDir, CreateEnvVarDictionary());
55+
56+
void AddToPath(string dir)
57+
{
58+
var pathVar = Environment.GetEnvironmentVariables()
59+
.Cast<DictionaryEntry>()
60+
.First(x => ((string) x.Key).Equals("PATH", StringComparison.OrdinalIgnoreCase));
61+
Environment.SetEnvironmentVariable
62+
(
63+
(string) pathVar.Key,
64+
(string) pathVar.Value + (OperatingSystem.IsWindows() ? $";{dir}" : $":{dir}")
65+
);
66+
}
67+
68+
static void CopyAll(IEnumerable<AbsolutePath> paths, AbsolutePath dir)
69+
{
70+
foreach (var path in paths)
71+
{
72+
CopyFile(path, dir / Path.GetFileName(path), FileExistsPolicy.Overwrite);
73+
}
74+
}
75+
4176
[Nuke.Common.Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
4277
readonly string Configuration = IsLocalBuild ? "Debug" : "Release";
4378

build/submodules/GLFW

Submodule GLFW added at 7d5a16c

0 commit comments

Comments
 (0)