Skip to content

Commit 5a707d6

Browse files
Beyleysilkdotnetdotnet-bot
authored
Build SDL2 libraries in CI (#1438)
* SDL2.Native: Build Linux native libs in CI * New binaries for SDL2 on Linux 5.15.0-1036-azure #43-Ubuntu SMP Wed Mar 29 16:11:05 UTC 2023 (#1439) Co-authored-by: The Silk.NET Automaton <[email protected]> * SDL2.Native: Compile linux native libs with -O2, and strip libs * New binaries for SDL2 on Linux 5.15.0-1036-azure #43-Ubuntu SMP Wed Mar 29 16:11:05 UTC 2023 (#1440) Co-authored-by: The Silk.NET Automaton <[email protected]> * SDL2.Native: Build windows native libs in CI * New binaries for SDL2 on Microsoft Windows 10.0.20348 (#1446) Co-authored-by: The Silk.NET Automaton <[email protected]> * Native: Add "no changes added to commit" as possible ignore git error case for PrUpdatedNativeBinary * SDL2.Native: Build MacOS native libs in CI * Update SDL2 binaries (#1448) * New binaries for SDL2 on Darwin 21.6.0 Darwin Kernel Version 21.6.0: Thu Mar 9 20:08:59 PST 2023; root:xnu-8020.240.18.700.8~1/RELEASE_X86_64 * New binaries for SDL2 on Microsoft Windows 10.0.20348 --------- Co-authored-by: The Silk.NET Automaton <[email protected]> * Remove accidentally added submodule * Regenerate SDL to new version No code changes happened, just some shuffling of the file seemingly? * waaaaaa * Update checkout to v3.5.2 * Clone submodules manually, since `checkout` bad * Temporarily disable selfhosted runner just to see if that helps * Revert "Temporarily disable selfhosted runner just to see if that helps" This reverts commit ce3ae5a. * Update SDL2 binaries (#1450) * New binaries for SDL2 on Microsoft Windows 10.0.20348 * New binaries for SDL2 on Darwin 21.6.0 Darwin Kernel Version 21.6.0: Thu Mar 9 20:08:59 PST 2023; root:xnu-8020.240.18.700.8~1/RELEASE_X86_64 --------- Co-authored-by: The Silk.NET Automaton <[email protected]> * Dont clone submodules in `build.yml` --------- Co-authored-by: silkdotnet <[email protected]> Co-authored-by: The Silk.NET Automaton <[email protected]>
1 parent 6b13a42 commit 5a707d6

File tree

14 files changed

+228
-51
lines changed

14 files changed

+228
-51
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ jobs:
2626
# treated as candidates. We will never have a windows-latest self-hosted runner even if it is the latest.
2727
runs-on: ${{ github.repository == 'dotnet/Silk.NET' && startsWith(github.ref, 'refs/tags/') && 'windows-quick' || github.repository == 'dotnet/Silk.NET' && 'windows-2022' || 'windows-latest' }}
2828
steps:
29-
- uses: actions/checkout@v2
29+
- uses: actions/checkout@v3.5.2
3030
with:
31-
submodules: 'true'
31+
submodules: 'false'
3232
- name: Setup Java JDK 11
3333
uses: actions/[email protected]
3434
with:

.github/workflows/sdl2.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: SDL2
2+
on:
3+
push:
4+
branches-ignore:
5+
- "ci/*"
6+
- "develop/*"
7+
- "main"
8+
paths:
9+
- "build/submodules/SDL"
10+
- "build/nuke/Build.Native.cs"
11+
- ".github/workflows/sdl2.yml"
12+
jobs:
13+
Build:
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
env:
18+
- os: ubuntu-latest
19+
name: Linux
20+
nuke_invoke: ./build.sh
21+
- os: windows-latest
22+
name: Windows
23+
nuke_invoke: ./build.cmd
24+
extras: |
25+
pwsh build\Install-WindowsSDK.ps1
26+
- os: macos-latest
27+
name: Darwin
28+
nuke_invoke: ./build.sh
29+
extras: ""
30+
name: ${{ matrix.env.name }} Build
31+
runs-on: ${{ matrix.env.os }}
32+
steps:
33+
- uses: actions/checkout@v2
34+
with:
35+
token: ${{ secrets.PUSHABLE_GITHUB_TOKEN }}
36+
37+
- name: Checkout submodules, configure git
38+
run: |
39+
git -c submodule.third_party/git-hooks.update=none submodule update --init --recursive build/submodules/SDL
40+
git config --local user.email "[email protected]"
41+
git config --local user.name "The Silk.NET Automaton"
42+
43+
- name: Extra prerequisites
44+
run: |
45+
echo running extras
46+
${{ matrix.env.extras }}
47+
48+
# Install CMake
49+
- uses: lukka/get-cmake@latest
50+
if: runner.os != 'Linux'
51+
52+
- name: Build SDL2
53+
if: runner.os == 'Linux'
54+
uses: Beyley/run-as-1804@239b211a2ca687388b6251d6dab22cb90ac0391d
55+
with:
56+
command: |
57+
apt update
58+
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
59+
60+
wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
61+
chmod +x ./dotnet-install.sh
62+
./dotnet-install.sh --version 7.0.203
63+
./dotnet-install.sh --version 6.0.408
64+
65+
export DOTNET_ROOT=$HOME/.dotnet
66+
export PATH=$PATH:$HOME/.dotnet:$HOME/.dotnet/tools
67+
68+
# export the pushable token to the env of the docker container
69+
export PUSHABLE_GITHUB_TOKEN=${{ secrets.PUSHABLE_GITHUB_TOKEN }}
70+
71+
# mark workspace as safe
72+
git config --global --add safe.directory /github/workspace
73+
74+
${{ matrix.env.nuke_invoke }} SDL2
75+
env:
76+
PUSHABLE_GITHUB_TOKEN: ${{ secrets.PUSHABLE_GITHUB_TOKEN }}
77+
78+
- name: Build SDL2
79+
if: runner.os != 'Linux'
80+
run: ${{ matrix.env.nuke_invoke }} SDL2
81+
env:
82+
PUSHABLE_GITHUB_TOKEN: ${{ secrets.PUSHABLE_GITHUB_TOKEN }}
83+
84+

build/cache/sdl.json.gz

0 Bytes
Binary file not shown.

build/nuke/Build.Native.cs

Lines changed: 100 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ partial class Build
3535
? $" -j{Environment.ProcessorCount}"
3636
: string.Empty;
3737

38+
void CopyAs(AbsolutePath @out, string from, string to)
39+
{
40+
var file = @out.GlobFiles(from).First();
41+
CopyFile(file, to, FileExistsPolicy.Overwrite);
42+
}
43+
3844
string AndroidHome
3945
{
4046
get
@@ -330,6 +336,99 @@ string AndroidHome
330336
)
331337
);
332338

