Add Android KSP @ExpoModule/@JS processor#24
Draft
tsapeta wants to merge 1 commit into
Draft
Conversation
Introduce `android/`, the Android counterpart of the Swift macros in `apple/`.
Where Apple uses Swift compiler macros, Android uses a KSP `SymbolProcessor`:
the author annotates ordinary Kotlin and the processor generates the module's
JS surface at build time.
- `annotations/`: `@ExpoModule` on a `Module` class, `@JS` on functions and
properties.
- `processor/`: reads those annotations and generates a
`<Module>.expoModuleDefinition()` extension that builds `ModuleDefinitionData`
via core's existing `ModuleDefinition { … }` DSL. The author wires it in with
`override fun definition() = expoModuleDefinition()`, since KSP generates files
rather than rewriting the class the way a Swift macro does.
Covers sync functions, `suspend fun` (to a JS `Promise` via `AsyncFunction …
Coroutine`), getter-only and settable properties, `@JS("name")` overrides, and
diagnostics for a non-`Module` class or a private `@JS` member.
The generated code compiles against today's `expo-modules-core` with no core
changes. Tests use `kotlin-compile-testing` (the KSP analog of the Swift suite's
`assertExpansion`): they run the processor over fixtures and assert on the
generated source, compiling it against minimal core-DSL stubs. Like `apple/`,
this verifies shape, not that it links against real core.
The processor is first-party and Pika-independent: Pika (core's IR plugin for
`@OptimizedRecord`) is sealed and can't be extended.
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
Introduces
android/, the Android counterpart of the Swift macros inapple/. Where Apple uses Swift compiler macros, Android uses a KSP (Kotlin Symbol Processing) processor: the author annotates ordinary Kotlin and the processor generates the Expo module's JS surface at build time.This is the first in a series of PRs bringing the Expo Modules v2 author-facing model to Android (see
~/Work/plans/expo-modules-v2-android.md). It covers@ExpoModuleand@JSonly.What's here
annotations/— the markers an author applies:@ExpoModuleon aModuleclass,@JSon its functions and properties.processor/— the KSPSymbolProcessor. It reads@ExpoModule/@JSand generates a<Module>.expoModuleDefinition()extension that builds the module'sModuleDefinitionDatathrough core's existingModuleDefinition { … }DSL.Author API
Covered: sync functions (0..N args),
suspend fun(to a JSPromiseviaAsyncFunction … Coroutine), getter-only and settable properties,@JS("name")overrides, nullable types, and diagnostics for a non-Moduleclass or a private@JSmember.Design notes
@OptimizedRecord) is sealed and can't be extended, so the processor is written from scratch on the KSP API.expo-modules-core; the author opts in by returning it fromdefinition(). A later step can add a core convention sodefinition()doesn't need to be hand-written.@Recordis intentionally not here. Core'sRecordTypeConverteronly branches Pika-vs-reflection with no hook for a generated strategy, so a useful@Recordneeds a paired core change. It is sequenced for a later PR.Testing
Tests use
kotlin-compile-testing(the KSP analog of the Swift suite'sassertExpansion): they run the processor over fixture modules and assert on the generated source, compiling it against minimal stubs of the core DSL. A green run proves the generated code is valid Kotlin that type-checks. Like theapple/suite, this verifies shape, not that it links against real core, and integration is only proven by building a real module against core.15 tests (9 generator unit tests + 6 end-to-end processor tests), all green.
Status
Draft. Author API and generated shape are settled; the core-side discovery convention (so
definition()is automatic) and a real-module integration check are follow-ups.