Skip to content

Commit

Permalink
Frontend.Maui: build Maui on linux using GTK
Browse files Browse the repository at this point in the history
We use our own fork of maui for building maui-gtk since we
fixed some things.

Maui: added as submodule. Gtk workload: as automatic workload
manifest detection doesn't work for some reason, download and
uzip mainfest file so .NET knows about gtk workload.

Because of new versions of manifest, we got the following
error. So by skipping manifest update we make sure that
we don't get unwanted updates.
```
Workload installation failed: Failed to install manifest gtksharp.net.sdk.gtk version 3.24.24-rev.87-develop: gtksharp.net.sdk.gtk.manifest-6.0.300::3.24.24-rev.87-develop is not found in NuGet feeds https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-runtime-531f715f/nuget/v3/index.json;https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-emsdk-3f6c45a2/nuget/v3/index.json;https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-emsdk-3f6c45a2-1/nuget/v3/index.json;https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json;https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json;https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json;https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json;https://pkgs.dev.azure.com/xamarin/public/_packaging/SkiaSharp/nuget/v3/index.json;https://nuget.pkg.github.com/GtkSharp/index.json"..
```

Co-authored-by: webwarrior <[email protected]>
  • Loading branch information
parhamsaremi and webwarrior-ws committed Dec 12, 2024
1 parent a522d17 commit 9491d51
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 33 deletions.
35 changes: 33 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,37 @@ jobs:
linux-github--dotnet-and-mono:
runs-on: ubuntu-22.04
env:
GtkSharpVersion: 3.24.24.77-develop
DotnetVersion: 6.0.300
steps:
- uses: actions/checkout@v1
with:
submodules: false
submodules: true
# We also tested using 6.0.111 for both projects
# but MAUI failed to build on this version with this error:
# Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
# so instead we use 6.0.300
- name: Setup .NET SDK ${{ env.DotnetVersion }}
uses: actions/[email protected]
with:
dotnet-version: ${{ env.DotnetVersion }}
- name: Install gtk workload
run: |
dotnet nuget add source --username ${{ github.repository_owner }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/GtkSharp/index.json"
# For some reason automatic workload manifest detection doesn't work (see https://github.com/GtkSharp/GtkSharp/issues/355#issuecomment-1446262239), so download and uzip mainfest file manually
wget --user ${{ github.repository_owner }} --password ${{ secrets.GITHUB_TOKEN }} https://nuget.pkg.github.com/GtkSharp/download/gtksharp.net.sdk.gtk.manifest-${{ env.DotnetVersion }}/$GtkSharpVersion/gtksharp.net.sdk.gtk.manifest-${{ env.DotnetVersion }}.nupkg
DOTNET_DIR=/home/runner/.dotnet
WORKLOAD_MANIFEST_DIR=$DOTNET_DIR/sdk-manifests/${{ env.DotnetVersion }}/gtksharp.net.sdk.gtk
unzip -j gtksharp.net.sdk.gtk.manifest-${{ env.DotnetVersion }}.nupkg "data/*" -d $WORKLOAD_MANIFEST_DIR/
rm gtksharp.net.sdk.gtk.manifest-${{ env.DotnetVersion }}.nupkg
chmod 764 $WORKLOAD_MANIFEST_DIR/*
dotnet workload search
dotnet workload install gtk --skip-manifest-update
- name: Add Maui Nuget source
run: |
cd dependencies/maui
dotnet nuget add source --username ${{ github.repository_owner }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/GtkSharp/index.json"
- name: install missing dependencies
run: sudo apt install --yes fsharp nunit-console
- name: check mono version
Expand All @@ -242,6 +269,9 @@ 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 All @@ -258,7 +288,8 @@ jobs:
dotnet tool install fsxc --version ${{ env.FSXC_VERSION }}
find . -type f -name "*.fsx" | xargs -t -I {} dotnet fsxc {}
# ignore scripts/fsx submodule as compiling scripts there will result in error
find . -type f -name "*.fsx" ! -path "./scripts/fsx/*" | xargs -t -I {} dotnet fsxc {}
linux-github--dotnet-and-newmono:
runs-on: ubuntu-22.04
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "scripts/fsx"]
path = scripts/fsx
url = https://github.com/nblockchain/fsx.git
[submodule "dependencies/maui"]
path = dependencies/maui
url = https://github.com/nblockchain/CrossMaui.git
1 change: 1 addition & 0 deletions dependencies/maui
Submodule maui added at 404d6a
1 change: 1 addition & 0 deletions scripts/make.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ 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
3 changes: 2 additions & 1 deletion scripts/sanitycheck.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ let FindOffendingPrintfUsage () =
"scripts{0}" +
"src{1}GWallet.Frontend.Console{0}" +
"src{1}GWallet.Backend.Tests{0}" +
"src{1}GWallet.Backend{1}FSharpUtil.fs",
"src{1}GWallet.Backend{1}FSharpUtil.fs{0}" +
"dependencies",
Path.PathSeparator,
Path.DirectorySeparatorChar
)
Expand Down
3 changes: 2 additions & 1 deletion src/GWallet.Frontend.Maui/App.xaml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ open Microsoft.Maui.Controls.Xaml

type App() as this =
inherit Application()
let GlobalState = GlobalState()

do this.LoadFromXaml typeof<App> |> ignore<App>
do this.MainPage <- AppShell()
do this.MainPage <- (WelcomePage GlobalState) :> Page
14 changes: 0 additions & 14 deletions src/GWallet.Frontend.Maui/AppShell.xaml

This file was deleted.

9 changes: 0 additions & 9 deletions src/GWallet.Frontend.Maui/AppShell.xaml.fs

This file was deleted.

32 changes: 28 additions & 4 deletions src/GWallet.Frontend.Maui/GWallet.Frontend.Maui.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<!-- NOTE: when making changes to the lines below, maybe remove CheckEolWorkloads tag too -->
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('linux'))">net6.0-gtk</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net6.0-tizen</TargetFrameworks> -->

Expand Down Expand Up @@ -43,17 +44,33 @@
<PropertyGroup>
<GenerateRuntimeConfigurationFiles>false</GenerateRuntimeConfigurationFiles>
</PropertyGroup>
<PropertyGroup Condition="$(TargetPlatformIdentifier) == 'gtk'">
<UseMaui>false</UseMaui>
<MauiSubmodulePath>$(MSBuildProjectDirectory)\..\..\dependencies\maui\</MauiSubmodulePath>
<_MauiBuildTasksLocation>$(MauiSubmodulePath).nuspec\</_MauiBuildTasksLocation>
<GtkProjectFolder>Platforms\Gtk\</GtkProjectFolder>
</PropertyGroup>

<ItemGroup Condition="$(TargetPlatformIdentifier) == 'gtk'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.5" />
<ProjectReference Include="$(MauiSubmodulePath)src\BlazorWebView\src\Maui\Microsoft.AspNetCore.Components.WebView.Maui.csproj" />
<ProjectReference Include="$(MauiSubmodulePath)src\Essentials\src\Essentials.csproj" />
<ProjectReference Include="$(MauiSubmodulePath)src\Controls\src\Core\Controls.Core.csproj" />
<ProjectReference Include="$(MauiSubmodulePath)src\Controls\src\Xaml\Controls.Xaml.csproj" />
<ProjectReference Include="$(MauiSubmodulePath)src\Core\src\Core.csproj" />
<ProjectReference Include="$(MauiSubmodulePath)src\Compatibility\Core\src\Compatibility.csproj" />
<ProjectReference Include="$(MauiSubmodulePath)src\Controls\Foldable\src\Controls.Foldable.csproj" />
<ProjectReference Include="$(MauiSubmodulePath)src\Controls\Maps\src\Controls.Maps.csproj" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="WelcomePage.xaml" />
<Compile Include="..\GWallet.Frontend.XF\FrontendHelpers.fs" />
<Compile Include="..\GWallet.Frontend.XF\GlobalState.fs" />
<Compile Include="..\GWallet.Frontend.XF\WelcomePage.xaml.fs">
<DependentUpon>WelcomePage.xaml</DependentUpon>
</Compile>
<EmbeddedResource Include="AppShell.xaml" />
<Compile Include="AppShell.xaml.fs">
<DependentUpon>AppShell.xaml</DependentUpon>
</Compile>
<EmbeddedResource Include="App.xaml" />
<Compile Include="App.xaml.fs">
<DependentUpon>App.xaml</DependentUpon>
Expand Down Expand Up @@ -89,6 +106,11 @@
<PackageReference Include="FSharp.Core" Version="6.0.3" />
</ItemGroup>

<ItemGroup Condition="$(TargetPlatformIdentifier) == 'gtk'">
<Compile Include="$(GtkProjectFolder)GtkApp.fs" />
<Compile Include="$(GtkProjectFolder)Program.fs" />
</ItemGroup>

<ItemGroup Condition="$(TargetPlatformIdentifier) == 'android'">
<AndroidResource Include="$(MonoAndroidResourcePrefix)/*/*" />
<AndroidResource Remove="$(MonoAndroidResourcePrefix)/raw/.*" />
Expand Down Expand Up @@ -133,5 +155,7 @@
<ItemGroup>
<ProjectReference Include="..\GWallet.Backend\GWallet.Backend.fsproj" />
</ItemGroup>

<Import Condition="$(TargetPlatformIdentifier) == 'gtk'" Project="$(MauiSubmodulePath)src\Maui.InTree.props" />

</Project>
14 changes: 12 additions & 2 deletions src/GWallet.Frontend.Maui/MauiProgram.fs
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
namespace GWallet.Frontend.Maui

open Microsoft.Maui.Hosting
#if GTK
open Gdk
open Microsoft.Extensions.Configuration
open Microsoft.Extensions.DependencyInjection
open Microsoft.Extensions.DependencyInjection.Extensions
#endif
open Microsoft.Maui.Controls.Compatibility.Hosting
open Microsoft.Maui.Controls.Hosting
open Microsoft.Maui.Hosting

type MauiProgram =
static member CreateMauiApp() =
MauiApp
.CreateBuilder()
.UseMauiApp<App>()
#if GTK
.UseMauiCompatibility()
#endif
.ConfigureFonts(fun fonts ->
fonts
.AddFont("OpenSans-Regular.ttf", "OpenSansRegular")
.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold")
|> ignore
)
.Build()
.Build()
12 changes: 12 additions & 0 deletions src/GWallet.Frontend.Maui/Platforms/Gtk/GtkApp.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace GWallet.Frontend.Maui

open System
open Gtk
open Microsoft.Maui
open Microsoft.Maui.Graphics
open Microsoft.Maui.Hosting

type GtkApp() =
inherit MauiGtkApplication()

override _.CreateMauiApp() = MauiProgram.CreateMauiApp()
15 changes: 15 additions & 0 deletions src/GWallet.Frontend.Maui/Platforms/Gtk/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace GWallet.Frontend.Maui

open System
open System.Threading.Tasks
open GLib
open Microsoft.Extensions.Hosting
open Microsoft.Maui
open Microsoft.Maui.Hosting

module Program =
[<EntryPoint>]
let main _args =
let app = GtkApp()
app.Run()
0

0 comments on commit 9491d51

Please sign in to comment.