JavaScriptKit: import Android module for non-Wasm Android targets#722
Merged
kateinoigakukun merged 1 commit intoswiftwasm:mainfrom Apr 21, 2026
Merged
Conversation
Building JavaScriptKit for the Swift 6.3 Android SDK triples
(e.g. aarch64-unknown-linux-android28, x86_64-unknown-linux-android30)
fails in ThreadLocal.swift with:
error: cannot find 'pthread_key_create' in scope
error: cannot find 'pthread_key_t' in scope
Android uses Bionic, exposed to Swift as the `Android` module, rather
than Glibc. The existing conditional falls through to
`#error("Unsupported platform")` on Android.
Add a `canImport(Android)` branch between the Darwin and Glibc
branches, matching the pattern already used by Foundation and
swift-corelibs-libdispatch. No Wasm, Darwin, or Glibc behavior
changes.
kateinoigakukun
approved these changes
Apr 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
canImport(Android)branch toThreadLocal.swift's platform-import conditional so JavaScriptKit compiles for the Swift 6.3 Android SDK.Problem
Building any JavaScriptKit consumer for an Android triple via the official Swift SDK for Android (
swift-6.3.1-RELEASE_android) currently fails inSources/JavaScriptKit/ThreadLocal.swift:Android uses Bionic, which Swift exposes as the
Androidmodule — notGlibc. The existing conditional therefore falls through to#error("Unsupported platform")on Android triples.Reproduction
swift sdk install https://download.swift.org/swift-6.3.1-release/android-sdk/swift-6.3.1-RELEASE/swift-6.3.1-RELEASE_android.artifactbundle.tar.gz \ --checksum 8193a4e96538635131a154736c8896fba0e5a1c30e065524f00ed78719bac35a # From any package that depends on JavaScriptKit: swift build --swift-sdk swift-6.3.1-RELEASE_androidFix
Insert a
canImport(Android)branch between the Darwin and Glibc branches, matching the pattern used in Foundation (swift-corelibs-foundation) and swift-corelibs-libdispatch for the same pthread imports:ThreadLocal.swiftis the only file underSources/JavaScriptKit/that has this conditional-import shape; all other Swift sources either are Wasm-gated already or don't reference libc. No behavior change on Wasm, Darwin, or Glibc targets — only the previously-unreachable Android branch is newly covered.Test plan
swift build --swift-sdk swift-6.3.1-RELEASE_androidsucceeds through the Swift-compile phase for a consumer package that uses@JS(tested onx86_64-unknown-linux-android30). Without the patch: fails with the errors above. With the patch: compiles cleanly.swift package --swift-sdk swift-6.3.1-RELEASE_wasm jsstill produces byte-identical Wasm output for the same consumer (no Wasm regression).Context
Part of enabling Swift-on-Android via the Swift 6.3 Android SDK + upcoming
@cattribute for ABI-stable C exports from@JSclasses. Downstream work (separate from this PR) consumesJavaScriptKiton Android through the Android.so+ JSI path on React Native; that work is blocked only by this one import conditional.