[plugin] Line-buffer stdout in the plugin helper so output streams as produced#682
Merged
Conversation
On Glibc/Musl, stdout is an `extern FILE *` global var, which Swift 6 strict concurrency rejects as "not concurrency-safe" when passed to setvbuf. Import the platform libc with @preconcurrency to suppress the diagnostic for that symbol. Verified with `swift build --target AWSLambdaPluginHelper` in the swiftlang/swift:nightly-6.4.x-bookworm container. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Motivation
When running the SwiftPM plugins (
lambda-init,lambda-build,lambda-deploy), output from thedeploy/deletecommands — and the helper's--helptext — only appeared on screen once the command had finished, instead of streaming as it was produced.The cause is stdio buffering. SwiftPM runs plugins with stdout connected to a pipe rather than a TTY, so the C runtime block-buffers stdout. The three plugins (
AWSLambdaInitializer,AWSLambdaBuilder,AWSLambdaDeployer) print nothing themselves — each is a thin wrapper that spawns the sharedAWSLambdaPluginHelperexecutable and lets it inherit stdout. All user-facingprint()output therefore originates from that one helper process, where it sat in the block buffer until exit.Change
Force line buffering at the start of
AWSLambdaPluginHelper.main():This makes each printed line flush on its newline, so output streams live. Because all three commands funnel through this single entry point, one call covers
init,build,deploy,delete, and the help text — no per-call-site changes and no risk of missing futureprintcalls.The platform libc import block follows the existing pattern in
Sources/AWSLambdaRuntime/Lambda.swift.Scope
AWSLambdaPackager) and the#if swift(<6.4)PluginUtils.swiftpath are intentionally left untouched — their output already streams as produced.Testing
swift build --target AWSLambdaPluginHelpersucceeds.🤖 Generated with Claude Code