Build libbinaryen as a monolithic statically/shared library#2463
Build libbinaryen as a monolithic statically/shared library#2463kripken merged 2 commits intoWebAssembly:masterfrom ImmanuelHaffner:libbinaryen
Conversation
libraries to CMake object libraries.
According to CMake documentation: "Libraries and targets following PRIVATE are linked to, but are not made part of the link interface." This is exactly what we want, as we only want the C API to be part of the interface.
|
Thanks @ImmanuelHaffner ! This is beyond my understanding of CMake, so hopefully someone more knowledgeable can review. However, given this works for you, and passes CI here, it looks good to me. Except for one issue - making those PRIVATE means that only the binaryen C API is exported, if I understand correctly. That means libbinaryen is no longer useful for projects that want to use the internal C++ API surface. I'm not sure if we have such users or not. |
|
I'm no CMake expert, but this looks just fine to me as well. If we do have users of our C++ interface, they are almost certainly C++ projects themselves, in which case they can just add Binaryen to their build. So making the C++ API private sounds good to me. It doesn't have any stability guarantees anyway. |
|
Sounds good, merging! |
|
This seems to hit a problem on the mac build bot, which runs after merging, That does look like a cmake-related error, so it looks like a regression from this? @ImmanuelHaffner We can revert this, and investigate, if there isn't an obvious quick fix here. |
|
There may be a quick fix. The official Cmake Syntax for linking object libraries is described as: "Instead other targets created by add_library() or add_executable() may reference the objects using an expression of the form $<TARGET_OBJECTS:objlib> as a source, where objlib is the object library name." |
|
There is progress in #2472, but as we don't have a fix yet, reverting for now while we continue the investigation. |
This PR addressess issue #2450
So far, the CMake configuration did not produce a standalone statically linked or shared library of libbinaryen. The command
TARGET_LINK_LIBRARIES(binaryen passes wasm asmjs emscripten-optimizer ir cfg support)that was intended to provide this library actually just told CMake that every target, to which the library
binaryenis linked, the other libraries (passes,wasm, ...) must also be linked. This works fine if you include this repository with CMakeadd_subdirectorybut fails to provide a standalone library that can be used by third-parties.This PR solves this problem by constructing the libraries of the subdirectories (
passes,wasm, ...) asOBJECTlibraries. From the CMake documentation: "An object library compiles source files but does not archive or link their object files into a library. Instead other targets created by add_library() or add_executable() may reference the objects [...]".This modification prevents the archiving/linking of the object files of subdirectories and enables linking
binaryenas a standalone library. (One important observation here, that was totally not obvious for me, is that CMake simply does not link multiple static libraries into a single static library, for portability reasons IIRC. See this informative answer on the CMake mailing list: https://cmake.org/pipermail/cmake/2018-September/068263.html )Further, declare the libraries as
PRIVATEly linked tobinaryen, because we do not want their symbols to leak through the statically linked or shared library. CMake documentation says: "Libraries and targets following PRIVATE are linked to, but are not made part of the link interface."