-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: configurable custom wasm sections (#2679)
- Loading branch information
1 parent
db3de4d
commit 7819485
Showing
29 changed files
with
684 additions
and
75 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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.