Skip to content

Commit 8fe56ba

Browse files
authored
chore: use rattler-sandbox as an external tool (#1921)
1 parent fd74dd8 commit 8fe56ba

File tree

6 files changed

+38
-123
lines changed

6 files changed

+38
-123
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,6 @@ rattler_redaction = { version = "0.1.12" }
196196
rattler_repodata_gateway = { version = "0.24.7", default-features = false, features = [
197197
"gateway",
198198
] }
199-
rattler_sandbox = { version = "0.1.11", default-features = false, features = [
200-
"tokio",
201-
] }
202199
rattler_shell = { version = "0.25.2", default-features = false, features = [
203200
"sysinfo",
204201
] }

py-rattler-build/Cargo.lock

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

src/main.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ use rattler_upload::upload_from_args;
2121
use tempfile::{TempDir, tempdir};
2222

2323
fn main() -> miette::Result<()> {
24-
// Initialize sandbox in sync/single-threaded context before anything else
25-
#[cfg(any(
26-
all(target_os = "linux", target_arch = "x86_64"),
27-
all(target_os = "linux", target_arch = "aarch64"),
28-
target_os = "macos"
29-
))]
30-
rattler_sandbox::init_sandbox();
31-
3224
// Stack size varies significantly across platforms:
3325
// - Windows: only 1MB by default
3426
// - macOS/Linux: ~8MB by default

src/script/mod.rs

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,11 @@ impl Decoder for CrLfNormalizer {
556556
}
557557
}
558558

559+
/// Find the rattler-sandbox executable in PATH
560+
fn find_rattler_sandbox() -> Option<PathBuf> {
561+
which::which("rattler-sandbox").ok()
562+
}
563+
559564
/// Spawns a process and replaces the given strings in the output with the given replacements.
560565
/// This is used to replace the host prefix with $PREFIX and the build prefix with $BUILD_PREFIX
561566
async fn run_process_with_replacements(
@@ -565,30 +570,28 @@ async fn run_process_with_replacements(
565570
sandbox_config: Option<&SandboxConfiguration>,
566571
) -> Result<std::process::Output, std::io::Error> {
567572
let mut command = if let Some(sandbox_config) = sandbox_config {
568-
#[cfg(any(
569-
all(target_os = "linux", target_arch = "x86_64"),
570-
all(target_os = "linux", target_arch = "aarch64"),
571-
target_os = "macos"
572-
))]
573-
{
574-
tracing::info!("{}", sandbox_config);
575-
rattler_sandbox::tokio::sandboxed_command(
576-
args[0],
577-
&sandbox_config.with_cwd(cwd).exceptions(),
578-
)
579-
}
573+
tracing::info!("{}", sandbox_config);
580574

581-
// If the platform is not supported, log a warning and run the command without sandboxing
582-
#[cfg(not(any(
583-
all(target_os = "linux", target_arch = "x86_64"),
584-
all(target_os = "linux", target_arch = "aarch64"),
585-
target_os = "macos"
586-
)))]
587-
{
588-
tracing::warn!("Sandboxing is not supported on this platform");
589-
// mark variable as used
590-
let _ = sandbox_config;
591-
tokio::process::Command::new(args[0])
575+
// Try to find rattler-sandbox executable
576+
if let Some(sandbox_exe) = find_rattler_sandbox() {
577+
let mut cmd = tokio::process::Command::new(sandbox_exe);
578+
579+
// Add sandbox configuration arguments
580+
let sandbox_args = sandbox_config.with_cwd(cwd).to_args();
581+
cmd.args(&sandbox_args);
582+
583+
// Add the actual command to execute (as positional arguments)
584+
cmd.arg(args[0]);
585+
cmd.args(&args[1..]);
586+
587+
cmd
588+
} else {
589+
tracing::error!("rattler-sandbox executable not found in PATH");
590+
tracing::error!("Please install it by running: pixi global install rattler-sandbox");
591+
return Err(std::io::Error::new(
592+
std::io::ErrorKind::NotFound,
593+
"rattler-sandbox executable not found. Please install it with: pixi global install rattler-sandbox",
594+
));
592595
}
593596
} else {
594597
tokio::process::Command::new(args[0])

src/script/sandbox.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -165,37 +165,30 @@ impl SandboxConfiguration {
165165
}
166166
}
167167

168-
#[cfg(any(
169-
all(target_os = "linux", target_arch = "x86_64"),
170-
all(target_os = "linux", target_arch = "aarch64"),
171-
target_os = "macos"
172-
))]
173-
/// Get the list of exceptions for the sandbox
174-
pub fn exceptions(&self) -> Vec<rattler_sandbox::Exception> {
175-
let mut exceptions = Vec::new();
168+
/// Convert the sandbox configuration to command-line arguments for the rattler-sandbox executable
169+
pub fn to_args(&self) -> Vec<String> {
170+
let mut args = Vec::new();
171+
176172
if self.allow_network {
177-
exceptions.push(rattler_sandbox::Exception::Networking);
173+
args.push("--network".to_string());
178174
}
179175

180176
for path in &self.read {
181-
exceptions.push(rattler_sandbox::Exception::Read(
182-
path.to_string_lossy().to_string(),
183-
));
177+
args.push("--fs-read".to_string());
178+
args.push(path.to_string_lossy().to_string());
184179
}
185180

186181
for path in &self.read_execute {
187-
exceptions.push(rattler_sandbox::Exception::ExecuteAndRead(
188-
path.to_string_lossy().to_string(),
189-
));
182+
args.push("--fs-exec-and-read".to_string());
183+
args.push(path.to_string_lossy().to_string());
190184
}
191185

192186
for path in &self.read_write {
193-
exceptions.push(rattler_sandbox::Exception::ReadAndWrite(
194-
path.to_string_lossy().to_string(),
195-
));
187+
args.push("--fs-write-and-read".to_string());
188+
args.push(path.to_string_lossy().to_string());
196189
}
197190

198-
exceptions
191+
args
199192
}
200193
}
201194

0 commit comments

Comments
 (0)