339+
AbsolutePath SDL2Path => RootDirectory / "build" / "submodules" / "SDL";
340+
341+
Target SDL2 => CommonTarget
342+
(
343+
x => x.Before(Compile)
344+
.After(Clean)
345+
.Executes
346+
(
347+
() =>
348+
{
349+
var runtimes = RootDirectory / "src" / "Native" / "Silk.NET.SDL.Native" / "runtimes";
350+
351+
var x86BuildDir = SDL2Path / "buildx86";
352+
var x64BuildDir = SDL2Path / "buildx64";
353+
var ARM64BuildDir = SDL2Path / "buildARM64";
354+
EnsureCleanDirectory(x86BuildDir);
355+
EnsureCleanDirectory(x64BuildDir);
356+
EnsureCleanDirectory(ARM64BuildDir);
357+
358+
if(OperatingSystem.IsWindows())
359+
{
360+
var prepare = "cmake .. -DBUILD_SHARED_LIBS=ON";
361+
var build = $"cmake --build . --config Release{JobsArg}";
362+
363+
InheritedShell($"{prepare} -A Win32", x86BuildDir).AssertZeroExitCode();
364+
InheritedShell(build, x86BuildDir).AssertZeroExitCode();
365+
366+
InheritedShell($"{prepare} -A X64", x64BuildDir).AssertZeroExitCode();
367+
InheritedShell(build, x64BuildDir).AssertZeroExitCode();
368+
369+
InheritedShell($"{prepare} -A arm64", ARM64BuildDir).AssertZeroExitCode();
370+
InheritedShell(build, ARM64BuildDir).AssertZeroExitCode();
371+
372+
CopyFile(x86BuildDir / "Release" / "SDL2.dll", runtimes / "win-x86" / "native" / "SDL2.dll", FileExistsPolicy.Overwrite);
373+
CopyFile(x64BuildDir / "Release" / "SDL2.dll", runtimes / "win-x64" / "native" / "SDL2.dll", FileExistsPolicy.Overwrite);
374+
CopyFile(ARM64BuildDir / "Release" / "SDL2.dll", runtimes / "win-arm64" / "native" / "SDL2.dll", FileExistsPolicy.Overwrite);
375+
}
376+
377+
if(OperatingSystem.IsLinux())
378+
{
379+
if(RuntimeInformation.OSArchitecture == Architecture.Arm64)
380+
{
381+
InheritedShell("cmake ..", x86BuildDir).AssertZeroExitCode();
382+
InheritedShell("cmake --build .", x86BuildDir).AssertZeroExitCode();
383+
384+
CopyFile(ARM64BuildDir / "libSDL2-2.0.so.0.2600.5", runtimes / "linux-arm64" / "native" / "libSDL2-2.0.so", FileExistsPolicy.Overwrite);
385+
}
386+
else if (RuntimeInformation.OSArchitecture == Architecture.X64)
387+
{
388+
var envVars32bit = "CFLAGS='-m32 -O2' CXXFLAGS='-m32 -O2' LDFLAGS=-m32";
389+
var envVars64bit = "CFLAGS=-O2 CXXFLAGS=-O2";
390+
391+
InheritedShell($"{envVars32bit} ./configure --prefix={x86BuildDir}", SDL2Path).AssertZeroExitCode();
392+
InheritedShell($"{envVars32bit} make {JobsArg}", SDL2Path).AssertZeroExitCode();
393+
InheritedShell($"make install", SDL2Path).AssertZeroExitCode();
394+
395+
InheritedShell($"{envVars64bit} ./configure --prefix={x64BuildDir}", SDL2Path).AssertZeroExitCode();
396+
InheritedShell($"{envVars64bit} make {JobsArg}", SDL2Path).AssertZeroExitCode();
397+
InheritedShell($"make install", SDL2Path).AssertZeroExitCode();
398+
399+
//Strip the libraries
400+
InheritedShell($"strip {x86BuildDir / "lib" / "libSDL2-2.0.so.0.2600.5"}", SDL2Path).AssertZeroExitCode();
401+
InheritedShell($"strip {x64BuildDir / "lib" / "libSDL2-2.0.so.0.2600.5"}", SDL2Path).AssertZeroExitCode();
402+
403+
CopyFile(x86BuildDir / "lib" / "libSDL2-2.0.so.0.2600.5", runtimes / "linux-x86" / "native" / "libSDL2-2.0.so", FileExistsPolicy.Overwrite);
404+
CopyFile(x64BuildDir / "lib" / "libSDL2-2.0.so.0.2600.5", runtimes / "linux-x64" / "native" / "libSDL2-2.0.so", FileExistsPolicy.Overwrite);
405+
}
406+
else
407+
{
408+
throw new Exception($"Unable to build SDL libs on your architecture ({RuntimeInformation.OSArchitecture}).");
409+
}
410+
}
411+
412+
if(OperatingSystem.IsMacOS())
413+
{
414+
var prepare = "cmake .. -DBUILD_SHARED_LIBS=ON";
415+
var build = $"cmake --build . --config Release{JobsArg}";
416+
417+
InheritedShell($"{prepare} -DCMAKE_OSX_ARCHITECTURES=x86_64", x64BuildDir).AssertZeroExitCode();
418+
InheritedShell(build, x64BuildDir).AssertZeroExitCode();
419+
420+
InheritedShell($"{prepare} -DCMAKE_OSX_ARCHITECTURES=arm64", ARM64BuildDir).AssertZeroExitCode();
421+
InheritedShell(build, ARM64BuildDir).AssertZeroExitCode();
422+
423+
CopyAs(x64BuildDir, "**/*.dylib", runtimes / "osx-x64" / "native" / "libSDL2-2.0.dylib");
424+
CopyAs(ARM64BuildDir, "**/*.dylib", runtimes / "osx-arm64" / "native" / "libSDL2-2.0.dylib");
425+
}
426+
427+
PrUpdatedNativeBinary("SDL2");
428+
}
429+
)
430+
);
431+
333432
AbsolutePath GLFWPath => RootDirectory / "build" / "submodules" / "GLFW";
334433

