Icon HelpCircleForumIcon Link

⌘K

Icon HelpCircleForumIcon Link
Nightly /
Forc Build

Icon LinkCompile

The output produced will depend on the project's program type.

  • script, predicate and contract projects will produce their bytecode in binary format <project-name>.bin.
  • script projects will also produce a file containing the hash of the bytecode binary <project-name>-bin-hash (using fuel_cypto::Hasher).
  • predicate projects will also produce a file containing the root hash of the bytecode binary <project-name>-bin-root (using fuel_tx::Contract::root_from_code).
  • contract and library projects will also produce the public ABI in JSON format <project-name>-abi.json.

Usage: forc build [OPTIONS]

Options:

-p, --path <PATH>

Path to the project.

If not specified, current working directory will be used.

--offline

Offline mode.

Prevents Forc from using the network when managing dependencies. Meaning it will only try to use previously downloaded dependencies.

-t, --terse

Terse mode.

Limited warning and error output.

--output-directory <OUTPUT_DIRECTORY>

The directory in which Forc output artifacts are placed.

By default, this is <project-root>/out.

--locked

Requires that the Forc.lock file is up-to-date.

If the lock file is missing, or it needs to be updated, Forc will exit with an error.

--ipfs-node <IPFS_NODE>

The IPFS node to use for fetching IPFS sources.

[possible values: PUBLIC, LOCAL, <GATEWAY_URL>]

--ast

Print the generated Sway AST (Abstract Syntax Tree)

--dca-graph <DCA_GRAPH>

Print the computed Sway DCA (Dead Code Analysis) graph.

DCA graph is printed to the specified path. If specified '' graph is printed to the stdout.

--dca-graph-url-format <DCA_GRAPH_URL_FORMAT>

URL format to be used in the generated DCA graph .dot file.

Variables {path}, {line}, and {col} can be used in the provided format. An example for vscode would be: "vscode://file/{path}:{line}:{col}"

--asm <ASM>..>

Print the generated ASM (assembler).

Values that can be combined:

  • virtual: initial ASM with virtual registers and abstract control flow.
  • allocated: ASM with registers allocated, but still with abstract control flow.
  • abstract: short for both virtual and allocated ASM.
  • final: final ASM that gets serialized to the target VM bytecode.
  • all: short for virtual, allocated, and final ASM.

[possible values: virtual, allocated, abstract, final, all]

--bytecode

Print the bytecode.

This is the final output of the compiler.

--ir <IR>..>

Print the generated Sway IR (Intermediate Representation).

Values that can be combined:

  • initial: initial IR prior to any optimization passes.
  • final: final IR after applying all optimization passes. : the name of an optimization pass. Prints the IR state after that pass.
  • all: short for initial, final, and all the optimization passes.
  • modified: print a requested optimization pass only if it has modified the IR.

[possible values: initial, final, all, modified, inline, simplify-cfg, sroa, dce, fn-dce, fn-dedup-release, fn-dedup-debug, mem2reg, memcpyopt, const-folding, arg-demotion, const-demotion, ret-demotion, misc-demotion]

--time-phases

Output the time elapsed over each part of the compilation process

--reverse-order

Output build errors and warnings in reverse order

--metrics-outfile <METRICS_OUTFILE>

Output compilation metrics into the specified file

-v, --verbose...

Use verbose output

--json-abi

Minify JSON ABI files.

By default the JSON for ABIs is formatted for human readability. By using this option JSON output will be "minified", i.e. all on one line without whitespace.

-s, --silent

Silence all output

--json-storage-slots

Minify JSON storage slot files.

By default the JSON for initial storage slots is formatted for human readability. By using this option JSON output will be "minified", i.e. all on one line without whitespace.

-L, --log-level <LOG_LEVEL>

Set the log level

-o, --output-bin <BIN_FILE>

Create a binary file at the provided path representing the final bytecode

-g, --output-debug <DEBUG_FILE>

Create a file at the provided path containing debug information.

If the file extension is .json, JSON format is used. Otherwise, an .elf file containing DWARF format is emitted.

--build-profile <BUILD_PROFILE>

The name of the build profile to use

[default: debug]

--release

Use the release build profile.

The release profile can be customized in the manifest file.

--error-on-warnings

Treat warnings as errors

--build-target <BUILD_TARGET>

Build target to use for code generation

[default: fuel] [possible values: fuel, evm, midenvm]

--tests

Also build all tests within the project

--no-encoding-v1

Disable the "new encoding" feature

-h, --help

Print help (see a summary with '-h')

-V, --version

Print version

EXAMPLES:

Icon LinkCompile the current projectx

forc build

Icon LinkCompile the current project from a different path

forc build --path

Icon LinkCompile the current project without updating dependencies

forc build --path --locked

Icon LinkEXAMPLE

Compile the sway files of the current project.

$ forc build
Compiled script "my-fuel-project".
Bytecode size is 28 bytes.

The output produced will depend on the project's program type. Building script, predicate and contract projects will produce their bytecode in binary format <project-name>.bin. Building contracts and libraries will also produce the public ABI in JSON format <project-name>-abi.json.

By default, these artifacts are placed in the out/ directory.

If a Forc.lock file did not yet exist, it will be created in order to pin each of the dependencies listed in Forc.toml to a specific commit or version.