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

Specifies a path to actor IDL files.

--actor-alias

Specifies an actor import alias.

-c

Compiles programs to WebAssembly.

--check

Performs type checking only.

--debug

Respects debug expressions in the source (the default).

-dp

Dumps parse.

-dt

Dumps type-checked AST.

-dl

Dumps intermediate representation

--error-detail

Displays detailed error message for syntax errors.

-help,--help

Displays usage information.

--hide-warnings

Hides compiler warnings.

--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).

-iR

Interprets the lowered code.

--map

Outputs a source map.

-no-await

Disables await-lowering (with -iR).

-no-async

Disables async-lowering (with -iR).

-no-check-ir

Skips intermediate code checking.

-no-link

Disables statically-linked runtime.

-no-system-api

Disables system API imports.

-o

Creates an output file.

-p

Sets the print depth.

--package <pkg-name> <pkg-URL>

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

--print-deps

Prints the dependencies for a given source file.

--profile

Activates profiling counters in interpreters.

--profile-field <field>

Includes the given field from the program result in the profile file.

--profile-file

Sets profiling output file.

--profile-line-prefix <prefix>

Adds the specified prefix string to each profile line.

-r

Interprets programs.

--release

Ignores debug expressions in the source.

-stub-system-api

Uses the the stub version of the system API.

-t

Activates tracing in interpreters.

-v

Generates verbose output.

--version

Displays version information.

-wasi-system-api

Uses the WASI system API (wasmtime).