Create hello-platform for Windows #10
No files matched your search
@@ -1,32 +1,94 @@
|
||||
## Prerequisites
|
||||
|
||||
### macOS
|
||||
|
||||
* `brew install raylib`
|
||||
|
||||
### iOS
|
||||
|
||||
* `brew install xcodegen`
|
||||
* ghera's [raylib-ios-xcframeworks][rzip] release unpacked and placed alongside the project
|
||||
|
||||
### Android
|
||||
|
||||
* Android Studio Quail 3 (2026.1.3)
|
||||
* Install Android Studio Quail 3 (2026.1.3)
|
||||
|
||||
### iOS
|
||||
|
||||
* Install Xcode 26
|
||||
* Install XcodeGen
|
||||
|
||||
`brew install xcodegen`
|
||||
* Get ghera's [raylib-ios-xcframeworks][rzip]
|
||||
|
||||
Unpack and place it alongside the project
|
||||
|
||||
### Linux
|
||||
|
||||
* Ubuntu 24.04
|
||||
* [Swiftly][swiftly] + Swift (installed by Swiftly)
|
||||
* Swift dependencies (proposed by Swiftly after Swift installation)
|
||||
* Install Ubuntu 24.04
|
||||
* Install [Swiftly][swiftly] + Swift (installed by Swiftly)
|
||||
* Install Swift dependencies (proposed by Swiftly after Swift installation)
|
||||
|
||||
`apt-get -y install binutils git gnupg2 libcurl4-openssl-dev libgcc-13-dev libpython3-dev libstdc++-13-dev libxml2-dev libncurses-dev libz3-dev pkg-config zlib1g-dev`
|
||||
* CrossSwiftUI dependency
|
||||
* Install CrossSwiftUI dependency
|
||||
|
||||
`apt-get -y install libgtk-4-dev`
|
||||
|
||||
### macOS
|
||||
|
||||
* Install Xcode 26
|
||||
* Install Raylib 6
|
||||
|
||||
`brew install raylib`
|
||||
|
||||
### Windows
|
||||
|
||||
![Developer mode][w11-dev-mode]
|
||||
|
||||
* Install Windows 11
|
||||
|
||||
Use x64 Windows if you want to target both Intel and ARM
|
||||
|
||||
* Install [Visual Studio 2022 and Swift toolchain][vs]
|
||||
* Install App Runtime
|
||||
|
||||
`winget install --id Microsoft.WindowsAppRuntime.1.5 -e --source winget`
|
||||
|
||||
* Enable developer mode
|
||||
|
||||
Settings -> System -> Advanced -> Developer Mode: On (see the screenshot above)
|
||||
|
||||
* Install Git Bash
|
||||
|
||||
`winget install --id Git.Git -e --source winget`
|
||||
|
||||
While in Git Bash installation wizard, select defaults
|
||||
|
||||
* Inside Git Bash: configure Git to use actual symlinks
|
||||
|
||||
`git config --global core.symlinks true`
|
||||
|
||||
* Inside GitBash: find the location of `swift.exe`
|
||||
|
||||
```
|
||||
$ find /c -name swift.exe
|
||||
/c/Users/mk/AppData/Local/Programs/Swift/Toolchains/6.4.2+Asserts/usr/bin/swift.exe
|
||||
```
|
||||
|
||||
* Inside Git Bash: to `~/.bash_profile` add Swift location (without `swift.exe`) to `PATH`
|
||||
|
||||
`export PATH="$PATH:/c/Users/mk/AppData/Local/Programs/Swift/Toolchains/6.4.2+Asserts/usr/bin"`
|
||||
|
||||
* Restart Git Bash
|
||||
|
||||
* Make sure Swift compiler is working
|
||||
|
||||
```
|
||||
$ swift --version
|
||||
Swift version 6.4.2 (swift-6.4.2-RELEASE)
|
||||
Target: aarch64-unknown-windows-msvc
|
||||
Build config: +assertions
|
||||
```
|
||||
|
||||
## Components
|
||||
|
||||
| Component | macOS | iOS | Android | Linux | Windows | Description |
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
| hp | √ | √ | √ | ? | | **h**ello-**p**latform is a simple UI to validate platform support |
|
||||
| hp | √ | √ | √ | √ | √ | **h**ello-**p**latform is a simple UI to validate platform support |
|
||||
| hrb | | | | | | **h**ello-**r**ayli**b** is a simple raylib rendering to validate platform support |
|
||||
|
||||
[rzip]: https://github.com/ghera/raylib-iOS/releases/download/6.2.0-iOS/raylib-ios-xcframeworks-6.2.0-iOS.zip
|
||||
[swiftly]: https://www.swift.org/install/linux/
|
||||
[vs]: https://www.swift.org/install/windows/
|
||||
[w11-dev-mode]: docs/img/w11-dev-mode.jpg
|
||||
@@ -0,0 +1,35 @@
|
||||
import WinSDK
|
||||
|
||||
func otherSetupWindowIcon(_ iconId: Int) {
|
||||
// Only visit windows owned by this UI thread, never another application's window
|
||||
EnumThreadWindows(GetCurrentThreadId(), { wnd, iconId in
|
||||
let resource = UnsafePointer<WCHAR>(bitPattern: Int(iconId))
|
||||
let module = GetModuleHandleW(nil)
|
||||
|
||||
// Small icon
|
||||
if let small = LoadImageW(
|
||||
module,
|
||||
resource,
|
||||
UINT(IMAGE_ICON),
|
||||
GetSystemMetrics(SM_CXSMICON),
|
||||
GetSystemMetrics(SM_CYSMICON),
|
||||
UINT(LR_SHARED)
|
||||
) {
|
||||
SendMessageW(wnd, UINT(WM_SETICON), WPARAM(ICON_SMALL), LPARAM(Int(bitPattern: small)))
|
||||
}
|
||||
|
||||
// Large icon
|
||||
if let large = LoadImageW(
|
||||
module,
|
||||
resource,
|
||||
UINT(IMAGE_ICON),
|
||||
GetSystemMetrics(SM_CXICON),
|
||||
GetSystemMetrics(SM_CYICON),
|
||||
UINT(LR_SHARED)
|
||||
) {
|
||||
SendMessageW(wnd, UINT(WM_SETICON), WPARAM(ICON_BIG), LPARAM(Int(bitPattern: large)))
|
||||
}
|
||||
|
||||
return true
|
||||
}, LPARAM(iconId))
|
||||
}
|
||||
@@ -223,3 +223,36 @@ 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 and generated Swift dialect via
|
||||
relative symlinks. It reuses the SwiftCrossUI model and view in `components/hp/linux`. 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.
|
||||
|
||||
### Windows executable icon
|
||||
|
||||
`res/AppIcon.res` is a ready-made Windows resource containing six icon sizes
|
||||
(16–256px) from the shared `res/AppIcon.png`, with icon group ID 101.
|
||||
`ver-windows/res/AppIcon.res` links to it. No ICO or RC file is required by the
|
||||
Windows target, and the build does not compile resources.
|
||||
|
||||
`step/buildWindows` exports `APP_RES_DIR` as the absolute Git Bash
|
||||
`ver-windows/res` path derived from `$SDIR/../ver-windows/res`.
|
||||
The entry script obtains `SDIR` with `pwd -P`;
|
||||
no resource copy is needed. The manifest appends `/AppIcon.res` and passes it to the linker.
|
||||
Manual SwiftPM commands that evaluate the manifest also need `APP_RES_DIR`.
|
||||
Windows compilation and the live window/taskbar icon require verification on
|
||||
Windows; no Windows build was performed when this wiring was added.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 116 KiB |
Executable
+8
@@ -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"
|
||||
Executable
+8
@@ -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"
|
||||
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
TARGET=$1
|
||||
STEP=$((STEP+1))
|
||||
echo -e "\n> > > > Step №$STEP. Build '$TARGET' for Windows"
|
||||
|
||||
cd "$SDIR/../ver-windows"
|
||||
export APP_RES_DIR="$SDIR/../ver-windows/res"
|
||||
swift build
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
TARGET=$1
|
||||
STEP=$((STEP+1))
|
||||
echo -e "\n> > > > Step №$STEP. Run Windows app for '$TARGET'"
|
||||
|
||||
cd "$SDIR/../ver-windows"
|
||||
"./.build/debug/$TARGET.exe"
|
||||
@@ -0,0 +1,25 @@
|
||||
// swift-tools-version: 5.10
|
||||
import Foundation
|
||||
import PackageDescription
|
||||
|
||||
let resDir = ProcessInfo.processInfo.environment["APP_RES_DIR"]!
|
||||
|
||||
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: "SwiftCrossUI", package: "swift-cross-ui"),
|
||||
.product(name: "WinUIBackend", package: "swift-cross-ui")
|
||||
],
|
||||
path: "src",
|
||||
linkerSettings: [
|
||||
.unsafeFlags(["-Xlinker", "\(resDir)/AppIcon.res"])
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
../../../../res/AppIcon.res
|
||||
@@ -0,0 +1,16 @@
|
||||
import SwiftCrossUI
|
||||
import WinUIBackend
|
||||
|
||||
@main
|
||||
struct HPApp: App {
|
||||
let delegate = HPAppDelegate()
|
||||
|
||||
var body: some Scene {
|
||||
WindowGroup("Hello platform") {
|
||||
HPView(delegate.hpVM)
|
||||
.onAppear {
|
||||
delegate.setup()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
final class HPAppDelegate {
|
||||
let hp = HPComponent()
|
||||
let hpVM = HPVM()
|
||||
|
||||
func setup() {
|
||||
otherSetupConsoleLogging(hp.ctrl, "HP")
|
||||
hp.setup()
|
||||
otherSetupWindowIcon(101)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
../../ver-mac/src/dialect.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/hp/hp.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/hp/linux/hpVM.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../../components/hp/linux/view/HPView.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/other/other.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/other/windows/otherWindows.swift
|
||||
File renamed without changes.
File renamed without changes.
Binary file not shown.
Reference in new issue
Block a user