Skip to content

Commit a3af2c3

Browse files
committed
Use a Shared build for cppinterop while building for wasm
1 parent e84d4aa commit a3af2c3

File tree

2 files changed

+115
-95
lines changed

2 files changed

+115
-95
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ jobs:
12811281
-DCMAKE_PREFIX_PATH=$PREFIX \
12821282
-DLLVM_DIR=$LLVM_BUILD_DIR/lib/cmake/llvm \
12831283
-DClang_DIR=$LLVM_BUILD_DIR/lib/cmake/clang \
1284-
-DBUILD_SHARED_LIBS=OFF \
1284+
-DBUILD_SHARED_LIBS=ON \
12851285
-DCODE_COVERAGE=${{ env.CODE_COVERAGE }} \
12861286
-DCMAKE_INSTALL_PREFIX=$PREFIX \
12871287
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \

lib/Interpreter/CMakeLists.txt

+114-94
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,126 @@
1-
set(LLVM_LINK_COMPONENTS
2-
${LLVM_TARGETS_TO_BUILD}
3-
BinaryFormat
4-
Core
5-
Object
6-
OrcJit
7-
Support
8-
)
9-
# FIXME: Investigate why this needs to be conditionally included.
10-
if ("LLVMFrontendDriver" IN_LIST LLVM_AVAILABLE_LIBS)
11-
list(APPEND LLVM_LINK_COMPONENTS FrontendDriver)
12-
endif()
13-
if ("LLVMOrcDebugging" IN_LIST LLVM_AVAILABLE_LIBS)
14-
list(APPEND LLVM_LINK_COMPONENTS OrcDebugging)
15-
endif()
1+
if(EMSCRIPTEN)
2+
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
3+
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-s SIDE_MODULE=1")
4+
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-s SIDE_MODULE=1")
5+
set(CMAKE_STRIP FALSE)
166

