diff --git a/docs/hello-platform.md b/docs/hello-platform.md index 510ca2b..c345250 100644 --- a/docs/hello-platform.md +++ b/docs/hello-platform.md @@ -223,3 +223,21 @@ it installs the executable, launcher and icon for the current user and refreshes the desktop/icon caches. It requires GNU sed, gtk-update-icon-cache and update-desktop-database. The standalone `install-linux` script has been replaced by this packaging step. + +## Windows (WinUI) + +`ver-windows/` mirrors the Linux SwiftCrossUI target with `WinUIBackend`. +It shares the counter component, model, view, and generated Swift dialect via +relative symlinks. Check out the repository with Git symlinks enabled on Windows +(Developer Mode or appropriate symlink permissions are needed). + +With the Windows Swift toolchain, Windows SDK, and the Windows App SDK runtime +required by SwiftCrossUI's WinUI backend installed, run in Git Bash from `hello/hello-platform`: + +```bash +util/build-windows +util/run-windows +``` + +The build uses the existing generated Swift dialect, like the Linux build. +The run script locates the existing debug executable without rebuilding it. diff --git a/hello/hello-platform/util/build-windows b/hello/hello-platform/util/build-windows new file mode 100755 index 0000000..e7a2826 --- /dev/null +++ b/hello/hello-platform/util/build-windows @@ -0,0 +1,8 @@ +#!/bin/bash -e +SDIR=$(cd "$(dirname "$0")" && pwd -P) + +T=$SDIR/step +TARGET=hello-platform + +STEP=0 +source "$T/buildWindows" "$TARGET" diff --git a/hello/hello-platform/util/run-windows b/hello/hello-platform/util/run-windows new file mode 100755 index 0000000..143dec8 --- /dev/null +++ b/hello/hello-platform/util/run-windows @@ -0,0 +1,8 @@ +#!/bin/bash -e +SDIR=$(cd "$(dirname "$0")" && pwd -P) + +T=$SDIR/step +TARGET=hello-platform + +STEP=0 +source "$T/runWindows" "$TARGET" diff --git a/hello/hello-platform/util/step/buildWindows b/hello/hello-platform/util/step/buildWindows new file mode 100644 index 0000000..9fbdf61 --- /dev/null +++ b/hello/hello-platform/util/step/buildWindows @@ -0,0 +1,7 @@ +#!/bin/bash -e + +TARGET=$1 +STEP=$((STEP+1)) +echo "Step $STEP: build $TARGET for Windows" + +swift build --package-path "$(cygpath -m "$SDIR/../ver-windows")" diff --git a/hello/hello-platform/util/step/runWindows b/hello/hello-platform/util/step/runWindows new file mode 100644 index 0000000..17fff94 --- /dev/null +++ b/hello/hello-platform/util/step/runWindows @@ -0,0 +1,13 @@ +#!/bin/bash -e + +TARGET=$1 +STEP=$((STEP+1)) +echo "Step $STEP: run $TARGET for Windows" + +BIN_DIR=$(swift build --package-path "$(cygpath -m "$SDIR/../ver-windows")" --show-bin-path) +EXE="$(cygpath -u "${BIN_DIR%$'\r'}")/$TARGET.exe" +if [[ ! -f "$EXE" ]]; then + echo "Run util/build-windows first." >&2 + exit 1 +fi +exec "$EXE" diff --git a/hello/hello-platform/ver-windows/Package.swift b/hello/hello-platform/ver-windows/Package.swift new file mode 100644 index 0000000..954fe46 --- /dev/null +++ b/hello/hello-platform/ver-windows/Package.swift @@ -0,0 +1,19 @@ +// swift-tools-version: 5.10 +import PackageDescription + +let package = Package( + name: "hello-platform", + dependencies: [ + .package(url: "https://github.com/moreSwift/swift-cross-ui", branch: "v0.10.0") + ], + targets: [ + .executableTarget( + name: "hello-platform", + dependencies: [ + .product(name: "WinUIBackend", package: "swift-cross-ui"), + .product(name: "SwiftCrossUI", package: "swift-cross-ui") + ], + path: "src" + ) + ] +) diff --git a/hello/hello-platform/ver-windows/src/HPApp.swift b/hello/hello-platform/ver-windows/src/HPApp.swift new file mode 100644 index 0000000..8ccedd9 --- /dev/null +++ b/hello/hello-platform/ver-windows/src/HPApp.swift @@ -0,0 +1,14 @@ +import WinUIBackend +import SwiftCrossUI + +@main +struct HPApp: App { + let delegate = HPAppDelegate() + + var body: some Scene { + WindowGroup("Hello platform") { + HPView(delegate.hpVM) + } + } +} + diff --git a/hello/hello-platform/ver-windows/src/HPAppDelegate.swift b/hello/hello-platform/ver-windows/src/HPAppDelegate.swift new file mode 100644 index 0000000..574afa6 --- /dev/null +++ b/hello/hello-platform/ver-windows/src/HPAppDelegate.swift @@ -0,0 +1,11 @@ +import SwiftCrossUI + +final class HPAppDelegate { + let hp = HPComponent() + let hpVM = HPVM() + + init() { + otherSetupConsoleLogging(hp.ctrl, "HP") + hp.setup() + } +} diff --git a/hello/hello-platform/ver-windows/src/dialect.swift b/hello/hello-platform/ver-windows/src/dialect.swift new file mode 120000 index 0000000..a931c95 --- /dev/null +++ b/hello/hello-platform/ver-windows/src/dialect.swift @@ -0,0 +1 @@ +../../ver-mac/src/dialect.swift \ No newline at end of file diff --git a/hello/hello-platform/ver-windows/src/hp/hp.swift b/hello/hello-platform/ver-windows/src/hp/hp.swift new file mode 120000 index 0000000..3df34ea --- /dev/null +++ b/hello/hello-platform/ver-windows/src/hp/hp.swift @@ -0,0 +1 @@ +../../../../../components/hp/linux/hp.swift \ No newline at end of file diff --git a/hello/hello-platform/ver-windows/src/hp/hpVM.swift b/hello/hello-platform/ver-windows/src/hp/hpVM.swift new file mode 120000 index 0000000..7394425 --- /dev/null +++ b/hello/hello-platform/ver-windows/src/hp/hpVM.swift @@ -0,0 +1 @@ +../../../../../components/hp/linux/hpVM.swift \ No newline at end of file diff --git a/hello/hello-platform/ver-windows/src/hp/view/HPView.swift b/hello/hello-platform/ver-windows/src/hp/view/HPView.swift new file mode 120000 index 0000000..1b79f15 --- /dev/null +++ b/hello/hello-platform/ver-windows/src/hp/view/HPView.swift @@ -0,0 +1 @@ +../../../../../../components/hp/linux/view/HPView.swift \ No newline at end of file diff --git a/hello/hello-platform/ver-windows/src/other/other.swift b/hello/hello-platform/ver-windows/src/other/other.swift new file mode 120000 index 0000000..8c61410 --- /dev/null +++ b/hello/hello-platform/ver-windows/src/other/other.swift @@ -0,0 +1 @@ +../../../../../components/other/other.swift \ No newline at end of file