Skip to main content

Crate nativeview_codegen

Crate nativeview_codegen 

Source
Expand description

Bi-directional & multi-target Native View Engine (NV) code generator.

Organized as a compiler pipeline:

  • abi: Askama-rendered host ABI data (Core + Scene ABI, word-table field specs, golden XXH64 vectors) for the static packages/core/host-* runtimes.

  • schema: Intermediate representations and validation (export, hybrid).

  • frontend: Input specification parsers (rn_spec, and hybrid_spec via nativeview-hybrid-spec).

  • targets: Output-language code emitters (c_cpp, rust, swift, kotlin_java, dart, typescript) plus unified multi-target dispatchers.

  • direct_specs: discovery of the packages/modules/*/src/spec.rs Direct-FFI specs and their module-leaf layout.

Dependencies: nativeview-abi / nativeview-hash (ABI descriptors, XXH64), nativeview-hybrid-spec (the hybrid spec IR, syn 2 frontend, and Rust emitter), serde derives on the IR, askama (templates), and toml (module [package.metadata.nativeview] for spec discovery). Reading specs from JSON files is the CLI’s job (nativeview-cli), so this crate never links serde_json.

Re-exports§

pub use abi::generate_abi_files;
pub use abi::generate_all_abi_files;
pub use abi::generate_c_abi_header;
pub use abi::generate_dart_module_table_file;
pub use abi::generate_flat_op_codec_files;
pub use abi::generate_flat_op_codec_files_for_module;
pub use abi::generate_hash_vector_files;
pub use abi::generate_java_module_table_file;
pub use abi::generate_module_c_abi_header;
pub use abi::generate_module_java_abi_file;
pub use abi::generate_module_table_header;
pub use abi::generate_shared_value_sets_c;
pub use abi::generate_shared_value_sets_dart;
pub use abi::generate_shared_value_sets_java;
pub use abi::generate_shared_value_sets_swift;
pub use abi::generate_shared_value_sets_ts;
pub use abi::generate_swift_module_table_file;
pub use abi::generate_table_files;
pub use abi::generate_ts_module_table_file;
pub use abi::validate_merged_shared_value_sets;
pub use abi::java_host::generate_java_host_files;
pub use abi::policy::PolicySymbol;
pub use abi::policy::generate_policy_files;
pub use abi::policy::policy_container;
pub use abi::policy::policy_langs;
pub use abi::policy::policy_read_symbols;
pub use direct_specs::DirectSpec;
pub use direct_specs::ModuleLayout;
pub use direct_specs::ModuleLeaf;
pub use direct_specs::discover_direct_specs;
pub use direct_specs::discover_direct_specs_in;
pub use direct_specs::discover_module_layouts_in;
pub use direct_specs::generate_direct_spec_host_files;
pub use module_catalog::CMAKE_CATALOG_PATH;
pub use module_catalog::ModuleCatalog;
pub use module_catalog::discover_module_catalog_in;
pub use module_catalog::generate_cmake_module_catalog;
pub use abi::top_layer_vectors::PressVector;
pub use abi::top_layer_vectors::TopLayerVectors;
pub use abi::top_layer_vectors::generate_top_layer_vector_files;
pub use targets::export_pkg::ExportPackageMeta;
pub use targets::export_pkg::IosFrameworkPlistMeta;
pub use targets::export_pkg::emit_android_library_manifest_xml;
pub use targets::export_pkg::emit_apple_export_anchor_h;
pub use targets::export_pkg::emit_apple_export_anchor_m;
pub use targets::export_pkg::emit_ios_framework_info_plist;
pub use targets::export_pkg::emit_nitro_android_build_gradle;
pub use targets::export_pkg::emit_nitro_package_swift;
pub use targets::export_pkg::emit_nitro_pkg_index_ts;
pub use targets::export_pkg::emit_nitro_pkg_package_json;
pub use targets::export_pkg::emit_rn_android_build_gradle;
pub use targets::export_pkg::emit_rn_pkg_index_ts;
pub use targets::export_pkg::emit_rn_pkg_package_json;
pub use targets::export_pkg::emit_rn_podspec;
pub use targets::export_pkg::emit_web_pkg_index_ts;
pub use targets::export_pkg::emit_web_pkg_package_json;
pub use targets::export_pkg::emit_web_pkg_tsconfig_json;
pub use targets::export_pkg::xml_escape;
pub use targets::nitro_ui::emit_nitro_json_with_module_name;
pub use embedded_templates::TemplateDrift;
pub use embedded_templates::verify_embedded_templates;
pub use error::CodegenError;
pub use frontend::parse_hybrid_rust_spec;
pub use frontend::parse_hybrid_rust_spec_file;
pub use frontend::parse_rn_spec;
pub use frontend::parse_rn_spec_file;
pub use schema::export::CommandSpec;
pub use schema::export::ComponentOptions;
pub use schema::export::DefaultValue;
pub use schema::export::EventBubbling;
pub use schema::export::EventSpec;
pub use schema::export::ExportComposeOutput;
pub use schema::export::ExportFlutterOutput;
pub use schema::export::ExportNitroUiOutput;
pub use schema::export::ExportRnOutput;
pub use schema::export::ExportSwiftUiOutput;
pub use schema::export::ExportTarget;
pub use schema::export::ExportWebComponentOutput;
pub use schema::export::GeneratedFile;
pub use schema::export::ImportRnOutput;
pub use schema::export::MultiTargetExportOutput;
pub use schema::export::ObjectField;
pub use schema::export::ParamSpec;
pub use schema::export::ParsedRnSpec;
pub use schema::export::PropSpec;
pub use schema::export::PropType;
pub use schema::export::RnComponentSpec;
pub use schema::export::TurboModuleMethod;
pub use schema::export::TurboModuleSpec;
pub use targets::generate_export_compose;
pub use targets::generate_export_flutter;
pub use targets::generate_export_nitro_ui;
pub use targets::generate_export_rn;
pub use targets::generate_export_rn_with_ios_module;
pub use targets::generate_export_swiftui;
pub use targets::generate_export_web_component;
pub use targets::generate_hybrid_all;
pub use targets::generate_hybrid_cpp;
pub use targets::generate_hybrid_dart;
pub use targets::generate_hybrid_kotlin;
pub use targets::generate_hybrid_rust;
pub use targets::generate_hybrid_swift;
pub use targets::generate_hybrid_target;
pub use targets::generate_hybrid_ts;
pub use targets::generate_import_rn;
pub use targets::HybridGenerateOutput;

Modules§

abi
Host ABI data generated with Askama templates (packages/core/codegen/templates/): the Core and runtime scene ABIs, the word-table field specs, and the golden XXH64 vectors. Every file lands next to the static runtime it plugs into (packages/core/host-{cxx,swift,java,dart,ts}).
direct_specs
Discovery of the Direct-FFI capability specs nv codegen abi renders, and the module-leaf layout their host bindings (and module-homed nv_policy! constants) land in.
embedded_templates
Proof that this build’s Askama code was compiled from the templates of the checkout it runs in.
error
frontend
Input specification parsers: React Native specs (rn_spec) and declarative hybrid Rust specs (hybrid_spec, delegated to nativeview_hybrid_spec::frontend).
module_catalog
Discovery and emission of cxx/cmake/NvModuleCatalog.generated.cmake from packages/modules/*/Cargo.toml ([package.metadata.nativeview.direct_host] and [package.metadata.nativeview.component]).
naming
Identifier and case-conversion utilities for Rust, TypeScript, C++20, ObjC++, and Kotlin.
schema
Schema IRs, layout computation, validation, and colocated AbiFileDescriptor bridges.
targets
Target-language code emitters organized by output language, plus unified multi-target dispatchers for Hybrid FFI and RN import/export. Host ABI data lives in crate::abi.

