Skip to content

Commit 17b88c6

Browse files
authored
feat: add optional visibility to metadata entries (#34)
Exposes ic-wasm's metadata visibility to users, per metadata entry.
1 parent 82328bc commit 17b88c6

10 files changed

Lines changed: 30 additions & 15 deletions

File tree

recipes/asset-canister/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ canisters:
2828
| version | string | No | SDK version tag to download the asset canister from (e.g., `0.30.2`) | latest |
2929
| dir | string | Yes | Directory containing frontend assets to synchronize to the canister | - |
3030
| build | array | No | Shell commands to build the frontend assets before deployment (e.g., `npm run build`) | [] |
31-
| metadata | array | No | Array of key-value pairs for custom metadata to inject into the WASM | [] |
31+
| metadata | array | No | Custom wasm metadata entries. Each takes `name`, `value`, and an optional `visibility` of `public` or `private` (omitted means private) | [] |
3232

3333
## Prerequisites
3434

@@ -69,6 +69,9 @@ canisters:
6969
value: "react"
7070
- name: "frontend:version"
7171
value: "1.0.0"
72+
- name: "build:commit"
73+
value: "a1b2c3d"
74+
visibility: public
7275
```
7376

7477
## Build Process

recipes/asset-canister/recipe.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{{! `version: string` Optional, The version of the asset canister to use. Defaults to the master branch}}
33
{{! `dir: string` Required, the directory of assets to synchronize }}
44
{{! `build: [string]` Optional, array of commands to build the frontend assets before deployment }}
5-
{{! `metadata: [name: string, value: string]`: An array of name/value pairs that get injected into the wasm metadata section }}
5+
{{! `metadata: [{name: string, value: string, visibility: string}]`: An array of entries that get injected into the wasm metadata section. `visibility` is optional, `public` or `private`; omitted means private, ic-wasm's default }}
66

77
build:
88

@@ -34,7 +34,7 @@ build:
3434
- type: script
3535
commands:
3636
{{#each metadata}}
37-
- sh -c 'ic-wasm "$ICP_WASM_OUTPUT_PATH" -o "${ICP_WASM_OUTPUT_PATH}" metadata "{{ name }}" -d "{{ value }}" --keep-name-section'
37+
- sh -c 'ic-wasm "$ICP_WASM_OUTPUT_PATH" -o "${ICP_WASM_OUTPUT_PATH}" metadata "{{ name }}" -d "{{ value }}"{{#if visibility}} -v {{ visibility }}{{/if}} --keep-name-section'
3838
{{/each}}
3939
{{/if}}
4040

recipes/motoko/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Compiler flags, per-canister args, and the Candid file are all configured in `mo
3333

3434
| Parameter | Type | Required | Description | Default |
3535
|-----------|---------|----------|----------------------------------------------|---------|
36-
| metadata | array | No | Array of key-value pairs for custom metadata | [] |
36+
| metadata | array | No | Custom wasm metadata entries. Each takes `name`, `value`, and an optional `visibility` of `public` or `private` (omitted means private) | [] |
3737
| shrink | boolean | No | Remove unused functions and debug info to reduce file size | false |
3838
| compress | boolean | No | Gzip compress the WASM file | false |
3939

@@ -83,6 +83,9 @@ canisters:
8383
metadata:
8484
- name: "canister:type"
8585
value: "backend"
86+
- name: "build:commit"
87+
value: "a1b2c3d"
88+
visibility: public
8689
```
8790

8891
```toml

recipes/motoko/recipe.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{! A recipe for building a Motoko canister using `mops build` }}
22
{{! `shrink: boolean` Optimizes the wasm with ic-wasm }}
33
{{! `compress: boolean` determines whether the wasm should be gzipped }}
4-
{{! `metadata: [name: string, value: string]`: An array of name/value pairs that get injected into the wasm metadata section }}
4+
{{! `metadata: [{name: string, value: string, visibility: string}]`: An array of entries that get injected into the wasm metadata section. `visibility` is optional, `public` or `private`; omitted means private, ic-wasm's default }}
55

66
build:
77
steps:
@@ -28,7 +28,7 @@ build:
2828
- ic-wasm "$ICP_WASM_OUTPUT_PATH" -o "${ICP_WASM_OUTPUT_PATH}" metadata "template:type" -d "motoko" --keep-name-section
2929
{{#if metadata}}
3030
{{#each metadata}}
31-
- ic-wasm "$ICP_WASM_OUTPUT_PATH" -o "${ICP_WASM_OUTPUT_PATH}" metadata "{{ name }}" -d "{{ value }}" --keep-name-section
31+
- ic-wasm "$ICP_WASM_OUTPUT_PATH" -o "${ICP_WASM_OUTPUT_PATH}" metadata "{{ name }}" -d "{{ value }}"{{#if visibility}} -v {{ visibility }}{{/if}} --keep-name-section
3232
{{/each}}
3333
{{/if}}
3434

recipes/prebuilt/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ canisters:
3131
| sha256 | string | No | SHA256 hash for integrity verification. Generate with `sha256sum <file>.wasm` | - |
3232
| shrink | boolean | No | Remove unused functions and debug info to reduce file size | false |
3333
| compress | boolean | No | Gzip compress the WASM file | false |
34-
| metadata | array | No | Array of key-value pairs for custom metadata to inject into the WASM | [] |
34+
| metadata | array | No | Custom wasm metadata entries. Each takes `name`, `value`, and an optional `visibility` of `public` or `private` (omitted means private) | [] |
3535

3636
## Prerequisites
3737

@@ -73,6 +73,9 @@ canisters:
7373
value: "2.1.0"
7474
- name: "build:environment"
7575
value: "production"
76+
- name: "build:commit"
77+
value: "a1b2c3d"
78+
visibility: public
7679
- name: "build:timestamp"
7780
value: "2024-01-01T00:00:00Z"
7881
```

recipes/prebuilt/recipe.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{{! `sha256: string` Optional, the hash of the wasm to deploy}}
44
{{! `shrink: boolean` Optimizes the wasm with ic-wasm }}
55
{{! `compress: boolean` determines whether the wasm should be gzipped }}
6-
{{! `metadata: [name: string, value: string]`: An array of name/value pairs that get injected into the wasm metadata section }}
6+
{{! `metadata: [{name: string, value: string, visibility: string}]`: An array of entries that get injected into the wasm metadata section. `visibility` is optional, `public` or `private`; omitted means private, ic-wasm's default }}
77

88
build:
99

@@ -32,7 +32,7 @@ build:
3232
- type: script
3333
commands:
3434
{{#each metadata}}
35-
- ic-wasm "$ICP_WASM_OUTPUT_PATH" -o "${ICP_WASM_OUTPUT_PATH}" metadata "{{ name }}" -d "{{ value }}" --keep-name-section
35+
- ic-wasm "$ICP_WASM_OUTPUT_PATH" -o "${ICP_WASM_OUTPUT_PATH}" metadata "{{ name }}" -d "{{ value }}"{{#if visibility}} -v {{ visibility }}{{/if}} --keep-name-section
3636
{{/each}}
3737
{{/if}}
3838

recipes/rust/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ By convention the canister `name` in `icp.yaml` should match the `[package] name
2626
| package | string | No | Cargo package name to build. Defaults to the canister name in `icp.yaml` | (canister name) |
2727
| locked | boolean | No | Use exact dependency versions from `Cargo.lock` (passes `--locked` to Cargo) | false |
2828
| candid | string | No | Path to a custom Candid interface file. If not provided, the interface is auto-extracted from the WASM using `candid-extractor` | (auto-extracted) |
29-
| metadata | array | No | Array of key-value pairs for custom metadata | [] |
29+
| metadata | array | No | Custom wasm metadata entries. Each takes `name`, `value`, and an optional `visibility` of `public` or `private` (omitted means private) | [] |
3030
| shrink | boolean | No | Remove unused functions and debug info to reduce file size | false |
3131
| compress | boolean | No | Gzip compress the WASM file | false |
3232

@@ -75,6 +75,9 @@ canisters:
7575
value: "1.0.0"
7676
- name: "build:profile"
7777
value: "release"
78+
- name: "build:commit"
79+
value: "a1b2c3d"
80+
visibility: public
7881
```
7982

8083
### Workspace Example

recipes/rust/recipe.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{{! `candid: string` The path to the Candid interface file }}
55
{{! `shrink: boolean` Optimizes the wasm with ic-wasm }}
66
{{! `compress: boolean` determines whether the wasm should be gzipped }}
7-
{{! `metadata: [name: string, value: string]`: An array of name/value pairs that get injected into the wasm metadata section }}
7+
{{! `metadata: [{name: string, value: string, visibility: string}]`: An array of entries that get injected into the wasm metadata section. `visibility` is optional, `public` or `private`; omitted means private, ic-wasm's default }}
88

99
build:
1010
steps:
@@ -36,7 +36,7 @@ build:
3636
{{/if}}
3737
{{#if metadata}}
3838
{{#each metadata}}
39-
- ic-wasm "$ICP_WASM_OUTPUT_PATH" -o "${ICP_WASM_OUTPUT_PATH}" metadata "{{ name }}" -d "{{ value }}" --keep-name-section
39+
- ic-wasm "$ICP_WASM_OUTPUT_PATH" -o "${ICP_WASM_OUTPUT_PATH}" metadata "{{ name }}" -d "{{ value }}"{{#if visibility}} -v {{ visibility }}{{/if}} --keep-name-section
4040
{{/each}}
4141
{{/if}}
4242

recipes/static-site/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ canisters:
2626
| dir | string | Yes | The single directory of built assets to synchronize to the canister | - |
2727
| build | array | No | Shell commands run before sync to produce the asset directory (e.g. `npm run build`) | [] |
2828
| presync | array | No | Shell commands run at sync time (after the canister exists), with the deployed canister IDs in the environment — see [Pre-sync environment](#pre-sync-environment) | [] |
29-
| metadata | array | No | Name/value pairs injected into the canister wasm via `ic-wasm` | [] |
29+
| metadata | array | No | Entries injected into the canister wasm via `ic-wasm`. Each takes `name`, `value`, and an optional `visibility` of `public` or `private` (omitted means private) | [] |
3030

3131
> The sync plugin owns the canister's full URL space and accepts **exactly one** asset directory, so `dir` is a single string rather than a list.
3232

@@ -66,6 +66,9 @@ canisters:
6666
metadata:
6767
- name: "frontend:framework"
6868
value: "react"
69+
- name: "build:commit"
70+
value: "a1b2c3d"
71+
visibility: public
6972
```
7073

7174
### With a pre-sync build that needs canister IDs

recipes/static-site/recipe.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{{! `dir: string` Required. The single directory of built assets to synchronize. }}
33
{{! `build: [string]` Optional. Commands run before sync to produce the asset directory. }}
44
{{! `presync: [string]` Optional. Commands run at sync time (after the canister exists), before assets upload, with the deployed canister IDs in the environment: ICP_CLI_CID, ICP_CLI_CID_<NAME>, ICP_CLI_NETWORK, ICP_CLI_ENVIRONMENT. }}
5-
{{! `metadata: [{name, value}]` Optional. Pairs injected into the canister wasm via ic-wasm. }}
5+
{{! `metadata: [{name, value, visibility}]` Optional. Entries injected into the canister wasm via ic-wasm. `visibility` is optional, `public` or `private`; omitted means private, ic-wasm's default. }}
66

77
build:
88
steps:
@@ -25,7 +25,7 @@ build:
2525
- type: script
2626
commands:
2727
{{#each metadata}}
28-
- sh -c 'ic-wasm "$ICP_WASM_OUTPUT_PATH" -o "$ICP_WASM_OUTPUT_PATH" metadata "{{ name }}" -d "{{ value }}" --keep-name-section'
28+
- sh -c 'ic-wasm "$ICP_WASM_OUTPUT_PATH" -o "$ICP_WASM_OUTPUT_PATH" metadata "{{ name }}" -d "{{ value }}"{{#if visibility}} -v {{ visibility }}{{/if}} --keep-name-section'
2929
{{/each}}
3030
{{/if}}
3131

0 commit comments

Comments
 (0)