Skip to content

Commit

Permalink
Build SDL2 libraries in CI (dotnet#1438)
Browse files Browse the repository at this point in the history
* SDL2.Native: Build Linux native libs in CI

* New binaries for SDL2 on Linux 5.15.0-1036-azure dotnet#43-Ubuntu SMP Wed Mar 29 16:11:05 UTC 2023 (dotnet#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 dotnet#43-Ubuntu SMP Wed Mar 29 16:11:05 UTC 2023 (dotnet#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 (dotnet#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 (dotnet#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 (dotnet#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]>
  • Loading branch information
3 people committed May 28, 2023
1 parent 6b13a42 commit 5a707d6
Show file tree
Hide file tree
Showing 14 changed files with 228 additions and 51 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ jobs:
# treated as candidates. We will never have a windows-latest self-hosted runner even if it is the latest.
runs-on: ${{ github.repository == 'dotnet/Silk.NET' && startsWith(github.ref, 'refs/tags/') && 'windows-quick' || github.repository == 'dotnet/Silk.NET' && 'windows-2022' || 'windows-latest' }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3.5.2
with:
submodules: 'true'
submodules: 'false'
- name: Setup Java JDK 11
uses: actions/[email protected]
with:
Expand Down
84 changes: 84 additions & 0 deletions .github/workflows/sdl2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: SDL2
on:
push:
branches-ignore:
- "ci/*"
- "develop/*"
- "main"
paths:
- "build/submodules/SDL"
- "build/nuke/Build.Native.cs"
- ".github/workflows/sdl2.yml"
jobs:
Build:
strategy:
fail-fast: false
matrix:
env:
- os: ubuntu-latest
name: Linux
nuke_invoke: ./build.sh
- os: windows-latest
name: Windows
nuke_invoke: ./build.cmd
extras: |
pwsh build\Install-WindowsSDK.ps1
- 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
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 build/submodules/SDL
git config --local user.email "[email protected]"
git config --local user.name "The Silk.NET Automaton"
- name: Extra prerequisites
run: |
echo running extras
${{ matrix.env.extras }}
# Install CMake
- uses: lukka/get-cmake@latest
if: runner.os != 'Linux'

- name: Build SDL2
if: runner.os == 'Linux'
uses: Beyley/run-as-1804@239b211a2ca687388b6251d6dab22cb90ac0391d
with:
command: |
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
wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
chmod +x ./dotnet-install.sh
./dotnet-install.sh --version 7.0.203
./dotnet-install.sh --version 6.0.408
export DOTNET_ROOT=$HOME/.dotnet
export PATH=$PATH:$HOME/.dotnet:$HOME/.dotnet/tools
# export the pushable token to the env of the docker container
export PUSHABLE_GITHUB_TOKEN=${{ secrets.PUSHABLE_GITHUB_TOKEN }}
# mark workspace as safe
git config --global --add safe.directory /github/workspace
${{ matrix.env.nuke_invoke }} SDL2
env:
PUSHABLE_GITHUB_TOKEN: ${{ secrets.PUSHABLE_GITHUB_TOKEN }}

- name: Build SDL2
if: runner.os != 'Linux'
run: ${{ matrix.env.nuke_invoke }} SDL2
env:
PUSHABLE_GITHUB_TOKEN: ${{ secrets.PUSHABLE_GITHUB_TOKEN }}


Binary file modified build/cache/sdl.json.gz
Binary file not shown.
107 changes: 100 additions & 7 deletions build/nuke/Build.Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ partial class Build
? $" -j{Environment.ProcessorCount}"
: string.Empty;

void CopyAs(AbsolutePath @out, string from, string to)
{
var file = @out.GlobFiles(from).First();
CopyFile(file, to, FileExistsPolicy.Overwrite);
}

string AndroidHome
{
get
Expand Down Expand Up @@ -330,6 +336,99 @@ string AndroidHome
)
);

AbsolutePath SDL2Path => RootDirectory / "build" / "submodules" / "SDL";

Target SDL2 => CommonTarget
(
x => x.Before(Compile)
.After(Clean)
.Executes
(
() =>
{
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();
InheritedShell($"{prepare} -A X64", x64BuildDir).AssertZeroExitCode();
InheritedShell(build, x64BuildDir).AssertZeroExitCode();
InheritedShell($"{prepare} -A arm64", ARM64BuildDir).AssertZeroExitCode();
InheritedShell(build, ARM64BuildDir).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);
}
if(OperatingSystem.IsLinux())
{
if(RuntimeInformation.OSArchitecture == Architecture.Arm64)
{
InheritedShell("cmake ..", x86BuildDir).AssertZeroExitCode();
InheritedShell("cmake --build .", x86BuildDir).AssertZeroExitCode();
CopyFile(ARM64BuildDir / "libSDL2-2.0.so.0.2600.5", runtimes / "linux-arm64" / "native" / "libSDL2-2.0.so", FileExistsPolicy.Overwrite);
}
else if (RuntimeInformation.OSArchitecture == Architecture.X64)
{
var envVars32bit = "CFLAGS='-m32 -O2' CXXFLAGS='-m32 -O2' LDFLAGS=-m32";
var envVars64bit = "CFLAGS=-O2 CXXFLAGS=-O2";
InheritedShell($"{envVars32bit} ./configure --prefix={x86BuildDir}", SDL2Path).AssertZeroExitCode();
InheritedShell($"{envVars32bit} make {JobsArg}", SDL2Path).AssertZeroExitCode();
InheritedShell($"make install", SDL2Path).AssertZeroExitCode();
InheritedShell($"{envVars64bit} ./configure --prefix={x64BuildDir}", SDL2Path).AssertZeroExitCode();
InheritedShell($"{envVars64bit} make {JobsArg}", SDL2Path).AssertZeroExitCode();
InheritedShell($"make install", SDL2Path).AssertZeroExitCode();
//Strip the libraries
InheritedShell($"strip {x86BuildDir / "lib" / "libSDL2-2.0.so.0.2600.5"}", SDL2Path).AssertZeroExitCode();
InheritedShell($"strip {x64BuildDir / "lib" / "libSDL2-2.0.so.0.2600.5"}", SDL2Path).AssertZeroExitCode();
CopyFile(x86BuildDir / "lib" / "libSDL2-2.0.so.0.2600.5", runtimes / "linux-x86" / "native" / "libSDL2-2.0.so", FileExistsPolicy.Overwrite);
CopyFile(x64BuildDir / "lib" / "libSDL2-2.0.so.0.2600.5", runtimes / "linux-x64" / "native" / "libSDL2-2.0.so", FileExistsPolicy.Overwrite);
}
else
{
throw new Exception($"Unable to build SDL libs on your architecture ({RuntimeInformation.OSArchitecture}).");
}
}
if(OperatingSystem.IsMacOS())
{
var prepare = "cmake .. -DBUILD_SHARED_LIBS=ON";
var build = $"cmake --build . --config Release{JobsArg}";
InheritedShell($"{prepare} -DCMAKE_OSX_ARCHITECTURES=x86_64", x64BuildDir).AssertZeroExitCode();
InheritedShell(build, x64BuildDir).AssertZeroExitCode();
InheritedShell($"{prepare} -DCMAKE_OSX_ARCHITECTURES=arm64", ARM64BuildDir).AssertZeroExitCode();
InheritedShell(build, ARM64BuildDir).AssertZeroExitCode();
CopyAs(x64BuildDir, "**/*.dylib", runtimes / "osx-x64" / "native" / "libSDL2-2.0.dylib");
CopyAs(ARM64BuildDir, "**/*.dylib", runtimes / "osx-arm64" / "native" / "libSDL2-2.0.dylib");
}
PrUpdatedNativeBinary("SDL2");
}
)
);