Structs§

FlatOpStreamDesc
Derives NvEncode and NvDecode for Tier-2 little-endian structs and enums.
HybridAliasSpec
Opaque handle or typedef alias declared with #[nv_hybrid_alias] pub type ... = ...;.
HybridConstSpec
Named constant declared with #[nv_hybrid_const] pub const ....
HybridEnumSpec
C-ABI enum declared with #[nv_hybrid_enum].
HybridEnumVariant
One variant of a #[repr(u8|u16|u32|i32)] #[nv_hybrid_enum].
HybridEventSpec
Typed event declared with #[event] or #[event(retained)] on a HybridModuleSpec or HybridViewSpec.
HybridFieldSpec
Named field of a #[nv_hybrid_struct] or #[nv_hybrid_union].
HybridFileSpec
Complete parsed or programmatically constructed Hybrid FFI specification file.
HybridMethodSpec
Method declared on a HybridModuleSpec, imperative #[method] on a HybridViewSpec, or C API function.
HybridModuleSpec
Nitro-style native module declared with #[nv_hybrid_module(name = "...")].
HybridParamSpec
Named parameter of a method or view event.
HybridPropSpec
Typed prop declared with #[prop] on a HybridViewSpec.
HybridStructSpec
Structured record declared with #[nv_hybrid_struct] or #[nv_hybrid_union].
HybridViewSpec
Nitro-style native view component declared with #[nv_hybrid_view(name = "...")].

