Skip to content

Commit dd103f5

Browse files
Perkseysilkdotnetdotnet-bot
authored
Build SDL2 for Android in CI and productise iOS support (#2211)
* Update sdl2.yml * Add aar to staging for CI * --native flag * Install workload * Retry * Install android workload in NUKE instead * Remove extra prereq * Update android action * Update sdl2.yml * Update sdl2.yml * Env var help * Install android workload somewhere else * Update sdl2.yml * Command line oddities * It appears this was no place for intelligence * ANDROID_HOME isn't being respected? * Override ANDROID_HOME? idk * Fix * Fix the attribute problem * Update paths for workflow * Contd attr fix * Use older JDK, and turns out it was our runner causing issues * Install JDK 21 AND 11 * Fix glaring issue with Path.PathSeparator * Atempt to fix override logic * I really don't know anymore * More respect env var changes * Fix parameter being misused * Fix a silly mistake * Fix a silly mistake 2 * Update Core.cs * Don't force include *everything* * Fix build error * Declare public API in CI If this is incorrect, a human is expected to notice. * Declare APIs in CI using dotnet format for Windowing.Sdl * Install .NET 7 * Install workloads * Install even more workloads * Update SilkDroid.cs * Attempt * Ugh I give up * May have figured it out? * Update SDL2 binaries (#2223) * New binaries for SDL2 on Darwin 23.5.0 Darwin Kernel Version 23.5.0: Wed May 1 20:12:39 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_VMAPPLE * New binaries for SDL2 on Microsoft Windows 10.0.20348 * New binaries for SDL2 on Darwin 23.6.0 Darwin Kernel Version 23.6.0: Wed Jul 31 20:50:13 PDT 2024; root:xnu-10063.141.1.700.5~1/RELEASE_ARM64_VMAPPLE * New binaries for SDL2 on Microsoft Windows 10.0.20348 * New binaries for SDL2 on Darwin 23.6.0 Darwin Kernel Version 23.6.0: Wed Jul 31 20:50:13 PDT 2024; root:xnu-10063.141.1.700.5~1/RELEASE_ARM64_VMAPPLE * New binaries for SDL2 on Microsoft Windows 10.0.20348 * New binaries for SDL2 on Microsoft Windows 10.0.20348 * New binaries for SDL2 on Darwin 23.6.0 Darwin Kernel Version 23.6.0: Wed Jul 31 20:50:13 PDT 2024; root:xnu-10063.141.1.700.5~1/RELEASE_ARM64_VMAPPLE * New binaries for SDL2 on Darwin 23.6.0 Darwin Kernel Version 23.6.0: Wed Jul 31 20:50:13 PDT 2024; root:xnu-10063.141.1.700.5~1/RELEASE_ARM64_VMAPPLE * New binaries for SDL2 on Microsoft Windows 10.0.20348 * New binaries for SDL2 on Darwin 23.6.0 Darwin Kernel Version 23.6.0: Wed Jul 31 20:50:13 PDT 2024; root:xnu-10063.141.1.700.5~1/RELEASE_ARM64_VMAPPLE * New binaries for SDL2 on Microsoft Windows 10.0.20348 * New binaries for SDL2 on Darwin 23.6.0 Darwin Kernel Version 23.6.0: Wed Jul 31 20:50:13 PDT 2024; root:xnu-10063.141.1.700.5~1/RELEASE_ARM64_VMAPPLE * New binaries for SDL2 on Microsoft Windows 10.0.20348 * New binaries for SDL2 on Darwin 23.6.0 Darwin Kernel Version 23.6.0: Wed Jul 31 20:50:13 PDT 2024; root:xnu-10063.141.1.700.5~1/RELEASE_ARM64_VMAPPLE * New binaries for SDL2 on Microsoft Windows 10.0.20348 * New binaries for SDL2 on Darwin 23.6.0 Darwin Kernel Version 23.6.0: Wed Jul 31 20:50:13 PDT 2024; root:xnu-10063.141.1.700.5~1/RELEASE_ARM64_VMAPPLE * New binaries for SDL2 on Microsoft Windows 10.0.20348 --------- Co-authored-by: The Silk.NET Automaton <[email protected]> Co-authored-by: Dylan Perks <[email protected]> * Push PRs to experimental feed with a different version string * Stop pulling in GLFW on Android * Add buildTransitive as well as build * Productise iOS support * Stop duplicating build into buildTransitive, use csproj instead * Fix build * Upversion native binary package * Attempt to stop linking away Microsoft.iOS.dll * Fix build * Fix MonoPInvokeCallback usage * Fix NewsstandKit problem * Revert to last working build and build back up from there * Undo SilkMobile changes as doing things properly is breaking in 2.X --------- Co-authored-by: silkdotnet <[email protected]> Co-authored-by: The Silk.NET Automaton <[email protected]>
1 parent a9c75a6 commit dd103f5

File tree

37 files changed

+520
-132
lines changed

37 files changed

+520
-132
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,12 @@ jobs:
5959
run: ./build.sh ValidateSolution
6060
- name: Pack (CI)
6161
if: ${{ github.repository != 'dotnet/Silk.NET' || !startsWith(github.ref, 'refs/tags/') }}
62-
# TODO build native mixins such as BuildLibSilkDroid
6362
# Use a release NUKE so it doesn't interfere with the debug build
64-
run: dotnet run --project build/nuke/Silk.NET.NUKE.csproj -c Release -- Pack --configuration Debug --msbuild-properties VersionSuffix=build${{ github.run_number }}.0 ContinuousIntegrationBuild=true
63+
run: dotnet run --project build/nuke/Silk.NET.NUKE.csproj -c Release -- Pack --configuration Debug --msbuild-properties VersionSuffix=${{ github.event_name != 'pull_request' && format('build{0}.0', github.run_number) || format('pr{0}.{1}', github.event.number, github.run_number) }} ContinuousIntegrationBuild=true
6564
env:
6665
ANDROID_HOME: /Users/runner/Library/Android/sdk
6766
- name: Pack (CD)
6867
if: ${{ github.repository == 'dotnet/Silk.NET' && startsWith(github.ref, 'refs/tags/') }}
69-
# TODO build native mixins such as BuildLibSilkDroid
7068
run: ./build.sh Pack --configuration Release --msbuild-properties ContinuousIntegrationBuild=true
7169
- name: Upload Unsigned Artifacts to Actions
7270
uses: actions/upload-artifact@v4
@@ -76,10 +74,10 @@ jobs:
7674
if-no-files-found: warn
7775
retention-days: 1
7876
- name: Push to Experimental Feed
79-
if: ${{ github.repository == 'dotnet/Silk.NET' && github.event_name != 'pull_request' }}
77+
if: ${{ github.repository == 'dotnet/Silk.NET' }}
8078
run: ./build.sh PushToNuGet --skip Clean Restore Compile Pack --nuget-feed https://dotnet.github.io/Silk.NET/nuget/experimental/index.json --nuget-username ${{ secrets.EXP_NUGET_USERNAME }} --nuget-password ${{ secrets.EXP_NUGET_PASSWORD }} --nuget-api-key ${{ secrets.EXP_NUGET_PASSWORD }}
8179
- name: Push to GitHub Packages
82-
if: ${{ github.repository == 'dotnet/Silk.NET' && github.event_name != 'pull_request' }}
80+
if: ${{ github.repository == 'dotnet/Silk.NET' }}
8381
run: ./build.sh PushToNuGet --skip Clean Restore Compile Pack --nuget-feed https://nuget.pkg.github.com/dotnet/index.json --nuget-api-key ${{ secrets.GITHUB_TOKEN }}
8482
PushRelease:
8583
name: Push Release to NuGet

.github/workflows/sdl2.yml

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ on:
1010
- "build/cmake/*"
1111
- build/nuke/Native/Core.cs
1212
- build/nuke/Native/SDL2.cs
13+
- build/nuke/Native/SilkDroid.cs
14+
- build/nuke/Build.Support.cs
1315
- .github/workflows/sdl2.yml
1416
jobs:
1517
Build:
@@ -21,15 +23,12 @@ jobs:
2123
- os: ubuntu-22.04
2224
name: Linux
2325
nuke_invoke: ./build.sh
24-
- os: windows-2022
26+
- os: windows-latest # runner is not setup for android yet
2527
name: Windows
26-
nuke_invoke: ./build.cmd
27-
extras: |
28-
pwsh build\Install-WindowsSDK.ps1
28+
nuke_invoke: ./build.cmd BuildLibSilkDroid
2929
- os: macos-14
3030
name: Darwin
3131
nuke_invoke: ./build.sh
32-
extras: ""
3332
name: ${{ matrix.env.name }} Build
3433
runs-on: ${{ matrix.env.os }}
3534
steps:
@@ -42,12 +41,52 @@ jobs:
4241
git -c submodule.third_party/git-hooks.update=none submodule update --init --recursive build/submodules/SDL
4342
git config --local user.email "[email protected]"
4443
git config --local user.name "The Silk.NET Automaton"
45-
46-
- name: Extra prerequisites
44+
- name: Setup .NET Core
45+
uses: actions/setup-dotnet@v3
46+
if: runner.os == 'Windows'
47+
with:
48+
dotnet-version: |
49+
6.0.201
50+
7.0.*
51+
8.0.*
52+
env:
53+
DOTNET_INSTALL_DIR: ~/.dotnet
54+
- name: Setup PowerShell Core
55+
continue-on-error: true
56+
if: runner.os == 'Windows'
57+
run: dotnet tool install --global PowerShell
58+
- name: Setup Java JDK 21
59+
uses: actions/[email protected]
60+
if: runner.os == 'Windows'
61+
with:
62+
java-version: 21
63+
distribution: "temurin"
64+
- name: Set PATH
65+
if: runner.os == 'Windows'
66+
id: set_path
4767
run: |
48-
echo running extras
49-
${{ matrix.env.extras }}
50-
68+
echo "cur_path=$env:PATH\n" >> $env:GITHUB_OUTPUT
69+
- name: Setup Android Environment
70+
uses: android-actions/setup-android@v3
71+
if: runner.os == 'Windows'
72+
env:
73+
PATH: "${{ env.DOTNET_ROOT }};${{ env.DOTNET_ROOT }}\\tools;${{ steps.set_path.outputs.cur_path }}"
74+
- name: Install Android Platforms
75+
if: runner.os == 'Windows'
76+
run: |
77+
sdkmanager --install "build-tools;30.0.2"
78+
sdkmanager --install "platform-tools"
79+
sdkmanager --install "platforms;android-31"
80+
sdkmanager --install "platforms;android-33"
81+
sdkmanager --install "platforms;android-34"
82+
sdkmanager --install "ndk-bundle"
83+
sdkmanager --install "ndk;21.4.7075529"
84+
- name: Setup Java JDK 11
85+
uses: actions/[email protected]
86+
if: runner.os == 'Windows'
87+
with:
88+
java-version: 11
89+
distribution: "temurin"
5190
# Install CMake
5291
- uses: lukka/get-cmake@latest
5392
if: runner.os != 'Linux'
@@ -110,10 +149,13 @@ jobs:
110149
env:
111150
PUSHABLE_GITHUB_TOKEN: ${{ secrets.PUSHABLE_GITHUB_TOKEN }}
112151

152+
- name: Install Workloads
153+
if: runner.os == 'Windows'
154+
run: dotnet workload install android ios maccatalyst
155+
113156
- name: Build SDL2
114157
if: runner.os != 'Linux'
115-
run: ${{ matrix.env.nuke_invoke }} SDL2
158+
run: ${{ matrix.env.nuke_invoke }} SDL2 ${{ runner.os == 'Windows' && format('{0} {1}', '--native true --android-home-value', env.ANDROID_HOME) || '' }}
116159
env:
117160
PUSHABLE_GITHUB_TOKEN: ${{ secrets.PUSHABLE_GITHUB_TOKEN }}
118161

119-

build/nuke/Build.Support.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ partial class Build
3535
/// - Microsoft VSCode https://nuke.build/vscode
3636
public static int Main() => Execute<Build>(x => x.Compile);
3737

38-
[Parameter("Outputs build warnings instead of keeping the MSBuild logging quiet with just errors.")]
38+
[Nuke.Common.Parameter("Outputs build warnings instead of keeping the MSBuild logging quiet with just errors.")]
3939
bool Warnings;
4040

4141
static int IndexOfOrThrow(string x, char y)
@@ -126,6 +126,18 @@ Dictionary<string, object> ProcessedMsbuildProperties
126126
{
127127
// probably hasn't existed yet, don't care.
128128
}
129+
try
130+
{
131+
if (Native)
132+
{
133+
DotNet("workload install android");
134+
}
135+
}
136+
catch
137+
{
138+
// oh well. maybe it's already installed?
139+
}
140+
129141
GenerateSolution();
130142
}
131143
);

build/nuke/Native/Core.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
partial class Build {
3030
[Nuke.Common.Parameter("Build native code")] readonly bool Native;
3131

32-
[CanBeNull] string AndroidHomeValue;
32+
[Nuke.Common.Parameter("Android home. Will be determined from dotnet if not provided.")] [CanBeNull] string AndroidHomeValue;
3333

3434
static string JobsArg => string.IsNullOrWhiteSpace(GitHubActions.Instance?.Job)
3535
? $" -j{Jobs}"
@@ -66,7 +66,8 @@ public void PrUpdatedNativeBinary(string name)
6666

6767
Git("fetch --all", RootDirectory);
6868
Git("pull");
69-
Git($"add -f src/Native/*/runtimes/*/native/*", RootDirectory);
69+
Git("add -f src/Native/*/runtimes/*/native/*", RootDirectory);
70+
Git("add **/*.aar **/*.java **/PublicAPI.Unshipped.txt", RootDirectory);
7071
var newBranch = $"ci/{curBranch}/{name.ToLower().Replace(' ', '_')}_bins";
7172
var curCommit = GitCurrentCommit(RootDirectory);
7273
var commitCmd = InheritedShell

build/nuke/Native/SilkDroid.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ string AndroidHome
3636
return AndroidHomeValue;
3737
}
3838

