Architecturealpha
The parts of moxzi, how a .mo file becomes a running actor, and why the same compiler runs everywhere.
moxzi has two parts: a Motoko compiler, and a runtime that executes compiled actors with Internet Computer semantics. Both are used by every tool.
The compiler is an actor#
The compiler is written in Motoko and compiled to compiler.wasm. It isn't an ordinary program with a main function: it's an actor, with methods to upload files, start a compile job, and advance that job one step at a time. The linker, linker.wasm, is an actor too.
So anything that can run a Motoko actor can run the compiler:
| Tool | Runs the compiler on |
|---|---|
moxzi build | Your machine, inside moxzi |
moxzi build --remote | A canister on the Internet Computer |
The compiler in moxzi-web | A browser tab |
Because it's the same compiler.wasm in each case, the output is the same.
The runtime#
The runtime executes actors with the Internet Computer's rules: one message at a time per actor, rollback when a message traps, await between actors, timers, cycles, upgrades and HTTPS outcalls. It's written once, in Rust, and used by:
| Tool | How |
|---|---|
moxzi | To run the compiler and linker |
moxzid | To host your actors as a server |
moxzi-web | Compiled to wasm, to host actors in a page |
| Actor platforms | As libmoxzi_rts, loaded into the platform's process |
| moxzi.game | To run the game's actors |
From source to running actor#
- Collect sources.
moxzifollows imports and asksmopswhere packages are.moxzi depsshows the result. - Upload. The sources go into the compiler actor's file system, under
/src/and/pkg/. - Compile.
moxzistarts a job and callsstepuntil it finishes. The result is an unlinked module. - Link. The linker adds the Motoko runtime system, and any native kernels the application opted into, and produces a deployable module.
- Run. Install the module on the IC, host it with
moxzid, load it in a page, or run it on an actor platform. The bytes are the same in each case.
moxzi build does steps 1 to 4 and prints the hash of the compiler that did the work.
Limitations#
| Limitation | |
|---|---|
| A build compiles one entry file and everything it imports | There's no incremental compilation. The on-chain builder caches whole builds |
| The runtime system linked into modules is fixed | Choose the compact variant with --compact-rts for moxzid and moxzi-web |