# 11.4.2 forc-build

Compile the current or target project.

编译当前或指定的项目。

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`, `predicate` 和`contract`项目将以二进制格式`<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`).\
  `script`项目还将生成一个包含字节码二进制文件`<project-name>-bin-hash` 哈希值的文件（使用`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`).\
  `predicate` 项目还将生成一个包含字节码二进制文件 `<project-name>-bin-root` 的 **root** 哈希值的文件（使用 `fuel_tx::Contract::root_from_code`）
* `contract` and `library` projects will also produce the public ABI in JSON format `<project-name>-abi.json`.\
  `contract`和`library`项目还将生成 JSON 格式的公共 ABI `<project-name>-abi.json`。

### 用法 (USAGE):

forc build \[OPTIONS]

### 选项 (OPTIONS):

`--ast`

Print the generated Sway AST (Abstract Syntax Tree)

打印生成的Sway AST（抽象语法树）

`--build-profile` <_BUILD\_PROFILE_>

Name of the build profile to use.

If unspecified, forc will use debug build profile.

要用的构建配置文件的名称。

如果未指定，forc 将使用调试构建配置文件。

`--build-target` <_BUILD\_TARGET_>

Build target to use for code generation

构建用于代码生成的目标

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

`--dca-graph` <_DCA\_GRAPH_>

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

打印计算出的 Sway DCA 图表。 DCA图打印到指定路径。如果指定"图形"将打印为标准输出

`--dca-graph-url-format` <_DCA\_GRAPH\_URL\_FORMAT_>

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

指定生成的点文件中使用的 url 格式。变量 {path}、{line} {col} 可以按提供的格式使用。 vscode 的示例为：“vscode://file/{path}:{line}:{col}”

`--error-on-warnings`

Treat warnings as errors

将警告视为错误

`--finalized-asm`

Print the finalized ASM.

This is the state of the ASM with registers allocated and optimisations applied.

打印最终的 ASM。

这是分配注册器并应用优化的 ASM 状态。

`-g`, `--output-debug` <_DEBUG\_FILE_>

If set, outputs source file mapping in JSON format

如果设置，则以 JSON 格式输出源文件映射

`-h`, `--help`

Print help information

打印帮助信息

`--intermediate-asm`

Print the generated ASM.

打印生成的ASM。

This is the state of the ASM prior to performing register allocation and other ASM optimisations.

这是执行注册器分配和其他 ASM 优化之前 ASM 的状态。

`--ir`

Print the generated Sway IR (Intermediate Representation)

打印生成的 Sway IR（中间表示）

`--json-abi`

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

默认情况下，ABI 的 JSON 的格式适合人类阅读。通过使用此选项，JSON 输出将被“缩小”，即全部在一行上，没有空格

`--json-abi-with-callpaths`

Outputs json abi with callpaths instead of names for struct and enums

输出带有调用路径的 json abi，​​而不是结构和穷举的名称 `--json-storage-slots`

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

默认情况下，初始存储槽的 JSON 被格式化为人类可读。通过使用此选项，JSON 输出将被“缩小”，即全部在一行上，没有空格

`-L`, `--log-level` <_LOG\_LEVEL_>

Set the log level

设置日志级别

`--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

要求 Forc.lock 文件是最新的。如果锁定文件丢失，或者需要更新，Forc 将退出并出现错误

`-o`, `--output-bin` <_BIN\_FILE_>

If set, outputs a binary file representing the script bytes

如果设置，则输出表示脚本字节的二进制文件

`--offline`

Offline mode, prevents Forc from using the network when managing dependencies. Meaning it will only try to use previously downloaded dependencies

离线模式可防止 Forc 在管理依赖项时使用网络。这意味着它只会尝试使用以前下载的依赖

`--output-directory` <_OUTPUT\_DIRECTORY_>

The directory in which the sway compiler output artifacts are placed.

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

放置 sway 编译器输出工件的目录。 默认情况下，这是`<project-root>/out`

`-p`, `--path` <_PATH_>

Path to the project, if not specified, current working directory will be used

项目路径，如果未指定，将使用当前工作目录

`--release`

Use release build plan. If a custom release plan is not specified, it is implicitly added to the manifest file.

使用发布构建计划。如果未指定自定义发布计划，则会将其隐式添加到清单文件中。

If --build-profile is also provided, forc omits this flag and uses provided build-profile.

如果还提供了 --build-profile，则 forc 会忽略此标志并使用提供的 build-profile。

`-s`, `--silent`

Silence all output

消除所有输出

`-t`, `--terse`

Terse mode. Limited warning and error output

简洁模式。有限的警告和错误输出

`--tests`

Also build all tests within the project

还构建项目内的所有测试

`--time-phases`

Output the time elapsed over each part of the compilation process

输出编译过程每个部分所花费的时间

`-v`, `--verbose`

Use verbose output

使用详细输出

### 示例 (EXAMPLE)

Compile the sway files of the current project.

编译当前项目的sway文件。

`$ 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`.

产生的输出将取决于项目的程序类型。构建脚本、谓词和合约项目将以二进制格式`<project-name>.bin`生成字节码。构建合约和库还将生成 JSON 格式的公共 ABI`<project-name>-abi.json`。

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

默认情况下，这些工件放置在`out/`目录中。

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.

如果`Forc.lock`文件尚不存在，则会创建该文件，以便将`Forc.toml`中列出的每个依赖项固定到特定的提交或版本。
