Skip to content

Commit

Permalink
scripts,CI: determine & build frontend in scripts
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
webwarrior-ws committed May 28, 2024
1 parent d79213a commit 9a1456f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 36 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,12 @@ jobs:
uses: actions/setup-dotnet@v1.7.2
with:
dotnet-version: '8.0.300'
- name: Replace global.json in root dir
run: |
# Use global.json from src/GWallet.Frontend.Maui as it specifies .NET8
cp ./src/GWallet.Frontend.Maui/global.json ./
- name: install maui workload
run: dotnet workload install maui
- name: configure
run: ./configure.sh
- name: build in DEBUG mode
run: make
- name: Build Maui Android frontend
run: dotnet build src/GWallet.Frontend.Maui/GWallet.Frontend.Maui.fsproj --framework=net8.0-android
- name: Build Android APK
run: dotnet publish src/GWallet.Frontend.Maui/GWallet.Frontend.Maui.fsproj --framework net8.0-android --configuration Release
# Upload artifact fails with "permission denied" error without this
Expand Down Expand Up @@ -226,10 +220,6 @@ jobs:
uses: actions/setup-dotnet@v1.7.2
with:
dotnet-version: ${{ env.DotnetVersion }}
- name: Replace global.json in src/GWallet.Frontend.Maui
run: |
# Use global.json from root as it specifies .NET6
cp ./global.json ./src/GWallet.Frontend.Maui/
- name: Install gtk workload
run: |
wget -O gtksharp.net.sdk.gtk.manifest-${{ env.DotnetVersion }}.nupkg https://globalcdn.nuget.org/packages/gtksharp.net.sdk.gtk.manifest-${{ env.DotnetVersion }}.$GtkSharpVersion.nupkg
Expand All @@ -254,9 +244,6 @@ jobs:
run: ./configure.sh
- name: build in DEBUG mode
run: make
- name: build Maui frontend
run: |
dotnet build src/GWallet.Frontend.Maui/GWallet.Frontend.Maui.fsproj --framework=net6.0-gtk
- name: sanity check
run: make sanitycheck
- name: unit tests
Expand Down Expand Up @@ -667,11 +654,6 @@ jobs:
run: |
git submodule foreach git fetch --all && git submodule sync --recursive && git submodule update --init --recursive
dotnet fsi ./scripts/snap_bump.fsx
- name: Replace global.json in src/GWallet.Frontend.Maui
run: |
# Use global.json from root as it specifies .NET6
cp ./global.json ./src/GWallet.Frontend.Maui/
- name: Generate snap package
run: ./scripts/snap_build_maui.sh || (cat /home/runner/.local/state/snapcraft/log/*.log && exit 1)
Expand Down
4 changes: 2 additions & 2 deletions global.json → global-net6.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.113",
"version": "6.0.400",
"rollForward": "latestMinor"
}
}
}
2 changes: 1 addition & 1 deletion src/GWallet.Frontend.Maui/global.json → global-net8.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"version": "8.0.0",
"rollForward": "latestMinor"
}
}
}
42 changes: 35 additions & 7 deletions scripts/configure.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
open System
open System.IO
open System.Linq
open System.Text.RegularExpressions

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

let mauiWorkloads =
match buildTool with
| Some "dotnet" ->
let workloadListResult =
Process
.Execute({ Command = "dotnet"; Arguments = "workload list" }, Echo.All)
.Unwrap("dotnet workload list command failed")
Regex.Matches(workloadListResult, "^(maui[a-zA-Z0-9\\-]*)", RegexOptions.Multiline)
|> Seq.map (fun each -> each.Value)
|> Seq.toList
| _ -> List.Empty

let frontend =
if not (List.isEmpty mauiWorkloads) then
if mauiWorkloads |> List.exists (fun workload -> workload.Contains "gtk") then
"Maui/Gtk"
else
"Maui"
elif areGtkLibsAbsentOrDoesNotApply then
"Console"
else
"Xamarin.Forms"

let configFileToBeWritten =
let initialConfigFile = Map.empty.Add("Prefix", prefix.FullName)
let initialConfigFile =
Map.empty
.Add("Prefix", prefix.FullName)
.Add("Frontend", frontend)

let configFileStageTwo =
match legacyBuildTool with
Expand Down Expand Up @@ -240,12 +266,14 @@ let version = Misc.GetCurrentVersion(rootDir)

let repoInfo = Git.GetRepoInfo()

let frontend =
if areGtkLibsAbsentOrDoesNotApply then
"Console"
else
"Xamarin.Forms"

if not (List.isEmpty mauiWorkloads) then
let globalJsonFile =
if frontend = "Maui/Gtk" then
"global-net6.json"
else
"global-net8.json"

File.Copy(globalJsonFile, "global.json")

Console.WriteLine()
Console.WriteLine(sprintf
Expand Down
22 changes: 14 additions & 8 deletions scripts/make.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,17 @@ type FrontendProject =
type FrontendApp =
| Console
| Gtk
| Maui
member self.GetProjectName() =
match self with
| Console -> CONSOLE_FRONTEND_APP
| Gtk -> GTK_FRONTEND_APP
| Maui -> MAUI_FRONTEND_APP
member self.GetExecutableName() =
match self with
| Console -> CONSOLE_FRONTEND_APP
| Gtk -> UNIX_NAME
| Maui -> MAUI_FRONTEND_APP
override self.ToString() =
sprintf "%A" self

Expand Down Expand Up @@ -310,17 +313,15 @@ let DotNetBuild
()
| _ -> ()

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

let JustBuild binaryConfig maybeConstant: FrontendApp*FileInfo =
let maybeBuildTool = Map.tryFind "BuildTool" buildConfigContents
let maybeLegacyBuildTool = Map.tryFind "LegacyBuildTool" buildConfigContents
let maybeConfigFrontend = Map.tryFind "Frontend" buildConfigContents

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

FrontendApp.Console
Expand All @@ -398,6 +398,13 @@ let JustBuild binaryConfig maybeConstant: FrontendApp*FileInfo =
FrontendApp.Console

| _ -> FrontendApp.Console
| Some "dotnet", _ when maybeConfigFrontend |> Option.exists (fun value -> value.StartsWith "Maui") ->
if maybeConfigFrontend = Some "Maui/Gtk" then
BuildMauiProject binaryConfig "net6.0-gtk"
else
BuildMauiProject binaryConfig "net8.0-android"

FrontendApp.Maui
| Some buildTool, Some legacyBuildTool when buildTool = "dotnet" && legacyBuildTool = "xbuild" ->
if FsxHelper.AreGtkLibsPresent Echo.All then
BuildSolutionOrProject
Expand Down Expand Up @@ -481,7 +488,6 @@ let MakeAll (maybeConstant: Option<string>) =
#endif
let buildConfig = BinaryConfig.Debug
let frontend,_ = JustBuild buildConfig maybeConstant
CopyXamlFiles()
frontend,buildConfig

let RunFrontend (frontend: FrontendApp) (buildConfig: BinaryConfig) (maybeArgs: Option<string>) =
Expand Down

0 comments on commit 9a1456f

Please sign in to comment.