Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
4d68560
Satisfy template: rename template to haskell-mobile
Mar 15, 2026
fafce47
Merge pull request #1 from jappeace-sloth/satisfy-template
jappeace Mar 15, 2026
46f6d69
Add Android aarch64 cross-compilation via haskell.nix
Mar 15, 2026
96918ae
Fix Android cross-compilation: use nixpkgs-2305 with LLVM 14
Mar 16, 2026
9a9d485
Add full Android APK pipeline: Haskell FFI → .so → JNI → APK
Mar 16, 2026
d4d4096
Merge pull request #2 from jappeace-sloth/android-cross-compilation
jappeace Mar 16, 2026
36647bd
Add iOS build pipeline: Haskell → static lib → mac2ios patching
Mar 16, 2026
ab64b97
Fix iOS build: use haskell.nix master instead of armv7a branch
Mar 16, 2026
3758b78
Fix iOS: use nixpkgs-2305 to avoid ghc943 bootstrap issue
Mar 16, 2026
12c664c
Replace haskell.nix with nixpkgs GHC for iOS build
Mar 17, 2026
2bd4301
Merge pull request #3 from jappeace-sloth/ios-build-pipeline
jappeace Mar 17, 2026
e479143
Remove haskell.nix, use nixpkgs cross-compilation for Android
Mar 17, 2026
191c601
Fix android build: add explicit GMP and libffi library paths
Mar 17, 2026
32947e7
Use authToken for cachix in android and ios CI jobs
Mar 17, 2026
c07b282
Merge pull request #4 from jappeace-sloth/remove-haskell-nix
jappeace Mar 17, 2026
6e42865
Upload Android APK and iOS library as CI artifacts
Mar 17, 2026
d4cc872
Only build and upload artifacts on master branch
Mar 17, 2026
9e10e2f
Merge pull request #5 from jappeace-sloth/ci-upload-artifacts
jappeace Mar 17, 2026
4d8e5da
Add iOS IPA build to CI, XcodeGen project spec, and rewrite Readme
Mar 17, 2026
36537cd
Merge pull request #6 from jappeace-sloth/ios-ipa-build
jappeace Mar 18, 2026
7ad05e3
draft roadmap
jappeace Mar 18, 2026
a870804
Add lifecycle event callbacks for Android and iOS
Mar 18, 2026
74d206e
Fix lifecycle test race condition
Mar 18, 2026
ca4d992
Refactor: replace global IORef with StablePtr MobileContext
Mar 18, 2026
165637f
Add platform-aware lifecycle logging and update sample app
Mar 18, 2026
80f8347
Change platformLog to accept Text, update demo as lifecycle listener
Mar 19, 2026
2ffdd56
Fix iOS/Android build: add OverloadedStrings pragma to Lifecycle.hs
Mar 19, 2026
ad41dbb
Add Backpack-based app hook for MobileContext
Mar 19, 2026
6b8fc98
Trigger CI re-run (previous run canceled by iOS cache flake)
Mar 19, 2026
f8cd778
Fix nix builds: move hsig out of src, copy sources into build dir
Mar 19, 2026
fe4e2e7
Fix Windows CI: use short builddir for Backpack long paths
Mar 19, 2026
32a67b1
Fix nix mobile builds: create HaskellMobile dir before copying sources
Mar 20, 2026
d726617
Add quote fortune found me
jappeace Mar 21, 2026
f795591
Add Android emulator test for lifecycle callbacks
Mar 23, 2026
dacf72f
Add iOS Simulator lifecycle test
Mar 23, 2026
d9ffdc4
Fix simulator test: resolve nixpkgs from npins for xcodegen
Mar 23, 2026
ce611f6
Fix ios.nix header filename and bundle assets in simulator test
Mar 23, 2026
a30d1e4
Fix simulator build: use classic linker and fix cleanup permissions
Mar 23, 2026
08a8548
Fix simulator xcodebuild: use Release config, disable debug dylib
Mar 23, 2026
f74ce90
Fix simulator linker: use ld-classic binary directly
Mar 23, 2026
9aa7373
Fix linker path: use xcode-select instead of xcrun for ld-classic
Mar 23, 2026
982c795
Bundle xcodegen in derivation, run test without nix-shell
Mar 23, 2026
2255eb0
Link libgmp for integer-gmp symbols in simulator build
Mar 23, 2026
2b3861c
Merge libgmp into static library for self-contained linking
Mar 23, 2026
6f32456
Build static libgmp and merge into iOS static library
Mar 23, 2026
a3f7737
Fix libtool in ios.nix, add CI concurrency cancellation
Mar 23, 2026
cb7a8cb
Add explicit Info.plist generation to xcodegen project
Mar 23, 2026
bb354b1
Fix simulator log capture: add --level info and use composedMessage
Mar 23, 2026
d82643e
Merge pull request #7 from jappeace-sloth/lifecycle-callbacks
jappeace Mar 23, 2026
4e23ef5
Add declarative UI bridge with native rendering via direct FFI
Mar 24, 2026
2587d59
Fix iOS build: add include path for UIBridge.h
Mar 24, 2026
e29d1ec
Add OverloadedStrings pragma to App.hs for standalone GHC builds
Mar 24, 2026
c52d9bd
Add ImportQualifiedPost pragma to Render.hs for nix builds
Mar 24, 2026
edbdcc9
Remove W prefix from Widget constructors, drop smart constructors
Mar 24, 2026
9643d07
Add emulator UI rendering test
Mar 24, 2026
441e854
Fix emulator-ui: set ANDROID_HOME, add debug output, fix sysimg path
Mar 24, 2026
8690122
Add iOS UI bridge + simulator UI rendering test
Mar 24, 2026
5f902d4
Fix iOS logging and UI test assertions
Mar 24, 2026
3c9c139
Fix xcodebuild destination for CI runners
Mar 24, 2026
cfd1fa3
Restrict xcodebuild to arm64 for simulator builds
Mar 24, 2026
39bc614
Remove -destination from xcodebuild, use -sdk + ARCHS instead
Mar 24, 2026
42e38c9
Share nix store cache between related CI jobs
Mar 24, 2026
12ce91d
Fix ios-ui test race: schedule auto-tap after initial render
Mar 25, 2026
234d8ff
Make ios-ui test robust against os_log message loss
Mar 25, 2026
db900dd
Merge pull request #9 from jappeace-sloth/ios-ui-bridge
jappeace Mar 25, 2026
a5ee457
Consolidate CI into nix/ci.nix
Mar 25, 2026
4a6ea59
Simplify CI to two nix jobs: android (ubuntu) and ios (macos)
Mar 25, 2026
0a9a152
Fix flaky iOS simulator tests: use subsystem predicate and retry
Mar 25, 2026
0a9ffe2
Merge pull request #11 from jappeace-sloth/consolidate-ci-nix
jappeace Mar 25, 2026
1103898
Add TextInput widget for text entry support
Mar 27, 2026
e94d86e
Make sub-libraries public for external Backpack consumers
Mar 27, 2026
c09652b
Merge pull request #12 from jappeace-sloth/text-input-widget
jappeace Mar 27, 2026
d0691fe
Consolidate sub-libraries into single library
Mar 29, 2026
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
87 changes: 52 additions & 35 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,69 +7,86 @@ on:
permissions:
actions: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
nix:
android:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Local cache
uses: actions/cache@v4
with:
path: /nix/store
key: "${{ runner.os }}-nix-cache"
key: "${{ runner.os }}-nix-android-cache"
restore-keys: |
${{ runner.os }}-nix-android-
- uses: cachix/install-nix-action@v31
with:
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}

