fuzzybinary / dart_shared_library

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

Building a dylib. #2

Closed modulovalue closed 1 year ago

modulovalue commented 1 year ago

Hello Jeff,

I've tried building a dylib on macos. Here's how it went:

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?

fuzzybinary commented 1 year ago

Hi @modulovalue

Genie is just the project generator that I use and it should support xcode (though to be honest I haven't tested it recently).

Try running

./tools/mac/genie xcode11
# or xcode10 if 11 doesn't work

The resulting xcode workspace and project should then be in ./build/projects/xcode11. Resulting files should end up in ./build/mac_[platform], although I'm not sure I copy over the dependent files (.dart / .so / etc.) as part of the mac build.

modulovalue commented 1 year ago

Try running [...]

Thank you, I was able to use that to generate an xcode project.

I'm on an M1 mac. I've tried renaming all x86 references in the genie.lua to arm64 equivalents and that seems to have worked.

However, running the dart_dll (as well as the sample projects) from within xcode gives me:

ld: library not found for -ldart

But something is happening now. There are files being generated into .build/mac_xcode11/obj/Debug/dart_dll/ but I can't find a dylib anywhere.

I assume that running dart_dll from within xcode would generate the dylib. Is that correct?

fuzzybinary commented 1 year ago

Yes, but that linking error means it can't find the dart library prodcued by building the Dart SDK. I'm not sure where Dart puts the compiled library on the M1. Double check that the libdirs in the genie script matches the output directory from Dart.

I'll try to get some time to build on my M1 and see if I can make the necessary modifications to the genie script to have it work on both the M1 and Intel chips. Might be a bit though.

fuzzybinary commented 1 year ago

I lied and got to it tonight. The changes to the genie script should now properly set up directories for arm64 macs, though the documentation isn't updated.

Note that the FFI examaple does require you also dart pub get inside the examples/simplle_example_ffi directory.

modulovalue commented 1 year ago

@fuzzybinary Thank you, your changes work for me as well. I can now open the generated dylib in Dart.

For future reference: the -ldart issue seems to have been caused by me moving the dart-sdk into dart_shared_library without recompiling it after moving it.