Eliminate redundant SwiftPM builds in sign-and-notarize-cli#75
Conversation
|
Agent-Logs-Url: https://github.com/beeper/platform-imessage/sessions/5c2f86e7-126f-4957-b0b7-8e226aa25732 Co-authored-by: mokagio <1218433+mokagio@users.noreply.github.com>
sign-and-notarize-cli
| bin_for_arch() { | ||
| swift build -c release --triple "${1}-apple-macosx11" --product imessage-cli --show-bin-path | ||
| printf >&2 "==> building %s\n" "$target_arch" | ||
| swift build -c release --triple "${target_arch}-apple-macosx11" --product imessage-cli --show-bin-path |
There was a problem hiding this comment.
Critical: --show-bin-path skips the build. Per SwiftPM's SwiftBuildCommand.swift, when --show-bin-path is passed the command early-returns after printing the path:
if options.shouldPrintBinPath {
return try print(swiftCommandState.productsBuildParameters.buildPath.description)
}No compilation happens. The previous code worked because build_arch (without --show-bin-path) actually compiled, and bin_for_arch re-invoked SwiftPM only to query the cached path. After this change:
- Clean checkout:
arm64_bin/x86_binpoint at non-existent files;lipo -create(orstripin the single-arch branch) fails with no-such-file. - Warm checkout: whatever stale
imessage-clihappens to sit at the printed path is what gets stripped, signed, and notarized — silently shipping outdated bits.
Minimal fix that keeps the single-callsite ergonomics:
build_arch() {
local target_arch="$1"
printf >&2 "==> building %s\n" "$target_arch"
swift build -c release --triple "${target_arch}-apple-macosx11" --product imessage-cli >&2
swift build -c release --triple "${target_arch}-apple-macosx11" --product imessage-cli --show-bin-path
}This still costs one extra SwiftPM process per arch for the path lookup (same as the original bin_for_arch pattern), but it actually builds.
There was a problem hiding this comment.
Wow, good catch. On a clean cache, this does
✦ ➜ ./scripts/sign-and-notarize-cli
==> building arm64
==> building x86_64
==> creating universal binary
fatal error: /Applications/Xcode-26.3.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: can't open input file: /Users/gio/Developer/a8c/platform-imessage/.build/arm64-apple-macosx/release/imessage-cli (No such file or directory)
There was a problem hiding this comment.
Thanks for confirming on a clean cache — that lipo: can't open input file is exactly the failure mode. Want me to push the two-invocation fix (real build to stderr, then --show-bin-path for the captured path), or are you planning to take it from here?
|
The implementation attempt in #75 showed a minor SLOC decrease at the cost of less clear code. Closing for the time being. |
The implementation attempt in #75 showed a minor SLOC decrease at the cost of less clear code. Closing for the time being. —@mokagio
This stacked PR addresses review feedback on the local signing/notarization script: the previous flow invoked
swift buildmore times than necessary when resolving per-arch binary paths.The update ensures each architecture triggers a single SwiftPM invocation and reuses its resolved bin path.
Build path resolution
build_archnow runsswift build ... --show-bin-pathand returns the path for that architecture.Redundant invocation removal
bin_for_archfunction that re-invokedswift build.build_archoutput.binaryfrom the samebuild_archoutput.