Giter VIP home page Giter VIP logo

dart_shared_libray's People

Contributors

derkleinepunk avatar fuzzybinary avatar mchandler-plato avatar modulovalue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

dart_shared_libray's Issues

Dart dynamic reload

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:

  1. Load dart from .so
  2. Launch Isolate
  3. On event (any event which user wants) load new library, launch new isolate
  4. Kill first isolate in first library

I know that it requires some work but my question is about theoretical probability without Dart SDK/VM code modifications

dart_dll.h symbols mangled in the exported dylib.

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?

Building a dylib.

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?

Some improvements

Hey, just started playing with this library and wanted to document some issues/improvements.

  1. Shared objects are exporting all symbols, this makes them a lot larger than they need to be.
    Ideally non Dart public API symbols will be hidden (by using -fvisibility=hidden for instance).
0000000002580fd0 b _ZZNSt3__212_GLOBAL__N_14makeINS_8time_getIcNS_19istreambuf_iteratorIcNS_11char_traitsIcEEEEEEJjEEERT_DpT0_E3buf
0000000002580ff0 b 
  1. Debug info could be split from the shared object using -gsplit-dwarf or by running separate commands after build (with strip and objcopy)

  2. 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

CMake/Makefile support

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?

Add an API to directly execute dart code?

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?

NoSuchMethodError: No top-level method 'simplePrint' declared.

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"

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.