facebook / hermes

A JavaScript engine optimized for running React Native.
https://hermesengine.dev/
MIT License
9.41k stars 596 forks source link

Linking static hermes #1375

Closed manuelpuyol closed 4 weeks ago

manuelpuyol commented 1 month ago

👋 what's the current state with Static Hermes?

I've cloned main and built it with -DHERMES_STATIC_LINK=ON, but when I try to the host-functions example in https://github.com/tmikov/hermes-jsi-demos with the static build, I get a bunch of undefined reference errors like

/usr/bin/ld: /src/hermes/build/API/hermes/libhermes.a(hermes.cpp.o): in function `hermes::hbc::BCProviderFromSrc::isFunctionLazy(unsigned int) const':
hermes.cpp:(.text._ZNK6hermes3hbc17BCProviderFromSrc14isFunctionLazyEj[_ZNK6hermes3hbc17BCProviderFromSrc14isFunctionLazyEj]+0x10): undefined reference to `hermes::hbc::BytecodeModule::getFunction(unsigned int)'
neildhar commented 1 month ago

Hey @manuelpuyol, to clarify, Static Hermes is the next version of Hermes that improves performance and spec compliance, and is currently being developed on the static_h branch. Are you trying to link against that, or are you just trying to consume the current Hermes build on main as a static library?

manuelpuyol commented 1 month ago

hey @neildhar I was trying with the current main branch, but can try again with static_h though I see it's quite a bit behind main. My goal was to generate .a files instead of .so so I could embed hermes in the compiled binary and be able to run it in different machines without having to compile hermes in each one

neildhar commented 1 month ago

I see, unfortunately, the hermes build on main does not have the ability to distribute a standalone .a file, but you have a few other options:

  1. Build Hermes as a dynamic library and ship it with your executable. This is how Hermes is typically distributed in mobile apps, so it is the most easily supported.
  2. Add the Hermes build as a subdirectory in your larger CMake project, and take a direct dependency against the CMake target for libhermes. This should allow you to produce a statically linked executable (but it will not produce a standalone .a file)
  3. Build against static_h, where we have the hermesvm_a target that is a standalone static library. However, the static_h branch is under very active development, so the details will change over time. (but we intend to keep the ability to produce a standalone static library)
manuelpuyol commented 4 weeks ago

yeah that makes sense, thank you