@@ -30,10 +30,12 @@ class SentryCli < Formula
3030 depends_on "openssl@3"
3131 end
3232
33+ # Allow setting environment variable to disable swift sandbox.
34+ # Upstreamed at https://github.com/getsentry/sentry-cli/pull/2587.
35+ patch :DATA
36+
3337 def install
34- # Disable the nested sandbox to avoid errors when building in our own sandbox.
35- # TODO: Upstream a way to optionally include `--disable-sandbox` in the `swift` invocation.
36- inreplace "apple-catalog-parsing/build.rs" , '"build",' , '"build", "--disable-sandbox",'
38+ ENV [ "SWIFT_DISABLE_SANDBOX" ] = "1"
3739 system "cargo" , "install" , *std_cargo_args
3840
3941 generate_completions_from_executable ( bin /"sentry-cli" , "completions" )
@@ -47,3 +49,51 @@ def install
4749 assert_match "Auth token is required for this request." , output
4850 end
4951end
52+
53+ __END__
54+ diff --git i/apple-catalog-parsing/build.rs w/apple-catalog-parsing/build.rs
55+ index a381d4c8..2a1027be 100644
56+ --- i/apple-catalog-parsing/build.rs
57+ +++ w/apple-catalog-parsing/build.rs
58+ @@ -22,19 +22,30 @@ fn main() {
59+
60+ let out_dir = env::var("OUT_DIR").expect("OUT_DIR is set for build scripts");
61+
62+ + let scratch_path = format!("{out_dir}/swift-scratch");
63+ + let triple = format!("{arch}-apple-macosx10.12");
64+ + let mut args = vec![
65+ + "build",
66+ + "-c",
67+ + "release",
68+ + "--package-path",
69+ + "native/swift/AssetCatalogParser",
70+ + "--scratch-path",
71+ + &scratch_path,
72+ + "--triple",
73+ + &triple,
74+ + ];
75+ +
76+ + // Allow swift to be run with `--disable-sandbox` in case cargo has been invoked inside a
77+ + // sandbox already. Nested sandboxes are not allowed on Darwin.
78+ + println!("cargo:rerun-if-env-changed=SWIFT_DISABLE_SANDBOX");
79+ + if std::env::var_os("SWIFT_DISABLE_SANDBOX").map_or(false, |s| s != "0") {
80+ + args.push("--disable-sandbox");
81+ + }
82+ +
83+ // Compile Swift code
84+ let status = Command::new("swift")
85+ - .args([
86+ - "build",
87+ - "-c",
88+ - "release",
89+ - "--package-path",
90+ - "native/swift/AssetCatalogParser",
91+ - "--scratch-path",
92+ - &format!("{out_dir}/swift-scratch"),
93+ - "--triple",
94+ - &format!("{arch}-apple-macosx10.12"),
95+ - ])
96+ + .args(&args)
97+ .status()
98+ .expect("Failed to compile SPM");
99+
0 commit comments