beetlebug▾
/

Runtimes

A runtime is the ztk program of one target, such as an iPhone, the iOS Simulator, an Android phone, or Windows. ztk bundle --target, ztk --ios, and ztk --android copy the runtime of the target into the app, with your scripts. The ztk program that you run is the runtime of your own computer, so an app for the same computer needs no download.

The release of each version of ztk has the runtime of each target. ztk runtime downloads them into a cache of your user, checks each one, and lists them.

The targets

Target Platform File
x86_64-linux, aarch64-linux Linux ztk
x86_64-macos, aarch64-macos macOS ztk
x86_64-windows Windows ztk.exe
aarch64-ios iPhone and iPad ztk
aarch64-ios-simulator, x86_64-ios-simulator The iOS Simulator on Apple silicon and on an Intel Mac ztk
aarch64-linux-android, x86_64-linux-android An Android phone, and the emulator on an x86-64 computer libztk.so

Windows on ARM has no runtime yet: the file commands of ztcl run on Windows for x86-64 only. An ARM computer with Windows runs the program of x86_64-windows through its emulation of x86-64.

The commands

ztk runtime list                           # each target, and where its runtime is
ztk runtime install aarch64-ios-simulator  # download one or more runtimes, or `all`
ztk runtime update                         # after an upgrade of ztk: the runtimes of the new version
ztk runtime remove aarch64-ios-simulator   # one or more, or `all`
ztk runtime prune                          # remove the runtimes of the other versions of ztk
ztk runtime path aarch64-ios-simulator     # the file of a runtime

list shows where the runtime of each target is:

The runtimes of ztk 1.0.0-beta.5:
  x86_64-linux             Linux          missing
  aarch64-macos            macOS          this program  /opt/homebrew/bin/ztk
  aarch64-ios-simulator    iOS Simulator  in the cache  ~/Library/Caches/ztk/runtime/1.0.0-beta.5/aarch64-ios-simulator/ztk
  ...

An upgrade of ztk keeps the runtimes of the old version in their folder. After an upgrade, list shows them as outdated, with one line at the end:

2 runtimes are of another version of ztk. `ztk runtime update` gets the runtimes of ztk 1.0.0-beta.8 in their place, and `ztk runtime prune` removes the old files.

ztk bundle, ztk --ios, and ztk --android say the same when a target has only a runtime of another version: they name its version and offer ztk runtime update.

update installs the runtimes of the version of the ztk that runs it, for each target with a runtime of another version in the cache, then removes the runtimes of the other versions, only after each new runtime is in place. Run it after an upgrade of ztk. prune removes the runtimes of the other versions with no download. remove removes runtimes from the cache only. install and update ask no question, and they accept --yes before or after the targets, so a script can give --yes to each command of ztk.

Where they go

Each version of ztk has its own folder, because a runtime works only with the ztk of its version:

System Folder
macOS ~/Library/Caches/ztk/runtime/VERSION/TARGET/
Linux $XDG_CACHE_HOME/ztk/runtime/VERSION/TARGET/, or ~/.cache/ztk/runtime/VERSION/TARGET/
Windows %LOCALAPPDATA%\ztk\runtime\VERSION\TARGET\

ztk bundle looks for the runtime of a target in this order, and uses the first one it finds:

  1. the file of --runner;
  2. lib/ztk/runtime/TARGET/ next to the folder of ztk;
  3. the ztk program itself, for the target of your computer;
  4. the cache.

How ztk checks a download

A release has these files for the runtimes, with VERSION for the version of ztk:

File What it has
ztk-runtimes-VERSION.json The list of the runtimes: the version, and for each target its file, its size, and the SHA-256 of the file
ztk-runtimes-VERSION.json.sig The Ed25519 signature of the list
ztk-runtime-VERSION-TARGET.gz The runtime of one target, compressed with gzip

The release job signs the list with the secret key of the project. Each ztk has the public key of that secret key in it. ztk runtime install installs a runtime only when each of these holds:

  1. The signature of the list checks with the public key in ztk, so the list is the one of the project.
  2. The version in the list is the version of the ztk that runs.
  3. The size and the SHA-256 of the runtime, after the download, are the ones of the list.

When a check fails, ztk installs no file and names the check that failed, such as "the SHA-256 of the runtime is not the one of the manifest". The download goes to a temporary file next to its place in the cache, so a stopped download leaves no half file.

A ztk that you build from source has the public key of the project too (src/bundle/runtime-key.txt), so it installs the runtimes of the release of its version. A build with -Druntime-key= and no key downloads no runtime.

When a runtime is missing

ztk bundle --target, ztk --ios, and ztk --android never download in silence.

On a terminal, ztk asks first, before any request to the network:

ztk: the runtime of aarch64-ios-simulator for ztk 1.0.0-beta.5 is not on this computer.
Download it from the release of ztk on GitHub? [y/N]

The answer y or yes downloads and checks the runtime, then the command goes on. Another answer stops the command.

With no terminal, as in a script or in CI, ztk downloads only when you allow it:

ztk bundle --yes -o App.app --target aarch64-ios-simulator main.tcl
ztk --ios --yes main.tcl
ZTK_RUNTIME_DOWNLOAD=1 ztk bundle -o app.exe --target x86_64-windows main.tcl

With neither, the command stops, and its message starts with this line:

ztk: no runtime of aarch64-ios-simulator on this computer. Run `ztk runtime install aarch64-ios-simulator`, or give --yes or ZTK_RUNTIME_DOWNLOAD=1 to download it.

A CI job can also run ztk runtime install TARGET as a step of its own, before ztk bundle.

With no network, the download fails with its reason, and the message of ztk bundle names the other ways to get the runtime: ztk runtime install when the network is back, a build from source, or --runner.

A mirror

ZTK_RUNTIME_URL gives another folder with the files of the release, with https:// or http://, such as a mirror inside a company network:

ZTK_RUNTIME_URL=https://mirror.example.com/ztk/v1.0.0-beta.5 ztk runtime install all

The list must still have the signature of the project, so a mirror can serve the files but cannot change them.

Build your own

The runtimes build from the source of ztk with Zig. A runtime next to ztk comes before the cache, so a build of your own needs no download:

zig build runtimes                                              # Linux, macOS, and Windows
zig build runtimes -Druntime-targets=aarch64-ios-simulator      # iOS: on a Mac with Xcode
zig build android -Dtarget=aarch64-linux-android                # Android: with ANDROID_NDK_HOME

Each one goes into zig-out/lib/ztk/runtime/TARGET/, where zig-out/bin/ztk finds it. ztk bundle --runner FILE uses a runtime from any other place.

See also