Skip to content

[plugin] Line-buffer stdout in the plugin helper so output streams as produced#682

Merged
sebsto merged 4 commits into
mainfrom
fix/plugin_flush
Jun 29, 2026
Merged

[plugin] Line-buffer stdout in the plugin helper so output streams as produced#682
sebsto merged 4 commits into
mainfrom
fix/plugin_flush

Conversation

@sebsto

@sebsto sebsto commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Motivation

When running the SwiftPM plugins (lambda-init, lambda-build, lambda-deploy), output from the deploy/delete commands — and the helper's --help text — 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 shared AWSLambdaPluginHelper executable and lets it inherit stdout. All user-facing print() 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():

setvbuf(stdout, nil, _IOLBF, 0)

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 future print calls.

The platform libc import block follows the existing pattern in Sources/AWSLambdaRuntime/Lambda.swift.

Scope

  • The archiver plugin (AWSLambdaPackager) and the #if swift(<6.4) PluginUtils.swift path are intentionally left untouched — their output already streams as produced.

Testing

  • swift build --target AWSLambdaPluginHelper succeeds.
  • Verified locally that deploy/delete output now appears line-by-line as produced.

🤖 Generated with Claude Code

@sebsto sebsto added the 🔨 semver/patch No public API change. label Jun 29, 2026
@sebsto sebsto self-assigned this Jun 29, 2026
sebsto and others added 3 commits June 29, 2026 15:05
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>
@sebsto sebsto merged commit 5cce9e1 into main Jun 29, 2026
53 checks passed
@sebsto sebsto deleted the fix/plugin_flush branch June 29, 2026 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant