Skip to content

Configuration-aware bridge generation: honor #if DEBUG so debug-only Swift API can be excluded from release Kotlin bridges #715

Description

@piercifani

Context: SkipFuse app, native mode with bridging. We keep mock factories for SwiftUI/Compose previews in shared Swift behind conditional compilation. On iOS, #if DEBUG strips them from release builds. On Android there is no equivalent: the bridge generator evaluates #if DEBUG as false in every configuration, including skip export --debug.

Repro: given a bridged entity with a debug-only mock factory:

// Sources/AppData/EEvent.swift
// SKIP @bridge
public struct EEvent {
    public let id: String
    public let title: String
}

#if DEBUG
// SKIP @bridge
extension EEvent {
    public static func mock(id: String = "mock_id") -> EEvent {
        EEvent(id: id, title: "Mock event")
    }
}
#endif 

the generated Kotlin facade omits the extension even in a debug export — the output under .build/plugins/outputs/.../skipstone/.../EEvent.kt contains the EEvent bridge but no mock(), so this Compose preview fails with Unresolved reference 'mock':

@Preview
@Composable
fun EventCellPreview() {
    CUIEventCell(event = EEvent.mock())   // e: Unresolved reference 'mock'
}

which works, but means every mock factory — implementations, fake-data string literals, and their Kotlin bridge classes — ships in release Android builds. R8 can strip the unreferenced bridge classes from the DEX, but the native implementations and strings still ship in the production .so. On iOS the same code is correctly stripped from release, so the two platforms can't be given parity here.

Request: a way for skip export --release to exclude blocks from bridge generation and native compilation that --debug includes. Either honoring DEBUG to match SwiftPM's debug-configuration behavior

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions