Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ You can still disable the canister http feature through configuration:

### feat: custom canister `wasm` field can now specify a URL from which to download

- note that dfx will report an error if a custom canister's `wasm` field is a URL and the canister also has `build` steps.

### feat: custom canister `candid` field can now specify a URL from which to download

### feat: deploy NNS canisters
Expand Down
4 changes: 2 additions & 2 deletions docs/dfx-json-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
"properties": {
"build": {
"title": "Build Commands",
"description": "Commands that are executed in order to produce this canister's WASM module. Expected to produce the WASM in the path specified by the 'wasm' field.",
"description": "Commands that are executed in order to produce this canister's WASM module. Expected to produce the WASM in the path specified by the 'wasm' field. No build commands are allowed if the `wasm` field is a URL.",
"allOf": [
{
"$ref": "#/definitions/SerdeVec_for_String"
Expand All @@ -203,7 +203,7 @@
},
"wasm": {
"title": "WASM Path",
"description": "Path to WASM to be installed. URLs to a WASM module are also acceptable.",
"description": "Path to WASM to be installed. URLs to a WASM module are also acceptable. A canister that has a URL to a WASM module can not also have `build` steps.",
"type": "string"
}
}
Expand Down
21 changes: 21 additions & 0 deletions e2e/tests-dfx/build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ teardown() {
assert_match "$ID"
}

@test "report an error if a canister defines both a wasm url and a build step" {
install_asset wasm/identity
mkdir -p www/wasm
mv main.wasm www/wasm/
mv main.did www/wasm
start_webserver --directory www
dfx_start

dfx_new

jq '.canisters={}' dfx.json | sponge dfx.json

jq '.canisters.e2e_project.candid="http://localhost:'"$E2E_WEB_SERVER_PORT"'/wasm/main.did"' dfx.json | sponge dfx.json
jq '.canisters.e2e_project.wasm="http://localhost:'"$E2E_WEB_SERVER_PORT"'/wasm/main.wasm"' dfx.json | sponge dfx.json
jq '.canisters.e2e_project.type="custom"' dfx.json | sponge dfx.json
jq '.canisters.e2e_project.build="echo nope"' dfx.json | sponge dfx.json

assert_command_fail dfx deploy
assert_contains "Canister 'e2e_project' defines its wasm field as a URL, and has a build step."
}

@test "build uses default build args" {
install_asset default_args
dfx_start
Expand Down
2 changes: 2 additions & 0 deletions src/dfx/src/config/dfinity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ pub enum CanisterTypeProperties {
Custom {
/// # WASM Path
/// Path to WASM to be installed. URLs to a WASM module are also acceptable.
/// A canister that has a URL to a WASM module can not also have `build` steps.
wasm: String,

/// # Candid File
Expand All @@ -147,6 +148,7 @@ pub enum CanisterTypeProperties {
/// # Build Commands
/// Commands that are executed in order to produce this canister's WASM module.
/// Expected to produce the WASM in the path specified by the 'wasm' field.
/// No build commands are allowed if the `wasm` field is a URL.
build: SerdeVec<String>,
},
/// # Motoko-Specific Properties
Expand Down
6 changes: 6 additions & 0 deletions src/dfx/src/lib/canister_info/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ impl CanisterInfoFactory for CustomCanisterInfo {
)
};
let (input_wasm_url, output_wasm_path) = if let Ok(input_wasm_url) = Url::parse(&wasm) {
if !build.is_empty() {
bail!(
"Canister '{}' defines its wasm field as a URL, and has a build step.",
info.name
);
}
let filename = input_wasm_url.path_segments().ok_or_else(|| {
anyhow!(
"unable to determine path segments for url {}",
Expand Down