From 9e6b82b9bfc4e9740cb5849ff3dd13c45152f8c3 Mon Sep 17 00:00:00 2001 From: webwarrior Date: Thu, 16 Feb 2023 12:00:45 +0100 Subject: [PATCH] scripts,GitHubCI,Backend: add .NET6 snap Use .NET6 to build snap package. Publish Frontend.Console as single executable in in snap_build script. Modified launch script to point to gwallet executable generated with new settings. Set InvariantGlobalization to true in Backend and Frontend.Console projects to fix error when launching gwallet installed by snap. Error in question was: ``` Process terminated. Couldn't find a valid ICU package installed on the system. Please install libicu using your package manager and try again. Alternatively you can set the configuration flag System.Globalization.Invariant to true if you want to run with no globalization support. ``` Set correct configPath when GWallet is in a snap package. Build mono snap package alongside .net6. Also upload mono snap package as artifact and test it. It is needed because the frontend branch can't switch yet to dotnet-based snap. When building snap package with .NET6, only include single-file executable in package. Added "publish" command to make.fsx and Makefile. --- .github/workflows/CI.yml | 34 +++++++++- Makefile | 3 + scripts/make.fsx | 66 ++++++++++++++++++- scripts/snap_build.sh | 4 ++ src/GWallet.Backend/Config.fs | 22 ++++--- src/GWallet.Backend/GWallet.Backend.fsproj | 1 + .../GWallet.Frontend.Console.fsproj | 1 + 7 files changed, 119 insertions(+), 12 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 80dbad177..8f8a7a028 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -516,7 +516,7 @@ jobs: if: github.event_name == 'pull_request' run: ./conventions/commitlint.sh --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose - snap_pkg: + snap_pkg_mono: needs: - conventions @@ -551,7 +551,37 @@ jobs: - uses: actions/upload-artifact@v3 name: Upload snap package as artifact with: - name: snap + name: snap-mono + path: ./*.snap + + snap_pkg_dotnet: + + needs: + - conventions + + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v1 + - name: Install snap tools + run: | + sudo apt update + ./scripts/install_snapcraft.sh + + - name: Generate snap package + run: | + ./scripts/snap_build.sh + + - name: Install snap + # dangerous because it's a local snap (not one from the SnapStore) + run: sudo snap install --dangerous *.snap + + - name: Test snap + run: gwallet --version + + - uses: actions/upload-artifact@v3 + name: Upload snap package as artifact + with: + name: snap-dotnet path: ./*.snap - name: Upload snap package to Snap Store diff --git a/Makefile b/Makefile index 45cf347b2..fc5a12536 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,9 @@ check: release: @./scripts/make.sh release + +publish: + @./scripts/make.sh publish zip: @./scripts/make.sh zip diff --git a/scripts/make.fsx b/scripts/make.fsx index 2b3d5164f..20a24a165 100644 --- a/scripts/make.fsx +++ b/scripts/make.fsx @@ -4,6 +4,8 @@ open System open System.IO open System.Linq open System.Diagnostics +open System.Runtime.InteropServices + #if !LEGACY_FRAMEWORK #r "nuget: Fsdk, Version=0.6.0--date20230818-1152.git-83d671b" @@ -117,6 +119,17 @@ let prefix = buildConfigContents |> GetOrExplain "Prefix" let libPrefixDir = DirectoryInfo (Path.Combine (prefix, "lib", UNIX_NAME)) let binPrefixDir = DirectoryInfo (Path.Combine (prefix, "bin")) + +let GetRuntimeId () = + let osName = + match Misc.GuessPlatform() with + | Misc.Platform.Linux -> "linux" + | Misc.Platform.Windows -> "win" + | Misc.Platform.Mac -> "osx" + let archName = RuntimeInformation.ProcessArchitecture.ToString().ToLower() + sprintf "%s-%s" osName archName + +#if LEGACY_FRAMEWORK let wrapperScript = """#!/usr/bin/env bash set -eo pipefail @@ -133,6 +146,19 @@ DIR_OF_THIS_SCRIPT=$(dirname "$(realpath "$0")") FRONTEND_PATH="$DIR_OF_THIS_SCRIPT/../lib/$UNIX_NAME/$GWALLET_PROJECT.exe" exec mono "$FRONTEND_PATH" "$@" """ +#else +let wrapperScript = """#!/usr/bin/env bash +set -eo pipefail +DIR_OF_THIS_SCRIPT=$(dirname "$(realpath "$0")") +FRONTEND_PATH="$DIR_OF_THIS_SCRIPT/../lib/$UNIX_NAME/$GWALLET_PROJECT" +arch=$(uname -i) +if [ "$arch" != 'x86_64' ]; then + echo "$arch not supported (only x86_64 is supported for now), please file a bug" + exit 1 +fi +exec "$FRONTEND_PATH" "$@" +""" +#endif let NugetRestore (projectOrSolution: FileInfo) = let nugetArgs = @@ -581,6 +607,33 @@ match maybeTarget with | _ -> () #endif +| Some "publish" -> +#if LEGACY_FRAMEWORK + failwith "Legacy frameworks don't support publish command" +#else + let buildConfig = BinaryConfig.Release + let frontend,_ = JustBuild buildConfig None + + let projectFile = + Path.Combine ( + FsxHelper.RootDir.FullName, + "src", + frontend.GetProjectName(), + frontend.GetProjectName() + ".fsproj") + |> FileInfo + let runtimeId = GetRuntimeId() + let publishCommand = + { + Command = "dotnet" + Arguments = + sprintf + "publish --configuration Release -property:PublishSingleFile=true --self-contained true --runtime %s %s" + runtimeId + projectFile.FullName + } + Process.Execute(publishCommand, Echo.All).UnwrapDefault() + |> ignore +#endif | Some("install") -> let buildConfig = BinaryConfig.Release @@ -608,7 +661,18 @@ match maybeTarget with Console.WriteLine "Installing..." Console.WriteLine () - Misc.CopyDirectoryRecursively (mainBinariesDir buildConfig, libDestDir, []) + + let publishDir = + Path.Combine ((mainBinariesDir buildConfig).FullName, "net6.0", GetRuntimeId(), "publish") + |> DirectoryInfo + if publishDir.Exists then + // single-file app + let executable = Path.Combine(publishDir.FullName, frontend.GetProjectName()) |> FileInfo + if not libDestDir.Exists then + libDestDir.Create() + executable.CopyTo(Path.Combine(libDestDir.FullName, frontend.GetProjectName()), true) |> ignore + else + Misc.CopyDirectoryRecursively (mainBinariesDir buildConfig, libDestDir, List.Empty) let finalLauncherScriptInDestDir = Path.Combine(binDestDir.FullName, launcherScriptFile.Name) |> FileInfo if not (Directory.Exists(finalLauncherScriptInDestDir.Directory.FullName)) then diff --git a/scripts/snap_build.sh b/scripts/snap_build.sh index 3196aa8db..03a878929 100755 --- a/scripts/snap_build.sh +++ b/scripts/snap_build.sh @@ -10,6 +10,10 @@ rm -rf ./staging ./configure.sh --prefix=./staging "$@" make +if [ `which dotnet` ] +then + make publish +fi make install snapcraft --destructive-mode diff --git a/src/GWallet.Backend/Config.fs b/src/GWallet.Backend/Config.fs index 9ccbf1ccf..d8f44aa08 100644 --- a/src/GWallet.Backend/Config.fs +++ b/src/GWallet.Backend/Config.fs @@ -75,15 +75,19 @@ module Config = let internal GetConfigDirForThisProgram() = let configPath = -(* NOTE: we used to support UWP via the Xamarin.Essentials code below, but MAUI is a higher priority than resurrecting UWP now: - if (not isWindows) || Xamarin.Essentials.DeviceInfo.Platform <> Xamarin.Essentials.DevicePlatform.UWP then - Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) - else //UWP - Xamarin.Essentials.FileSystem.AppDataDirectory -*) - Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) - - // TODO: rename to "geewallet", following a similar approach as DAI->SAI rename + match Environment.GetEnvironmentVariable "SNAP" with + | snapVar when not (String.IsNullOrEmpty snapVar) -> + match Environment.GetEnvironmentVariable "HOME" with + | homeVar when not (String.IsNullOrEmpty homeVar) -> + homeVar + snapVar + ".config" + | _ -> failwith "$HOME environment variable is absent or empty" + (* NOTE: we used to support UWP via the Xamarin.Essentials code below, but MAUI is a higher priority than resurrecting UWP now: + if (not isWindows) || Xamarin.Essentials.DeviceInfo.Platform <> Xamarin.Essentials.DevicePlatform.UWP then + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + else //UWP + Xamarin.Essentials.FileSystem.AppDataDirectory + *) + | _ -> Environment.GetFolderPath Environment.SpecialFolder.ApplicationData let configDir = DirectoryInfo(Path.Combine(configPath, "gwallet")) if not configDir.Exists then configDir.Create() diff --git a/src/GWallet.Backend/GWallet.Backend.fsproj b/src/GWallet.Backend/GWallet.Backend.fsproj index 75e953bc2..73d325f49 100644 --- a/src/GWallet.Backend/GWallet.Backend.fsproj +++ b/src/GWallet.Backend/GWallet.Backend.fsproj @@ -3,6 +3,7 @@ netstandard2.0 true + true diff --git a/src/GWallet.Frontend.Console/GWallet.Frontend.Console.fsproj b/src/GWallet.Frontend.Console/GWallet.Frontend.Console.fsproj index 5acc9469f..cfa3193f8 100644 --- a/src/GWallet.Frontend.Console/GWallet.Frontend.Console.fsproj +++ b/src/GWallet.Frontend.Console/GWallet.Frontend.Console.fsproj @@ -1,6 +1,7 @@  netstandard2.0 + true