> For the complete documentation index, see [llms.txt](https://docs.midnight.network/llms.txt)

# Compact compiler usage page

This is the usage page of **compactc**, a compiler for Compact. This document assumes you are using **compactc** directly. Typically, however, the compiler is invoked via the **compact** tool's `compile` command, which is described in the [usage page for that tool](https://docs.midnight.network/compact/compilation-and-tooling/dev-tool-usage.md).

# NAME

compactc

# OVERVIEW

The Compact compiler, **compactc**, is part of the Compact toolchain. It takes as input a Compact source program in a specified source file and translates it into several target files in a specified directory.

# SYNOPSIS

**compactc** *flag* **...** *sourcepath* *targetpath*

# DESCRIPTION

The flags *flag* **...** are optional. They are described under FLAGS later in this document.

*sourcepath* should identify a file containing a Compact source program, and *targetpath* should identify a target directory into which the target files are to be placed. The target directory is created if it does not already exist.

**compactc** compiles the source file and produces from it the following target files:

* a Typescript type-definition file *targetdir***/contract/index.d.ts**,

* a Javascript source file *targetdir***/contract/index.js**,

* a Javascript source-map file *targetdir***/contract/index.js.map**,

* a contract-information file *targetdir***/compiler/contract-info.json**,

* one Zk/ir circuit file *targetdir***/zkir/***circuitname***.zkir** and one binary Zk/ir circuit file *targetdir***/zkir/***circuitname***.bzkir** for each circuit *circuitname* that requires a proof,

* a pair of proving keys *targetdir***/keys/***circuitname***.prover** and *targetdir***/keys/***circuitname***.verifier** for each circuit *circuitname* that requires a proof, and

* a manifest file *targetdir***/compiler/contract-manifest.json**, organized by directory, listing the generated files identified above along with their sizes and SHA-256 sums.

Compact source files can include other Compact source files via an **include** form:

**include** '*name*';

They can also import externally defined modules via an **import** form:

**import** *name*; **import** '*name*';

By default, the compiler looks for include files and externally defined modules with non-absolute pathnames relative to the directory of the including or importing file under the full filename *name***.compact**. If this fails, it looks for the file in the *Compact search list*. The Compact search list is

* the value of the **--compact-path** command-line option, if provided,
* otherwise the value of the **COMPACT\_PATH** environment variable, if set,
* otherwise empty. The search list is a colon-separated (semicolon-separated on Windows) list of directory pathnames *dirpath***:...:***dirpath* (*dirpath***;...;***dirpath* under Windows), and the compiler looks under the full pathname *dirpath***/***name***.compact** for each *dirpath* in order until the file is found or the set of *dirpath* entries is exhausted.

Most Compact source programs should import the standard library **CompactStandardLibrary**. This is typically done by placing the following line near the top of the program:

**import CompactStandardLibrary;**

**CompactStandardLibrary** is built into the compiler, not found in the filesystem.

# FLAGS

The following flags, if present, affect the compiler's behavior as follows:

**--help**

Prints help text and exits.

**--version**

Prints the compiler version and exits. Builds that recorded a commit follow the version with that commit and its date in parentheses.

**--verbose**

Given together with **--version**, in either order, prints the version, commit, commit date, and language and runtime versions as separate fields, showing *unknown* for anything the build did not record.

**--language-version**

Prints the language version supported by the compiler and exits.

**--runtime-version**

Prints the runtime version required by the compiler and exits.

**--ledger-version**

Prints the ledger version required by the compiler and exits.

**--vscode**

Causes the compiler to omit newlines from error messages, so that they are rendered properly within the VS Code extension for Compact.

**--skip-zk**

Causes the compiler to skip the generation of proving keys. Generating proving keys can be time-consuming, so this option is useful when debugging only the Typescript output. The compiler also skips, after printing a warning message, the generation of proving keys when it cannot find zkir.

**--no-communications-commitment**

Omits the contract communications commitment that enables data integrity for contract-to-contract calls.

**--sourceRoot *sourceRoot-value***

Overrides the compiler's setting of the sourceRoot field in the generated source-map (.js.map) file. By default, the compiler tries to determine a useful value based on the source and target-directory pathnames, but this value might not be appropriate for the deployed structure of the application.

**--compact-path *search list***

Sets the Compact path, overriding the default value, which is the value of the environment variable COMPACT\_PATH, if it is set, and empty otherwise. ***search list*** should be a colon-separated (semicolon-separated under Windows) sequence of directory pathnames. The Compact path controls where the compiler looks for include and external module files with non-absolute pathnames. It always looks first relative to the directory of the including or importing file, then in each directory in the Compact path from left to right.

**--trace-search**

Causes the compiler to print a sequence of messages saying where it is looking for each included file and imported module source file.

**--trace-passes**

Causes the compiler to print tracing information that is generally useful only to compiler developers.

# EXAMPLES

Assuming **src/test.compact** contains a well-formed Compact program containing circuits *foo*, *bar*, and *baz* where *foo* and *bar* are exported but *baz* is not and *foo* touches (reads or writes) a ledger field but *bar* does not:

```
compactc src/test.compact obj/test
```

produces:

```
obj/test/contract/index.d.ts

obj/test/contract/index.js

obj/test/contract/index.js.map



obj/test/compiler/contract-info.json

obj/test/compiler/contract-manifest.json



obj/test/zkir/foo.zkir

obj/test/zkir/foo.bzkir



obj/test/keys/foo.prover

obj/test/keys/foo.verifier
```

Note that

```
compactc --skip-zk src/test.compact obj/test
```

produces the same, except without the keys.

# EXIT STATUS

**compactc** exits with status 0 on success and with a nonzero status on failure. In particular, it exits with status 1 if the command line is malformed.
