Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions Documentation/Plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ AppRuntime's contracts.
| arm64 and x86_64 Linux with glibc (Debian 13, Ubuntu 24.04+) | armv7, musl |
| Native slices linked into the host | wasm2c (AppRuntime's shim, as on Darwin); WasmKit for development |
| Wayland and X11 through SDL3; a headless driver for tests | Multiple windows |
| `Renderer`, `BluetoothCentral` and friends, GL surfaces, web views, files, settings, the built-ins | Location (GeoClue), Device (UPower, sysfs), Networking (libcurl), Formatting (ICU), Motion (iio-sensor-proxy), NFC (neard) |
| `Renderer`, `BluetoothCentral` and friends, GL surfaces, web views, files, settings, model stores, date and number formatting, the built-ins | Location (GeoClue), Device (UPower, sysfs), Networking (libcurl), Motion (iio-sensor-proxy), NFC (neard) |

## 2. Process model

Expand Down Expand Up @@ -100,6 +100,16 @@ The package depends on AppRuntime without its `GuestExports` trait, like
DarwinAppRuntime, so the slice's `rt_dispatch` and `rt_finalize` are the
only ones linked (`HostRuntime.md` §8 in DarwinAppRuntime).

Some contracts need nothing of Linux's own, and AppRuntime has them for
every host written in Swift; this host registers them as they are:

- **Formatting** (`DynamicFormatting`): AppRuntime's `RuntimeFormatting`,
`LocaleInfo`, `NumberFormat` and `DateFormat` over Swift Foundation,
which formats with ICU, so a guest doesn't link it. Foundation on Linux
doesn't read the POSIX environment for the user's locale, so
`RuntimeFormatting` does: `LC_ALL`, else `LANG`, and `LANGUAGE` for the
preferred languages. The time zone is `TZ`, else the system's.

## 4. Startup

1. Read the app's keys (`RTABIVersion`, `RTContracts`, `RTCapabilities`,
Expand Down Expand Up @@ -385,8 +395,9 @@ SQLite one, CoreModel-SQLite, with SQLite compiled in, so a device needs no
later Flatpak and AppImage, whose manifests carry the capabilities
(`--system-talk-name=org.bluez` for `bluetooth`).
3. **More contracts**: Location (GeoClue2), Device (UPower, sysfs),
Networking (libcurl or AsyncHTTPClient), Formatting (ICU), Motion
(iio-sensor-proxy), NFC (neard).
Networking (libcurl or AsyncHTTPClient), Motion (iio-sensor-proxy),
NFC (neard). Formatting is done: AppRuntime's `RuntimeFormatting`
(§3).
4. **Player**: what DarwinUI and Cacao add: Cacao's AT-SPI bridge, input
replay for end-to-end tests.

Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ let package = Package(
.target(name: "CLinuxHost"),
.target(
name: "LinuxHostApp",
dependencies: ["LinuxHost", "LinuxUI", "LinuxBluetooth", "LinuxGraphics", "LinuxWebKit", "LinuxCoreModel", "CLinuxHost", runtime("CRuntime"),
dependencies: ["LinuxHost", "LinuxUI", "LinuxBluetooth", "LinuxGraphics", "LinuxWebKit", "LinuxCoreModel", "CLinuxHost", runtime("CRuntime"), runtime("RuntimeFormatting"),
.product(name: "CacaoSDL", package: "Cacao")],
swiftSettings: host
),
Expand All @@ -189,7 +189,7 @@ let package = Package(
// doesn't build Cacao.
.target(
name: "LinuxPackager",
dependencies: ["LinuxHost", "LinuxBluetooth", "LinuxGraphics", "LinuxWebKit", "LinuxCoreModel", runtime("DynamicUI"),
dependencies: ["LinuxHost", "LinuxBluetooth", "LinuxGraphics", "LinuxWebKit", "LinuxCoreModel", runtime("RuntimeFormatting"), runtime("DynamicUI"),
.product(name: "Crypto", package: "swift-crypto")]
),
.executableTarget(
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ added to its database between launches:
| `LinuxGraphics` | `Surface`: GLES 2.0 drawn in EGL pbuffers, loaded at run time, and read back into the player's `GLSurface` view ([plan](Documentation/Plan.md) §7) |
| `LinuxWebKit` | `WebContent`: WPE WebKit pages, loaded at run time, drawn into shared memory and shown by the player's `WebView` view ([plan](Documentation/Plan.md) §8) |
| `LinuxCoreModel` | `LinuxModelStore`: the app's CoreModel stores in SQLite, through AppRuntime's `HostModelStore` and CoreModel-SQLite ([plan](Documentation/Plan.md) §9) |
| `LinuxHostApp`, `linux-app-host` | The app's `main`: the host, and Cacao's window and loop |
| `LinuxHostApp`, `linux-app-host` | The app's `main`: the host, and Cacao's window and loop. It also registers AppRuntime's `RuntimeFormatting`, dates and numbers over Swift Foundation ([plan](Documentation/Plan.md) §3) |
| `LinuxPackager`, `linux-app` | The packager: validation, the host build, wasm2c, the install tree, PortMaster ports |

## Building
Expand Down
8 changes: 5 additions & 3 deletions Sources/LinuxHostApp/HostApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import LinuxCoreModel
import LinuxGraphics
import LinuxWebKit
import LinuxUI
import RuntimeFormatting

/// The app's `main` (`Plan.md` §4): finds the app's bundle, checks and
/// prepares the app, calls `rt_main`, and runs Cacao's main loop with a
Expand All @@ -26,11 +27,12 @@ import LinuxUI
public enum HostApp {

/// Every module this host has: the SwiftUI player (DarwinUI, on Cacao),
/// Bluetooth, GL surfaces and web pages, which the player shows, and
/// the app's files, settings and model stores.
/// Bluetooth, GL surfaces and web pages, which the player shows, the
/// app's files, settings and model stores, and AppRuntime's date and
/// number formatting over Swift Foundation.
public static let modules: [any HostModule.Type] = [
DarwinUI.self, LinuxBluetooth.self, LinuxGraphics.self, LinuxWebKit.self, LinuxFiles.self, LinuxDefaults.self,
LinuxModelStore.self,
LinuxModelStore.self, HostFormattingModule.self,
]

/// The window's title: the app's name.
Expand Down
5 changes: 3 additions & 2 deletions Sources/LinuxPackager/Validator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ import LinuxWebKit
import LinuxHost
import DynamicUI
import RuntimeABI
import RuntimeFormatting

/// What this host implements: the built-ins and its modules' contracts.
public enum HostContracts {

/// The modules `linux-app-host` registers (`HostApp.modules`): the
/// player's contracts, without building the player, Bluetooth,
/// graphics, web views, files, settings and model stores.
/// graphics, web views, files, settings, model stores and formatting.
nonisolated(unsafe) public static let modules: [any HostModule.Type] = [
PlayerContracts.self, LinuxBluetooth.self, LinuxGraphics.self, LinuxWebKit.self, LinuxFiles.self, LinuxDefaults.self,
LinuxModelStore.self,
LinuxModelStore.self, HostFormattingModule.self,
]

public static var provided: [String: ContractDescriptor] {
Expand Down
11 changes: 11 additions & 0 deletions Tests/LinuxPackagerTests/PackagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ import Testing
#expect(lenient.filter { $0.severity == .error }.count == 1, "the wrong kind is still an error")
}

/// AppRuntime's `RuntimeFormatting`, which the host registers as it is.
@Test func formattingIsImplemented() throws {
let fixture = try Fixture(contracts: [
("org.pureswift.ui.Renderer", 1, "contract"),
("org.pureswift.formatting.Locale", 1, "contract"),
("org.pureswift.formatting.NumberFormat", 1, "contract"),
("org.pureswift.formatting.DateFormat", 1, "contract"),
])
#expect(try diagnostics(fixture).isEmpty)
}

@Test func newerABIsAndBadNames() throws {
let messages = try diagnostics(Fixture(identifier: "nodots", executable: "../Demo", abi: 99)).map(\.message)
#expect(messages.contains { $0.contains("rt ABI 99") })
Expand Down
Loading