- uses: cachix/cachix-action@v15
with:
name: jappie
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: nix-build
- run: nix-shell --run "echo OK"
- run: nix-build nix/android.nix
- run: nix-build nix/apk.nix -o result-apk
- name: Upload Android APK
if: github.ref == 'refs/heads/master'
uses: actions/upload-artifact@v4
with:
name: haskell-mobile-android
path: result-apk/haskell-mobile.apk
- name: Build UI test
run: nix-build nix/emulator-ui.nix -o result-emulator-ui
- name: Run UI rendering test
run: ./result-emulator-ui/bin/test-ui
- name: Cancel workflow on failure
if: failure()
continue-on-error: true
run: gh run cancel ${{ github.run_id }}
env:
GH_TOKEN: ${{ github.token }}

cabal:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: true
matrix:
ghc:
- '9.12'
- '9.10'
- '9.8'
- '9.6'
os: [ubuntu-latest, macOS-latest, windows-latest]

ios:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: haskell-actions/setup@v2
with:
ghc-version: ${{ matrix.ghc }}

- name: Cabal cache
- name: Local cache
uses: actions/cache@v4
env:
cache-name: cache-cabal
with:
path: ~/.cabal
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/*.cabal') }}-${{ hashFiles('**/cabal.project') }}
path: /nix/store
key: "${{ runner.os }}-nix-ios-cache"
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
- name: Cabal update
run: cabal update
- name: Build using cabal
run: cabal build all
- name: Test
run: cabal test all
${{ runner.os }}-nix-ios-
- uses: cachix/install-nix-action@v31
with:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- uses: cachix/cachix-action@v15
with:
name: jappie
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: nix-build nix/ios.nix
- name: Build simulator test
run: nix-build nix/simulator.nix -o result-simulator
- name: Run simulator lifecycle test
run: ./result-simulator/bin/test-lifecycle-ios
- name: Build UI test
run: nix-build nix/simulator-ui.nix -o result-simulator-ui
- name: Run UI rendering test
run: ./result-simulator-ui/bin/test-ui-ios
- name: Upload iOS library
if: github.ref == 'refs/heads/master'
uses: actions/upload-artifact@v4
with:
name: haskell-mobile-ios
path: |
result/lib/libHaskellMobile.a
result/include/HaskellMobile.h
- name: Cancel workflow on failure
if: failure()
continue-on-error: true
Expand Down
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ network-uri-lenses.cabal
dist*
.#*
result
result-*
TAGS

