Skip to content

Prove generated DISABLE_ conditions strip guarded Swift symbols - #313

Merged
kirich1409 merged 1 commit into
developfrom
fea-2-ios-flag-stripping
Nov 6, 2026
Merged

kirich1409 merged 1 commit into
developfrom
fea-2-ios-flag-stripping

Conversation

@kirich1409

Copy link
Copy Markdown
Contributor

Closes #211

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Chore / refactor

Checklist

  • Tests added or updated
  • Docs updated (KDoc, README, CHANGELOG)
  • ./gradlew spotlessCheck passes
  • CHANGELOG.md updated

Notes for reviewers

The generator already emits DISABLE_<FLAG> for a local boolean whose default is false. Nothing compiled that condition and checked the guarded symbol was gone. This adds that check. Plugin behavior, iosApp, remote-flag filtering, the wiki, and CHANGELOG.md are unchanged. Issue 211 can be closed from the fixture evidence.

:featured-swift-dce-tests applies dev.androidbroadcast.featured and declares boolean("new_checkout", default = false). tasks.test depends on generateXcconfig and reads build/featured/FeatureFlags.generated.xcconfig. The test fails if that file is missing or blank, or if the DISABLE_* tokens (ignoring $(inherited)) are not exactly DISABLE_NEW_CHECKOUT. It then compiles GuardedCheckoutSymbol with swiftc -c -O and only those parsed tokens as -D, and checks nm -g. The same file compiled without those tokens must still contain the symbol. A hand-written -D is not a substitute.

The module depends on :core because the plugin auto-wires generated ConfigParam sources into the Kotlin/JVM compilation, and those sources import the Featured runtime.

Hosts without swiftc skip the compile. A skip is not a pass. The macOS build-ios job runs ./gradlew :featured-swift-dce-tests:test -PrequireSwiftDce=true, so a missing toolchain fails CI. Ubuntu ./gradlew test may skip this test; a green Ubuntu job is not this proof.

Verified locally on Apple Swift 6.2 and /usr/bin/nm:

  • default = false produces SWIFT_ACTIVE_COMPILATION_CONDITIONS = $(inherited) DISABLE_NEW_CHECKOUT, and the test passes with the compile not skipped.
  • default = true writes a blank xcconfig and the test fails before compilation.
  • A fixture guarded by a different condition still contains GuardedCheckoutSymbol after compilation with the generated -D, and the test fails.
  • With swiftc absent, the test skips. With -PrequireSwiftDce=true, that skip fails.

No SDK, simulator, or toolchain was installed.

Issue 211 had no check that a symbol behind #if !DISABLE_* is absent when
generateXcconfig emits the matching condition. Add featured-swift-dce-tests
and run it on the macOS CI job. A missing or mismatched condition fails
before compilation. Hosts without swiftc skip; -PrequireSwiftDce=true does not.
@kirich1409
kirich1409 marked this pull request as ready for review November 6, 2026 21:44
Copilot AI balanced review requested due to automatic review settings November 6, 2026 21:44
@kirich1409
kirich1409 merged commit 14436c4 into develop Nov 6, 2026
8 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Because swiftc and nm are not task inputs, installing Swift or changing toolchains can leave the test incorrectly up-to-date or reuse a stale cached success.

1 open issue
What changed in this PR

Adds automated verification that the Featured plugin’s generated Swift compilation conditions remove guarded symbols, complementing the existing Android R8 checks.

Changes:

  • Adds a test module that consumes generated xcconfig conditions.
  • Compiles a Swift fixture with and without those conditions and checks symbol absence and presence.
  • Runs the verification in macOS CI with missing Swift tooling treated as a failure.
File Description
settings.gradle.kts Registers the Swift verification module.
featured-swift-dce-tests/​src/​test/​swift/​GuardedCheckout.swift Adds a conditionally compiled symbol fixture.
featured-swift-dce-tests/​src/​test/​kotlin/​dev/​androidbroadcast/​featured/​swift/​SwiftFlagStrippingTest.kt Validates generated conditions and checks compiled symbols.
featured-swift-dce-tests/​build.gradle.kts Wires flag generation, dependencies, and test inputs.
.github/​workflows/​ci.yml Requires Swift verification in the macOS job.

Review effort: Balanced

inputs.file(swiftDceTestArguments.xcconfig)
inputs.file(swiftDceTestArguments.fixture)
inputs.property("requireSwiftDce", swiftDceTestArguments.requireSwiftDce)
jvmArgumentProviders.add(swiftDceTestArguments)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants