fuzzybinary / dart_shared_libray Goto Github PK
View Code? Open in Web Editor NEWAn attempt to package Dart into a usable shared library (.dll / .so)
License: Other
An attempt to package Dart into a usable shared library (.dll / .so)
License: Other
Is it possible to take current Dart SDK version without additional modifications and make reloading of Dart libraries based on this project ?
Example use case:
I know that it requires some work but my question is about theoretical probability without Dart SDK/VM code modifications
I'm trying to invoke the functions declared in dart_dll.h from a dylib.
It looks like the names are mangled and therefore not visible under the name that the header defines.
modulovalue@MacBook-Air-von-Modestas bin % nm libdart_dll.dylib | grep 'DartDll'
000000000000461c T __Z15DartDll_RunMainP12_Dart_Handle
00000000000048d4 T __Z16DartDll_Shutdownv
000000000000406c T __Z18DartDll_Initializev
00000000000045c0 T __Z18DartDll_LoadScriptPKcS0_
0000000000004790 T __Z27DartDll_DrainMicrotaskQueuev
// Other symbols are not mangled as expected
...
0000000000041d28 T _Dart_LoadLibrary
0000000000041994 T _Dart_LoadLibraryFromKernel
000000000003f0b4 T _Dart_LoadScriptFromKernel
0000000000043d0c T _Dart_LoadingUnitLibraryUris
0000000000041338 T _Dart_LookupLibrary
0000000000036b7c T _Dart_MapContainsKey
0000000000036834 T _Dart_MapGetAt
...
I can invoke the functions under the mangled name (without one leading underscore e.g. _Z18DartDll_Initializev
)
I've tried extending the macro in dart_dll.h to make these symbols 'visible' under macos:
#ifdef _WIN
#ifdef DART_DLL_EXPORTING
#define DART_DLL_EXPORT __declspec(dllexport)
#else
#define DART_DLL_EXPORT __declspec(dllimport)
#endif
#elif defined(__APPLE__) // <-
#define DART_DLL_EXPORT __attribute__((visibility("default"))) // <-
#else
#define DART_DLL_EXPORT
#endif
But that doesn't seem to have any effect i.e. the symbols are still mangled.
I feel like I'm missing something simple here, do you know what it would take to export the actual identifiers that can be found in dart_dll.h
?
Hello Jeff,
I've tried building a dylib on macos. Here's how it went:
✅ Modify the BUILD.gn files to add a libdart target. [...]
(doesn't seem to be necessary on macos?)
Make sure all correct environment variables are set [...]
✅ Build libdart with:
python ./tools/build.py --no-goma -m release libdart
❌ Generate build scripts with genie (located in tools/[platform]) e.g.
tools/win/genie.exe vs2022
I've tried running the mac genie binary with various arguments (e.g. macosx, the lua file made it seem like that could work), but I was only able to get something out of genie with vs2022.
I've downloaded visual studio for mac. Visual studio displays an Unknown solution item type
error to the right of dart_dll and the sample projects. I've tried building the generated project, but that failed. (it succeeded according to visual studio, but it finished immediately with no output.)
Do have you any advice on how to successfully build a dylib on macos or any suggestions for what I should try next?
Does the library support any mobile devices
Hey, just started playing with this library and wanted to document some issues/improvements.
-fvisibility=hidden
for instance).0000000002580fd0 b _ZZNSt3__212_GLOBAL__N_14makeINS_8time_getIcNS_19istreambuf_iteratorIcNS_11char_traitsIcEEEEEEJjEEERT_DpT0_E3buf
0000000002580ff0 b
Debug info could be split from the shared object using -gsplit-dwarf
or by running separate commands after build (with strip
and objcopy
)
Missing some include files like dart_tools_api.h
, dart_native_api.h
, dart_api_dl.h
, dart_tools_api.h
and dart_version.h
[build] D:\Projects\Privat\dart_shared_libray\src\isolate_setup.cpp(222,8): error C2660: "dart::bin::DFE::CompileAndReadScript": Funktion akzeptiert keine 7 Argumente
I hope You Unterstand it in German.
dart-lang/sdk@2310994#diff-b437e35aa82b9ca7f474a2f3709391c7b91195fc3f20e7c1853cc509f74d44ef
I don't Understand what this Change do. Sorry
I'm interested in experimenting with this library.
Would you accept a PR to add a CMake and/or Makefile conversion of your Genie script?
First of all thank you very much for your work, I happen to have the need to embed the Dart VM to execute the code. Here is the code I read in dart_api_impl_test.cc
and it seems that the VM can execute Dart code directly in string form:
TEST_CASE(DartAPI_InstanceOf) {
const char* kScriptChars =
"class OtherClass {\n"
" static returnNull() { return null; }\n"
"}\n"
"class InstanceOfTest {\n"
" InstanceOfTest() {}\n"
" static InstanceOfTest testMain() {\n"
" return new InstanceOfTest();\n"
" }\n"
"}\n";
Dart_Handle result;
// Create a test library and Load up a test script in it.
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
// Fetch InstanceOfTest class.
Dart_Handle type =
Dart_GetNonNullableType(lib, NewString("InstanceOfTest"), 0, NULL);
EXPECT_VALID(type);
// Invoke a function which returns an object of type InstanceOf..
Dart_Handle instanceOfTestObj =
Dart_Invoke(type, NewString("testMain"), 0, NULL);
EXPECT_VALID(instanceOfTestObj);
}
Can you add an API like TestCase::LoadTestScript
?
Hi, I ran your example but got an error, can you see what could be the reason?
G:\Repository\git_code\c++\dart_shared_libray\.build\win64_vs2019\bin>simple_example.exe
Initializig Dart ----
Dart initialized, error was: null
Created isolate main
* 8373a Setting working directory: G:\Repository\git_code\c++\dart_shared_libray\.build\win64_vs2019\bin
The Dart VM service is listening on http://127.0.0.1:5858/
* 8373a Working directory URI: file:///G:/Repository/git_code/c++/dart_shared_libray/.build/win64_vs2019/bin/
* 286f Setting working directory: G:\Repository\git_code\c++\dart_shared_libray\.build\win64_vs2019\bin
* 286f Working directory URI: file:///G:/Repository/git_code/c++/dart_shared_libray/.build/win64_vs2019/bin/
Failed to invoke main: Unhandled exception:
NoSuchMethodError: No top-level method 'simplePrint' declared.
Receiver: top-level
Tried calling: simplePrint()
#0 NoSuchMethodError._throwNew (dart:core-patch/errors_patch.dart:191:5)
#1 simplePrint (file:///G:/Repository/git_code/c++/dart_shared_libray/.build/win64_vs2019/bin/hello_world.dart)
#2 main (file:///G:/Repository/git_code/c++/dart_shared_libray/.build/win64_vs2019/bin/hello_world.dart:4:3)
#3 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#4 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:26)
The Dart version I compiled is:
Dart SDK version: 3.0.0-edge.0c05e33836662da52b963158ccd6b9c211208429 (be) (Sat Feb 18 12:37:40 2023 +0000) on "windows_x64"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.