[SpiderMonkey] exposing internal APIs when embedding into a C++ project?

I am trying to create a debug build of SpiderMonkey and load it as a library in a different C++ project while exposing internal APIs like the BytecodeEmitter, etc.

I tried updating the moz.build files:

EXPORTS.frontend += [
  "frontend/AbstractScopePtr.h",
  "frontend/AsyncEmitter.h",
  "frontend/BytecodeCompiler.h",
  "frontend/BytecodeControlStructures.h",
  "frontend/BytecodeEmitter.h",
...

After the build I tried to load up the project

include_directories(
    ${SPIDERMONKEY_OBJ_DIR}/dist/include
)
...
target_link_libraries(metal_monkey PRIVATE
    ${ICU_LIBRARIES}
    /home/mm/wd/mozilla-unified/obj-debug-x86_64-pc-linux-gnu/js/src/build/libjs_static.a
    z
    dl
    pthread
    stdc++
)

But the build fails with a bunch of linker errors

[100%] Linking CXX executable mmm
/usr/bin/ld: /home/mm/wd/mozilla-unified/obj-debug-x86_64-pc-linux-gnu/js/src/build/libjs_static.a(Unified_cpp_js_src18.o): in function `mozilla::Array<js::GlobalObjectData::ConstructorWithProto, 95ul>::operator[](unsigned long) const':
/home/mm/wd/mozilla-unified/obj-debug-x86_64-pc-linux-gnu/dist/include/mozilla/Array.h:51: undefined reference to `mozilla::detail::InvalidArrayIndex_CRASH(unsigned long, unsigned long)'
/usr/bin/ld: /home/mm/wd/mozilla-unified/obj-debug-x86_64-pc-linux-gnu/dist/include/mozilla/Array.h:51: undefined reference to `mozilla::detail::InvalidArrayIndex_CRASH(unsigned long, unsigned long)'
/usr/bin/ld: /home/mm/wd/mozilla-unified/obj-debug-x86_64-pc-linux-gnu/dist/include/mozilla/Array.h:51: undefined reference to `mozilla::detail::InvalidArrayIndex_CRASH(unsigned long, unsigned long)'
/usr/bin/ld: /home/mm/wd/mozilla-unified/obj-debug-x86_64-pc-linux-gnu/dist/include/mozilla/Array.h:51: undefined reference to `mozilla::detail::InvalidArrayIndex_CRASH(unsigned long, unsigned long)'
/usr/bin/ld: /home/mm/wd/mozilla-unified/obj-debug-x86_64-pc-linux-gnu/dist/include/mozilla/Array.h:51: undefined reference to `mozilla::detail::InvalidArrayIndex_CRASH(unsigned long, unsigned long)'
/usr/bin/ld: /home/mm/wd/mozilla-unified/obj-debug-x86_64-pc-linux-gnu/js/src/build/libjs_static.a(Unified_cpp_js_src18.o): in function `mozilla::IsUtf8(mozilla::Span<char const, 18446744073709551615ul>)':
...

I know this is not the intended mode of operation but I wanted to experiment a bit with SpiderMonkey without directly modifying the source code, any help is appreciated :slight_smile:

I am a beginner to the project so I apologize for dumb questions :slightly_frowning_face:

Symbols are hidden by default. You would need to add JS_PUBLIC_API to everything you’re using, and perhaps some JS_PUBLIC_DATA. That’s probably pretty annoying for experimentation, so you might want to try hacking in a -fvisibility=default flag somewhere, or sticking #pragma GCC visibility push(default) into a header like jstypes.h or js-config.h. (There may be problems with that approach.)

For further information, you may need to post your metal_monkey logo for us to examine, because that sounds like it would look pretty cool.

Hey Steve, thanks for the reply. Exposing the functions using JS_PUBLIC_API worked :confetti_ball:. Sadly we dont have a logo for metal monkey (yet) :see_no_evil_monkey: With metal monkey we are looking into experimenting with static analysis of JS code with SpiderMonkey bytecode as the backend.