Skip to content

Commit 519f208

Browse files
zees-devsdankel
andauthored
Forc.toml metadata support (#6728)
# Description Adds support for `metadata` as `[project.metadata]` or `[workspace.metadata]` in `Forc.toml` of value `toml::Value` - Addresses: https://github.com/FuelLabs/rfcs/blob/22bf3936a37b60bb496232c1b52bf59e204a0697/text/rfcs/0006-metadata-in-forc-manifest.md#reference-level-explanation - Resolves: #2180 ## Linked examples of usage - FuelLabs/example-forc-plugins#1 --------- Co-authored-by: Sophie Dankel <[email protected]>
1 parent 9741809 commit 519f208

File tree

2 files changed

+366
-3
lines changed

2 files changed

+366
-3
lines changed

docs/book/src/forc/manifest_reference.md

+78
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The `Forc.toml` (the _manifest_ file) is a compulsory file for each package and
1111
* For the recommended way of selecting an entry point of large libraries please take a look at: [Libraries](./../sway-program-types/libraries.md)
1212
* `implicit-std` - Controls whether provided `std` version (with the current `forc` version) will get added as a dependency _implicitly_. _Unless you know what you are doing, leave this as default._
1313
* `forc-version` - The minimum forc version required for this project to work properly.
14+
* `metadata` - Metadata for the project; can be used by tools which would like to store package configuration in `Forc.toml`.
1415

1516
* [`[dependencies]`](#the-dependencies-section) — Defines the dependencies.
1617
* `[network]` — Defines a network for forc to interact with.
@@ -41,8 +42,85 @@ entry = "main.sw"
4142
organization = "Fuel_Labs"
4243
license = "Apache-2.0"
4344
name = "wallet_contract"
45+
46+
[project.metadata]
47+
indexing = { namespace = "counter-contract", schema_path = "out/release/counter-contract-abi.json" }
48+
```
49+
50+
### Metadata Section in `Forc.toml`
51+
52+
The `[project.metadata]` section provides a dedicated space for external tools and plugins to store their configuration in `Forc.toml`. The metadata key names are arbitrary and do not need to match the tool's name.
53+
54+
#### Workspace vs Project Metadata
55+
56+
Metadata can be defined at two levels:
57+
58+
Workspace level - defined in the workspace\'s root `Forc.toml`:
59+
60+
```toml
61+
[workspace.metadata]
62+
my_tool = { shared_setting = "value" }
63+
```
64+
65+
Project level - defined in individual project\'s `Forc.toml`:
66+
67+
```toml
68+
[project.metadata.any_name_here]
69+
option1 = "value"
70+
option2 = "value"
71+
72+
[project.metadata.my_custom_config]
73+
setting1 = "value"
74+
setting2 = "value"
75+
```
76+
77+
Example for an indexing tool:
78+
79+
```toml
80+
[project.metadata.indexing]
81+
namespace = "counter-contract"
82+
schema_path = "out/release/counter-contract-abi.json"
4483
```
4584

85+
When both workspace and project metadata exist:
86+
87+
* Project-level metadata should take precedence over workspace metadata
88+
* Tools can choose to merge workspace and project settings
89+
* Consider documenting your tool's metadata inheritance behavior
90+
91+
#### Guidelines for Plugin Developers
92+
93+
Best Practices
94+
95+
* Choose clear, descriptive metadata key names
96+
* Document the exact metadata key name your tool expects
97+
* Don't require `Forc.toml` if tool can function without it
98+
* Consider using TOML format for dedicated config files
99+
* Specify how your tool handles workspace vs project metadata
100+
101+
Implementation Notes
102+
103+
* The metadata section is optional
104+
* Forc does not parse metadata contents
105+
* Plugin developers handle their own configuration parsing
106+
* Choose unique metadata keys to avoid conflicts with other tools
107+
108+
#### Example Use Cases
109+
110+
* Documentation generation settings
111+
* Formatter configurations
112+
* Debugger options
113+
* Wallet integration
114+
* Contract indexing
115+
* Testing frameworks
116+
117+
This allows for a streamlined developer experience while maintaining clear separation between core Forc functionality and third-party tools.
118+
119+
#### External Tooling Examples
120+
121+
* [forc-index-ts](https://github.com/FuelLabs/example-forc-plugins/tree/master/forc-index-ts): A TypeScript CLI tool for parsing `Forc.toml` metadata to read contract ABI JSON file.
122+
* [forc-index-rs](https://github.com/FuelLabs/example-forc-plugins/tree/master/forc-index-rs): A Rust CLI tool for parsing `Forc.toml` metadata to read contract ABI JSON file.
123+
46124
## The `[dependencies]` section
47125

48126
The following fields can be provided with a dependency:

0 commit comments

Comments
 (0)