Skip to content

Commit

Permalink
fix: correctly detect hyphenated bin artifact file path (#4069)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamspofford-dfinity authored Jan 21, 2025
1 parent 47f6b43 commit 6d2b777
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# UNRELEASED

### fix: correctly detects hyphenated Rust bin crates

### fix: removes unnecessary tsc step in sveltekit build script

### feat!: `dfx info pocketic-config-port`
Expand Down
3 changes: 3 additions & 0 deletions e2e/assets/hyphenated-project/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[workspace]
resolver = "2"
members = ["hyphenated-lib", "hyphenated-bin"]
15 changes: 15 additions & 0 deletions e2e/assets/hyphenated-project/dfx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": 1,
"canisters": {
"hyphenated-bin": {
"type": "rust",
"candid": "name.did",
"package": "hyphenated-bin"
},
"hyphenated-lib": {
"type": "rust",
"candid": "name.did",
"package": "hyphenated-lib"
}
}
}
8 changes: 8 additions & 0 deletions e2e/assets/hyphenated-project/hyphenated-bin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "hyphenated-bin"
version = "0.0.0"
publish = false

[dependencies]
ic-cdk = "0.17"
candid = "0.10"
6 changes: 6 additions & 0 deletions e2e/assets/hyphenated-project/hyphenated-bin/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![no_main]

#[ic_cdk::query]
fn name() -> String {
"bin".into()
}
11 changes: 11 additions & 0 deletions e2e/assets/hyphenated-project/hyphenated-lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "hyphenated-lib"
version = "0.0.0"
publish = false

[lib]
crate-type = ["cdylib"]

[dependencies]
ic-cdk = "0.17"
candid = "0.10"
4 changes: 4 additions & 0 deletions e2e/assets/hyphenated-project/hyphenated-lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[ic_cdk::query]
fn name() -> String {
"lib".into()
}
3 changes: 3 additions & 0 deletions e2e/assets/hyphenated-project/name.did
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
service : {
name : () -> (text) query;
}
11 changes: 11 additions & 0 deletions e2e/tests-dfx/deploy.bash
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,14 @@ teardown() {
assert_command_fail dfx deploy --mode reinstall --wasm-memory-persistence keep
assert_contains "--skip-pre-upgrade and --wasm-memory-persistence can only be used with mode 'upgrade' or 'auto'."
}

@test "can deploy a hyphenated project" {
setup_rust
install_asset hyphenated-project
dfx_start
assert_command dfx deploy
assert_command dfx canister call hyphenated-bin name
assert_contains bin
assert_command dfx canister call hyphenated-lib name
assert_contains lib
}
6 changes: 5 additions & 1 deletion src/dfx/src/lib/canister_info/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ impl CanisterInfoFactory for RustCanisterInfo {
"More than one bin/cdylib {phrasing} found"
);

let wasm_name = target.name.replace('-', "_");
let wasm_name = if target.kind.iter().any(|t| t == "bin") {
target.name.clone()
} else {
target.name.replace('-', "_")
};
let output_wasm_path = metadata
.target_directory
.join(format!("wasm32-unknown-unknown/release/{wasm_name}.wasm"))
Expand Down

0 comments on commit 6d2b777

Please sign in to comment.