[plugin] Add swift-static-sdk cross-compile option (no container)#689
Merged
Conversation
… format The build options now span two independent axes: how to compile (docker, container, swift-static-sdk) and what to package (zip, oci). Reorganise the lambda-build section into "Choosing how to compile" and "Choosing the package format" subsections so the two choices read clearly, instead of a flat list of sibling topics. Also correct the binary-size note: static musl does not produce a meaningfully larger binary, since the Swift stdlib dominates and is statically linked either way. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #332.
Adds
--cross-compile swift-static-sdktolambda-build. It compiles a statically linked, musl-based binary directly on the host using the Static Linux SDK, with no Docker orcontainerinvolved. The resultingbootstrapruns as-is on the Lambdaprovided.al2023runtime.What it does
StaticLinuxSDKBuildBackendthat shells out toswift build --swift-sdk <triple>, slotting into the existingBuildBackendabstraction. No changes to the archive or deploy paths.--architectureselects the target:arm64maps toaarch64-swift-linux-musl,x64tox86_64-swift-linux-musl. Because the SDK genuinely cross-compiles, either architecture can be built from either host.swift build --swift-sdk <triple> --show-bin-path, which resolves the SDK exactly as the real build does. It does not parseswift sdk list, whose output is SDK bundle ids that never contain the target triple.--scratch-pathunder.build. The command plugin holds the workspace lock on the default.buildfor its whole run, so a nested build against the same directory would deadlock waiting for that lock. A separate scratch path avoids it.--base-docker-image,--swift-version,--disable-docker-image-update,--base-oci-image, and--archive-format oci), rather than silently ignoring them.A note on binary size
Building the same trivial Lambda both ways (release, stripped), the static-linux-sdk binary is about 16 MB and the container (glibc) binary is about 19 MB. The two are closer than you might expect, and the reason is worth recording: both statically link the Swift standard library via
--static-swift-stdlib, so their.textsections are within a few KB of each other (around 11 MB each). The C library is the small part. musl links statically and stays compact; glibc is not statically linked at all in the container build, it stays dynamic. So the size floor for both is the Swift runtime, not libc, and static musl comes out slightly smaller rather than larger. If we want to reduce size further, the lever is the Swift stdlib footprint, not the choice of libc.Testing
bootstrap, and writes a build manifest recordingarm64.--archive-format zippaths still build with no false positives.Semver: minor.