Create hello-platform for Linux (#13)
Co-authored-by: Михаил Капелько <kornerr@gmail.com>
This commit is contained in:
1 parent
45ca185094
commit
614392c921
23 files changed
+4720
-7
No files matched your search
@@ -9,14 +9,24 @@
|
|||||||
* `brew install xcodegen`
|
* `brew install xcodegen`
|
||||||
* ghera's [raylib-ios-xcframeworks][rzip] release unpacked and placed alongside the project
|
* ghera's [raylib-ios-xcframeworks][rzip] release unpacked and placed alongside the project
|
||||||
|
|
||||||
[rzip]: https://github.com/ghera/raylib-iOS/releases/download/6.2.0-iOS/raylib-ios-xcframeworks-6.2.0-iOS.zip
|
|
||||||
|
|
||||||
### Android
|
### Android
|
||||||
|
|
||||||
* Android Studio Quail 3 (2026.1.3)
|
* Android Studio Quail 3 (2026.1.3)
|
||||||
|
|
||||||
|
### Linux
|
||||||
|
|
||||||
|
* Ubuntu 24.04
|
||||||
|
* [Swiftly][swiftly] + Swift (installed by Swiftly)
|
||||||
|
* 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
|
||||||
|
`apt-get -y install libgtk-4-dev`
|
||||||
|
|
||||||
## Components
|
## Components
|
||||||
|
|
||||||
| Name | Description | macOS | iOS | Android | Linux | Windows | Raspberry Pi |
|
| Component | macOS | iOS | Android | Linux | Windows | Description |
|
||||||
| --- | --- | --- | --- | --- | --- | --- | --- |
|
| --- | --- | --- | --- | --- | --- | --- |
|
||||||
| hp | **hello-platform** is a simple UI to validate platform support | √ | √ | √ | | | |
|
| hp | √ | √ | √ | ? | | **h**ello-**p**latform is a simple UI 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/
|
||||||
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
../hp.swift
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import SwiftCrossUI
|
||||||
|
|
||||||
|
final class HPVM: ObservableObject {
|
||||||
|
@Published var countText = ""
|
||||||
|
|
||||||
|
static private(set) weak var shared: HPVM?
|
||||||
|
|
||||||
|
init() {
|
||||||
|
Self.shared = self
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import SwiftCrossUI
|
||||||
|
|
||||||
|
struct HPView: View {
|
||||||
|
@State var vm: HPVM
|
||||||
|
|
||||||
|
init(_ vm: HPVM) {
|
||||||
|
self.vm = vm
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack(spacing: 16) {
|
||||||
|
Text("Hello, platform!")
|
||||||
|
.font(.largeTitle)
|
||||||
|
Text(vm.countText)
|
||||||
|
.font(.title3.monospaced())
|
||||||
|
Button("Increment") {
|
||||||
|
hpSet(F.didClickIncrement, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(40)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,7 +12,7 @@ struct HPView: View {
|
|||||||
Text("Hello, platform!")
|
Text("Hello, platform!")
|
||||||
.font(.largeTitle)
|
.font(.largeTitle)
|
||||||
Text(vm.countText)
|
Text(vm.countText)
|
||||||
.font(.title3.monospacedDigit())
|
.font(.title3.monospaced())
|
||||||
Button("Increment") {
|
Button("Increment") {
|
||||||
hpSet(F.didClickIncrement, true)
|
hpSet(F.didClickIncrement, true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -195,3 +195,31 @@ AGP 8.7.3 does not accept every newer JDK.
|
|||||||
the macOS file, so `prepare-ios` regenerates the same source. The Kotlin
|
the macOS file, so `prepare-ios` regenerates the same source. The Kotlin
|
||||||
`dialect.kt` lives in `ver-android` and is generated from the same
|
`dialect.kt` lives in `ver-android` and is generated from the same
|
||||||
`dialect.yml`.
|
`dialect.yml`.
|
||||||
|
|
||||||
|
## Linux launcher icon
|
||||||
|
|
||||||
|
`ver-linux` uses GtkBackend with application ID
|
||||||
|
`org.opengamestudio.hello-platform`. On Linux run
|
||||||
|
`hello/hello-platform/util/build-linux` from the repository root to build and install
|
||||||
|
the executable under `~/.local/bin`, the desktop entry under
|
||||||
|
`${XDG_DATA_HOME:-~/.local/share}/applications`, and the shared 1024px
|
||||||
|
`res/AppIcon.png` under the matching hicolor icon name. The launcher uses an
|
||||||
|
absolute executable path. Launch from the desktop application menu after
|
||||||
|
installation; GTK's application ID matches the desktop and icon names.
|
||||||
|
Desktop-entry installation uses `cp` and GNU `sed -i`; Python is not required.
|
||||||
|
The replacement supports spaces but assumes paths contain no sed replacement
|
||||||
|
metacharacters (`&`, `|`, backslashes) or desktop-entry quoting characters.
|
||||||
|
Requires the normal Swift/GTK build dependencies. Installation is per-user and
|
||||||
|
requires no root privileges.
|
||||||
|
|
||||||
|
The Linux build runs `step/buildLinux` followed by `step/packageLinux`.
|
||||||
|
The shared launcher template is `res/linux-app.desktop`; packaging copies it
|
||||||
|
and substitutes `%APP_NAME%`, `%APP_EXEC%` and `%APP_ID%`.
|
||||||
|
`util/run-linux` uses `gtk-launch org.opengamestudio.hello-platform` to launch
|
||||||
|
the installed desktop entry with its icon association. Run `util/build-linux`
|
||||||
|
first to install/update that entry and executable; `gtk-launch` must be available.
|
||||||
|
`packageLinux` is sourced with the target and display name, like `packageMac`;
|
||||||
|
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.
|
||||||
File diff suppressed because it is too large.
Load diff
Executable
+9
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
SDIR=$(cd "$(dirname "$0")" ; pwd -P)
|
||||||
|
|
||||||
|
T=$SDIR/step
|
||||||
|
TARGET=hello-platform
|
||||||
|
|
||||||
|
STEP=0
|
||||||
|
source $T/buildLinux $TARGET
|
||||||
|
source $T/packageLinux $TARGET hello-platform
|
||||||
Executable
+7
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
SDIR=$(cd "$(dirname "$0")" ; pwd -P)
|
||||||
|
|
||||||
|
T=$SDIR/step
|
||||||
|
|
||||||
|
STEP=0
|
||||||
|
source $T/runLinux hello-platform hello-platform
|
||||||
Executable
+8
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
TARGET=$1
|
||||||
|
STEP=$((STEP+1))
|
||||||
|
echo -e "\n> > > > Step №$STEP. Build '$TARGET' for Linux"
|
||||||
|
|
||||||
|
cd $SDIR/../ver-linux
|
||||||
|
swift build
|
||||||
@@ -4,4 +4,4 @@ TARGET=$1
|
|||||||
STEP=$((STEP+1))
|
STEP=$((STEP+1))
|
||||||
echo -e "\n> > > > Step №$STEP. Generate Dialect for '$TARGET'"
|
echo -e "\n> > > > Step №$STEP. Generate Dialect for '$TARGET'"
|
||||||
|
|
||||||
$SDIR/../../../../dialect/util/run-generator --file=$SDIR/../dialect.yml
|
$SDIR/../../../util/run-generator --file=$SDIR/../dialect.yml
|
||||||
Executable
+29
@@ -0,0 +1,29 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
TARGET=$1
|
||||||
|
APP_NAME=$2
|
||||||
|
|
||||||
|
STEP=$((STEP+1))
|
||||||
|
echo -e "\n> > > > Step №$STEP. Make '$APP_NAME' Linux package for '$TARGET'"
|
||||||
|
APP_DIR="$SDIR/../ver-linux"
|
||||||
|
DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}"
|
||||||
|
BIN_DIR="$HOME/.local/bin"
|
||||||
|
APP_ID=org.opengamestudio.$TARGET
|
||||||
|
|
||||||
|
mkdir -p "$BIN_DIR" "$DATA_DIR/applications" "$DATA_DIR/icons/hicolor/1024x1024/apps"
|
||||||
|
cp "$APP_DIR/.build/debug/$TARGET" "$BIN_DIR/$TARGET"
|
||||||
|
cp "$SDIR/../../../res/AppIcon.png" \
|
||||||
|
"$DATA_DIR/icons/hicolor/1024x1024/apps/$APP_ID.png"
|
||||||
|
|
||||||
|
# Use an absolute executable path: graphical sessions may omit ~/.local/bin.
|
||||||
|
DESKTOP_FILE="$DATA_DIR/applications/$APP_ID.desktop"
|
||||||
|
cp "$SDIR/../../../res/linux-app.desktop" "$DESKTOP_FILE"
|
||||||
|
sed -i \
|
||||||
|
-e "s|%APP_NAME%|$APP_NAME|g" \
|
||||||
|
-e "s|%APP_EXEC%|$BIN_DIR/$TARGET|g" \
|
||||||
|
-e "s|%APP_ID%|$APP_ID|g" \
|
||||||
|
"$DESKTOP_FILE"
|
||||||
|
|
||||||
|
# Update icon cache for new icon to be visible
|
||||||
|
gtk-update-icon-cache --force --ignore-theme-index "$DATA_DIR/icons/hicolor"
|
||||||
|
update-desktop-database "$DATA_DIR/applications"
|
||||||
Executable
+8
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
TARGET=$1
|
||||||
|
APP_NAME=$2
|
||||||
|
STEP=$((STEP+1))
|
||||||
|
echo -e "\n> > > > Step №$STEP. Run Linux app for '$TARGET'"
|
||||||
|
|
||||||
|
gtk-launch "org.opengamestudio.$TARGET"
|
||||||
@@ -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: "GtkBackend", package: "swift-cross-ui"),
|
||||||
|
.product(name: "SwiftCrossUI", package: "swift-cross-ui")
|
||||||
|
],
|
||||||
|
path: "src"
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import GtkBackend
|
||||||
|
import SwiftCrossUI
|
||||||
|
|
||||||
|
@main
|
||||||
|
struct HPApp: App {
|
||||||
|
var backend: GtkBackend {
|
||||||
|
GtkBackend(appIdentifier: "org.opengamestudio.hello-platform")
|
||||||
|
}
|
||||||
|
let delegate = HPAppDelegate()
|
||||||
|
|
||||||
|
var body: some Scene {
|
||||||
|
WindowGroup("Hello platform") {
|
||||||
|
HPView(delegate.hpVM)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import SwiftCrossUI
|
||||||
|
|
||||||
|
final class HPAppDelegate {
|
||||||
|
let hp = HPComponent()
|
||||||
|
let hpVM = HPVM()
|
||||||
|
|
||||||
|
init() {
|
||||||
|
otherSetupConsoleLogging(hp.ctrl, "HP")
|
||||||
|
hp.setup()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../ver-mac/src/dialect.swift
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../../components/hp/linux/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,9 @@
|
|||||||
|
[Desktop Entry]
|
||||||
|
Type=Application
|
||||||
|
Name=%APP_NAME%
|
||||||
|
Comment=%APP_NAME% sample
|
||||||
|
Exec="%APP_EXEC%"
|
||||||
|
Icon=%APP_ID%
|
||||||
|
Terminal=false
|
||||||
|
Categories=Development;
|
||||||
|
StartupWMClass=%APP_ID%
|
||||||
Executable
+4
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
SDIR=$(cd "$(dirname "$0")" ; pwd -P)
|
||||||
|
|
||||||
|
swift "$SDIR/../ext/generator-script.swift" "$@"
|
||||||
Reference in new issue
Block a user