Skip to content

Opt out of swift-protobuf default traits - #71

Merged
gjcairo merged 6 commits into
grpc:mainfrom
sachinsharma3191:opt-out-binarydelimited-streams-trait
Oct 28, 2026
Merged

gjcairo merged 6 commits into
grpc:mainfrom
sachinsharma3191:opt-out-binarydelimited-streams-trait

Conversation

@sachinsharma3191

Copy link
Copy Markdown
Contributor

Motivation

The swift-protobuf dependency here takes the default trait set, which includes
BinaryDelimitedStreams. That trait gates BinaryDelimited.swift — the only file in the
SwiftProtobuf module that imports full Foundation, for InputStream and OutputStream.

SwiftPM unions trait requests across the dependency graph, so taking the defaults here
re-enables the trait for every package in a build that includes grpc-swift-extras,
including ones that have deliberately opted out. grpc-swift-2 already passes
traits: [], and grpc-swift-protobuf does too with a comment naming this exact reason.

The practical effect: a downstream package cannot prove it avoids linking
libFoundation.so on Linux while depending on grpc-swift-extras. I ran into this on
apple/swift-temporal-sdk#166,
which adds a Foundation-linkage CI check. With grpc-swift-extras opted out,
-DBinaryDelimitedStreams disappears from the build plan; without it, the opt-out in that
package has no effect.

Modifications

Add traits: [] to the swift-protobuf dependency, matching the two sibling repositories.

Result

No functional change. Nothing in grpc-swift-extras uses BinaryDelimited or the
FieldMaskUtilities-gated APIs, and swift build --build-tests passes with the traits
disabled. Downstream packages can now opt out effectively.

The swift-protobuf dependency took the default trait set, which includes
`BinaryDelimitedStreams`. That trait gates the only part of the
SwiftProtobuf module that imports full Foundation, for InputStream and
OutputStream in BinaryDelimited.swift.

SwiftPM unions trait requests across the dependency graph, so this
re-enabled the trait for every package in any build including
grpc-swift-extras, overriding packages that had deliberately opted out.
grpc-swift-2 and grpc-swift-protobuf already pass `traits: []` for this
reason; this brings grpc-swift-extras in line.

Nothing here uses BinaryDelimited or the FieldMaskUtilities-gated APIs,
so there is no functional change.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@linux-foundation-easycla

linux-foundation-easycla Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: sachinsharma3191 / name: Sachin Sharma (8e2e6cb)

Comment thread Package.swift Outdated
.package(
url: "https://github.com/apple/swift-protobuf.git",
from: "1.31.0"
from: "1.31.0",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should bump the swift-protobuf version here; things may still build fine if SPM resolves to anything over 1.36.0 but traits were introduced in 1.36.0 so we shouldn't keep 1.31.0 here as it can cause issues.

Let's bump it to the latest minor while we're at it, 1.39.0.

sachinsharma3191 added a commit to sachinsharma3191/swift-temporal-sdk that referenced this pull request Oct 21, 2026
`BinaryDelimited.swift` is the only file in the SwiftProtobuf module that
imports full Foundation, for InputStream and OutputStream, and
swift-protobuf already gates it behind the `BinaryDelimitedStreams`
trait. The trait is enabled by default, so the import is opt-out rather
than unconditional.

The SDK uses neither BinaryDelimited nor the FieldMaskUtilities-gated
APIs, so nothing is lost by opting out. The trait landed in
swift-protobuf 1.36.0, which is already the declared minimum, so no
version bump is needed.

This alone does not clear the linkage test: SwiftPM unions trait
requests across the dependency graph, and grpc-swift-extras still takes
the defaults, which re-enables the trait for every package in the build.
That is fixed upstream in grpc/grpc-swift-extras#71; this change is what
makes the opt-out effective once that ships.

Signed-off-by: Sachin Sharma <sachinsharma31261@gmail.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Traits were introduced in swift-protobuf 1.36.0, so declaring
`traits: []` against a 1.31.0 floor was inconsistent even though SPM
resolved higher in practice. Bump to 1.39.0, the latest minor, matching
grpc-swift-protobuf.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Comment thread Package.swift Outdated
.package(
url: "https://github.com/apple/swift-protobuf.git",
from: "1.31.0"
// Traits were introduced in 1.36.0; 1.39.0 is the latest minor.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this comment, it's irrelevant and will become stale.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure let me remove it and address other changes as well

Comment thread Package.swift Outdated
url: "https://github.com/apple/swift-protobuf.git",
// Traits were introduced in 1.36.0; 1.39.0 is the latest minor.
from: "1.39.0",
// Opt-out of default traits to avoid pulling in full Foundation from `BinaryDelimitedStreams`

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment was useful, I was only referring to the version comment, can you add this one back please.

@FranzBusch FranzBusch added the 🔨 semver/patch No public API change. label Oct 27, 2026
Generated code updates reflect changes from grpc-swift-2 with swift-protobuf 1.39.0
compatibility, including improvements to documentation strings.
@gjcairo
gjcairo enabled auto-merge (squash) October 28, 2026 09:59
@gjcairo
gjcairo merged commit d3bd853 into grpc:main Oct 28, 2026
39 checks passed
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.

3 participants