39+
if ((Environment.GetEnvironmentVariable("ANDROID_HOME") ?? Environment.GetEnvironmentVariable("ANDROID_SDK_ROOT")) is {} sdk)
40+
{
41+
AndroidHomeValue = sdk;
42+
return sdk;
43+
}
44+
3945
var utils = RootDirectory / "build" / "utilities";
4046
DotNet($"build \"{utils / "android_probe.proj"}\" /t:GetAndroidJar");
4147
AndroidHomeValue = (AbsolutePath) File.ReadAllText(utils / "android.jar.gen.txt") / ".." / ".." / "..";
@@ -80,14 +86,15 @@ string AndroidHome
8086

8187
var envVars = CreateEnvVarDictionary();
8288
envVars["ANDROID_HOME"] = AndroidHome;
89+
envVars["ANDROID_SDK_ROOT"] = AndroidHome;
8390

8491
foreach (var ndk in Directory.GetDirectories((AbsolutePath) AndroidHome / "ndk")
8592
.OrderByDescending(x => Version.Parse(Path.GetFileName(x))))
8693
{
8794
envVars["ANDROID_NDK_HOME"] = ndk;
8895
}
8996

90-
using var process = StartShell($".{Path.PathSeparator}gradlew build", silkDroid, envVars);
97+
using var process = StartShell($".{Path.DirectorySeparatorChar}gradlew build", silkDroid, envVars);
9198
process.AssertZeroExitCode();
9299
var ret = process.Output;
93100
CopyFile
@@ -96,6 +103,12 @@ string AndroidHome
96103
SourceDirectory / "Windowing" / "Silk.NET.Windowing.Sdl" / "Android" / "app-release.aar",
97104
FileExistsPolicy.Overwrite
98105
);
106+
107+
// Not expecting this to succeed, but we need to do this so we generate the bindings to go in the public API.
108+
InheritedShell($"dotnet build \"{SourceDirectory / "Windowing" / "Silk.NET.Windowing.Sdl" / "Silk.NET.Windowing.Sdl.csproj"}\"").AssertWaitForExit();
109+
110+
// Update the public API.
111+
InheritedShell(string.Format(FormatDeclCmd, SourceDirectory / "Windowing" / "Silk.NET.Windowing.Sdl" / "Silk.NET.Windowing.Sdl.csproj")).AssertZeroExitCode();
99112
return ret;
100113
}
101114
)

