fuzzybinary / dart_shared_library

An attempt to package Dart into a usable shared library (.dll / .so)
Other
77 stars 10 forks source link

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:

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:

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. build_dart commandline

cd ./scripts/build_helpers
dart pub get
cd ../..
dart ./scripts/build_helpers/bin/build_dart.dart

This script does the following:

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

Troubleshooting

Unresolved externals building Dart on Linux

Two possible causes of this are having the snap package for Flutter installed, or having depot_tools not too far down your path.

First, uninstall the Flutter snap package and remove the dart-sdk build directory at dart-sdk/sdk/out and attempt to rebuild Dart.

If that doesn't work, put depot_tools at the front of your path, instead of at the end. Clean the dart-sdk build directory, then attempt a rebuild.