Skip to content

BridgeJS: Replace the extraction logic with SwiftExtract - #808

Open
kateinoigakukun wants to merge 2 commits into
mainfrom
yt/bridgejs-swift-extract
Open

kateinoigakukun wants to merge 2 commits into
mainfrom
yt/bridgejs-swift-extract

Conversation

@kateinoigakukun

@kateinoigakukun kateinoigakukun commented Aug 21, 2026 •

Copy link
Copy Markdown
Member

Overview

This replaces BridgeJS's hand-written declaration extractor (SwiftToSkeleton plus TypeDeclResolver) with SwiftExtract from swift-binding-generator-core, the extraction layer shared with swift-java. SwiftToSkeleton now runs SwiftAnalyzer and lowers its result into the skeleton in ExportLowering and ImportLowering. All JavaScript-specific rules (BridgeType mapping, @JS arguments, namespaces, diagnostics) stay in BridgeJS.

The first commit is Yuta's original proof of concept. The second commit finishes it:

1. Released dependency. The symlinks into a local swift-java checkout are replaced by swift-binding-generator-core 0.1.0 (.upToNextMinor). Two gaps found along the way were fixed upstream before the release: a caller-provided build configuration for #if (swiftlang/swift-binding-generator-core#14) and declarations like var a: Int, b: String (swiftlang/swift-binding-generator-core#15).

2. Parity with current main. The upstream changes made since the proof of concept are ported: custom exported type names, protocol refinement and constrained generic imports, any T and (T), escaped parameter names, the async/throwing struct initializer diagnostic, and the diagnostic for non-class conformers of @JS protocols. Types and members are emitted in source order, so the snapshots and the committed Generated/ bindings are unchanged. Diagnostic messages are unchanged. As before, declarations in every #if branch are extracted: BridgeJS removes the directives before analysis.

3. Behavior changes.

  • @JS actor now gets a clear diagnostic.
  • Extensions through a typealias of a @JS type now work.

BridgeJS tests, bridge-js-generate.sh (no diff), check:bridgejs-dts, make unittest and the PlayBridgeJS example (also run in WebAssembly) pass.

@krodak
krodak force-pushed the yt/bridgejs-swift-extract branch from f379618 to 4fd5e0e Compare December 2, 2026 10:55
@krodak
krodak marked this pull request as ready for review December 2, 2026 10:55
@krodak

krodak commented Dec 2, 2026

Copy link
Copy Markdown
Member

@kateinoigakukun I continued your draft here (rebased on main, moved to the released swift-binding-generator-core and ported what landed since). Could you review my commit on top of yours? GitHub doesn't let me request a review from the PR author.

@krodak krodak changed the title BridgeJS: replace the extraction logic with SwiftExtract Dec 2, 2026
@krodak
krodak requested a review from MaxDesiatov December 2, 2026 10:55

@kateinoigakukun kateinoigakukun left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@krodak Thanks for following up! Looks good to me!

.package(url: "https://github.com/swiftlang/swift-syntax", from: "603.0.0"),
.package(
url: "https://github.com/swiftlang/swift-binding-generator-core",
.upToNextMinor(from: "0.1.0")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Because of swift-subprocess dependency, I prefer we don't tag new JavaScriptKit before new SBGC is tagged that includes swiftlang/swift-binding-generator-core#21 and relaxes swift-subprocess package graph constraint.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmm, can we even remove the swift-subprocess dependency from SBGC? The usage seems pretty trivial and not worth spending time fetching the dependency. It slows down the example projects build

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agreed, swift-subprocess seems to be only used by the static build config plugin to run swift frontend -print-static-build-config once, so Foundation.Process would do. @MaxDesiatov would you be up for folding that into swiftlang/swift-binding-generator-core#21 instead of bumping the version?

I could also send a separate PR if you'd rather keep #21 as is

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't mind either way, it's up to @ktoso as the codeowner to consider removing it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants