IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.0.0
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

mojo precompile

Precompiles a Mojo package.

Synopsis​

mojo precompile [options] <path>

Description​

Precompiles a directory of Mojo source files into a binary package suitable to share and import into other Mojo programs and modules. A precompiled Mojo package is faster to build with compared to building it from source. It is not intended as a distributable format as it is tied to the version of the compiler that produced it. Loading a precompiled package using a compiler of a different version will error. Despite this, it is technically portable across different systems because it is not an architecture-specific format (it includes only non-elaborated code). The code becomes an architecture-specific executable only after it's imported into a Mojo program that is then compiled with mojo build.

To create a Mojo package, first add an __init__.mojo file to your package directory. Then pass that directory name to this command, and specify the output path and filename with -o.

For more information, see Mojo modules and packages.

Options​

Output options​

-o <PATH>​

Sets the path and filename for the output package. The filename must end with .mojoc or .mojopkg. The filename given here defines the package name you can then use to import the code (minus the file extension). If you don't specify this option, a .mojoc file is generated in the current working directory, with a name based on the name of the input directory.

Compilation options​

-I <PATH>​

Appends the given path to the list of directories to search for imported Mojo files.

Compilation diagnostic options​

Controls how the Mojo compiler outputs diagnostics related to compiling and running Mojo source code.

--diagnose-missing-doc-strings​

Emits diagnostics for missing or partial doc strings.

--max-notes-per-diagnostic <INTEGER>​

When the Mojo compiler emits diagnostics, it sometimes also prints notes with additional information. This option sets an upper threshold on the number of notes that can be printed with a diagnostic. If not specified, the default maximum is 10.

--disable-builtins​

Do not use builtins when create package.

--disable-warnings​

Do not print warning messages.

--experimental-fixit​

Automatically apply fix-its to the code, and rerun the command again after the fix-its are applied. WARNING: this feature is highly experimental and may result in irreversible data loss.

--experimental-export-fixit <YAML_FILE>​

Export fix-its to a YAML file in clang-tidy format instead of applying them directly. The file can be applied using 'clang-apply-replacements'. WARNING: this feature is highly experimental.

--Werror​

Treat warnings as errors.

--Wno-error​

Do not treat warnings as errors.

--warn-on-unstable-apis​

Warn when using unstable APIs from the standard library.

--ignore-incompatible-precompiled-file-errors​

Ignore errors encountered when loading incompatible Mojo precompiled files.

--ignore-deprecated <NAME>​

Suppress the deprecation warning for the given declaration (e.g. Foo.bar, or some_fn for a top-level declaration).

Common options​

--diagnostic-format <FORMAT>​

The format in which diagnostics and error messages are printed. Must be one of "text" or "json" ("text" is the default).

--help, -h​

Displays help information.

--help-hidden​

Displays help for hidden options.