nitro_generator 0.2.3
nitro_generator: ^0.2.3 copied to clipboard
Code generator for Nitro Modules (Nitrogen). Converts *.native.dart specs to Dart FFI, Kotlin, Swift, and C++ bindings.
0.2.3 #
- Fix: Array — Updated the Swift generator to correctly bridge
Uint8Listparameters asDatawhen matching native Swift signatures, ensuring type-safe binary data transfer without manual casts. - Improved: Header Generator — The generated C++ bridge headers now automatically include
nitro.h. - Improved: Dependency Sync: Synchronized the Nitro ecosystem to version 0.2.3.
0.2.2 #
- Fix: stable annotation resolution — updated
SpecExtractorto useTypeChecker.fromRuntimefor all Nitro annotations, ensuring they are correctly identified when re-exported through thenitroruntime package. This resolves "No @NitroModule annotated classes found" and "UNKNOWN_RETURN_TYPE" errors for enums/structs in complex specifications. - Improved: spec-level type registration — ensured that all enums and structs defined in a spec library are correctly added to the valid type set before function, property, and stream validation.
0.2.1 #
- Fix: non-zero-copy TypedData function parameters now produce correct JNI arrays — previously the raw C pointer (
float*,int32_t*, …) was passed directly as the JNI call argument, causing a crash at runtime. The generator now emitsNewFloatArray/NewIntArray/SetFloatArrayRegion/ etc. and passes the properjarrayreference. ADeleteLocalRefis emitted after the call in every return-type path. - Fix: removed redundant
env->ExceptionClear()at JNI call sites —nitro_report_jni_exceptionalready callsExceptionClear()internally; the duplicate call at each call site was a no-op and has been removed. - Fix:
_streamJobsmap now uses a compositePair<String, Long>key — keying only ondartPortmeant two simultaneous subscriptions on different streams could theoretically overwrite each other's coroutine job if they received the same port value. The key is nowPair(streamName, dartPort). - Polish: spec-path attribution in all generated files — every generated file (Dart, Kotlin, Swift, C++, CMake) now includes
// Generated from: <spec>.native.dartat the top, making it easy to trace any generated file back to its source spec when working with multiple modules. - Polish:
checkDisposed()annotated@pragma('vm:prefer-inline')— the single-field_disposedcheck is now inlined by the Dart VM/AOT compiler, eliminating the call overhead on every generated method invocation. - Performance: single-pass AST extraction in
SpecExtractor—_extractRecordTypespreviously calledlibrary.annotatedWithtwice (once to collect names, once to build types); it now collects class elements in one pass and reuses the list._extractPropertiesand_extractStreamspreviously made two separate loops overelement.accessors; they are now merged into a single combined pass. - Decoupled from the
nitroruntime package to resolvepub.devplatform warnings. - Now depends on the pure-Dart
nitro_annotationspackage. - This ensures the generator is recognized as a cross-platform Dart package.
0.2.0 #
- New:
@HybridRecordBinary Bridge Generator — Generated extensions now use a compact binary protocol (uint8_t*/Pointer<Uint8>) instead of UTF-8 JSON strings, significantly reducing serialization overhead.- Breaking: Extension methods renamed to standard codec names:
fromJson→fromNative/fromReader,toJson→writeFields/toNative. - Full support for
@HybridRecordin Kotlin (.bridge.g.kt) via@Keep data classwith companiondecode/encodemethods. Swift support updated fortoNativeandRecordReaderintegrations.
- Breaking: Extension methods renamed to standard codec names:
- New: Comprehensive Collection Bridging — Added binary-first support for:
List<primitive>(int, double, bool, String) viaRecordWriter.encodePrimitiveList.Map<String, T>using the UTF-8 JSON path (dynamic values).- Nested lists and nullable record fields.
- Improved: Swift Stream Stability — Fixed a compiler error in
_register_*_streamby heap-allocating@HybridStructitems before passing them to the C emit callback. - Improved: Code Quality & Lints — Generated code now follows strict Dart linting rules:
- Cleaned up unbraced for-loops and unused local variable declarations.
- Renamed internal variables to follow public naming conventions (e.g.,
_rawResult→rawResult).
- Testing: Added 28+ regression tests for Kotlin record emission and updated 200+ existing tests to match the binary wire format.
0.1.3 #
- Swift generator: fixed
@_cdeclString type crash (EXC_BAD_ACCESS) —Stringparameters now useUnsafePointer<CChar>?(Cconst char*) and return values useUnsafeMutablePointer<CChar>?(malloc'dchar*), withString(cString:)conversion at the boundary andstrdup()for returns so Dart'stoDartStringWithFree()/free()pairs correctly. - Swift generator: async
String-returning methods useDispatchSemaphore+Task.detachedwith astrdup(result)return. - Swift generator:
Stringproperty getters returnstrdup-allocated C strings; setters acceptUnsafePointer<CChar>?and convert withString(cString:).
0.1.2 #
- Swift generator: replaced
@objc public static func _call_*pattern with top-level@_cdecl("_call_*") public funcstubs. Swift structs and Swift-only protocols cannot cross the Objective-C boundary. - Swift generator:
boolreturn type now maps toInt8(matching C'sint8_t) instead ofBool. - Swift generator: struct-returning functions now return
UnsafeMutableRawPointer?(heap-allocated, caller frees) instead ofAny?.
0.1.1 #
- Renamed package from
nitrogentonitro_generatorto avoid a naming conflict onpub.dev.
0.1.0 #
- Initial release of Nitro code generator.
- Generates Dart FFI, Kotlin, Swift, and C++ bindings.
- Support for
HybridObject,HybridStruct, andHybridEnum. - Support for
@nitroAsyncmethods. - Support for
@NitroStreamwith Backpressure strategies.