diff --git a/Cargo.lock b/Cargo.lock index 2547c7a7e..3e6edb12a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3882,6 +3882,12 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "path-slash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e91099d4268b0e11973f036e885d652fb0b21fedcf69738c627f94db6a44f42" + [[package]] name = "pathdiff" version = "0.2.3" @@ -5363,6 +5369,7 @@ dependencies = [ "mockito", "num-bigint", "open", + "path-slash", "pathdiff", "phf", "predicates", diff --git a/Cargo.toml b/Cargo.toml index 5842c403c..eaa8e83d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -108,6 +108,7 @@ termcolor_output = "1.0.1" ed25519-dalek = ">= 2.1.1" http = "1.0.0" walkdir = "2.5.0" +path-slash = "0.2.1" toml_edit = "0.22.20" toml = "0.8.19" reqwest = { version = "0.12.7", default-features = false, features = ["rustls-tls"] } diff --git a/cmd/crates/soroban-test/tests/it/build.rs b/cmd/crates/soroban-test/tests/it/build.rs index dddf87fd8..84c42fd32 100644 --- a/cmd/crates/soroban-test/tests/it/build.rs +++ b/cmd/crates/soroban-test/tests/it/build.rs @@ -106,7 +106,7 @@ fn build_with_image_selects_package_by_manifest_path() { .arg("build") .arg("--image") .arg("docker.io/stellar/stellar-cli:latest") - .arg(manifest_path_arg(&add_path())) + .arg(format!("--manifest-path={}", add_path())) .arg("--print-commands-only") .assert() .success() diff --git a/cmd/soroban-cli/Cargo.toml b/cmd/soroban-cli/Cargo.toml index 1e1d26225..038edb213 100644 --- a/cmd/soroban-cli/Cargo.toml +++ b/cmd/soroban-cli/Cargo.toml @@ -61,6 +61,7 @@ serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } serde-aux = { workspace = true } hex = { workspace = true } +path-slash = { workspace = true } num-bigint = "0.4" # Pinned to match the version pulled in by soroban-rpc (jsonrpsee-core) so that # downcasting RPC errors to `ErrorObjectOwned` resolves to the same type. diff --git a/cmd/soroban-cli/src/commands/contract/build/container.rs b/cmd/soroban-cli/src/commands/contract/build/container.rs index d90773827..c6299e998 100644 --- a/cmd/soroban-cli/src/commands/contract/build/container.rs +++ b/cmd/soroban-cli/src/commands/contract/build/container.rs @@ -16,6 +16,7 @@ use std::path::{Path, PathBuf}; use std::process::Stdio; use cargo_metadata::MetadataCommand; +use path_slash::PathExt as _; use semver::Version; use crate::commands::{container::shared, global}; @@ -282,7 +283,7 @@ fn forwarded_build_args( .strip_prefix(workspace_root) .map(Path::to_path_buf) .unwrap_or(abs); - args.push(format!("--manifest-path={}", rel.display())); + args.push(format!("--manifest-path={}", rel.to_slash_lossy())); } if cmd.profile != "release" { args.push(format!("--profile={}", cmd.profile)); @@ -767,14 +768,17 @@ mod tests { use super::*; use crate::commands::contract::build::BuildArgs; - fn ws() -> &'static Path { - Path::new("/tmp/ws") + fn ws() -> PathBuf { + // Routed through `std::path::absolute` (as `forwarded_build_args` itself does + // for `manifest_path`) so both sides of the `strip_prefix` in + // `forwarded_build_args` agree on drive letter/prefix on Windows. + std::path::absolute(Path::new("/tmp/ws")).unwrap() } #[test] fn forwarded_build_args_defaults() { let cmd = Cmd::default(); - let args = forwarded_build_args(&cmd, ws(), None, true, true, true); + let args = forwarded_build_args(&cmd, &ws(), None, true, true, true); assert_eq!(args[..2], ["contract".to_string(), "build".to_string()]); // Default optimize=true → bare `--optimize`; no `--locked` unless asked. assert!(args.contains(&"--optimize".to_string())); @@ -788,7 +792,7 @@ mod tests { locked: true, ..Cmd::default() }; - let args = forwarded_build_args(&cmd, ws(), Some("contract-a"), true, true, true); + let args = forwarded_build_args(&cmd, &ws(), Some("contract-a"), true, true, true); assert!(args.contains(&"--locked".to_string())); assert!(args.contains(&"--package=contract-a".to_string())); } @@ -800,7 +804,7 @@ mod tests { locked: true, ..Cmd::default() }; - let args = forwarded_build_args(&cmd, ws(), None, false, true, true); + let args = forwarded_build_args(&cmd, &ws(), None, false, true, true); assert!(!args.iter().any(|a| a == "--locked")); } @@ -810,7 +814,7 @@ mod tests { // though optimize defaults to true. let cmd = Cmd::default(); assert!(cmd.build_args.optimize); - let args = forwarded_build_args(&cmd, ws(), None, true, false, false); + let args = forwarded_build_args(&cmd, &ws(), None, true, false, false); assert!(!args.iter().any(|a| a.starts_with("--optimize"))); } @@ -830,7 +834,7 @@ mod tests { }, ..Cmd::default() }; - let args = forwarded_build_args(&cmd, ws(), None, true, true, true); + let args = forwarded_build_args(&cmd, &ws(), None, true, true, true); assert!(args.contains(&"--profile=dev".to_string())); assert!(args.contains(&"--features=a,b".to_string())); assert!(args.contains(&"--all-features".to_string())); @@ -851,7 +855,7 @@ mod tests { }, ..Cmd::default() }; - let args = forwarded_build_args(&cmd, ws(), None, true, true, false); + let args = forwarded_build_args(&cmd, &ws(), None, true, true, false); assert!(!args.iter().any(|a| a.starts_with("--optimize"))); } @@ -861,7 +865,7 @@ mod tests { manifest_path: Some(PathBuf::from("/tmp/ws/contracts/add/Cargo.toml")), ..Cmd::default() }; - let args = forwarded_build_args(&cmd, ws(), None, true, true, true); + let args = forwarded_build_args(&cmd, &ws(), None, true, true, true); assert!(args.contains(&"--manifest-path=contracts/add/Cargo.toml".to_string())); }