Git Product home page Git Product logo

dart-zig-interop's Introduction

Dart Zig Interop

Unlike the Dart-C FFI, this repo shows some demo for the Dart-Zig FFI.

Used those versions as of Feb 2024:

  • Zig SDK: 0.12.0-dev.2250
  • Dart SDK: 3.4.0-00.0.dev (Flutter 3.19.0-0.3.pre)
  • Debian Sid

There are 2 different ways:

  • Manual FFI (under the src directory)
  • Automatic FFI with the ffigen command (under the src-ffigen directory)

How to run the manual FFI demos

To build all the Zig libraries:

# Build the library
$ cd src/library
$ zig build --summary all

For the hello world example:

# Install packages and run the caller
$ cd src/dart/01-hello-world
$ dart pub get
$ dart run hello.dart

For the primitives example:

# Install packages and run the caller
$ cd src/dart/02-primitives
$ dart pub get
$ dart run primitives.dart

For the structs example:

# Install packages and run the caller
$ cd src/dart/03-structs
$ dart pub get
$ dart run structs.dart

For the async example:

# Install packages and run the caller
$ cd src/dart/04-async
$ dart pub get
$ dart run async.dart

How to run the automatic FFI demos

To build all the Zig libraries:

# Build the library
$ cd src-ffigen/library
$ zig build --summary all

Manually update the header files:

$ nv src-ffigen/library/zig-cache/hello.h
$ mv src-ffigen/library/zig-cache/hello.h src-ffigen/dart/01-hello-world

Update the pubspec.yaml:

$ nv src-ffigen/app/01-hello-world/pubspec.yaml

Generate the ffi file:

$ cd src-ffigen/app/01-hello-world
$ dart run ffigen

Run the demo:

$ dart run hello.dart

โš ๏ธ the async demo doesn't work with the ffigen command, but other 3 demos work well.

dart-zig-interop's People

Contributors

bus710 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.