MCPcopy Index your code
hub / github.com/dart-sys/dart-sys

github.com/dart-sys/dart-sys @v4.1.5

Chat with this repo
repository ↗ · DeepWiki ↗ · release v4.1.5 ↗ · + Follow
86 symbols 112 edges 22 files 14 documented · 16%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Fork of dart-sys before the upstream is published

<img src="https://raw.githubusercontent.com/dart-sys/dart-sys-branding-assets/main/dart-sys%20header.png" alt="Dart-sys brand header"

Dart-sys

Stars Forks Crates.io License: MIT License: Apache 2.0 Docs.rs CI

Rust bindings to the Dart ffi api

Prerequisites 🔧

You will need the following tools available on your system:

Unix/Linux 🐧

No additional requirements :)

MacOS 🍎

No additional requirements :)

Windows 🪟

On Windows platforms, dynamic libraries are linked against the executable, not into the executable as is the case o Unix platforms.

⚠️ Important ⚠️

This means that (on Windows) you will Need to have the Dart SDK installed and available on your system path to be able to compile Dart-sys.

Installing 📦

Run the following Cargo command in your project directory:

cargo add dart-sys

Or add the following line to your Cargo.toml:

dart-sys = "4.1.5"

Usage 💻

Examples 📚

An extremely straightforward example of using dart-sys would be like such:

use dart_sys::{Dart_Handle, Dart_NewIntegerFromI64};

#[no_mangle]
/// Adds two integers together.
pub extern "C" fn dart_sys_example_extension_sum(
    a: Dart_Handle,
    b: Dart_Handle,
) -> Dart_Handle {
    let a = unsafe { Dart_NewIntegerFromI64(a) };
    let b = unsafe { Dart_NewIntegerFromI64(b) };
    a + b
}

#[no_mangle]
/// Multiplies two integers together.
pub extern "C" fn dart_sys_example_extension_product(
    a: Dart_Handle,
    b: Dart_Handle,
) -> Dart_Handle {
    let a = unsafe { Dart_NewIntegerFromI64(a) };
    let b = unsafe { Dart_NewIntegerFromI64(b) };
    a * b
}
import 'dart:ffi';

// open and link to the native library
final DynamicLibrary nativeLib = DynamicLibrary.open('libdart_sys_example_extension.so');

// lookup the sum function in the native library
final int Function(int, int) sum = nativeLib
    .lookup<NativeFunction<Int32 Function(Int32, Int32)>>('dart_sys_example_extension_sum')
    .asFunction();

// lookup the product function in the native library
final int Function(int, int) product = nativeLib
    .lookup<NativeFunction<Int32 Function(Int32, Int32)>>('dart_sys_example_extension_product')
    .asFunction();

void main() {
    print(sum(1, 2)); // 3
    print(product(1, 2)); // 2
}

While this example is certainly possible, you are not likely to ever use Dart-sys for this purpose. See the examples directory for more in-depth examples of how to use Dart-sys. All examples are tested using GitHub Actions and documented verbosely.

Built With 🛠️

  • Rust - A systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety.
  • Dart - A client-optimized language for fast apps on any platform.
  • Dart Native Extensions - A mechanism for writing native code in C/C++ and calling it from Dart.
  • bindgen - A Rust library for generating bindings to C and C++ APIs.

Contributing ✏️

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests. If you have any questions, please open an issue, or contact admin gutenfries@gmail.com directly.

Versioning 🪧

We use SemVer for versioning. For the versions available, see the tags on this repository.

License 📜

Dart-sys is open-sourced and released under the terms and conditions of one or both of the following licenses:

Acknowledgments 🙏

Core symbols most depended-on inside this repo

dart_sdk_path
called by 9
codegen/src/utils/paths.rs
temp_dir
called by 7
codegen/src/utils/paths.rs
dart_sys_crate_path
called by 7
codegen/src/utils/paths.rs
dart_sdk_include_path
called by 5
codegen/src/utils/paths.rs
repo_root
called by 3
codegen/src/utils/paths.rs
download
called by 2
codegen/src/update_dart_sdk/mod.rs
create_coordinate
called by 1
examples/structs/src/lib.rs
update_dart_sdk
called by 1
codegen/src/update_dart_sdk/mod.rs

Shape

Class 54
Function 31
Enum 1

Languages

Rust84%
C++12%
C5%

Modules by API surface

dart-sys/src/lib.rs42 symbols
dart-sys/dart-sdk/include/dart_api.h8 symbols
codegen/src/utils/paths.rs7 symbols
examples/structs/src/lib.rs5 symbols
examples/primitives/src/lib.rs5 symbols
dart-sys/dart-sdk/include/dart_api_dl.c4 symbols
codegen/src/update_dart_sdk/mod.rs4 symbols
dart-sys/dart-sdk/include/dart_native_api.h2 symbols
codegen/src/log.rs2 symbols
tests/hello_local/src/main.rs1 symbols
tests/hello_git/src/main.rs1 symbols
tests/hello_cargo/src/main.rs1 symbols

For agents

$ claude mcp add dart-sys \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page