### Install Information Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/docs/cmake-file-api.7.rst.txt Details about the 'install' member, which is present when a target has an install rule. ```APIDOC ## install ### Description Optional member that is present when the target has an :command:`install` rule. The value is a JSON object with members: ### Parameters #### Request Body - **prefix** (object) - Required - A JSON object specifying the installation prefix. It has one member: - **path** (string) - Required - A JSON object specifying the installation prefix. It has one member: - **destinations** (array) - Required - A JSON array of entries specifying an install destination path. Each entry is a JSON object with members: - **path** (string) - Required - A string specifying the install destination path. The path may be absolute or relative to the install prefix. - **backtrace** (integer) - Optional - Optional member that is present when a CMake language backtrace to the :command:`install` command invocation that specified this destination is available. The value is an unsigned integer 0-based index into the ``backtraceGraph`` member's ``nodes`` array. ### Response #### Success Response (200) - **prefix** (object) - Installation prefix details. - **destinations** (array) - List of installation destinations. #### Response Example { "prefix": { "path": "/usr/local/prefix" }, "destinations": [ { "path": "bin", "backtrace": 1 } ] } ``` -------------------------------- ### Install Rule Configuration Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/docs/cmake-file-api.7.rst.txt Defines the configuration for installing targets, including installation prefix and destination paths. The 'backtrace' member provides a link to the CMake command invocation for debugging purposes. ```json { "install": { "prefix": { "path": "/path/to/install/prefix" }, "destinations": [ { "path": "/usr/local/bin", "backtrace": 0 } ] } } ``` -------------------------------- ### Installation Artifact Types Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/docs/cmake-file-api.7.rst.txt This section details the different types of installation artifacts and their associated members. ```APIDOC ## Installation Artifact Types ### Description Details the various types of installation artifacts and their specific properties. ### Method N/A ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **type** (string) - The type of the installation artifact. Possible values include: - `"file"`: For `install(FILES)` calls. - `"directory"`: For `install(DIRECTORIES)` calls. - `"target"`: For `install(TARGETS)` calls. - `"export"`: For `install(EXPORT)` calls. - `"script"`: For `install(SCRIPT)` calls. - `"code"`: For `install(CODE)` calls. - `"importedRuntimeArtifacts"`: For `install(IMPORTED_RUNTIME_ARTIFACTS)` calls. - `"runtimeDependencySet"`: For `install(RUNTIME_DEPENDENCY_SET)` or `install(TARGETS)` with `RUNTIME_DEPENDENCIES`. - `"fileSet"`: For `install(TARGETS)` with `FILE_SET`. - `"cxxModuleBmi"`: For `install(TARGETS)` with `CXX_MODULES_BMI`. - **destination** (string) - The destination directory for the artifact. - **paths** (array of strings) - A list of source paths for the artifact. - **exportName** (string) - The name of the export (only for `"export"` type). - **exportTargets** (array of objects) - A list of targets included in the export (only for `"export"` type). Each object has: - `id` (string) - Unique target identifier. - `index` (integer) - 0-based index in the `targets` array. - **scriptFile** (string) - The file path for the script (only for `"script"` type). - **isExcludeFromAll** (boolean) - True if `EXCLUDE_FROM_ALL` option is used. - **isForAllComponents** (boolean) - True if `ALL_COMPONENTS` option is used with `install(SCRIPT|CODE)`. - **isOptional** (boolean) - True if `OPTIONAL` option is used. - **targetId** (string) - Unique identifier for the target (only for `"target"` type). - **targetIndex** (integer) - 0-based index for the target in the `targets` array (only for `"target"` type). - **targetIsImportLibrary** (boolean) - True if the installer is for a Windows DLL import library or AIX linker import file. - **targetInstallNamelink** (string) - Indicates how symlinks are handled for targets (`skip` or `only`). - **runtimeDependencySetName** (string) - Name of the runtime dependency set (only for `"runtimeDependencySet"` type created by `install(RUNTIME_DEPENDENCY_SET)`). - **runtimeDependencySetType** (string) - Type of the runtime dependency set (`library` or `framework`). - **fileSetName** (string) - Name of the file set (only for `"fileSet"` type). - **fileSetType** (string) - Type of the file set. - **fileSetDirectories** (array of strings) - Directories associated with the file set. - **fileSetTarget** (string) - Target associated with the file set. - **cxxModuleBmiTarget** (string) - Target associated with the C++ module BMI. ### Response Example ```json { "type": "file", "destination": "/usr/local/bin", "paths": ["/path/to/executable"], "isOptional": true } ``` ``` -------------------------------- ### Install react-native-node-api using npm Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/host/README.md This command installs the react-native-node-api library using npm. It's a prerequisite for using the library in your React Native project. Ensure you have Node.js and npm installed. ```bash npm install react-native-node-api ``` -------------------------------- ### Good Schema Pattern Example (TypeScript) Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/copilot-instructions.md Illustrates a robust schema pattern using Zod, including enums for 'kind', optional fields, arrays for index fields, and nested objects for required structures. ```typescript const index = z.number().int().min(0); export const MySchemaV1 = z.object({ kind: z.enum(["validValue1", "validValue2"]), optionalField: z.string().optional(), parentIndex: index.optional(), // For *Index fields childIndexes: z.array(index).optional(), // For *Indexes fields requiredNested: z.object({ major: z.number(), minor: z.number(), }), }); ``` -------------------------------- ### Good Minor Version Schema Pattern (TypeScript) Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/copilot-instructions.md Shows how to define schema versions for minor updates, starting with a base version and extending it with new fields for later versions. It also demonstrates parent schema versioning and exporting a union of all versions. ```typescript // Base version schema (earliest version) const ItemV2_0 = z.object({ name: z.string(), type: z.enum(["TYPE1", "TYPE2"]), paths: z.object({ source: z.string(), build: z.string(), }), }); // Extended version schema (adds fields introduced in v2.3) const ItemV2_3 = ItemV2_0.extend({ jsonFile: z.string(), metadata: z .object({ version: z.string(), }) .optional(), }); // Parent schema versions const ContainerV2_0 = z.object({ kind: z.literal("container"), version: z.object({ major: z.literal(2), minor: z.number().max(2), // Versions 2.0-2.2 }), items: z.array(ItemV2_0), }); const ContainerV2_3 = ContainerV2_0.extend({ version: z.object({ major: z.literal(2), minor: z.number().min(3), // Versions 2.3+ }), items: z.array(ItemV2_3), }); // Union export for all versions export const ContainerV2 = z.union([ContainerV2_0, ContainerV2_3]); ``` -------------------------------- ### CMake File API v1 Shared Stateless Query Example Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/docs/cmake-file-api.7.rst.txt This example demonstrates creating a shared stateless query file for a specific object kind and major version. The file is created in the query directory and should not be removed without coordination. ```cmake /.cmake/api/v1/query/-v ``` -------------------------------- ### CMake File API v1 Client Stateless Query Example Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/docs/cmake-file-api.7.rst.txt This example shows how a client can create an owned stateless query file for a specific object kind and major version. The file resides in a client-specific subdirectory within the query directory and can be removed by the owning client. ```cmake /.cmake/api/v1/query/client-/-v ``` -------------------------------- ### CMake File API v1 Client Stateful Query Example (query.json) Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/docs/cmake-file-api.7.rst.txt This example illustrates the structure of a client stateful query file (query.json). It allows a client to request specific versions of object kinds. The file is located in a client-specific subdirectory and can be updated or removed by the owning client. ```json { "requests": [ { "kind": "" , "version": 1 }, { "kind": "" , "version": { "major": 1, "minor": 2 } }, { "kind": "" , "version": [2, 1] } ] } ``` -------------------------------- ### Object Kind: configureLog Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/docs/cmake-file-api.7.rst.txt Describes the location and contents of a `cmake-configure-log(7)` file. This object kind is available starting from version 3.26. ```APIDOC ## Object Kind: configureLog (version 1) ### Description Describes the location and contents of a `cmake-configure-log(7)` file. ### Version - major: 1 - minor: 0 ### Members - **path** (string) - The path to the configure log file. Clients must read the log file from this path. The log file may not exist if no events are logged. - **eventKindNames** (array of strings) - A JSON array whose entries are each a JSON string naming one of the `cmake-configure-log(7)` versioned event kinds. Clients must ignore event kinds not listed in this field. ``` -------------------------------- ### Install Node-API as Dev Dependency for Library Source: https://github.com/callstackincubator/react-native-node-api/blob/main/docs/USAGE.md Installs `react-native-node-api` as a development dependency for a library. It also uses `--save-exact` to ensure a specific version is recorded. ```bash npm install react-native-node-api --save-dev --save-exact ``` -------------------------------- ### Install Node-API Dependencies for React Native App Source: https://github.com/callstackincubator/react-native-node-api/blob/main/docs/USAGE.md Installs the necessary packages for a React Native application to use a Node-API library. This includes the library itself and the react-native-node-api package, which is required due to limitations in the React Native Community CLI's auto-linking. ```bash npm install --save calculator-lib react-native-node-api ``` -------------------------------- ### Introduction to CMake File-Based API Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/docs/cmake-file-api.7.rst.txt Overview of the CMake File-Based API, its purpose, and versioning. ```APIDOC ## Introduction to CMake File-Based API CMake provides a file-based API that clients may use to get semantic information about the buildsystems CMake generates. Clients may use the API by writing query files to a specific location in a build tree to request zero or more `Object Kinds`. When CMake generates the buildsystem in that build tree it will read the query files and write reply files for the client to read. The file-based API uses a ``/.cmake/api/`` directory at the top of a build tree. The API is versioned to support changes to the layout of files within the API directory. API file layout versioning is orthogonal to the versioning of `Object Kinds` used in replies. This version of CMake supports only one API version, `API v1`. Projects may also submit queries for the current run using the :command:`cmake_file_api` command. ``` -------------------------------- ### v1 Client Stateful Query Files Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/docs/cmake-file-api.7.rst.txt How to create client-owned stateful query files using query.json. ```APIDOC ## v1 Client Stateful Query Files Stateful query files allow clients to request a list of versions of each of the `Object Kinds` and get only the most recent version recognized by the CMake that runs. Clients may create owned stateful queries by creating ``query.json`` files in client-specific query subdirectories. The form is:: /.cmake/api/v1/query/client-/query.json where ``client-`` is literal, ```` is a string uniquely identifying the client, and ``query.json`` is literal. Each client must choose a unique ```` identifier via its own means. ``query.json`` files are stateful queries owned by the client ````. The owning client may update or remove them at any time. When a given client installation is updated it may then update the stateful query it writes to build trees to request newer object versions. This can be used to avoid asking CMake to generate multiple object versions unnecessarily. A ``query.json`` file must contain a JSON object: ```json { "requests": [ { "kind": "" , "version": 1 }, { "kind": "" , "version": { "major": 1, "minor": 2 } }, { "kind": "" , "version": [2, 1] } ] } ``` ``` -------------------------------- ### Version Nested Schemas and Export Union (TypeScript) Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/copilot-instructions.md Demonstrates versioning nested schemas separately to avoid duplication and exporting a union of all versions for flexible validation. This approach helps maintain DRY principles and allows for specifying exact version schemas when needed. ```typescript // Version nested schemas separately to avoid duplication const SourceV2_0 = z.object({ path: z.string(), // ... base fields }); const SourceV2_5 = SourceV2_0.extend({ fileSetIndex: index.optional(), // Added in v2.5 }); const CompileGroupV2_0 = z.object({ sourceIndexes: z.array(index), language: z.string(), // ... base fields }); const CompileGroupV2_1 = CompileGroupV2_0.extend({ precompileHeaders: z.array(PrecompileHeader).optional(), // Added in v2.1 }); // Build main object versions using versioned nested schemas const TargetV2_0 = z.object({ // ... base fields sources: z.array(SourceV2_0).optional(), compileGroups: z.array(CompileGroupV2_0).optional(), }); const TargetV2_1 = TargetV2_0.extend({ compileGroups: z.array(CompileGroupV2_1).optional(), // Use versioned nested schema }); const TargetV2_5 = TargetV2_2.extend({ fileSets: z.array(FileSet).optional(), sources: z.array(SourceV2_5).optional(), // Use versioned nested schema }); // Export union of all versions for flexible validation export const TargetV2 = z.union([ TargetV2_0, TargetV2_1, TargetV2_2, TargetV2_5, TargetV2_6, TargetV2_7, TargetV2_8, ]); // Also export individual versions for specific use cases export { TargetV2_0, TargetV2_1, TargetV2_2, TargetV2_5, TargetV2_6, TargetV2_7, TargetV2_8, }; ``` -------------------------------- ### v1 Client Stateless Query Files Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/docs/cmake-file-api.7.rst.txt How to create client-owned stateless query files for requesting object kinds. ```APIDOC ## v1 Client Stateless Query Files Client stateless query files allow clients to create owned requests for major versions of the `Object Kinds` and get all requested versions recognized by the CMake that runs. Clients may create owned requests by creating empty files in client-specific query subdirectories. The form is:: /.cmake/api/v1/query/client-/-v where ``client-`` is literal, ```` is a string uniquely identifying the client, ```` is one of the `Object Kinds`, ``-v`` is literal, and ```` is the major version number. Each client must choose a unique ```` identifier via its own means. Files of this form are stateless queries owned by the client ````. The owning client may remove them at any time. ``` -------------------------------- ### Node.js Built-ins with Prefix Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/copilot-instructions.md Demonstrates the preference for using Node.js built-in modules with the `node:` prefix for clarity and to avoid potential global namespace conflicts. This practice ensures that the correct Node.js module is being imported. ```typescript import fs from "node:fs"; import path from "node:path"; import assert from "node:assert/strict"; ``` -------------------------------- ### Hierarchical Zod Schema Extension for Versioning Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/copilot-instructions.md Demonstrates the pattern for defining versioned schemas using Zod's `.extend()` method. This allows for creating a clear inheritance hierarchy, supporting multiple minor versions of an API schema while maintaining type safety and backward compatibility. ```typescript import { z } from "zod"; // Base schema for version 2.0 const DirectoryV2_0 = z.object({ type: z.literal("directory"), logical_name: z.string(), path: z.string() }); // Extended schema for version 2.3, adding 'permissions' const DirectoryV2_3 = DirectoryV2_0.extend({ permissions: z.string().optional(), // Example optional field for later version minor: z.number().min(3) // Constraint for version 2.3 and later }); // Exporting the union of all supported versions export const Directory = z.union([DirectoryV2_0, DirectoryV2_3]); // Example Usage: const dirV2_0Data = { type: "directory", logical_name: "src", path: "/path/to/src" }; const dirV2_3Data = { type: "directory", logical_name: "build", path: "/path/to/build", permissions: "rwxr-xr-x" }; console.log(DirectoryV2_0.safeParse(dirV2_0Data).success); // true console.log(DirectoryV2_3.safeParse(dirV2_3Data).success); // true console.log(Directory.safeParse(dirV2_0Data).success); // true console.log(Directory.safeParse(dirV2_3Data).success); // true // Example of data that would fail validation for V2_3 due to missing minor version constraint const invalidDirV2_3 = { ...dirV2_3Data, minor: 2 }; console.log(DirectoryV2_3.safeParse(invalidDirV2_3).success); // false ``` -------------------------------- ### Async File Operations with Node.js Promises Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/copilot-instructions.md Illustrates the preferred use of asynchronous APIs for file operations using Node.js's `fs.promises` module. This allows for non-blocking I/O, improving application performance, especially in I/O-bound tasks. ```typescript import { readFile, writeFile } from "node:fs/promises"; async function processFile(filePath: string): Promise { const content = await readFile(filePath, "utf-8"); // Process content... await writeFile(filePath, "modified content", "utf-8"); return content; } ``` -------------------------------- ### Good Function Pattern for File Reading (TypeScript) Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/copilot-instructions.md Presents a pattern for an asynchronous function that reads a file, validates its path and extension, parses JSON content using a Zod schema, and returns destructured values. ```typescript export async function readSomething(filePath: string) { assert( path.basename(filePath).startsWith("expected-") && path.extname(filePath) === ".json", "Expected a path to an expected-*.json file", ); const content = await fs.promises.readFile(filePath, "utf-8"); const { field1, field2 } = MySchemaV1.parse(JSON.parse(content)); // Use destructured values directly return { field1, field2 }; } ``` -------------------------------- ### CMake Reply Index File Structure Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/docs/cmake-file-api.7.rst.txt Illustrates the structure of a CMake reply index file (`index-*.json`). This file contains information about the CMake version, paths, generator settings, and a list of objects with their kinds, versions, and associated JSON files. It also details the `reply` section which maps kinds to their respective files. ```json { "cmake": { "version": { "major": 3, "minor": 14, "patch": 0, "suffix": "", "string": "3.14.0", "isDirty": false }, "paths": { "cmake": "/prefix/bin/cmake", "ctest": "/prefix/bin/ctest", "cpack": "/prefix/bin/cpack", "root": "/prefix/share/cmake-3.14" }, "generator": { "multiConfig": false, "name": "Unix Makefiles" } }, "objects": [ { "kind": "", "version": { "major": 1, "minor": 0 }, "jsonFile": "" }, { "...": "..." } ], "reply": { "-v": { "kind": "", "version": { "major": 1, "minor": 0 }, "jsonFile": "" }, "": { "error": "unknown query file" }, "...": {}, "client-": { "-v": { "kind": "", "version": { "major": 1, "minor": 0 }, "jsonFile": "" }, "": { "error": "unknown query file" }, "...": {}, "query.json": { "requests": [ {}, {}, {} ], "responses": [ { "kind": "", "version": { "major": 1, "minor": 0 }, "jsonFile": "" }, { "error": "unknown query file" }, { "...": {} } ], "client": {} } } } } ``` -------------------------------- ### Query Request Format Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/docs/cmake-file-api.7.rst.txt Describes the structure of a query request, including 'kind', 'version', and 'client' members. ```APIDOC ## Query Request Parameters ### Description Specifies one of the `Object Kinds`_ to be included in the reply. Clients may use the 'client' member to pass custom information. ### Parameters #### Request Body - **kind** (string) - Required - Specifies the object kind to be requested. - **version** (integer or object or array) - Required - Indicates the version(s) of the object kind that the client understands. Can be a major version integer, an object with 'major' and optional 'minor' components, or an array of these. - **client** (object) - Optional - Reserved for client use, preserved in the reply. ``` -------------------------------- ### v1 Shared Stateless Query Files Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/docs/cmake-file-api.7.rst.txt How to create shared stateless query files for requesting object kinds. ```APIDOC ## v1 Shared Stateless Query Files Shared stateless query files allow clients to share requests for major versions of the `Object Kinds` and get all requested versions recognized by the CMake that runs. Clients may create shared requests by creating empty files in the ``v1/query/`` directory. The form is:: /.cmake/api/v1/query/-v where ```` is one of the `Object Kinds`, ``-v`` is literal, and ```` is the major version number. Files of this form are stateless shared queries not owned by any specific client. Once created they should not be removed without external client coordination or human intervention. ``` -------------------------------- ### Launcher Configuration Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/docs/cmake-file-api.7.rst.txt Specifies details for target launchers, such as emulators or test runners. It includes the command path, arguments, and type of launcher. This feature was introduced in codemodel version 2.7. ```json { "launchers": [ { "command": "/path/to/emulator", "arguments": ["--some-option"], "type": "emulator" }, { "command": "/path/to/test_runner", "type": "test" } ] } ``` -------------------------------- ### Importing and Using a Native Function in JavaScript Source: https://github.com/callstackincubator/react-native-node-api/blob/main/docs/HOW-IT-WORKS.md This JavaScript snippet demonstrates how a React Native application imports a function (e.g., 'add') from a library and then calls it. This follows the successful initialization and export of native functionality through the Node-API. ```javascript import { add } from "calculator-lib"; console.log("1 + 2 =", add(1, 2)); ``` -------------------------------- ### API v1 Structure Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/docs/cmake-file-api.7.rst.txt Details the directory structure and file types for API v1. ```APIDOC ## API v1 Structure API v1 is housed in the ``/.cmake/api/v1/`` directory. It has the following subdirectories: * ``query/``: Holds query files written by clients. These may be `v1 Shared Stateless Query Files`, `v1 Client Stateless Query Files`, or `v1 Client Stateful Query Files`. * ``reply/``: Holds reply files written by CMake when it runs to generate a build system. Clients may read reply files only when referenced by a reply index: * ``index-*.json``: A `v1 Reply Index File` written when CMake generates a build system. * ``error-*.json``: A `v1 Reply Error Index` written when CMake fails to generate a build system due to an error. Clients may look for and read a reply index at any time. Clients may optionally create the ``reply/`` directory at any time and monitor it for the appearance of a new reply index. CMake owns all reply files. Clients must never remove them. Users can add query files to ``api/v1/query`` inside the :envvar:`CMAKE_CONFIG_DIR` to create user-wide queries for all CMake projects. ``` -------------------------------- ### Error Handling with Node.js Assert Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/copilot-instructions.md Illustrates using `assert` from `node:assert/strict` for runtime validation with descriptive error messages. This ensures that invalid states are caught early and provide helpful information for debugging. ```typescript import * as assert from "node:assert/strict"; interface Configuration { timeout: number; } function setupConfig(config: Configuration) { assert(typeof config.timeout === 'number' && config.timeout > 0, `Invalid timeout value: ${config.timeout}. Timeout must be a positive number.`); // Proceed with configuration setup console.log(`Configuration set with timeout: ${config.timeout}`); } try { setupConfig({ timeout: -10 }); } catch (error) { console.error(error.message); // Output: Invalid timeout value: -10. Timeout must be a positive number. } ``` -------------------------------- ### CXX Language Toolchain Configuration Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/docs/cmake-file-api.7.rst.txt Specifies the toolchain configuration for the CXX (C++) programming language. It details the compiler's path, ID, version, and provides lists of implicit include and link directories, as well as link libraries. The recognized C++ source file extensions are also enumerated. ```json { "language": "CXX", "compiler": { "path": "/usr/bin/c++", "id": "GNU", "version": "9.3.0", "implicit": { "includeDirectories": [ "/usr/include/c++/9", "/usr/include/x86_64-linux-gnu/c++/9", "/usr/include/c++/9/backward", "/usr/lib/gcc/x86_64-linux-gnu/9/include", "/usr/local/include", "/usr/include/x86_64-linux-gnu", "/usr/include" ], "linkDirectories": [ "/usr/lib/gcc/x86_64-linux-gnu/9", "/usr/lib/x86_64-linux-gnu", "/usr/lib", "/lib/x86_64-linux-gnu", "/lib" ], "linkFrameworkDirectories": [], "linkLibraries": [ "stdc++", "m", "gcc_s", "gcc", "c", "gcc_s", "gcc" ] } }, "sourceFileExtensions": [ "C", "M", "c++", "cc", "cpp", "cxx", "mm", "CPP" ] } ``` -------------------------------- ### Build Node-API Prebuilt Binaries Source: https://github.com/callstackincubator/react-native-node-api/blob/main/docs/USAGE.md Command to build the prebuilt binaries for a Node-API module using `cmake-rn`. This command compiles the native code and links it appropriately for use with React Native. ```bash npx cmake-rn ``` -------------------------------- ### Launcher Information Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/docs/cmake-file-api.7.rst.txt Details about the 'launchers' member, present for executable targets with specified launchers. ```APIDOC ## launchers ### Description Optional member that is present on executable targets that have at least one launcher specified by the project. The value is a JSON array of entries corresponding to the specified launchers. Each entry is a JSON object with members: ### Parameters #### Request Body - **command** (string) - Required - A string specifying the path to the launcher on disk, represented with forward slashes. If the file is inside the top-level source directory then the path is specified relative to that directory. - **arguments** (array) - Optional - An optional member that is present when the launcher command has arguments preceding the executable to be launched. The value is a JSON array of strings representing the arguments. - **type** (string) - Required - A string specifying the type of launcher. The value is one of the following: "emulator", "test". - "emulator": An emulator for the target platform when cross-compiling. See the :prop_tgt:`CROSSCOMPILING_EMULATOR` target property. - "test": A start program for the execution of tests. See the :prop_tgt:`TEST_LAUNCHER` target property. This field was added in codemodel version 2.7. ### Response #### Success Response (200) - **command** (string) - Path to the launcher. - **arguments** (array) - Arguments for the launcher command. - **type** (string) - Type of the launcher. #### Response Example { "launchers": [ { "command": "/path/to/emulator", "arguments": ["--platform", "ios"], "type": "emulator" } ] } ``` -------------------------------- ### Zod Schema for Optional Record Values Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/copilot-instructions.md Shows how to define Zod schemas where record values might be optional. This is useful when dealing with data structures where certain fields may not always be present, preventing validation errors for missing but permissible data. ```typescript import { z } from "zod"; // Schema where the value of each key in the record might be optional const optionalRecordSchema = z.record(z.string(), z.string().optional()); const data1 = { key1: "value1", key2: "value2" }; const data2 = { key1: "value1", key2: undefined }; const data3 = { key1: "value1" }; console.log(optionalRecordSchema.safeParse(data1).success); // true console.log(optionalRecordSchema.safeParse(data2).success); // true console.log(optionalRecordSchema.safeParse(data3).success); // true ``` -------------------------------- ### Link against Node-API with CMake Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-rn/README.md This CMake code demonstrates how to link an addon library against the `weak-node-api` library. It includes the necessary CMake configuration for `weak-node-api` and adds it to the target libraries of the addon. This approach is specific to `cmake-rn` and differs from `cmake-js`'s method. ```cmake cmake_minimum_required(VERSION 3.15...3.15) project(tests-buffers) include(${WEAK_NODE_API_CONFIG}) add_library(addon SHARED addon.c) target_link_libraries(addon PRIVATE weak-node-api) target_compile_features(addon PRIVATE cxx_std_20) ``` -------------------------------- ### Zod Schema for CMake File API Index Fields Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/copilot-instructions.md Defines a Zod schema for index fields in the CMake File API, ensuring they are unsigned 0-based integers. This adheres to the CMake File API specification and provides strong typing for index-related data. ```typescript import { z } from "zod"; const indexSchema = z.number().int().min(0); // Example usage in a larger schema: const someSchema = z.object({ startIndex: indexSchema, endIndex: indexSchema, items: z.array(z.object({ id: z.number() })) }); // Validation example: const validData = { startIndex: 0, endIndex: 5, items: [{ id: 1 }, { id: 2 }] }; const invalidData = { startIndex: -1, endIndex: 5, items: [] }; console.log(someSchema.safeParse(validData).success); // true console.log(someSchema.safeParse(invalidData).success); // false ``` -------------------------------- ### Async Function with Default Schema (TypeScript) Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/copilot-instructions.md Defines an asynchronous function to read a target configuration, accepting an optional schema parameter that defaults to the latest version. This promotes flexibility in handling different API versions. ```typescript export async function readTarget( filePath: string, schema: z.ZodSchema = TargetV2_8, // Default to latest version ) { // ... implementation } ``` -------------------------------- ### CMakefiles Object (v1) Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/docs/cmake-file-api.7.rst.txt Represents the configuration of CMake files, including paths, inputs, and globbing dependencies. ```APIDOC ## cmakeFiles Object (v1) ### Description Represents the configuration of CMake files, including source and build paths, input files, and globbing dependencies. ### Method GET ### Endpoint /api/cmakeFiles/v1 ### Parameters #### Query Parameters - **kind** (string) - Required - Must be "cmakeFiles" - **version** (object) - Required - Specifies the version, e.g., `{"major": 1, "minor": 0}` #### Request Body None ### Response #### Success Response (200) - **kind** (string) - The type of object, "cmakeFiles". - **version** (object) - The version of the cmakeFiles object. - **major** (integer) - The major version number. - **minor** (integer) - The minor version number. - **paths** (object) - Paths related to the build. - **source** (string) - Absolute path to the top-level source directory. - **build** (string) - Absolute path to the top-level build directory. - **inputs** (array) - An array of input files used by CMake. - Each element is an object with: - **path** (string) - Path to the input file. - **isGenerated** (boolean) - Optional. True if the file is generated under the build directory. - **isExternal** (boolean) - Optional. True if the file is outside the source or build directories. - **isCMake** (boolean) - Optional. True if the file is part of the CMake installation. - **globsDependent** (array) - Optional. Information about globbing dependencies. - Each element is an object with: - **expression** (string) - The globbing expression. - **recurse** (boolean) - Optional. True if `GLOB_RECURSE` was used. - **listDirectories** (boolean) - Optional. True if directories were listed. - **followSymlinks** (boolean) - Optional. True if `FOLLOW_SYMLINKS` was used. - **relative** (string) - Optional. The path specified with the `RELATIVE` option. - **paths** (array) - An array of strings representing the paths matched by the glob. #### Response Example ```json { "kind": "cmakeFiles", "version": { "major": 1, "minor": 1 }, "paths": { "build": "/path/to/top-level-build-dir", "source": "/path/to/top-level-source-dir" }, "inputs": [ { "path": "CMakeLists.txt" }, { "isGenerated": true, "path": "/path/to/top-level-build-dir/.../CMakeSystem.cmake" }, { "isExternal": true, "path": "/path/to/external/third-party/module.cmake" }, { "isCMake": true, "isExternal": true, "path": "/path/to/cmake/Modules/CMakeGenericSystem.cmake" } ], "globsDependent": [ { "expression": "src/*.cxx", "recurse": true, "paths": [ "src/foo.cxx", "src/bar.cxx" ] } ] } ``` ``` -------------------------------- ### ConfigureLog Object Structure (JSON) Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/docs/cmake-file-api.7.rst.txt Describes the JSON structure for a 'configureLog' object, which holds information about the location and content of a CMake configure log file. It includes the path to the log file and a list of event kinds it may contain. ```json { "kind": "configureLog", "version": { "major": 1, "minor": 0 }, "path": "/path/to/top-level-build-dir/CMakeFiles/CMakeConfigureLog.yaml", "eventKindNames": [ "try_compile-v1", "try_run-v1" ] } ``` -------------------------------- ### C Language Toolchain Configuration Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/docs/cmake-file-api.7.rst.txt Defines the toolchain configuration for the C programming language. This includes the compiler path, ID, version, and lists of implicit include and link directories and libraries. It also specifies the source file extensions recognized for C. ```json { "language": "c", "compiler": { "path": "/usr/bin/gcc", "id": "GNU", "version": "9.3.0", "implicit": { "includeDirectories": [ "/usr/include/c++/9", "/usr/include/x86_64-linux-gnu/c++/9", "/usr/include/c++/9/backward", "/usr/lib/gcc/x86_64-linux-gnu/9/include", "/usr/local/include", "/usr/include/x86_64-linux-gnu", "/usr/include" ], "linkDirectories": [ "/usr/lib/gcc/x86_64-linux-gnu/9", "/usr/lib/x86_64-linux-gnu", "/usr/lib", "/lib/x86_64-linux-gnu", "/lib" ], "linkFrameworkDirectories": [], "linkLibraries": [ "stdc++", "m", "gcc_s", "gcc", "c", "gcc_s", "gcc" ] } }, "sourceFileExtensions": [ "c", "m" ] } ``` -------------------------------- ### v1 Reply Index File Structure Source: https://github.com/callstackincubator/react-native-node-api/blob/main/packages/cmake-file-api/docs/cmake-file-api.7.rst.txt Details the structure of the CMake v1 reply index file, used to locate other reply files. ```APIDOC ## v1 Reply Index File ### Description CMake writes an `index-*.json` file to the `v1/reply/` directory upon successful build system generation. Clients must read this file first to locate other reply files. ### Endpoint `/.cmake/api/v1/reply/index-.json` ### Response Body (Success Response 200) - **cmake** (object) - Information about the CMake instance that generated the reply. - **version** (object) - Specifies the CMake version. - **major** (integer) - Major version component. - **minor** (integer) - Minor version component. - **patch** (integer) - Patch version component. - **suffix** (string) - Version suffix, if any. - **string** (string) - Full version string (e.g., "3.14.0"). - **isDirty** (boolean) - Indicates if the version was built with local modifications. - **paths** (object) - Paths to CMake-provided components. - **cmake** (string) - Path to the CMake executable. - **ctest** (string) - Path to the CTest executable. - **cpack** (string) - Path to the CPack executable. - **root** (string) - Path to the CMake installation root. - **generator** (object) - Information about the build system generator. - **multiConfig** (boolean) - Whether the generator supports multi-configuration builds. - **name** (string) - The name of the generator (e.g., "Unix Makefiles"). - **objects** (array) - A list of requested object kinds and their versions. - **kind** (string) - The kind of object. - **version** (object) - The version of the object (e.g., `{"major": 1, "minor": 0}`). - **jsonFile** (string) - The path to the JSON file containing the object's data. - **reply** (object) - Maps of available reply files organized by kind and version. - **`-v`** (object) - Entry for a specific object kind and major version. - **kind** (string) - The object kind. - **version** (object) - The object version. - **jsonFile** (string) - The path to the object's JSON file. - **client-``** (object) - Nested reply information for a specific client. - **`query.json`** (object) - Details of the processed query. - **requests** (array) - Original requests made by the client. - **responses** (array) - Results of the processed requests. - **kind** (string) - The kind of the response object. - **version** (object) - The version of the response object. - **jsonFile** (string) - The path to the response JSON file. - **error** (string) - Description of an error, if any. ```