335434
Target GLFW => CommonTarget
@@ -658,12 +757,6 @@ string AndroidHome
658757
(
659758
() =>
660759
{
661-
void CopyAs(AbsolutePath @out, string from, string to)
662-
{
663-
var file = @out.GlobFiles(from).First();
664-
CopyFile(file, to, FileExistsPolicy.Overwrite);
665-
}
666-
667760
var @out = AssimpPath / "build";
668761
var prepare = "cmake -S. -B build -D BUILD_SHARED_LIBS=ON";
669762
var build = $"cmake --build build --config Release{JobsArg}";
@@ -754,7 +847,7 @@ void PrUpdatedNativeBinary(string name, [CanBeNull] string glob = null)
754847
$"git commit -m \"New binaries for {name} on {RuntimeInformation.OSDescription}\""
755848
)
756849
.AssertWaitForExit();
757-
if (!commitCmd.Output.Any(x => x.Text.Contains("nothing to commit", StringComparison.OrdinalIgnoreCase)))
850+
if (!commitCmd.Output.Any(x => x.Text.Contains("no changes added to commit", StringComparison.OrdinalIgnoreCase) || x.Text.Contains("nothing to commit", StringComparison.OrdinalIgnoreCase)))
758851
{
759852
commitCmd.AssertZeroExitCode();
760853
}

build/submodules/SDL

Submodule SDL updated 1076 files
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)