Ship it

ztcl build makes one static binary of a program: the runtime of ztcl and the scripts, with no install step. The binary has the sandbox of the interpreter, so its capabilities are part of the build. This lesson ships jot, and ends the course.

One binary

Put the procs of jot in jot.tcl, with load and save from the prompt of lesson 8, and a main.tcl that reads the command line:

source [file join [file dirname [info script]] jot.tcl]
jot load
jot {*}$argv
jot save

Build it with the capabilities that it needs, and its folder:

ztcl build --allow file,channels -o jot --embed jot.tcl main.tcl
./jot add "buy milk"

--embed puts a file in the binary, under //zipfs:/app/. info script in main.tcl is //zipfs:/app/main.tcl, so source of a file next to it reads the embedded file. The binary has file and channels, and no network or exec. --root PATH keeps its files in one folder. --target aarch64-macos or --target x86_64-windows builds for another platform from the same computer. Build a program has each option.

{*}$argv passes the words of the command line as the subcommand and its arguments. The ensemble of jot accepts only its exported procs, so a word such as exec is an error. This is one of the few right places for {*} with input: the first word goes to an ensemble with a fixed list.

The JIT and threads, in short

Reading code an agent wrote

Ask an agent

Write the ztcl build command for jot with only the capabilities that its scripts use, and list each capability with the command that needs it.

Try this