-
Notifications
You must be signed in to change notification settings - Fork 4
Add cmake-file-api
package, implementing a TypeScript wrapper of the CMake file-based API
#257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3b8e3f0
Update shared TS configs
kraenhansen 5d12be8
Add new package scaffold
kraenhansen 1162b21
Add copilot instructions
kraenhansen edc675a
Add package specific instructions
kraenhansen 26a0b85
Add a test task
kraenhansen eac2b5f
Fix readIndex
kraenhansen 6668c85
Add codemodel
kraenhansen 3308647
Add target object kind
kraenhansen 7b376cf
Add cache object kind
kraenhansen 54215b4
Add cmakeFiles object kind
kraenhansen 9145f3b
Add toolchains object kind
kraenhansen 409629f
Add configureLog object kind
kraenhansen 1847818
Add separate query functions
kraenhansen b484e66
Add reply error index
kraenhansen 36541a9
Add an index
kraenhansen 898559b
Update version mechanism
kraenhansen 61303ee
Make ClientStatefulQueryReply more DRY
kraenhansen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Copilot Instructions for React Native Node-API | ||
|
||
This is a **monorepo** that brings Node-API support to React Native, enabling native addons written in C/C++/Rust to run on React Native across iOS and Android. | ||
|
||
## Package-Specific Instructions | ||
|
||
**IMPORTANT**: Before working on any package, always check for and read package-specific `copilot-instructions.md` files in the package directory. These contain critical preferences and patterns for that specific package. | ||
|
||
## Architecture Overview | ||
|
||
**Core Flow**: JS `require("./addon.node")` → Babel transform → `requireNodeAddon()` TurboModule call → native library loading → Node-API module initialization | ||
|
||
### Package Architecture | ||
|
||
See the [README.md](../README.md#packages) for detailed descriptions of each package and their roles in the system. Key packages include: | ||
|
||
- `packages/host` - Core Node-API runtime and Babel plugin | ||
- `packages/cmake-rn` - CMake wrapper for native builds | ||
- `packages/cmake-file-api` - TypeScript wrapper for CMake File API with Zod validation | ||
- `packages/ferric` - Rust/Cargo wrapper with napi-rs integration | ||
- `packages/gyp-to-cmake` - Legacy binding.gyp compatibility | ||
- `apps/test-app` - Integration testing harness | ||
|
||
## Critical Build Dependencies | ||
|
||
- **Custom Hermes**: Currently depends on a patched Hermes with Node-API support (see [facebook/hermes#1377](https://github.com/facebook/hermes/pull/1377)) | ||
- **Prebuilt Binary Spec**: All tools must output to the exact naming scheme: | ||
- Android: `*.android.node/` with jniLibs structure + `react-native-node-api-module` marker file | ||
- iOS: `*.apple.node` (XCFramework renamed) + marker file | ||
|
||
## Essential Workflows | ||
|
||
### Development Setup | ||
|
||
```bash | ||
npm ci && npm run build # Install deps and build all packages | ||
npm run bootstrap # Build native components (weak-node-api, examples) | ||
``` | ||
|
||
### Package Development | ||
|
||
- **TypeScript project references**: Use `tsc --build` for incremental compilation | ||
- **Workspace scripts**: Most build/test commands use npm workspaces (`--workspace` flag) | ||
- **Focus on Node.js packages**: AI development primarily targets the Node.js tooling packages rather than native mobile code | ||
- **No TypeScript type asserts**: You have to ask explicitly and justify if you want to add `as` type assertions. | ||
|
||
## Key Patterns | ||
|
||
### Babel Transformation | ||
|
||
The core magic happens in `packages/host/src/node/babel-plugin/plugin.ts`: | ||
|
||
```js | ||
// Input: require("./addon.node") | ||
// Output: require("react-native-node-api").requireNodeAddon("pkg-name--addon") | ||
``` | ||
|
||
### CMake Integration | ||
|
||
For linking against Node-API in CMakeLists.txt: | ||
|
||
```cmake | ||
include(${WEAK_NODE_API_CONFIG}) | ||
target_link_libraries(addon PRIVATE weak-node-api) | ||
``` | ||
|
||
### Cross-Platform Naming | ||
|
||
Library names use double-dash separation: `package-name--path-component--addon-name` | ||
|
||
### Testing | ||
|
||
- **Individual packages**: Some packages have VS Code test tasks and others have their own `npm test` scripts for focused iteration (e.g., `npm test --workspace cmake-rn`). Use the latter only if the former is missing. | ||
- **Cross-package**: Use root-level `npm test` for cross-package testing once individual package tests pass | ||
- **Mobile integration**: Available but not the primary AI development focus - ask the developer to run those tests as needed | ||
|
||
**Documentation**: Integration details, platform setup, and toolchain configuration are covered in existing repo documentation files. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "Test cmake-file-api", | ||
"command": "node", | ||
"args": ["--run", "test"], | ||
"options": { | ||
"cwd": "${workspaceFolder}/packages/cmake-file-api" | ||
}, | ||
"group": "test" | ||
} | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"extends": "./tsconfig.node.json", | ||
"compilerOptions": { | ||
"composite": true, | ||
"emitDeclarationOnly": true, | ||
"declarationMap": false | ||
}, | ||
"include": ["${configDir}/src/**/*.test.ts"], | ||
"exclude": [] | ||
/* | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.json" | ||
} | ||
] | ||
*/ | ||
} | ||
Comment on lines
+1
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a drive-by refactor, I'm creating this tsconfig, which I intent to share from other packages of the repo. |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"extends": "../../configs/tsconfig.cli.json" | ||
"extends": "../../configs/tsconfig.node.json" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# CMake File API (unofficial) | ||
|
||
The CMake File API provides an interface for querying CMake's configuration and project information. | ||
|
||
The API is based on files, where queries are written by client tools and read by CMake and replies are then written by CMake and read by client tools. The API is versioned, and the current version is v1 and these files are located in a directory named `.cmake/api/v1` in the build directory. | ||
|
||
This package provides a TypeScript interface to create query files and read replies and is intended to serve the same purpose to the TypeScript community that the [`cmake-file-api` crate](https://crates.io/crates/cmake-file-api), serves to the Rust community. |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created this as part of my use of Copilot.