Dart Native Interop
repository·main·Indexed 43 days ago
https://github.com/dart-lang/nativeFoundational ecosystem for Dart native interop, featuring FFI utilities, binding generators like ffigen and jnigen, and tools for managing native asset building and bundling via build and link hooks. Includes package:code_assets for managing executable code assets (C, C++, Rust, Go) and guidance on using the dart:ffi library for C interop.
What's inside Dart Native
- Swift2ObjC is an experimental tool designed to generate bindings that enable interoperability between Objective-C (ObjC) and Swift code. It is intended for developers needing to bridge these two languages within a single project environment.
Overview of package:ffigen
mainpackage:ffigenis a tool designed to simplify generatingdart:ffibindings from C and Objective-C header files. It uses a Dart script configuration via anFfiGeneratorobject to define how bindings are produced.Requirements:
- LLVM (version 18 or higher) must be installed on your system.
Overview of the host_name package
mainThehost_namepackage is a cross-platform Dart demonstration that retrieves the local machine's hostname on major desktop and mobile platforms. It serves as a minimal example of using Dart's build hooks alongside code assets anddart:ffito interface with system APIs (specificallygethostname).Overview of the stb_image demonstration project
mainThis project serves as a minimal, cross-platform demonstration of integrating Dart with native C libraries. It showcases three key technologies:
- Dart Build Hooks: Used to automate the compilation of native code.
- Code Assets: Used to manage and include external files.
- dart:ffi: Used to call C functions from Dart.
The specific implementation uses the
stbi_infofunction from thestb_image.hlibrary to retrieve an image's dimensions and color channels without loading the full file into memory.Overview of hooks_runner
mainThehooks_runnerpackage provides shared logic used by Dart launchers to invoke native assets CLIs. It is designed to standardize how tools interact with native asset hooks during the build process.Overview of package:code_assets
mainpackage:code_assetsprovides tools and structures for managing code assets within the Dart ecosystem. Documentation for this package includes guidance on resolving linking issues and a detailed JSON schema for asset configuration files.Overview of ApiSummarizer
mainApiSummarizer is a tool that analyzes Java source code or JAR files and outputs a JSON representation of the public API. It is primarily used by JNIgen to extract information about Java APIs for use in Dart.Overview of Swiftgen
mainSwiftgen is an experimental tool designed to generate bindings that enable interoperability between Dart and Swift code. It facilitates the communication and data exchange between these two languages within the native ecosystem.Overview of JSON Syntax Generator
mainpackage:json_syntax_generatoris a tool for generating Dart code from JSON schemas. It automates the creation of Dart classes that represent JSON structures, ensuring that complex schema features are correctly mapped to Dart's type system and naming conventions.Overview of Dart Native Assets and FFI packages
mainThedart-lang/nativerepository contains a collection of Dart packages designed to facilitate Foreign Function Interface (FFI) and the building and bundling of native assets. These tools allow Dart and Flutter developers to interoperate with native code (C, C++, Objective-C, Swift, Java, Kotlin, etc.) and manage native build processes.Overview of JNI Flutter
mainJNI Flutter is a support library designed to allow Dart code to access Flutter-specific Android APIs via the Java Native Interface (JNI). It is a specialized spin-off of thepackage:jnilibrary, specifically containing the APIs required to interact with the Flutter Android framework.Overview of native_toolchain_c
mainThe
native_toolchain_cpackage is a library designed to invoke the native C compiler installed on the host machine.Warning: This package is currently experimental and published under the
labs.dart.devpublisher. Users should expect a high rate of API changes and potential discontinuation. It is intended to solicit feedback to help evolve the package.