A template for an app that runs on iOS, Android, PC and Mac. Built using the Zig programming language, and using the floooh/sokol
graphics/app library.
Also, taken inspiration from kubkon/zig-ios-example
, MasterQ32/ZigAndroidTemplate
, and cnlohr/rawdrawandroid
sokol_served_three_ways.mp4
git clone https://github.com/geooot/zig-sokol-crossplatform-starter.git
You will need the 0.13
release of Zig, you can find it here.
For iOS
- xcode
- Edit
build.zig
withAPP_NAME
andBUNDLE_PREFIX
changed as necessary.
For Android
- Android SDK install with
ANDROID_HOME
environment variable set. - Java JDK, and
keytool
(should be included in JDK install).$JAVA_HOME
should be set to the install location - Edit
build.zig
withANDROID_
prefixed constants as necessary. You probably only need to change*_VERSION
const's to match what you have installed in your android SDK (check$ANDROID_HOME
). - Edit
build.zig
withAPP_NAME
andBUNDLE_PREFIX
changed as necessary.
For PC/Mac
- Nothing! Just
zig build run
.
Make sure to perform the edits and get the dependencies described in "Required Dependencies" before continuing below.
$ zig build run # builds and runs executable on your computer
$ zig build # builds everything (iOS, android, your computer)
$ zig build ios # generates iOS project (in zig-out/MyApp.xcodeproj).
# - You have to open xcode and build from there
$ zig build android # builds android apks (in zig-out/MyApp.apks).
# - You have to use `zig build bundletool -- install-apks --apks=zig-out/MyApp.apks`
# to install it to a device.
# - But you use the `.aab` file when submitting to Google Play.
$ zig build default # builds a executable for your computer
Features
- Ability to build for your PC, iOS, and Android
- Android App Bundle support.
- XCode project is an artifact. Configuration using YAML instead (thanks to
xcodegen
) - Pretty easy to modify build system (thanks to Zig).
- Small binaries, fast loading times!
Quirks
- Not really easy to debug for android. Surprisingly the xcode debugger works pretty well.
- Still need XCode to finish the build for iOS. It's needed for code signing and final linking.
In no particular order
- Move sokol-zig to be a zig dependency rather than a git submodule
- Can we get rid of the dependency on
xcodegen
andbundletool
? I think we can at least use zig package manager to fetch those dependencies on build. We need zip support (xcodegen releases itself as a zip file rather than a tarball) and single file download support (bundletool packages itself as a single.jar
) to make that possible.- Even crazier idea: reimplement
xcodegen
andbundletool
as zig libraries.
- Even crazier idea: reimplement
- In my sleep I still think about
kubkon/zig-ios-example
since it doesn't require generating a xcode project at all. I think in reality, people might need some xcode project generation support, but like... - Github Action CI/CD workflows.
- Add minimal WASM/WASI builds (lets move past emscripten).
This is Public Domain software with the UNLICENSE license. All code except for the following exceptions are under the UNLICENSE license.
build/auto-detect.zig
falls under the MIT License [[See here]].sokol-zig
(and sokol in general) fall under the Zlib license [[See here]].