Convert quarantine script to use FFI rather than Swift#22377
Conversation
There was a problem hiding this comment.
Pull request overview
This PR replaces the Swift-based Cask quarantine helper with a Ruby/Fiddle (FFI) implementation on macOS, and factors out a reusable macOS FFI wrapper (also used for shared-cache dylib detection).
Changes:
- Add
OS::Mac::FFIwrappers for libSystem/CoreFoundation/LaunchServices viaFiddle. - Switch Cask quarantine application from invoking
quarantine.swiftto setting quarantine properties via CoreFoundation/LaunchServices FFI. - Refactor macOS
LinkageCheckershared-cache detection to use the new FFI wrapper and simplify the base checker logic.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| Library/Homebrew/os/mac/ffi.rb | New macOS Fiddle-based wrappers for dyld/CoreFoundation/LaunchServices APIs. |
| Library/Homebrew/linkage_checker.rb | Simplifies “system dylib in shared cache” detection path. |
| Library/Homebrew/extend/os/mac/linkage_checker.rb | Uses the new FFI wrapper for _dyld_shared_cache_contains_path and removes old inline Fiddle setup. |
| Library/Homebrew/cask/quarantine.rb | Replaces Swift quarantine execution with direct CoreFoundation/LaunchServices FFI calls. |
| Library/Homebrew/cask/utils/quarantine.swift | Removes the Swift quarantine script previously used by quarantine support checks and quarantining. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
33bed90 to
bc54be7
Compare
MikeMcQuaid
left a comment
There was a problem hiding this comment.
This is interesting, thanks for the PR @Bo98. Things I think we need before merge:
- a lot more comments, the implementation is much harder to follow than the Swift one, and I don't even "know" Swift
- a lot more tests, particularly unit tests etc. for the
ffi.rblogic. In 2026, it should be very straightforward to get Claude or Codex or similar to do >90% of the work here.
Optional but recommended:
- I think it would make sense to also port the other script you mention and remove all Swift usage. Again, I think given you've got the foundations here, AI should make it fairly straightforward to follow the same approach and I think seeing this work with N > 1 would make the approach easier to review
| odebug "Quarantining #{download_path}" | ||
|
|
||
| raise "unexpected nil swift" unless swift | ||
| require "os/mac/ffi" |
There was a problem hiding this comment.
Probably shouldn't import os/mac stuff inside cask/quarantine now casks support macOS and Linux.
There was a problem hiding this comment.
Existing code already was entirely macOS specific. I suppose because Quarantine.available? is only ever true on macOS.
There was a problem hiding this comment.
Yeh, still feels a bit weird and perhaps a chance for some refactoring? Don't feel super strongly though.
May also want to consider opt-in/opt-out given that so if the approach does not seem stable/reliable we don't have to tag a new release to revert this for individual users. |
I agree. For clarity, are you referring more to The general goal is that:
In fact, I should probably be mentioning that mapping a bit more so I've added comments to ffi.rb to do that.
I guess challenge here is that some functions need the result of another one so might get very close to just copying I've gone ahead and added unit tests for quarantine.rb.
I think I was being overly cautious in that sentence. When I initially thought about doing this a while back, we had never used FFI. Since then, we do use FFI for all users in |
both ideally
even if it's just the subset that don't that'd be good or e.g. chaining multiple calls together
Ok, good. In that case I think it's probably worth porting both Swift scripts at once. |
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Looking better! More tests ideal but this is a big improvement.
Had been toying around with this idea for a year or so now, finally managed to clean it up enough to hopefully be shippable.
Swift is a great language to compile programs under but isn't very reliable as a psuedo-scripting language (which it's really not meant to be) like we were trying to do. It has a number of problems:
check_quarantine_supportthat reports 7(!) different reasons that quarantine might not work on a system - and 6 of them are Swift relatedmacos-14CI! https://github.com/Homebrew/homebrew-cask/actions/runs/25932611701/job/76231319882#step:11:205. This could easily happen to an end user machine, even on newer macOS.End goal is to delete
check_quarantine_supportentirely and make it always enabled on macOS. I still need to portcopy-xattrs.swiftfirst before that happens, so that change is not contained in this PR. I'd like to see if this approach proves stable and reliable for the current set of users before expanding it.brew lgtm(style, typechecking and tests) with your changes locally?