Skip to content

Commit 35088fc

Browse files
BridgeJS: Skip type handle registration for unlinked modules
`js test` generates the glue from every test target's skeletons, but the SwiftBuild build system links one binary per test target, so the eager registration hit a missing export.
1 parent 2b02b72 commit 35088fc

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,11 @@ public struct BridgeJSLink {
351351
for skeleton in skeletons {
352352
guard skeleton.typeRegistrationEntries != nil else { continue }
353353
let name = ABINameGenerator.typeRegistrationFunctionName(moduleName: skeleton.moduleName)
354-
declarations.append(" \(JSGlueVariableScope.reservedInstance).exports[\"\(name)\"]();")
354+
// The glue may describe more modules than the instance links in: `js test`
355+
// generates it from every test target's skeletons, while the SwiftBuild
356+
// build system produces one binary per test target. A module that isn't
357+
// linked in can't have its types used either, so skip its registration.
358+
declarations.append(" \(JSGlueVariableScope.reservedInstance).exports[\"\(name)\"]?.();")
355359
}
356360
declarations.append("}")
357361
declarations.append(contentsOf: GenericJSCodegen.runtimeHelperDeclarations())

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export async function createInstantiator(options, swift) {
5252
}
5353
__bjs_typeHandlesRegistered = true;
5454
instance.exports["bjs_core_register_type_handles"]();
55-
instance.exports["bjs_TestModule_register_type_handles"]();
55+
instance.exports["bjs_TestModule_register_type_handles"]?.();
5656
}
5757
function __bjs_codecForTypeId(typeId) {
5858
__bjs_registerTypeHandles();

0 commit comments

Comments
 (0)