17-
set(DLM
18-
DynamicLibraryManager.cpp
19-
DynamicLibraryManagerSymbol.cpp
20-
Paths.cpp
21-
)
22-
if (USE_CLING)
23-
set(LLVM_OPTIONAL_SOURCES ${LLVM_OPTIONAL_SOURCES} ${DLM})
24-
set(DLM)
25-
endif(USE_CLING)
26-
if (USE_REPL)
27-
#Use DML optional sources
28-
endif(USE_REPL)
7+
add_llvm_library(clangCppInterOp
8+
SHARED
299

30-
if (USE_CLING)
31-
set(cling_clang_interp clingInterpreter)
32-
endif()
33-
if (USE_REPL)
34-
set(cling_clang_interp clangInterpreter)
35-
endif()
10+
CppInterOp.cpp
11+
DynamicLibraryManager.cpp
12+
DynamicLibraryManagerSymbol.cpp
13+
Paths.cpp
3614

37-
set(link_libs
38-
${cling_clang_interp}
39-
clangAST
40-
clangBasic
41-
clangFrontend
42-
clangLex
43-
clangSema
15+
# Additional libraries from Clang and LLD
16+
LINK_LIBS
17+
clangInterpreter
18+
)
19+
else()
20+
set(LLVM_LINK_COMPONENTS
21+
${LLVM_TARGETS_TO_BUILD}
22+
BinaryFormat
23+
Core
24+
Object
25+
OrcJit
26+
Support
4427
)
28+
# FIXME: Investigate why this needs to be conditionally included.
29+
if ("LLVMFrontendDriver" IN_LIST LLVM_AVAILABLE_LIBS)
30+
list(APPEND LLVM_LINK_COMPONENTS FrontendDriver)
31+
endif()
32+
if ("LLVMOrcDebugging" IN_LIST LLVM_AVAILABLE_LIBS)
33+
list(APPEND LLVM_LINK_COMPONENTS OrcDebugging)
34+
endif()
4535

46-
if(NOT WIN32)
47-
list(APPEND link_libs dl)
48-
endif()
36+
set(DLM
37+
DynamicLibraryManager.cpp
38+
DynamicLibraryManagerSymbol.cpp
39+
Paths.cpp
40+
)
41+
if (USE_CLING)
42+
set(LLVM_OPTIONAL_SOURCES ${LLVM_OPTIONAL_SOURCES} ${DLM})
43+
set(DLM)
44+
endif(USE_CLING)
45+
if (USE_REPL)
46+
#Use DML optional sources
47+
endif(USE_REPL)
4948

50-
# Get rid of libLLVM-X.so which is appended to the list of static libraries.
51-
if (LLVM_LINK_LLVM_DYLIB)
52-
set(new_libs ${link_libs})
53-
set(libs ${new_libs})
54-
while(NOT "${new_libs}" STREQUAL "")
55-
foreach(lib ${new_libs})
56-
if(TARGET ${lib})
57-
get_target_property(transitive_libs ${lib} INTERFACE_LINK_LIBRARIES)
58-
if (NOT transitive_libs)
59-
continue()
60-
endif()
61-
foreach(transitive_lib ${transitive_libs})
62-
get_target_property(lib_type ${transitive_lib} TYPE)
63-
if("${lib_type}" STREQUAL "STATIC_LIBRARY")
64-
list(APPEND static_transitive_libs ${transitive_lib})
65-
else()
66-
# Filter our libLLVM.so and friends.
49+
if (USE_CLING)
50+
set(cling_clang_interp clingInterpreter)
51+
endif()
52+
if (USE_REPL)
53+
set(cling_clang_interp clangInterpreter)
54+
endif()
55+
56+
set(link_libs
57+
${cling_clang_interp}
58+
clangAST
59+
clangBasic
60+
clangFrontend
61+
clangLex
62+
clangSema
63+
)
64+
65+
if(NOT WIN32)
66+
list(APPEND link_libs dl)
67+
endif()
68+
69+
# Get rid of libLLVM-X.so which is appended to the list of static libraries.
70+
if (LLVM_LINK_LLVM_DYLIB)
71+
set(new_libs ${link_libs})
72+
set(libs ${new_libs})
73+
while(NOT "${new_libs}" STREQUAL "")
74+
foreach(lib ${new_libs})
75+
if(TARGET ${lib})
76+
get_target_property(transitive_libs ${lib} INTERFACE_LINK_LIBRARIES)
77+
if (NOT transitive_libs)
6778
continue()
6879
endif()
69-
if(NOT ${transitive_lib} IN_LIST libs)
70-
list(APPEND newer_libs ${transitive_lib})
71-
list(APPEND libs ${transitive_lib})
72-
endif()
73-
endforeach(transitive_lib)
74-
# Update the target properties with the list of only static libraries.
75-
set_target_properties(${lib} PROPERTIES INTERFACE_LINK_LIBRARIES "${static_transitive_libs}")
76-
set(static_transitive_libs "")
77-
endif()
78-
endforeach(lib)
79-
set(new_libs ${newer_libs})
80-
set(newer_libs "")
81-
endwhile()
82-
# We just got rid of the libLLVM.so and other components shipped as shared
83-
# libraries, we need to make up for the missing dependency.
84-
list(APPEND LLVM_LINK_COMPONENTS
85-
Coverage
86-
FrontendHLSL
87-
LTO
88-
)
89-
# We will need to append the missing dependencies to pull in the right
90-
# LLVM library dependencies.
91-
list(APPEND link_libs
92-
clangCodeGen
93-
clangStaticAnalyzerCore
94-
)
95-
endif(LLVM_LINK_LLVM_DYLIB)
80+
foreach(transitive_lib ${transitive_libs})
81+
get_target_property(lib_type ${transitive_lib} TYPE)
82+
if("${lib_type}" STREQUAL "STATIC_LIBRARY")
83+
list(APPEND static_transitive_libs ${transitive_lib})
84+
else()
85+
# Filter our libLLVM.so and friends.
86+
continue()
87+
endif()
88+
if(NOT ${transitive_lib} IN_LIST libs)
89+
list(APPEND newer_libs ${transitive_lib})
90+
list(APPEND libs ${transitive_lib})
91+
endif()
92+
endforeach(transitive_lib)
93+
# Update the target properties with the list of only static libraries.
94+
set_target_properties(${lib} PROPERTIES INTERFACE_LINK_LIBRARIES "${static_transitive_libs}")
95+
set(static_transitive_libs "")
96+
endif()
97+
endforeach(lib)
98+
set(new_libs ${newer_libs})
99+
set(newer_libs "")
100+
endwhile()
101+
# We just got rid of the libLLVM.so and other components shipped as shared
102+
# libraries, we need to make up for the missing dependency.
103+
list(APPEND LLVM_LINK_COMPONENTS
104+
Coverage
105+
FrontendHLSL
106+
LTO
107+
)
108+
# We will need to append the missing dependencies to pull in the right
109+
# LLVM library dependencies.
110+
list(APPEND link_libs
111+
clangCodeGen
112+
clangStaticAnalyzerCore
113+
)
114+
endif(LLVM_LINK_LLVM_DYLIB)
96115

97-
add_llvm_library(clangCppInterOp
98-
DISABLE_LLVM_LINK_LLVM_DYLIB
99-
CppInterOp.cpp
100-
${DLM}
101-
LINK_LIBS
102-
${link_libs}
103-
)
116+
add_llvm_library(clangCppInterOp
117+
DISABLE_LLVM_LINK_LLVM_DYLIB
118+
CppInterOp.cpp
119+
${DLM}
120+
LINK_LIBS
121+
${link_libs}
122+
)
123+
endif()
104124

105125
string(REPLACE ";" "\;" _VER CPPINTEROP_VERSION)
106126
set_source_files_properties(CppInterOp.cpp PROPERTIES COMPILE_DEFINITIONS

0 commit comments

Comments
 (0)