JaymoCodes / dart_shared_libray

An attempt to package Dart into a usable shared library (.dll / .so)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dart Dynamic Import Library

This is an attempt / POC to build the Dart VM into a dynamic library, importable in any platform Dart supports.

Eventual support

The hope is that the the dynamic library will eventually support the following targets:

  • A "Fully Featured" .dll / .so that supports booting Dart in different configurations:
    • Boot (or not) the service and kernel isolates
    • Support Dart Source Compilation and / or Kernel Isolates
    • JIT from source or .dil
  • An AOT Only .dll / .so

Additionally we may have a static target that uses the same interface as the dynamic library, so the VM can be embedded on platforms that don't support dynamic linking.

I also hope to support all platforms that Dart currently supports, plus a few extra.

Using

Lastest builds of the libraries are now available for certain targets as artifacts from Github Actions as well as all the headers necessary.

Github Actions currently builds a Windows x64 .dll, A Linux x64 .so, and a macOS x64 .dylib. You can build a M-series dylib for macOS, but Github Actions does not currently support it.

Building

Prerequisets

You need:

  • git
  • Dart 3+
  • C++ build tools for your platform (Visual Studio, XCode, gcc, etc)
  • CMake

Optionally, I recommend installing depot_tools and making sure it is on your path before running setup scripts. Without depot_tools, the scripts will download them anyway, but having them already set up will save you some time with subsequent builds.

Patching and Building Dart

NOTE: If you are building on Windows, I recommend running .\setup_env.ps1 before executing any other scripts.
This will set up some environment variables that will be needed to build Dart properly.

The first step is to build a statically linkable verison of Dart. This requires that we download Dart, patch some of the Dart build files, and then run the actual build. Thankfully there is a Dart script to do this.

dart ./scripts/build_helpers/bin/build_dart.dart

This script does the following:

  • Pulls down depot_tools if needed.
  • Clones a fresh copy of the Dart sdk git repo using fetch if needed.
  • Uses gsync to syncs the repo the the version of dart specificed in .dart_version.
  • Applies dart_sdk.patch to the repo to create the statically linkable libdart library
  • Builds libdart

CMake

Once Dart is built, you can use CMake to generate build files and / or build the libraries and examples

cmake -B ./.build .
cmake --build .\.build\ --config release

About

An attempt to package Dart into a usable shared library (.dll / .so)

License:Other


Languages

Language:C++ 50.1%Language:Dart 31.7%Language:C 9.1%Language:CMake 8.7%Language:PowerShell 0.4%