11.1清单参考 (Manifest Reference)
The Forc.toml
(the manifest file) is a compulsory file for each package and it is written in [TOML] format. Forc.toml
consists of the following fields:
Forc.toml
(manifest 文件)是每个包的强制文件,它以 [TOML] 格式编写。 Forc.toml
由以下字段组成:
[
project
] - Defines a sway project. [项目
] - 定义一个 sway 项目。name
- The name of the project.名称
- 项目的名称authors
- The authors of the project.作者
-项目的作者organization
- The organization of the project.组织
-项目的组织license
- The project license.许可证
- 项目许可implicit-std
- Controls whether providedstd
version (with the currentforc
version) will get added as a dependency implicitly. Unless you know what you are doing, leave this as default.implicit-std
- 控制是否将提供的std
版本(使用当前的forc
版本)添加为隐藏依赖。 除非您知道自己在做什么,否则请将其保留为默认值。forc-version
- The minimum forc version required for this project to work properly.forc-version
- 该项目正常运行所需的最低 forc 版本
dependencies
- Defines the dependencies.依赖
- 定义依赖项network
- Defines a network for forc to interact with.网络
- 定义 forc 交互的网络。url
-URL of the network.url
- 网络的 URLbuild-profiles
- Defines the build profiles.build-profiles
- 定义构建配置文件patch
- Defines the patches.补丁
- 定义补丁contract-dependencies
- Defines the contract dependencies.合约依赖
- 定义合约依赖。
[项目]
部分 (The [project]
section)
[项目]
部分 (The [project]
section)An example Forc.toml
is shown below. Under [project]
the following fields are optional:
下面显示了一个示例Forc.toml
。在[项目]
下,以下字段是可选的:
作者 authors
组织 organization
Also for the following fields, a default value is provided so omitting them is allowed:
此外,还为以下字段提供了默认值,因此允许省略它们:
entry
- (default : main.sw)入口
- (默认:main.sw)implicit-std
- (default : true)隐含标准
- (默认值:true)
[依赖]
部分 (The [dependencies]
section)
[依赖]
部分 (The [dependencies]
section)The following fields can be provided with a dependency:
可以为以下字段提供依赖:
version
- Desired version of the dependency版本
- 所需的依赖版本path
- The path of the dependency (if it is local)路径
- 依赖项的路径(如果是本地的)git
- The URL of the git repo hosting the dependencygit
- 托管依赖的 git 存储库的 URLbranch
- The desired branch to fetch from the git repo分支
- 从 git 存储库获取所需的分支tag
- The desired tag to fetch from the git repotag
- 从 git 存储库获取所需的标签rev
- The desired rev (i.e. commit hash) referencerev
- 所需的 rev(即提交哈希)参考
Please see dependencies for details
有关详细信息,请参阅依赖
[网络]
部分 (The [network]
section)
[网络]
部分 (The [network]
section)For the following fields, a default value is provided so omitting them is allowed:
对于以下字段,提供了默认值,因此允许省略它们:
URL
- (default: http://127.0.0.1:4000)URL
- (默认值:http://127.0.0.1:4000)
[build-profiles-*]
部分 (The [build-profiles-*]
section)
[build-profiles-*]
部分 (The [build-profiles-*]
section)The [build-profiles]
tables provide a way to customize compiler settings such as debug options.
[build-profiles]
表提供了一种自定义编译器设置(例如调试选项)的方法。
The following fields needs to be provided for a build-profile:
构建配置文件需要提供以下字段:
print-ast
- Whether to print out the generated AST (true) or not (false).print-ast
- 是否打印生成的 AST (true) 或不打印 (false)print-dca-graph
- Whether to print out the computed DCA graph (in GraphViz DOT format).print-dca-graph
- 是否打印计算出的 DCA 图表(以 GraphViz DOT 格式)print-finalized-asm
- Whether to compile to bytecode (false) or to print out the generated ASM (true).print-finalized-asm
- 是否编译为字节码 (false) 或打印生成的 ASM (true)print-intermediate-asm
- Whether to compile to bytecode (false) or to print out the generated ASM (true).print-intermediate-asm
- 是否编译为字节码 (false) 或打印生成的 ASM (true)。print-ir
- Whether to compile to bytecode (false) or to print out the generated IR (true).print-ir
- 是否编译为字节码 (false) 或打印生成的 IR (true)terse-mode
- Terse mode. Limited warning and error output.terse-mode
- 简洁模式。有限的警告和错误输出。
There are two default [build-profile]
available with every manifest file. These are debug
and release
profiles. If you want to override these profiles, you can provide them explicitly in the manifest file like the following example:
每个清单文件都有两个默认的[build-profile]
。这些是调试
和发布
配置文件。如果您想覆盖这些配置文件,您可以在清单文件中明确提供它们,如下例所示:
Since release
and debug
implicitly included in every manifest file, you can use them by just passing --release
or by not passing anything (debug is default). For using a user defined build profile there is --build-profile <profile name>
option available to the relevant commands. (For an example see forc-build)
由于release
和debug
隐式包含在每个清单文件中,因此您可以通过仅传递--release
或不传递任何内容(默认为debug
)来使用。要使用用户定义的构建配置文件,相关命令可以使用--build-profile <profile name>
选项。 (有关示例,请参阅forc-build)
Note that providing the corresponding cli options (like --print-finalized-asm
) will override the selected build profile. For example if you pass both --release
and --print-finalized-asm
, release build profile is omitted and resulting build profile would have a structure like the following:
请注意,提供相应的 cli 选项(如--print-finalized-asm
)将覆盖所选的构建配置文件。例如,如果您同时传递--release
和--print-finalized-asm
,则发布构建配置文件将被省略,生成的构建配置文件将具有如下结构:
print-finalized-asm - true 打印最终确定的asm - true
print-intermediate-asm - false 打印中间asm - false
print-ir - false 打印IR - false
terse - false terse - 错误
[补丁]
部分 (The [patch]
section)
[补丁]
部分 (The [patch]
section)The [patch] section of Forc.toml
can be used to override dependencies with other copies. The example provided below patches https://github.com/fuellabs/sway source with master branch of the same repo.
Forc.toml
的 [patch] 部分可用于覆盖与其他副本的依赖。下面提供的示例,使用同一存储库 https://github.com/fuellabs/sway 为源的主分支 。
In the example above, std
is patched with the test
branch from std
repo. You can also patch git dependencies with dependencies defined with a path.
在上面的示例中,std
是用std
存储库中的test
分支修补的。您还可以使用路径定义的依赖项来修补 git 依赖项。
Just like std
or core
you can also patch dependencies you declared with a git repo.
就像std
或 core
一样,您也可以修补使用 git 存储库声明的依赖项。
Note that each key after the [patch]
is a URL of the source that is being patched.
请注意,[patch]
后面的每个键都是正在修补的源的 URL。
[合约依赖]
部分 (The [contract-dependencies]
section)
[合约依赖]
部分 (The [contract-dependencies]
section)The [contract-dependenices]
table can be used to declare contract dependencies for a Sway contract or script. Contract dependencies are the set of contracts that our contract or script may interact with. Declaring [contract-dependencies]
makes it easier to refer to contracts in your Sway source code without having to manually update IDs each time a new version is deployed. Instead, we can use forc to pin and update contract dependencies just like we do for regular library dependencies.
[合约依赖 contract-dependenices]
表可用于声明 Sway 合约或脚本的合约依赖。合约依赖是合约或脚本可能与之交互的一组合约。声明[合约依赖 contract-dependenices]
可以更轻松地引用 Sway 源代码中的合约,而无需在每次部署新版本时手动更新 ID。相反,我们可以使用 forc 来固定和更新合约依赖,就像处理常规库依赖一样。
Contracts declared under [contract-dependencies]
are built and pinned just like regular [dependencies]
however rather than importing each contract dependency's entire public namespace we instead import their respective contract IDs as CONTRACT_ID
constants available via each contract dependency's namespace root. This means you can use a contract dependency's ID as if it were declared as a pub const
in the root of the contract dependency package as demonstrated in the example below.
在[合约依赖 contract-dependencies]
下,声明合约的构建和固定就像常规的[依赖项 dependencies]
一样,但是我们并不导入每个合约依赖的整个公共命名空间,而是将其各自合约 ID 导入,为可通过每个合约依赖的命名空间使用的CONTRACT_ID
常量根。这意味着您可以使用合约依赖的 ID,就好像它在合约依赖包的根目录中声明为pub const
一样,如下例所示。
Entries under [contract-dependencies]
can be declared in the same way that [dependencies]
can be declared. That is, they can refer to the path
or git
source of another contract. Note that entries under [contract-dependencies]
must refer to contracts and will otherwise produce an error.
[合约依赖 contract-dependencies]
下的条目可以以与[dependencies]
相同的方式声明。也就是说,他们可以引用另一个合约的path
或git
源。请注意,[dependencies]
下的条目必须引用合约,否则会产生错误。
Example Forc.toml
:
示例 Forc.toml
:
Example usage: 示例用法:
Because the ID of a contract is computed deterministically, rebuilding the same contract would always result in the same contract ID. Since two contracts with same contract ID cannot be deployed on the blockchain, a "salt" factor is needed to modify the contract ID. For each contract dependency declared under [contract-dependencies]
, salt
can be specified. An example is shown below:
由于合约的 ID 是确定性计算的,因此重建相同的合约将始终产生相同的合约 ID。由于两个具有相同合约ID的合约无法部署在区块链上,因此需要一个“盐”因子来修改合约ID。对于在[合约依赖 contract-dependencies]
下声明的每个合约依赖,可以指定“盐”。一个例子如下所示:
For contract dependencies that do not specify any value for salt
, a default of all zeros for salt
is implicitly applied.
对于未指定盐 salt
任何值的合约依赖,将默认把salt
的值设置为0。
Last updated