-
Notifications
You must be signed in to change notification settings - Fork 98
feat: configurable custom wasm sections #2679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4263e0e
feat: configurable custom wasm sections
4f932ce
clippy, format
280bce1
Update CHANGELOG.md
7d2713c
CHANGELOG: note that doc details are only in the JSON schema
250c315
Merge remote-tracking branch 'origin/master' into ericswanson/sdk-660…
cd2ab05
Add docs/concepts
2592609
Merge remote-tracking branch 'origin/master' into ericswanson/sdk-660…
f943485
remove internal docs links
d3f4f32
Merge remote-tracking branch 'origin/master' into ericswanson/sdk-660…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| # Canister Metadata | ||
|
|
||
| ## Overview | ||
|
|
||
| Canisters can store custom metadata, which is available from the state tree at `/canister/<canister id>/metadata/<name>`. | ||
|
|
||
| You can configure this metadata in dfx.json, per canister, in the `metadata` array. | ||
|
|
||
| Here is a simple example: | ||
|
|
||
| ```json | ||
| { | ||
| "canisters": { | ||
| "app_backend": { | ||
| "main": "src/app_backend/main.mo", | ||
| "type": "motoko" | ||
| }, | ||
| "app_frontend": { | ||
| "dependencies": [ | ||
| "app_backend" | ||
| ], | ||
| "frontend": { | ||
| "entrypoint": "src/app_frontend/src/index.html" | ||
| }, | ||
| "source": [ | ||
| "src/app_frontend/assets", | ||
| "dist/app_frontend/" | ||
| ], | ||
| "type": "assets", | ||
| "metadata": [ | ||
| { | ||
| "name": "alternative-domains", | ||
| "visibility": "public", | ||
| "path": "src/app_frontend/metadata/alternative-domains.cbor" | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "version": 1 | ||
| } | ||
| ``` | ||
| ## Fields | ||
|
|
||
| The [JSON schema](../dfx-json-schema.json) also documents these fields. | ||
|
|
||
| ### name | ||
|
|
||
| A string containing the name of the wasm section. | ||
|
|
||
| ### visibility | ||
|
|
||
| A string containing either `private` or `public` (the default). | ||
|
|
||
| Anyone can read the public metadata of a canister. | ||
|
|
||
| Only a controller of the canister can read its private metadata. | ||
|
|
||
| It is not possible to define metadata with the same name with both `private` and `public` visibility, unless they are for different networks. | ||
|
|
||
| ### networks | ||
|
|
||
| An array of strings containing the names of the networks that this metadata applies to. | ||
|
|
||
| If this field is absent, it applies to all networks. | ||
|
|
||
| If this field is present as an empty array, it does not apply to any networks. | ||
|
|
||
| If dfx.json contains more than one metadata entry with a given name, dfx will use the first entry that matches the current network and ignore any that follow. | ||
|
|
||
| ### path | ||
|
|
||
| A string containing the path of a file containing the wasm section contents. | ||
|
|
||
| ## The candid:service metadata | ||
|
|
||
| Dfx automatically adds `candid:service` metadata, with public visibility, for Rust and Motoko canisters. | ||
|
|
||
| You can, however, override this behavior by defining a metadata entry with `"name": "candid:service"`. You can change the visibility or the contents. | ||
|
|
||
| For Motoko canisters, if you specify a `path` for candid:service metadata (replacing the candid:service definition generated by `moc`), dfx will verify that the candid:service definition you provide is a valid subtype of the definition that `moc` generated. | ||
|
|
||
| ## A more complex example | ||
|
|
||
| In this example, we change the visibility of the `candid:service` metadata on the ic and staging networks to private, but leave it public for the local network. | ||
|
|
||
| ```json | ||
| { | ||
| "canisters": { | ||
| "app_backend": { | ||
| "main": "src/app_backend/main.mo", | ||
| "type": "motoko", | ||
| "metadata": [ | ||
| { | ||
| "name": "candid:service", | ||
| "networks": [ "ic", "staging" ], | ||
| "visibility": "private" | ||
| }, | ||
| { | ||
| "name": "candid:service", | ||
| "networks": [ "local" ], | ||
| "visibility": "public" | ||
| } | ||
| ] | ||
| }, | ||
| "app_frontend": { | ||
| "dependencies": [ | ||
| "app_backend" | ||
| ], | ||
| "frontend": { | ||
| "entrypoint": "src/app_frontend/src/index.html" | ||
| }, | ||
| "source": [ | ||
| "src/app_frontend/assets", | ||
| "dist/app_frontend/" | ||
| ], | ||
| "type": "assets" | ||
| } | ||
| }, | ||
| "version": 1 | ||
| } | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # DFX Concepts | ||
|
|
||
| - [Canister metadata](./canister-metadata.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| service : { | ||
| // custom_with_default_metadata | ||
| getCanisterId: () -> (principal) query; | ||
| amInitializer: () -> (bool) query; | ||
| } |
5 changes: 5 additions & 0 deletions
5
e2e/assets/metadata/custom/custom_with_private_candid_service_metadata.did
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| service : { | ||
| // custom_with_private_candid_service_metadata | ||
| getCanisterId: () -> (principal) query; | ||
| amInitializer: () -> (bool) query; | ||
| } |
5 changes: 5 additions & 0 deletions
5
e2e/assets/metadata/custom/custom_with_standard_candid_service_metadata.did
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| service : { | ||
| // custom_with_standard_candid_service_metadata | ||
| getCanisterId: () -> (principal) query; | ||
| amInitializer: () -> (bool) query; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| { | ||
| "version": 1, | ||
| "canisters": { | ||
| "custom_with_default_metadata": { | ||
| "type": "custom", | ||
| "candid": "custom_with_default_metadata.did", | ||
| "wasm": "main.wasm", | ||
| "build": "echo anything" | ||
| }, | ||
| "custom_with_standard_candid_service_metadata": { | ||
| "type": "custom", | ||
| "candid": "custom_with_standard_candid_service_metadata.did", | ||
| "wasm": "main.wasm", | ||
| "metadata": [ | ||
| { | ||
| "name": "candid:service" | ||
| } | ||
| ] | ||
| }, | ||
| "custom_with_private_candid_service_metadata": { | ||
| "type": "custom", | ||
| "candid": "custom_with_private_candid_service_metadata.did", | ||
| "wasm": "main.wasm", | ||
| "metadata": [ | ||
| { | ||
| "name": "candid:service", | ||
| "visibility": "private" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| actor { | ||
| public query func greet(name : Text) : async Text { | ||
| return "Hello, " # name # "!"; | ||
| }; | ||
|
|
||
| stable var a : Nat = 0; | ||
| public func inc_a() : async Nat { | ||
| a += 1; | ||
| return a; | ||
| }; | ||
|
|
||
| stable var b : Int = 0; | ||
| public func inc_b() : async Int { | ||
| b += 1; | ||
| return b; | ||
| }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| service : { | ||
| greet: (text) -> (text) query; | ||
| inc_b: () -> (nat); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| service : { | ||
| new_method: (text) -> (text) query; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| jq '.canisters.e2e_project_backend.main="main.mo"' dfx.json | sponge dfx.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| service : { | ||
| greet: (text) -> (text) query; | ||
| inc_a: () -> (int); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.