Your first program
Programs are ordinary WASI preview 1 binaries. Anything that compiles to
wasm32-wasip1 works; these pages use Rust.
Set up
Section titled “Set up”wackasm-opencomputers is
optional for plain programs, but it’s what starts your program in the shell’s
current directory, and it gives you components, signals, processes and the
internet card. Its API reference is built from the
latest sources; docs.rs has the released versions.
Write it
Section titled “Write it”Build it
Section titled “Build it”Keep the stack small: rustc’s default of 1 MiB is more RAM than most
computers have. In .cargo/config.toml in your project:
And in Cargo.toml, a release profile that keeps the binary small:
Run it
Section titled “Run it”Get mytool.wasm into /bin on a disk in the computer:
- download it with an internet card:
cd /bin, thencurl -O https://example.com/mytool.wasm; - or copy it into the disk’s folder on the server,
<world>/opencomputers/<disk address>/bin/.
Then type its name at the shell:
What works
Section titled “What works”println!,eprintln!and reading stdin, through the shell;std::env::args,std::env::varsandstd::process::exit;std::fs, on the files disk;std::time::SystemTimeandInstant(the computer’s uptime), and random numbers (getrandom, sorandworks);- floats, integers, allocation and panics. Panics with
panic = "abort"crash only your program, and the shell shows the message.
What doesn’t is on the Limits page.