Skip to content

Commit 1d05cdf

Browse files
committed
scripts,CI: determine & build frontend in scripts
Determine frontend to be built in configure script and build it in make script. Have 2 variants of global.json (one for MAUI/Gtk with .NET6 and one for other MAUI platfoprms with .NET8) and choose appropriate one in configure script.
1 parent d79213a commit 1d05cdf

File tree

5 files changed

+51
-35
lines changed

5 files changed

+51
-35
lines changed

.github/workflows/CI.yml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,12 @@ jobs:
2626
uses: actions/[email protected]
2727
with:
2828
dotnet-version: '8.0.300'
29-
- name: Replace global.json in root dir
30-
run: |
31-
# Use global.json from src/GWallet.Frontend.Maui as it specifies .NET8
32-
cp ./src/GWallet.Frontend.Maui/global.json ./
3329
- name: install maui workload
3430
run: dotnet workload install maui
3531
- name: configure
3632
run: ./configure.sh
3733
- name: build in DEBUG mode
3834
run: make
39-
- name: Build Maui Android frontend
40-
run: dotnet build src/GWallet.Frontend.Maui/GWallet.Frontend.Maui.fsproj --framework=net8.0-android
4135
- name: Build Android APK
4236
run: dotnet publish src/GWallet.Frontend.Maui/GWallet.Frontend.Maui.fsproj --framework net8.0-android --configuration Release
4337
# Upload artifact fails with "permission denied" error without this
@@ -226,10 +220,6 @@ jobs:
226220
uses: actions/[email protected]
227221
with:
228222
dotnet-version: ${{ env.DotnetVersion }}
229-
- name: Replace global.json in src/GWallet.Frontend.Maui
230-
run: |
231-
# Use global.json from root as it specifies .NET6
232-
cp ./global.json ./src/GWallet.Frontend.Maui/
233223
- name: Install gtk workload
234224
run: |
235225
wget -O gtksharp.net.sdk.gtk.manifest-${{ env.DotnetVersion }}.nupkg https://globalcdn.nuget.org/packages/gtksharp.net.sdk.gtk.manifest-${{ env.DotnetVersion }}.$GtkSharpVersion.nupkg
@@ -254,9 +244,6 @@ jobs:
254244
run: ./configure.sh
255245
- name: build in DEBUG mode
256246
run: make
257-
- name: build Maui frontend
258-
run: |
259-
dotnet build src/GWallet.Frontend.Maui/GWallet.Frontend.Maui.fsproj --framework=net6.0-gtk
260247
- name: sanity check
261248
run: make sanitycheck
262249
- name: unit tests
@@ -667,11 +654,6 @@ jobs:
667654
run: |
668655
git submodule foreach git fetch --all && git submodule sync --recursive && git submodule update --init --recursive
669656
dotnet fsi ./scripts/snap_bump.fsx
670-
671-
- name: Replace global.json in src/GWallet.Frontend.Maui
672-
run: |
673-
# Use global.json from root as it specifies .NET6
674-
cp ./global.json ./src/GWallet.Frontend.Maui/
675657
676658
- name: Generate snap package
677659
run: ./scripts/snap_build_maui.sh || (cat /home/runner/.local/state/snapcraft/log/*.log && exit 1)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "6.0.113",
3+
"version": "6.0.400",
44
"rollForward": "latestMinor"
55
}
6-
}
6+
}

src/GWallet.Frontend.Maui/global.json renamed to global-net8.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"version": "8.0.0",
44
"rollForward": "latestMinor"
55
}
6-
}
6+
}

scripts/configure.fsx

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
open System
44
open System.IO
55
open System.Linq
6+
open System.Text.RegularExpressions
67

78
#if !LEGACY_FRAMEWORK
89
#r "nuget: Fsdk, Version=0.6.0--date20231031-0834.git-2737eea"
@@ -202,9 +203,34 @@ let AddToDefinedConstants (constant: string) (configMap: Map<string, string>) =
202203
configMap
203204
|> Map.add configKey (sprintf "%s;%s" previousConstants constant)
204205

206+
let mauiWorkloads =
207+
match buildTool with
208+
| Some "dotnet" ->
209+
let workloadListResult =
210+
Process
211+
.Execute({ Command = "dotnet"; Arguments = "workload list" }, Echo.All)
212+
.Unwrap("dotnet workload list command failed")
213+
Regex.Matches(workloadListResult, "^(maui[a-zA-Z0-9\\-]*)", RegexOptions.Multiline).Cast<Match>()
214+
|> Seq.map (fun each -> each.Value)
215+
|> Seq.toList
216+
| _ -> List.Empty
217+
218+
let frontend =
219+
if not (List.isEmpty mauiWorkloads) then
220+
if mauiWorkloads |> List.exists (fun workload -> workload.Contains "gtk") then
221+
"Maui/Gtk"
222+
else
223+
"Maui"
224+
elif areGtkLibsAbsentOrDoesNotApply then
225+
"Console"
226+
else
227+
"Xamarin.Forms"
205228

206229
let configFileToBeWritten =
207-
let initialConfigFile = Map.empty.Add("Prefix", prefix.FullName)
230+
let initialConfigFile =
231+
Map.empty
232+
.Add("Prefix", prefix.FullName)
233+
.Add("Frontend", frontend)
208234

209235
let configFileStageTwo =
210236
match legacyBuildTool with
@@ -240,12 +266,14 @@ let version = Misc.GetCurrentVersion(rootDir)
240266

241267
let repoInfo = Git.GetRepoInfo()
242268

243-
let frontend =
244-
if areGtkLibsAbsentOrDoesNotApply then
245-
"Console"
246-
else
247-
"Xamarin.Forms"
248-
269+
if not (List.isEmpty mauiWorkloads) then
270+
let globalJsonFile =
271+
if frontend = "Maui/Gtk" then
272+
"global-net6.json"
273+
else
274+
"global-net8.json"
275+
276+
File.Copy(globalJsonFile, "global.json")
249277

250278
Console.WriteLine()
251279
Console.WriteLine(sprintf

scripts/make.fsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,17 @@ type FrontendProject =
5353
type FrontendApp =
5454
| Console
5555
| Gtk
56+
| Maui
5657
member self.GetProjectName() =
5758
match self with
5859
| Console -> CONSOLE_FRONTEND_APP
5960
| Gtk -> GTK_FRONTEND_APP
61+
| Maui -> MAUI_FRONTEND_APP
6062
member self.GetExecutableName() =
6163
match self with
6264
| Console -> CONSOLE_FRONTEND_APP
6365
| Gtk -> UNIX_NAME
66+
| Maui -> MAUI_FRONTEND_APP
6467
override self.ToString() =
6568
sprintf "%A" self
6669

@@ -310,17 +313,14 @@ let DotNetBuild
310313
()
311314
| _ -> ()
312315

313-
// We have to build Maui project for android twice because the first time we get
314-
// an error about Resource file not found. The second time it works.
315-
// https://github.com/fabulous-dev/FSharp.Mobile.Templates/tree/55a1f3a0fd5cc397e48677ef4ff9241b360b0e84
316-
let BuildMauiProject binaryConfig =
316+
let BuildMauiProject (binaryConfig: BinaryConfig) (frameworkIdentifier: string) =
317317
let mauiProjectFilePath = FrontendProject.Maui.GetProjectFile().FullName
318-
DotNetBuild mauiProjectFilePath binaryConfig "--framework net8.0-android" true
319-
DotNetBuild mauiProjectFilePath binaryConfig "--framework net8.0-android" false
318+
DotNetBuild mauiProjectFilePath binaryConfig (sprintf "--framework %s" frameworkIdentifier) true
320319

321320
let JustBuild binaryConfig maybeConstant: FrontendApp*FileInfo =
322321
let maybeBuildTool = Map.tryFind "BuildTool" buildConfigContents
323322
let maybeLegacyBuildTool = Map.tryFind "LegacyBuildTool" buildConfigContents
323+
let maybeConfigFrontend = Map.tryFind "Frontend" buildConfigContents
324324

325325
let solutionFile = FsxHelper.GetSolution SolutionFile.Default
326326
let getBuildToolAndArgs(buildTool: string) =
@@ -381,7 +381,6 @@ let JustBuild binaryConfig maybeConstant: FrontendApp*FileInfo =
381381
// somehow, msbuild doesn't restore the frontend dependencies (e.g. Xamarin.Forms) when targetting
382382
// the {LINUX|MAC}_SOLUTION_FILE below, so we need this workaround. TODO: just finish migrating to MAUI(dotnet restore)
383383
NugetRestore solution
384-
CopyXamlFiles()
385384
MSBuildRestoreAndBuild solution
386385

387386
FrontendApp.Console
@@ -398,6 +397,13 @@ let JustBuild binaryConfig maybeConstant: FrontendApp*FileInfo =
398397
FrontendApp.Console
399398

400399
| _ -> FrontendApp.Console
400+
| Some "dotnet", _ when maybeConfigFrontend |> Option.exists (fun value -> value.StartsWith "Maui") ->
401+
if maybeConfigFrontend = Some "Maui/Gtk" then
402+
BuildMauiProject binaryConfig "net6.0-gtk"
403+
else
404+
BuildMauiProject binaryConfig "net8.0-android"
405+
406+
FrontendApp.Maui
401407
| Some buildTool, Some legacyBuildTool when buildTool = "dotnet" && legacyBuildTool = "xbuild" ->
402408
if FsxHelper.AreGtkLibsPresent Echo.All then
403409
BuildSolutionOrProject

0 commit comments

Comments
 (0)