Use generated purego bindings for the native bridge #241
All Vouch review confidence checks passed
Residual risk 0.26 = Change Risk (0.45) × (1 − Review Confidence (0.43)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 451 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.366
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #241"
general
weight: 0.35
AkihiroSuda
Replace handwritten cgo API wrappers with Go bindings generated from macOS SDK declarations and Objective-C runtime metadata. The public Go API remains unchanged.
Most API calls use purego. A small Objective-C bridge handles callbacks, dispatch queues, file descriptors, and window UI. A normal
go buildcompiles these helpers from source and dynamically links Apple's system frameworks. Consumers need no Swift compiler, prebuilt bridge archive, or generation step. The same sources work withgo mod vendor. Builds still requireCGO_ENABLED=1and Xcode or Command Line Tools.Native object lifetime continues to follow Go GC, as it did before. The implementation replaces
runtime.SetFinalizerwithruntime.AddCleanupon a shared owner. Go pointer value copies share that owner and keep the underlying native reference alive.GC and native memory release are not simultaneous. Cleanup runs asynchronously, and the native release is queued. An Objective-C release drops one owned reference; other native owners can still keep the object alive. Generated wrappers use
runtime.KeepAliveto keep Go arguments alive through native calls.Private runtime bindings check receivers and method encodings before dispatch. They remain internal and unsafe because runtime metadata does not describe ownership or variadic arguments.
For review, start with the generators, ownership handling, native helpers, and public wrappers. Commit
4e530d1contains only the seven generated files, including the SDK contract tests. Review the code that produces them rather than each generated method. To reproduce the output, run:Some intermediate commits depend on later migration changes. Build and test from the final branch tip.
Compared with main (
c03d09a), this branch (923e91a) builds faster but takes longer to execute the measured host-side API calls.On an Apple M2 running macOS 27.0.1, Go 1.27.1, and Xcode 27.0, building
example/gui-linuxwith an empty Go build cache took 5.60 seconds instead of 16.13 seconds, a 65.3% reduction. These are medians of three runs per version, alternating execution order, with dependencies already downloaded. Unchanged builds with a populated cache took about 0.08 seconds for both versions.Runtime benchmarks showed the following regressions. Each result is the median of ten alternating runs per version, using identical benchmark code with
GOMAXPROCS=4.| API | Main | This branch | Execution time |
|---|---:|---:|---:|
|
VirtualMachineConfigurationMaximumAllowedCPUCount| 22.74 ns | 1.31 µs | 57.6× longer ||
MACAddress.String| 411.4 ns | 18.75 µs | 45.6× longer ||
VirtioNetworkDeviceConfiguration.SetMACAddress| 46.83 ns | 1.15 µs | 24.5× longer ||
NewNATNetworkDeviceAttachment| 416.6 ns | 2.34 µs | 5.6× longer |Go heap allocations also increased in all four benchmarks. These measurements cover host-side API operations, not guest execution throughput, VM boot time, or overall application runtime.
Related to #239 and #240.
Fixes #239