Skip to content

Conversation

@kateinoigakukun
Copy link
Member

@kateinoigakukun kateinoigakukun commented Jan 16, 2026

Motivation

Example

Given bridge-js.d.ts:

export class Greeter {
  constructor(name: string);
  greet(): string;
  get name(): string;
  set name(value: string);
}

ts2swift now emits human-read/writable Swift declarations:

@_spi(Experimental) import JavaScriptKit

@JSClass struct Greeter: _JSBridgedClass {
    @JSFunction init(_ name: String) throws (JSException)
    @JSFunction func greet() throws (JSException) -> String
    @JSGetter var name: String
    @JSSetter func setName(_ value: String) throws (JSException)
}

Then the macro-annotated importing declarations are processed by ImportSwiftMacros, then it produces ImportedModuleSkeleton.
ImportTS takes the generated ImportedModuleSkeleton and produce Swift glue code. Note that now ImportTS is not responsible to generate user-facing interface like class declarations, but just generate thunk implementations. (maybe the Swift macro might generate thunks directly in the future).

graph LR
    subgraph ModuleA
        A.swift --> G1[bridge-js generate]
        B.swift --> G1
        B1[bridge-js.d.ts] --> T1[[ts2swift]]
        T1 --> M1[BridgeJS.Macros.swift]
        M1 --> G1
        G1 --> G3[BridgeJS.json]
        G1 --> G2[BridgeJS.swift]
    end

    subgraph ModuleB
        C.swift --> G4[bridge-js generate]
        D.swift --> G4
        B2[bridge-js.d.ts] --> T2[[ts2swift]]
        T2 --> M2[BridgeJS.Macros.swift]
        M2 --> G4
        G4 --> G5[BridgeJS.swift]
        G4 --> G6[BridgeJS.json]
    end

    G3 --> L1[[bridge-js link]]
    G6 --> L1

    L1 --> F1[bridge-js.js]
    L1 --> F2[bridge-js.d.ts]
    ModuleA -----> App[App.wasm]
    ModuleB -----> App

    App --> PKG[[PackageToJS]]
    F1 --> PKG
    F2 --> PKG
Loading

@kateinoigakukun kateinoigakukun force-pushed the yt/import-js-macro branch 6 times, most recently from 6d49ec7 to b176aef Compare January 17, 2026 08:46
-Xlinker options are passed to host linker as well (for linking macro
plugins), which causes issues. Use a toolset file to set the options
only for the target being built.
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