Skip to content

Commit dde39c4

Browse files
committed
add SandboxBuilder image override
1 parent 7a4ef73 commit dde39c4

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/cmd/sandbox.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ pub struct SandboxBuilder {
146146
user: Option<String>,
147147
cmd: Vec<String>,
148148
enable_networking: bool,
149+
image: Option<String>,
149150
}
150151

151152
impl SandboxBuilder {
@@ -160,6 +161,7 @@ impl SandboxBuilder {
160161
user: None,
161162
cmd: Vec::new(),
162163
enable_networking: true,
164+
image: None,
163165
}
164166
}
165167

@@ -203,6 +205,14 @@ impl SandboxBuilder {
203205
self
204206
}
205207

208+
/// Override the image used for this sandbox.
209+
///
210+
/// By default rustwide will use the image configured with [`WorkspaceBuilder::sandbox_image`].
211+
pub fn image(mut self, image: SandboxImage) -> Self {
212+
self.image = Some(image.name);
213+
self
214+
}
215+
206216
pub(super) fn env<S1: Into<String>, S2: Into<String>>(mut self, key: S1, value: S2) -> Self {
207217
self.env.push((key.into(), value.into()));
208218
self
@@ -274,7 +284,11 @@ impl SandboxBuilder {
274284
args.push("--isolation=process".into());
275285
}
276286

277-
args.push(workspace.sandbox_image().name.clone());
287+
if let Some(image) = self.image {
288+
args.push(image);
289+
} else {
290+
args.push(workspace.sandbox_image().name.clone());
291+
}
278292

279293
for arg in self.cmd {
280294
args.push(arg);

src/crates/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ impl Crate {
7373
}
7474
}
7575

76-
pub(crate) fn copy_source_to(&self, workspace: &Workspace, dest: &Path) -> Result<(), Error> {
76+
/// Copy this crate's source to `dest`. If `dest` already exists, it will be replaced.
77+
pub fn copy_source_to(&self, workspace: &Workspace, dest: &Path) -> Result<(), Error> {
7778
if dest.exists() {
7879
info!(
7980
"crate source directory {} already exists, cleaning it up",

0 commit comments

Comments
 (0)