AbsolutePath GLFWPath => RootDirectory / "build" / "submodules" / "GLFW";

Target GLFW => CommonTarget
Expand Down Expand Up @@ -658,12 +757,6 @@ string AndroidHome
(
() =>
{
void CopyAs(AbsolutePath @out, string from, string to)
{
var file = @out.GlobFiles(from).First();
CopyFile(file, to, FileExistsPolicy.Overwrite);
}
var @out = AssimpPath / "build";
var prepare = "cmake -S. -B build -D BUILD_SHARED_LIBS=ON";
var build = $"cmake --build build --config Release{JobsArg}";
Expand Down Expand Up @@ -754,7 +847,7 @@ void PrUpdatedNativeBinary(string name, [CanBeNull] string glob = null)
$"git commit -m \"New binaries for {name} on {RuntimeInformation.OSDescription}\""
)
.AssertWaitForExit();
if (!commitCmd.Output.Any(x => x.Text.Contains("nothing to commit", StringComparison.OrdinalIgnoreCase)))
if (!commitCmd.Output.Any(x => x.Text.Contains("no changes added to commit", StringComparison.OrdinalIgnoreCase) || x.Text.Contains("nothing to commit", StringComparison.OrdinalIgnoreCase)))
{
commitCmd.AssertZeroExitCode();
}
Expand Down
2 changes: 1 addition & 1 deletion build/submodules/SDL
Submodule SDL updated 1076 files
Binary file modified src/Native/Silk.NET.SDL.Native/runtimes/linux-x64/native/libSDL2-2.0.so
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified src/Native/Silk.NET.SDL.Native/runtimes/osx-x64/native/libSDL2-2.0.dylib
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified src/Native/Silk.NET.SDL.Native/runtimes/win-x64/native/SDL2.dll
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 5a707d6

Please sign in to comment.