Compiler reference

The Motoko compiler (moc) is the primary tool for compiling Motoko programs into executable WebAssembly (Wasm) modules. The compiler runs in the background when you build projects using the DFINITY Canister SDK. If you invoke the compiler directly on the command-line, you can press CTRL-C to exit.

This section provides compiler command-line reference information.

moc

Use the Motoko compiler (moc) to compile Motoko programs into executable WebAssembly (Wasm) modules.

Basic usage

moc [option] [file ...]

Options

You can use the following options with the moc command.

Option Description

--actor-idl <idl-path>

Specifies a path to actor IDL (Candid) files.

--actor-alias <alias> <principal>

Specifies an actor import alias.

--args <file>

Read additional newline separated command line arguments from <file>

--args0 <file>

Read additional NUL separated command line arguments from <file>

-c

Compile to WebAssembly.

--check

Performs type checking only.

--compacting-gc

Link with compacting GC instead of copying GC.

--debug

Respects debug expressions in the source (the default).

--error-detail <n>

Set level of error message detail for syntax errors, n in [0..3] (default 2).

-help,--help

Displays usage information.

--hide-warnings

Hides compiler warnings.

-Werror

Treat warnings as errors.

--idl

Generates the interface description language specification.

-i

Runs the compiler in an interactive read–eval–print loop (REPL) shell so you can evaluate program execution (implies -r).

--map

Outputs a Javascript source map.

-no-system-api

Disables system API imports.

-o <file>

Specifies the output file.

-p <n>

Sets the print depth.

--package <package-name> <package-path>

Specifies a package-name package-path pair, separated by a space.

--print-deps

Prints the dependencies for a given source file.

-r

Interprets programs.

--release

Ignores debug expressions in the source.

-t

Activates tracing in interpreter.

-v

Generates verbose output.

--version

Displays version information.

-wasi-system-api

Uses the WASI system API (wasmtime).