*.hi
*.o
.envrc
.envrc

# Generated Xcode project (recreated via xcodegen)
ios/HaskellMobile.xcodeproj/

# Staging dirs populated from nix build output
ios/lib/
ios/include/
7 changes: 3 additions & 4 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Change log for template project
# Change log for haskell-mobile

## Version 0.0.0

import [template](https://github.com/jappeace/template).
## Version 1.0.0

Initial release of haskell-mobile.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2025 Jappie Klooster
Copyright (c) 2026 Jappie Klooster

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
159 changes: 90 additions & 69 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,89 +1,110 @@
[![https://jappieklooster.nl](https://img.shields.io/badge/blog-jappieklooster.nl-lightgrey)](https://jappieklooster.nl/tag/haskell.html)
[![Github actions build status](https://img.shields.io/github/actions/workflow/status/jappeace/haskell-template-project/nix.yaml?branch=master)](https://github.com/jappeace/haskell-template-project/actions)
[![Jappiejappie](https://img.shields.io/badge/discord-jappiejappie-black?logo=discord)](https://discord.gg/Hp4agqy)
[![Hackage version](https://img.shields.io/hackage/v/template.svg?label=Hackage)](https://hackage.haskell.org/package/template)
[![CI](https://img.shields.io/github/actions/workflow/status/jappeace/haskell-mobile/ci.yaml?branch=master)](https://github.com/jappeace/haskell-mobile/actions)

> The eye that looks ahead to the safe course is closed forever.
> To see a need and wait to be asked, is to already refuse.

Haskell project template.
# Haskell Mobile

Set up cabal within a nix shell.
If you like nix this is a good way of doing haskell development.
Write mobile apps in Haskell.
This project cross-compiles a Haskell library to Android (APK) and iOS (static library / IPA),
with a thin platform-native UI layer (Kotlin for Android, Swift for iOS).

similar to: https://github.com/monadfix/nix-cabal
except this has a makefile and ghcid.
We also make aggressive use of [pinning](https://wiki.nixos.org/wiki/FAQ/Pinning_Nixpkgs)
ensuring project builds for ever (theoretically).
## Building

Comes with:
+ [GHCID](https://jappieklooster.nl/ghcid-for-multi-package-projects.html)
+ a nix shell, meaning somewhat platform independence.
+ which is pinned by default
+ A couple of handy make commands.
+ Starting haskell files, assuming we put practically all code in library
+ Working test suite.
+ functioining CI (pick your favorite or keep both)
+ for various platforms with cabal
### Native (desktop)

## Usage
Enter the Nix shell and use cabal:

### Modifying for your project
Assuming the name of your new project is `new-project`.

```
git clone git@github.com:jappeace/haskell-template-project.git new-project
cd new-project
```bash
nix-shell
cabal build all
cabal test all
```

+ [ ] Edit template.cabal,
+ [ ] find and replace template with `new-project`
+ [ ] Update copyright
+ [ ] Update github
+ [ ] rename template.cabal to new-project.cabal
+ [ ] Edit Changelog.md
+ [ ] replace template with `new-project`
+ [ ] Also describe your version 1.0.0 release.
+ [x] Edit default.nix and shell.nix, replace template with `new-project`.
+ [ ] Edit copyright in LICENSE
+ [ ] For automatic bound bumping: In “Settings” → “Actions” → “General” → “Workflow permissions” tick “Allow GitHub Actions to create and approve pull requests”

#### Reconfigure remotes
```
git remote add template git@github.com:jappeace/haskell-template-project.git
git remote set-url origin git@github.com:YOUR-ORG-OR-USER-NAME/new-project.git
Or use the makefile shortcuts (`make build`, `make test`, `make ghcid`).

### Android APK

```bash
nix-build nix/android.nix # cross-compiled Haskell library
nix-build nix/apk.nix # full APK
```

We can get template updates like this if we want to by doing `git pull template`.
There will be a large amount of conflicts, but the merge commit should solve them permanently.
The APK is written to `result/haskell-mobile.apk`.

#### Readme
### iOS static library

+ [ ] Select desired badges.
+ [ ] Point build badges to right project
+ [ ] Give short project description.
+ [ ] Add new quote suited for the project.
For example for [fakedata-quickcheck](https://github.com/fakedata-haskell/fakedata-quickcheck#readme)
I used Kant because
he dealt with the question "what is truth" a lot.
+ [ ] Truncate this checklist
+ [ ] Truncate motivation for using this template
Requires macOS (same ISA as iOS aarch64):

### Tools
Enter the nix shell.
```
nix-shell
```
You can checkout the makefile to see what's available:
```
cat makefile
```bash
nix-build nix/ios.nix
```

### Running
```
make run
Produces `result/lib/libHaskellMobile.a` and `result/include/HaskellMobile.h`.

### iOS app (local dev)

After building the static library, generate an Xcode project with [XcodeGen](https://github.com/yonaskolb/XcodeGen):

```bash
# Stage the Haskell library where the Xcode project expects it
mkdir -p ios/lib ios/include
cp result/lib/libHaskellMobile.a ios/lib/
cp result/include/HaskellMobile.h ios/include/

# Generate and open
nix-shell -p xcodegen --run "cd ios && xcodegen generate"
open ios/HaskellMobile.xcodeproj
```

### Fast filewatch which runs tests
Configure signing in Xcode (team, bundle ID, provisioning profile), then build and run.

## Installing

### Android

```bash
adb install result/haskell-mobile.apk
```
make ghcid

### iOS

Use Xcode to deploy to a connected device, or download the IPA artifact from the
[CI Actions page](https://github.com/jappeace/haskell-mobile/actions) (master builds only, when signing secrets are configured).

## CI

The GitHub Actions workflow runs four jobs:

| Job | Platform | What it does |
|-----|----------|--------------|
| `nix` | Linux | `nix-build` + `nix-shell` smoke test |
| `android` | Linux | Cross-compile to Android, build APK (master) |
| `ios` | macOS | Cross-compile to iOS static lib, build IPA if signing secrets are set (master) |
| `cabal` | Linux/macOS/Windows | GHC 9.6 / 9.8 / 9.10 / 9.12 matrix build + tests |

### iOS signing secrets

The IPA build is conditional: without secrets, CI only builds the static library.
To enable IPA builds, add these repository secrets:

| Secret | Description |
|--------|-------------|
| `APPLE_CERTIFICATE_BASE64` | Base64-encoded `.p12` distribution certificate |
| `APPLE_CERTIFICATE_PASSWORD` | Password for the `.p12` file |
| `APPLE_PROVISIONING_PROFILE_BASE64` | Base64-encoded `.mobileprovision` file |
| `APPLE_TEAM_ID` | Apple Developer Team ID |

Generate the base64 values with:

```bash
base64 -i Certificates.p12 | pbcopy
base64 -i App.mobileprovision | pbcopy
```

# Roadmap

+ Test out lifecycles.
+ Need logging support in respective frameworks, make sure they get triggered.
+ Figure out how to do UI
+ need to be able to register callbacks on events, eg onButtonClick
+ tranistion between UI's?
39 changes: 39 additions & 0 deletions TODO/lifecycles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Deferred Lifecycle Events

Lifecycle events not yet implemented due to lack of cross-platform equivalents
or requiring platform-specific APIs beyond the current scope.

## Android-Only (deferred)

| Event | Reason |
|-------|--------|
| `onRestart` | No iOS equivalent; rare use case (Start already covers re-entering foreground) |
| `onSaveInstanceState` | Android-specific state persistence; iOS uses different restoration APIs |
| `onRestoreInstanceState` | Counterpart to onSaveInstanceState; same reasoning |
| `onConfigurationChanged` | Android-specific (rotation, locale change); iOS handles via SwiftUI environment |
| `onTrimMemory(level)` | Granular memory pressure with level parameter; iOS equivalent (didReceiveMemoryWarning) is a separate API |

## iOS-Only (deferred)

| Event | Reason |
|-------|--------|
| `viewWillAppear` / `viewDidAppear` | UIKit ViewController lifecycle, not available in SwiftUI without bridging |
| `viewWillDisappear` / `viewDidDisappear` | Same as above |
| `viewIsAppearing` (iOS 17+) | UIKit-only, requires iOS 17 minimum |
| `applicationWillTerminate` | Requires UIApplicationDelegate; SwiftUI has no direct equivalent |
| `didReceiveMemoryWarning` | Requires NotificationCenter subscription (`.UIApplication.didReceiveMemoryWarningNotification`) |
| State restoration | iOS uses NSUserActivity / scene-based state restoration, very different model from Android |

## Currently Implemented

| Event | Code | Android | iOS |
|-------|------|---------|-----|
| Create | 0 | `onCreate` | App `init()` |
| Start | 1 | `onStart` | (not fired) |
| Resume | 2 | `onResume` | `.active` |
| Pause | 3 | `onPause` | `.inactive` |
| Stop | 4 | `onStop` | `.background` |
| Destroy | 5 | `onDestroy` | (not fired) |
| LowMemory | 6 | `onLowMemory` | (not fired) |

iOS fires Create/Resume/Pause/Stop. Start/Destroy/LowMemory are Android-only in practice.
Loading
Loading