Enums§

HybridBinding
FFI binding mechanism for a hybrid module or view (binding = "direct" default, or "vtable").
HybridDefaultValue
Typed literal default value for a #[prop(default = ...)] on a HybridView.
HybridImpl
Which side implements a binding = "direct" module (impl = "rust" default, or "host").
HybridTarget
Target languages emitted by the Hybrid FFI generator.
HybridType
Rich typed system shared across Hybrid modules, views, structs, enums, and events.

Constants§

NV_HYBRID_ABI_VERSION
Current Hybrid FFI vtable ABI version stamped into every generated vtable (compile-time locked against nativeview_abi::hybrid::NV_HYBRID_ABI_VERSION in nativeview-codegen).
NV_HYBRID_INTERFACE_ID_BASE
Base interface ID for generated hybrid vtables (>= 0x1000_0000), keeping the low range (1..=4) permanently reserved for core NV interfaces (NV_IFACE_SURFACE..NV_IFACE_DEV).

Functions§

compute_hybrid_interface_id
Computes a deterministic hybrid interface_id >= 0x1000_0000 for a module or view.
export_all_targets
Exports every #[nv_hybrid_view] in file across multiple ExportTargets (or ExportTarget::ALL).
export_compose
Export one #[nv_hybrid_view] to a typed Jetpack Compose @Composable wrapping io.github.nativeview.compose.NvSurface.
export_flutter
Export one #[nv_hybrid_view] to a typed Flutter StatefulWidget using dart:ffi + nativeview_flutter.
export_lib_stem
Crate-level snake_case library stem shared by all views in file (lib<stem>.so, <stem>_web.js), ensuring multi-view specs load from one compiled crate binary while differentiating views by vtable_symbol / componentName.
export_nitro_ui
Export one #[nv_hybrid_view] to a margelo/nitro-ui bare Nitro view package (5 files).
export_rn
Export one #[nv_hybrid_view] to a drop-in React Native Fabric NativeComponent package (5 files).
export_swiftui
Export one #[nv_hybrid_view] to a typed SwiftUI View wrapping NativeViewSwiftUI.NvSurfaceRepresentable.
export_target
Exports every #[nv_hybrid_view] in file to one requested ExportTarget.
export_web_component
Export one #[nv_hybrid_view] to a Light-DOM Custom Element <nv-...> + .d.ts + typed React .tsx.
import_rn_file
CLI entrypoint (nv codegen import-rn): parse a .ts/.js spec file on disk (following RN re-export wrappers automatically) and emit Rust + C++20 files.
import_rn_source
Parse RN spec source text and emit zero-JS Rust + C++20 Fabric adapter files.
ios_core_framework_name
Dynamic iOS .framework / .xcframework bundle name for an exported component (<Mod>Core), keeping the dynamic Rust binary distinct from the CocoaPods/SwiftPM wrapper module <Mod>.
nitro_ios_anchor_fn
C anchor function exported by <Mod>Anchor’s NvExportAnchor.m in nitro-ui-pkg that resolves each view’s <vtable_symbol> from its isolated <Mod>Core.framework via dlopen(RTLD_LOCAL) + dlsym.
rn_codegen_spec_name
Canonical React Native codegenConfig.name and <react/renderer/components/<name>/*.h> header directory shared across package.json and generated ObjC++ Fabric ComponentViews.