build/props/bindings.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<WriteLinesToFile File="@(SilkGeneratedTargetFile)" Lines="@(SilkGeneratedTargetLine)" Overwrite="true" Encoding="UTF-8" Condition="'@(SilkPInvokeOverride)' != ''" />
3939
<ItemGroup Condition="'@(SilkPInvokeOverride)' != ''">
4040
<TfmSpecificPackageFile Include="@(SilkGeneratedTargetFile)" Link="build/$(_SilkNuGetShortFolderName)/$(PackageId).targets" Pack="true" PackagePath="build/$(_SilkNuGetShortFolderName)/$(PackageId).targets" />
41+
<TfmSpecificPackageFile Include="@(SilkGeneratedTargetFile)" Link="buildTransitive/$(_SilkNuGetShortFolderName)/$(PackageId).targets" Pack="true" PackagePath="buildTransitive/$(_SilkNuGetShortFolderName)/$(PackageId).targets" />
4142
</ItemGroup>
4243
</Target>
4344
<Target Name="SilkGenerateILLinkSubs" Condition="$(TargetFramework.Contains('net6')) or $(TargetFramework.Contains('net7')) or $(TargetFramework.Contains('net8'))">

src/Input/Silk.NET.Input/Silk.NET.Input.csproj

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0;net6.0;net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
55
<SilkMetapackage>true</SilkMetapackage>
66
</PropertyGroup>
77

