Skip to content

Commit 7b348de

Browse files
authored
Remove Legacy Xamarin & NUKE overhaul (#700)
* Remove Legacy Xamarin * NUKE overhaul * Get libsilkdroid building again * Attempt to fix build * Actually check in the aar
1 parent 2186106 commit 7b348de

14 files changed

+754
-832
lines changed

src/infrastructure/Silk.NET.NUKE/.editorconfig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
[*.cs]
2-
dotnet_style_qualification_for_field = false:warning
3-
dotnet_style_qualification_for_property = false:warning
4-
dotnet_style_qualification_for_method = false:warning
5-
dotnet_style_qualification_for_event = false:warning
62
dotnet_style_require_accessibility_modifiers = never:warning
73

84
csharp_style_expression_bodied_methods = true:silent
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.IO;
6+
using System.Linq;
7+
using Nuke.Common;
8+
using Nuke.Common.CI;
9+
using Nuke.Common.Tooling;
10+
using Nuke.Common.Tools.DotNet;
11+
using Nuke.Common.Tools.SignClient;
12+
using static Nuke.Common.Tools.DotNet.DotNetTasks;
13+
using static Nuke.Common.Tools.SignClient.SignClientTasks;
14+
15+
partial class Build
16+
{
17+
[Parameter("Code-signing service username")] readonly string SignUsername;
18+
[Parameter("Code-signing service password")] readonly string SignPassword;
19+
bool CanCodeSign => !string.IsNullOrWhiteSpace(SignUsername) && !string.IsNullOrWhiteSpace(SignPassword);
20+
21+
Target SignPackages => CommonTarget
22+
(
23+
x => x.Before(PushToNuGet)
24+
.After(Pack)
25+
.Produces("build/output_packages/*.nupkg")
26+
.Executes
27+
(
28+
() =>
29+
{
30+
if (!CanCodeSign)
31+
{
32+
ControlFlow.Fail("SignClient username and/or password not specified.");
33+
}
34+
35+
var outputs = Enumerable.Empty<Output>();
36+
var basePath = RootDirectory / "build" / "codesigning";
37+
var execPath = basePath / "tool" / (OperatingSystem.IsWindows() ? "SignClient.exe" : "SignClient");
38+
if (!File.Exists(execPath))
39+
{
40+
outputs = outputs.Concat
41+
(
42+
DotNetToolInstall
43+
(
44+
s => s.SetToolInstallationPath(basePath / "tool")
45+
.SetPackageName("SignClient")
46+
)
47+
);
48+
}
49+
50+
return Packages.Aggregate
51+
(
52+
outputs, (current, pkg) => current.Concat
53+
(
54+
SignClientSign
55+
(
56+
s => s.SetProcessToolPath(execPath)
57+
.SetBaseDirectory(PackageDirectory)
58+
.SetInput(pkg)
59+
.SetConfig(basePath / "config.json")
60+
.SetFileList(basePath / "filelist.txt")
61+
.SetUsername(SignUsername)
62+
.SetSecret(SignPassword)
63+
.SetName("Silk.NET")
64+
.SetDescription("Silk.NET")
65+
.SetDescriptionUrl("https://github.com/dotnet/Silk.NET")
66+
)
67+
)
68+
);
69+
}
70+
)
71+
);
72+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.IO;
5+
using System.Linq;
6+
using System.Runtime.InteropServices;
7+
using Nuke.Common;
8+
using Nuke.Common.Tooling;
9+
using Nuke.Common.Tools.DotNet;
10+
using static Nuke.Common.IO.FileSystemTasks;
11+
using static Nuke.Common.Tools.DotNet.DotNetTasks;
12+
using static Nuke.Common.Tooling.ProcessTasks;
13+
14+
partial class Build
15+
{
16+
[Parameter("If specified, when using the clean target removes the generated solution and stops.", Name = "Sln")]
17+
readonly bool CleanSln;
18+
19+
Target Clean => CommonTarget
20+
(
21+
x => x.Before(Restore)
22+
.Executes
23+
(
24+
() =>
25+
{
26+
if (CleanSln)
27+
{
28+
DeleteFile(RootDirectory / "Silk.NET.gen.sln");
29+
return Enumerable.Empty<Output>();
30+
}
31+
32+
var outputs = Enumerable.Empty<Output>();
33+
outputs = outputs.Concat
34+
(
35+
DotNetClean
36+
(
37+
s => s.SetProject(Solution)
38+
.SetProperties(ProcessedMsbuildProperties)
39+
)
40+
);
41+
42+
if (Directory.Exists(RootDirectory / "build" / "output_packages"))
43+
{
44+
Directory.Delete(RootDirectory / "build" / "output_packages", true);
45+
}
46+
47+
Directory.CreateDirectory(RootDirectory / "build" / "output_packages");
48+
49+
if (Native)
50+
{
51+
var silkDroid = SourceDirectory / "Windowing" / "SilkDroid";
52+
using var process = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
53+
? StartProcess("bash", "-c \"./gradlew clean\"", silkDroid)
54+
: StartProcess("cmd", "/c \".\\gradlew clean\"", silkDroid);
55+
process.AssertZeroExitCode();
56+
outputs = outputs.Concat(process.Output);
57+
}
58+
else
59+
{
60+
Logger.Warn("Skipping gradlew clean as the \"native\" feature-set has not been specified.");
61+
}
62+
63+
return outputs;
64+
}
65+
)
66+
);
67+
68+
Target Restore => CommonTarget
69+
(
70+
x => x.After(Clean)
71+
.Executes
72+
(
73+
() => DotNetRestore
74+
(
75+
s => s.SetProjectFile(Solution)
76+
.SetProperties(ProcessedMsbuildProperties)
77+
)
78+
)
79+
);
80+
81+
Target Compile => CommonTarget
82+
(
83+
x => x.DependsOn(Restore)
84+
.After(Clean)
85+
.Executes
86+
(
87+
() => DotNetBuild
88+
(
89+
s => s.SetProjectFile(Solution)
90+
.SetConfiguration(Configuration)
91+
.EnableNoRestore()
92+
.SetProperties(ProcessedMsbuildProperties)
93+
)
94+
)
95+
);
96+
97+
Target Test => CommonTarget
98+
(
99+
x => x.After(Compile)
100+
.Executes
101+
(
102+
() =>
103+
{
104+
foreach (var project in Solution.GetProjects("*"))
105+
{
106+
if (project.Name.EndsWith(".Tests"))
107+
{
108+
DotNetTest(s => s.SetProjectFile(project));
109+
}
110+
}
111+
}
112+
)
113+
);
114+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.IO;
5+
using Nuke.Common;
6+
using Nuke.Common.Tools.DotNet;
7+
using static Nuke.Common.Tools.DotNet.DotNetTasks;
8+
9+
partial class Build
10+
{
11+
Target RegenerateBindings => CommonTarget
12+
(
13+
x => x.After(Clean)
14+
.DependsOn(Restore)
15+
.Executes
16+
(
17+
() =>
18+
{
19+
var project = OriginalSolution.GetProject("Silk.NET.BuildTools");
20+
if (project == default)
21+
{
22+
Logger.Error("Couldn't find BuildTools in the solution file.");
23+
return;
24+
}
25+
26+
DotNetRun
27+
(
28+
s => s.SetProjectFile(project)
29+
.SetConfiguration("Release")
30+
.SetApplicationArguments(Path.Combine(RootDirectory, "generator.json"))
31+
);
32+
}
33+
)
34+
);
35+
36+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Collections;
6+
using System.Collections.Generic;
7+
using System.IO;
8+
using System.Linq;
9+
using System.Runtime.InteropServices;
10+
using JetBrains.Annotations;
11+
using Nuke.Common;
12+
using Nuke.Common.IO;
13+
using Nuke.Common.Tooling;
14+
using Nuke.Common.Tools.DotNet;
15+
using static Nuke.Common.IO.FileSystemTasks;
16+
using static Nuke.Common.Tooling.ProcessTasks;
17+
using static Nuke.Common.Tools.DotNet.DotNetTasks;
18+
19+
partial class Build
20+
{
21+
[Parameter("Build native code")] readonly bool Native;
22+
23+
[CanBeNull] string AndroidHomeValue;
24+
25+
string AndroidHome
26+
{
27+
get
28+
{
29+
if (AndroidHomeValue is not null)
30+
{
31+
return AndroidHomeValue;
32+
}
33+
34+
var utils = RootDirectory / "build" / "utilities";
35+
DotNet($"build \"{utils / "android_probe.proj"}\" /t:GetAndroidJar");
36+
AndroidHomeValue = (AbsolutePath) File.ReadAllText(utils / "android.jar.gen.txt") / ".." / ".." / "..";
37+
Logger.Info($"Android Home: {AndroidHomeValue}");
38+
return AndroidHomeValue;
39+
}
40+
}
41+
42+
Target BuildLibSilkDroid => CommonTarget
43+
(
44+
x => x.Before(Compile)
45+
.After(Clean)
46+
.Executes
47+
(
48+
() =>
49+
{
50+
if (!Native)
51+
{
52+
Logger.Warn("Skipping gradlew build as the --native parameter has not been specified.");
53+
return Enumerable.Empty<Output>();
54+
}
55+
56+
var sdl = RootDirectory / "build" / "submodules" / "SDL";
57+
var silkDroid = SourceDirectory / "Windowing" / "SilkDroid";
58+
var xcopy = new (string, string)[]
59+
{
60+
(sdl / "android-project" / "app" / "src" / "main" / "java",
61+
silkDroid / "app" / "src" / "main" / "java"),
62+
(sdl, silkDroid / "app" / "jni" / "SDL2")
63+
};
64+
65+
foreach (var (from, to) in xcopy)
66+
{
67+
if (!Directory.Exists(from))
68+
{
69+
ControlFlow.Fail
70+
($"\"{from}\" does not exist (did you forget to recursively clone the repo?)");
71+
}
72+
73+
CopyDirectoryRecursively(from, to, DirectoryExistsPolicy.Merge, FileExistsPolicy.Overwrite);
74+
}
75+
76+
var envVars = Environment.GetEnvironmentVariables()
77+
.Cast<DictionaryEntry>()
78+
.ToDictionary(x => (string) x.Key, x => (string) x.Value);
79+
envVars["ANDROID_HOME"] = AndroidHome;
80+
81+
foreach (var ndk in Directory.GetDirectories((AbsolutePath) AndroidHome / "ndk")
82+
.OrderByDescending(x => Version.Parse(Path.GetFileName(x))))
83+
{
84+
envVars["ANDROID_NDK_HOME"] = ndk;
85+
}
86+
87+
using var process = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
88+
? StartProcess("bash", "-c \"./gradlew build\"", silkDroid, envVars)
89+
: StartProcess("cmd", "/c \".\\gradlew build\"", silkDroid, envVars);
90+
process.AssertZeroExitCode();
91+
var ret = process.Output;
92+
CopyFile
93+
(
94+
silkDroid / "app" / "build" / "outputs" / "aar" / "app-release.aar",
95+
SourceDirectory / "Windowing" / "Silk.NET.Windowing.Sdl" / "Android" / "app-release.aar",
96+
FileExistsPolicy.Overwrite
97+
);
98+
return ret;
99+
}
100+
)
101+
);
102+
}

0 commit comments

Comments
 (0)