Building by hand, and other languages

terse build is a convenience: an image can be built with the compilers alone and terse pack. This article gives those commands, then what any other compiler or language runtime must do to make a Terse32 program.

By hand

terse build --show prints the commands it runs; terse build --write-lib lib writes the files they use. With those, in fish:

terse build --write-lib lib
set CFLAGS --target=riscv32-unknown-elf -march=rv32imc \
    -mabi=ilp32 -Os -ffreestanding -nostdlib -fno-builtin \
    -ffunction-sections -fdata-sections
clang $CFLAGS -I lib -c lib/crt0.S -o 0.o
clang $CFLAGS -I lib -c hello.c -o 1.o
clang $CFLAGS -I lib -c lib/terse.c -o 2.o
ld.lld -T lib/terse.ld --gc-sections 0.o 1.o 2.o \
    -o hello.elf
llvm-objcopy -O binary hello.elf hello.bin
terse pack --rom hello.bin --title hello --ram-pages 2 \
    --device 2:0 --device 3:0 -o hello.terse

(In sh, CFLAGS="...".) The build.sh of each program in programs/ is such a script. For Rust:

terse build --write-lib lib
rustc --edition 2024 --target riscv32imc-unknown-none-elf \
    -C opt-level=s -Cpanic=abort --crate-type rlib \
    --crate-name terse -o libterse.rlib lib/terse.rs
rustc --edition 2024 --target riscv32imc-unknown-none-elf \
    -C opt-level=s -Cpanic=abort -C lto --crate-type bin \
    -C link-arg=-Tlib/terse.ld --extern terse=libterse.rlib \
    -o hello.elf hello.rs
llvm-objcopy -O binary hello.elf hello.bin
terse pack --rom hello.bin --title hello --ram-pages 1 \
    --device 2:0 --device 3:0 -o hello.terse

rust-objcopy, which rustup's llvm-tools component installs, does what llvm-objcopy does.

Other languages

Anything that can produce RV32IMC machine code for a bare machine can make a Terse32 program. What its compiler and runtime must do:

Other compilers with a 32-bit RISC-V bare-metal target (Zig, for one) should fit these rules with their own start code and the linker script of "Building a program"; none has been tried.

Next: Running and publishing a program.