Skip to content

Commit b0eba00

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

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/build.rs

+7
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ impl BuildDirectory {
171171
Ok(())
172172
}
173173

174+
/// Get the path to the source code on the host machine (outside the sandbox).
175+
pub fn get_source_dir(&self, krate: &Crate) -> Result<PathBuf, Error> {
176+
let source_dir = self.source_dir();
177+
krate.copy_source_to(&self.workspace, source_dir.as_path())?;
178+
Ok(source_dir)
179+
}
180+
174181
fn build_dir(&self) -> PathBuf {
175182
self.workspace.builds_dir().join(&self.name)
176183
}

src/cmd/sandbox.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::path::{Path, PathBuf};
88
use std::time::Duration;
99

1010
/// The Docker image used for sandboxing.
11+
#[derive(Clone)]
1112
pub struct SandboxImage {
1213
name: String,
1314
}
@@ -146,6 +147,7 @@ pub struct SandboxBuilder {
146147
user: Option<String>,
147148
cmd: Vec<String>,
148149
enable_networking: bool,
150+
image: Option<SandboxImage>,
149151
}
150152

151153
impl SandboxBuilder {
@@ -160,6 +162,7 @@ impl SandboxBuilder {
160162
user: None,
161163
cmd: Vec::new(),
162164
enable_networking: true,
165+
image: None,
163166
}
164167
}
165168

@@ -203,6 +206,14 @@ impl SandboxBuilder {
203206
self
204207
}
205208

209+
/// Override the image used for this sandbox.
210+
///
211+
/// By default rustwide will use the image configured with [`WorkspaceBuilder::sandbox_image`].
212+
pub fn image(mut self, image: SandboxImage) -> Self {
213+
self.image = Some(image);
214+
self
215+
}
216+
206217
pub(super) fn env<S1: Into<String>, S2: Into<String>>(mut self, key: S1, value: S2) -> Self {
207218
self.env.push((key.into(), value.into()));
208219
self
@@ -274,7 +285,11 @@ impl SandboxBuilder {
274285
args.push("--isolation=process".into());
275286
}
276287

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

279294
for arg in self.cmd {
280295
args.push(arg);

0 commit comments

Comments
 (0)