88
<ItemGroup>
99
<ProjectReference Include="..\Silk.NET.Input.Common\Silk.NET.Input.Common.csproj" />
10-
<ProjectReference Include="..\Silk.NET.Input.Glfw\Silk.NET.Input.Glfw.csproj" />
11-
<ProjectReference Include="..\Silk.NET.Input.Sdl\Silk.NET.Input.Sdl.csproj" />
10+
</ItemGroup>
11+
12+
<ItemGroup Condition="'$(TargetFramework)' != 'net6.0-android' And '$(TargetFramework)' != 'net6.0-ios' And '$(TargetFramework)' != 'net6.0-maccatalyst' And '$(TargetFramework)' != 'net6.0'">
13+
<ProjectReference Include="..\Silk.NET.Input.Glfw\Silk.NET.Input.Glfw.csproj" />
14+
<ProjectReference Include="..\Silk.NET.Input.Sdl\Silk.NET.Input.Sdl.csproj" />
15+
</ItemGroup>
16+
17+
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0-android' Or '$(TargetFramework)' == 'net6.0-ios' Or '$(TargetFramework)' == 'net6.0-maccatalyst'">
18+
<ProjectReference Include="..\Silk.NET.Input.Sdl\Silk.NET.Input.Sdl.csproj" />
19+
</ItemGroup>
20+
21+
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
22+
<ProjectReference Include="..\Silk.NET.Input.Glfw\Silk.NET.Input.Glfw.csproj" />
1223
</ItemGroup>
1324

1425
<Import Project="..\..\..\build\props\common.props" />

src/Lab/Experiments/InputTest/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Drawing;
55
using System.Linq;
66
using System.Numerics;
7-
using Silk.NET.GLFW;
87
using Silk.NET.Input;
98
using Silk.NET.Windowing;
109
using MouseButton = Silk.NET.Input.MouseButton;

src/Lab/Experiments/Triangle/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Silk.NET.Maths;
88
using Silk.NET.OpenGL;
99
using Silk.NET.Windowing;
10-
using SdlProvider = Silk.NET.SDL.SdlProvider;
1110
using Shader = SampleBase.Shader;
1211

1312
namespace Triangle

src/Lab/Experiments/TriangleNET6/Program.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,13 @@
22
Triangle.Program.Run();
33
#elif __IOS__
44
using Silk.NET.Windowing;
5-
using Silk.NET.Windowing.Sdl;
65
using Silk.NET.Windowing.Sdl.iOS;
76
using Silk.NET.Input.Sdl;
8-
using Silk.NET.SDL;
9-
using System;
10-
using Triangle;
117

12-
static void Run(string[] args)
8+
SdlInput.RegisterPlatform();
9+
SilkMobile.RunApp(args, _ =>
1310
{
1411
Triangle.Program.API = new GraphicsAPI(ContextAPI.OpenGLES, ContextProfile.Core, ContextFlags.Default, new APIVersion(3, 0));
1512
Triangle.Program.Run();
16-
}
17-
18-
SdlInput.RegisterPlatform();
19-
Console.WriteLine("Hello, world!");
20-
SilkMobile.RunApp(args, Run);
21-
Console.WriteLine("Goodbye, world!");
22-
SdlProvider.SDL.Value.ThrowError();
13+
});
2314
#endif

0 commit comments

Comments
 (0)