Skip to content

[Bug]: Debug flags responsible for CppInterOp's emscripten build #419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
anutosh491 opened this issue Jan 8, 2025 · 3 comments
Open
Labels
bug Something isn't working stale

Comments

@anutosh491
Copy link
Collaborator

anutosh491 commented Jan 8, 2025

Description of bug

Currently this is how CppInterOp's emscripten build is conducted.

  set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
  set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-s SIDE_MODULE=1")
  set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-s SIDE_MODULE=1")
  set(CMAKE_STRIP FALSE)

  add_llvm_library(clangCppInterOp
    SHARED

    CppInterOp.cpp
    CXCppInterOp.cpp
    DynamicLibraryManager.cpp
    DynamicLibraryManagerSymbol.cpp
    Paths.cpp

    # Additional libraries from Clang and LLD
    LINK_LIBS
    clangInterpreter
  )

The first 4 lines are necessary to build SHARED objects through cmake using emscripten. Check comment (emscripten-core/emscripten#15276 (comment)). This is followed by add_llvm_library (more like a wrapper over add_library and target_link_libraries). We could even do something as simple as

  add_library(clangCppInterOp SHARED
    CppInterOp.cpp
    CXCppInterOp.cpp
    DynamicLibraryManager.cpp
    DynamicLibraryManagerSymbol.cpp
    Paths.cpp
  )

  target_link_libraries(clangCppInterOp clangInterpreter)

What operating system was you using when the bug occured?

MacOS

What is the architechture of the cpu on your system?

ARM

What did you build CppInterOp against?

Clang-repl (LLVM19)

@anutosh491 anutosh491 added the bug Something isn't working label Jan 8, 2025
@anutosh491
Copy link
Collaborator Author

anutosh491 commented Jan 8, 2025

But the link.txt generated during the build process is somewhat weird (lot of things might be unwanted )

/Users/anutosh491/work/emsdk/upstream/emscripten/em++ -fPIC -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -Wcast-qual -fno-strict-aliasing -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings -O3 -DNDEBUG -Wl,-z,defs -s SIDE_MODULE=1 -Wl,-soname,libclangCppInterOp.so -o ../libclangCppInterOp.so @CMakeFiles/clangCppInterOp.dir/objects1.rsp @CMakeFiles/clangCppInterOp.dir/linkLibs.rsp

  1. Not sure what adds the two -fPIC flags to begin with
  2. Long list of warning related flags. Do we want everything ?
-Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough  -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -Wcast-qual
  1. -Wl,-z,defs and -Wl,-soname

I don't think these are even recognized by Emscripten and Webassembly

I see these warnings at the end while building cppinterop

(xeus-cpp-wasm-build) anutosh491@Anutoshs-MacBook-Air build2 % emmake make -j1
make: make -j1
[ 16%] Linking CXX shared library ../libclangCppInterOp.so
em++: warning: ignoring unsupported linker flag: `-soname` [-Wlinkflags]
wasm-ld: warning: unknown -z value: defs
  1. I see -Wl,-soname,libclangCppInterOp.so.19.1 -o ../libclangCppInterOp.so.19.1

Why do we need to generate libclangCppInterOp.so.19.1 along with libclangCppInterOp.so ? I guess only l ibclangCppInterOp.so would suffice.

Rest things mostly look fine but I am not sure what is responsible for these flags being added. Do they come out of Emscripten's toolchain or cmake .... I am not yet sure !

@anutosh491
Copy link
Collaborator Author

Okay I see when we switch to a combination of add_library + target_link_libraries (instead of add_llvm_library) as raised in the issue description, we stop producing the libclangCppInterOp.so.19.1 and only produce libclangCppInterOp.so.

Copy link
Contributor

github-actions bot commented Apr 9, 2025

This issue is stale because it has been open for 90 days with no activity.

@github-actions github-actions bot added the stale label Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale
Projects
None yet
Development

No branches or pull requests

1 participant