Skip to content

Commit 1e3bc83

Browse files
Fix manifest path separator in container build (#2688)
### What Build `--manifest-path` for `contract build --container`/`--image` with a forward-slash join instead of `Path::display()`. ### Why `rel.display()` renders with the host OS separator, so on Windows it emits backslashes even though the path is passed to `contract build` running inside a Linux container, breaking every Windows CI run (`build-and-test-windows (msrv)` and `(latest)`) since #2678 landed. ### Known limitations N/A
1 parent e89b669 commit 1e3bc83

5 files changed

Lines changed: 24 additions & 11 deletions

File tree

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ termcolor_output = "1.0.1"
108108
ed25519-dalek = ">= 2.1.1"
109109
http = "1.0.0"
110110
walkdir = "2.5.0"
111+
path-slash = "0.2.1"
111112
toml_edit = "0.22.20"
112113
toml = "0.8.19"
113114
reqwest = { version = "0.12.7", default-features = false, features = ["rustls-tls"] }

cmd/crates/soroban-test/tests/it/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn build_with_image_selects_package_by_manifest_path() {
106106
.arg("build")
107107
.arg("--image")
108108
.arg("docker.io/stellar/stellar-cli:latest")
109-
.arg(manifest_path_arg(&add_path()))
109+
.arg(format!("--manifest-path={}", add_path()))
110110
.arg("--print-commands-only")
111111
.assert()
112112
.success()

cmd/soroban-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ serde = { workspace = true, features = ["derive"] }
6161
serde_json = { workspace = true }
6262
serde-aux = { workspace = true }
6363
hex = { workspace = true }
64+
path-slash = { workspace = true }
6465
num-bigint = "0.4"
6566
# Pinned to match the version pulled in by soroban-rpc (jsonrpsee-core) so that
6667
# downcasting RPC errors to `ErrorObjectOwned` resolves to the same type.

cmd/soroban-cli/src/commands/contract/build/container.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::path::{Path, PathBuf};
1616
use std::process::Stdio;
1717

1818
use cargo_metadata::MetadataCommand;
19+
use path_slash::PathExt as _;
1920
use semver::Version;
2021

2122
use crate::commands::{container::shared, global};
@@ -282,7 +283,7 @@ fn forwarded_build_args(
282283
.strip_prefix(workspace_root)
283284
.map(Path::to_path_buf)
284285
.unwrap_or(abs);
285-
args.push(format!("--manifest-path={}", rel.display()));
286+
args.push(format!("--manifest-path={}", rel.to_slash_lossy()));
286287
}
287288
if cmd.profile != "release" {
288289
args.push(format!("--profile={}", cmd.profile));
@@ -767,14 +768,17 @@ mod tests {
767768
use super::*;
768769
use crate::commands::contract::build::BuildArgs;
769770

770-
fn ws() -> &'static Path {
771-
Path::new("/tmp/ws")
771+
fn ws() -> PathBuf {
772+
// Routed through `std::path::absolute` (as `forwarded_build_args` itself does
773+
// for `manifest_path`) so both sides of the `strip_prefix` in
774+
// `forwarded_build_args` agree on drive letter/prefix on Windows.
775+
std::path::absolute(Path::new("/tmp/ws")).unwrap()
772776
}
773777

774778
#[test]
775779
fn forwarded_build_args_defaults() {
776780
let cmd = Cmd::default();
777-
let args = forwarded_build_args(&cmd, ws(), None, true, true, true);
781+
let args = forwarded_build_args(&cmd, &ws(), None, true, true, true);
778782
assert_eq!(args[..2], ["contract".to_string(), "build".to_string()]);
779783
// Default optimize=true → bare `--optimize`; no `--locked` unless asked.
780784
assert!(args.contains(&"--optimize".to_string()));
@@ -788,7 +792,7 @@ mod tests {
788792
locked: true,
789793
..Cmd::default()
790794
};
791-
let args = forwarded_build_args(&cmd, ws(), Some("contract-a"), true, true, true);
795+
let args = forwarded_build_args(&cmd, &ws(), Some("contract-a"), true, true, true);
792796
assert!(args.contains(&"--locked".to_string()));
793797
assert!(args.contains(&"--package=contract-a".to_string()));
794798
}
@@ -800,7 +804,7 @@ mod tests {
800804
locked: true,
801805
..Cmd::default()
802806
};
803-
let args = forwarded_build_args(&cmd, ws(), None, false, true, true);
807+
let args = forwarded_build_args(&cmd, &ws(), None, false, true, true);
804808
assert!(!args.iter().any(|a| a == "--locked"));
805809
}
806810

@@ -810,7 +814,7 @@ mod tests {
810814
// though optimize defaults to true.
811815
let cmd = Cmd::default();
812816
assert!(cmd.build_args.optimize);
813-
let args = forwarded_build_args(&cmd, ws(), None, true, false, false);
817+
let args = forwarded_build_args(&cmd, &ws(), None, true, false, false);
814818
assert!(!args.iter().any(|a| a.starts_with("--optimize")));
815819
}
816820

@@ -830,7 +834,7 @@ mod tests {
830834
},
831835
..Cmd::default()
832836
};
833-
let args = forwarded_build_args(&cmd, ws(), None, true, true, true);
837+
let args = forwarded_build_args(&cmd, &ws(), None, true, true, true);
834838
assert!(args.contains(&"--profile=dev".to_string()));
835839
assert!(args.contains(&"--features=a,b".to_string()));
836840
assert!(args.contains(&"--all-features".to_string()));
@@ -851,7 +855,7 @@ mod tests {
851855
},
852856
..Cmd::default()
853857
};
854-
let args = forwarded_build_args(&cmd, ws(), None, true, true, false);
858+
let args = forwarded_build_args(&cmd, &ws(), None, true, true, false);
855859
assert!(!args.iter().any(|a| a.starts_with("--optimize")));
856860
}
857861

@@ -861,7 +865,7 @@ mod tests {
861865
manifest_path: Some(PathBuf::from("/tmp/ws/contracts/add/Cargo.toml")),
862866
..Cmd::default()
863867
};
864-
let args = forwarded_build_args(&cmd, ws(), None, true, true, true);
868+
let args = forwarded_build_args(&cmd, &ws(), None, true, true, true);
865869
assert!(args.contains(&"--manifest-path=contracts/add/Cargo.toml".to_string()));
866870
}
867871

0 commit comments

Comments
 (0)