Skip to content

Commit 4377684

Browse files
committed
[interop] Upgrade to latest, add tag file for diff workflow
1 parent a1f36bd commit 4377684

26 files changed

+834
-188
lines changed

Diff for: .github/workflows/cppinterop-diff.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@ jobs:
1212
uses: actions/checkout@v4
1313
with:
1414
path: root
15+
- name: Determine tag that CppInterOp in ROOT is based
16+
id: determine-tag
17+
run: |
18+
tag_file=root/interpreter/CppInterOp/cppinterop-version.tag
19+
echo "tag=$(cat $tag_file)" >> $GITHUB_OUTPUT
20+
rm $tag_file
1521
- name: Check out CppInterOp
1622
uses: actions/checkout@v4
1723
with:
1824
repository: compiler-research/CppInterOp
19-
ref: 33bfa391c9322bd7cb79f954e54eedef486c999a
25+
ref: ${{ steps.determine-tag.outputs.tag }}
2026
path: CppInterOp
2127
- name: Drop directories that are not added to ROOT
2228
working-directory: CppInterOp

Diff for: interpreter/CppInterOp/CMakeLists.txt

+3-15
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ endif()
246246
message(fatal "LLVM/CppInterOp requires c++14 or later")
247247
endif()
248248
endif()
249-
249+
250250
## Find supported Cling
251-
251+
252252
if (CPPINTEROP_USE_CLING)
253253
if (NOT Cling_FOUND AND DEFINED Cling_DIR)
254254
find_package(Cling REQUIRED CONFIG ${cling_extra_hints} NO_DEFAULT_PATH)
@@ -307,13 +307,6 @@ include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
307307
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
308308
add_definitions(${LLVM_DEFINITIONS_LIST})
309309

310-
if (CPPINTEROP_USE_CLING)
311-
message(STATUS "CLING_INCLUDE_DIRS: ${CLING_INCLUDE_DIRS}")
312-
endif(CPPINTEROP_USE_CLING)
313-
message(STATUS "CLANG_INCLUDE_DIRS: ${CLANG_INCLUDE_DIRS}")
314-
message(STATUS "LLVM_INCLUDE_DIRS: ${LLVM_INCLUDE_DIRS}")
315-
message(STATUS "LLVM_DEFINITIONS_LIST: ${LLVM_DEFINITIONS_LIST}")
316-
317310
# If the llvm sources are present add them with higher priority.
318311
if (LLVM_BUILD_MAIN_SRC_DIR)
319312
# LLVM_INCLUDE_DIRS contains the include paths to both LLVM's source and
@@ -361,7 +354,7 @@ endif()
361354

362355
# Add appropriate flags for GCC
363356
if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
364-
if (APPLE)
357+
if (APPLE OR EMSCRIPTEN)
365358
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -Wcast-qual -fno-strict-aliasing -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings")
366359
else()
367360
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -Wcast-qual -fno-strict-aliasing -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings")
@@ -451,11 +444,6 @@ option(CPPINTEROP_ENABLE_DOXYGEN "Use doxygen to generate CppInterOp interal API
451444
option(CPPINTEROP_ENABLE_SPHINX "Use sphinx to generage CppInterOp user documentation")
452445

453446

454-
if(EMSCRIPTEN)
455-
message("Build with emscripten")
456-
set(CPPINTEROP_ENABLE_TESTING OFF)
457-
endif()
458-
459447
if(MSVC)
460448

461449
set(MSVC_EXPORTLIST

Diff for: interpreter/CppInterOp/Emscripten-build-instructions.md

+13-10
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ git clone https://github.com/emscripten-core/emsdk.git
2525
./emsdk/emsdk install 3.1.73
2626
```
2727

28-
and activate the emsdk environment
28+
and activate the emsdk environment (we are defining SYSROOT_PATH for use later)
2929

3030
```bash
3131
./emsdk/emsdk activate 3.1.73
3232
source ./emsdk/emsdk_env.sh
33+
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
3334
```
3435

3536
Now clone the 19.x release of the LLVM project repository and CppInterOp (the building of the emscripten version of llvm can be
@@ -68,10 +69,13 @@ emcmake cmake -DCMAKE_BUILD_TYPE=Release \
6869
-DLLVM_INCLUDE_EXAMPLES=OFF \
6970
-DLLVM_INCLUDE_TESTS=OFF \
7071
-DLLVM_ENABLE_THREADS=OFF \
72+
-DLLVM_BUILD_TOOLS=OFF \
73+
-DLLVM_ENABLE_LIBPFM=OFF \
74+
-DCLANG_BUILD_TOOLS=OFF \
7175
../llvm
72-
emmake make clang -j $(nproc --all)
73-
emmake make clang-repl -j $(nproc --all)
74-
emmake make lld -j $(nproc --all)
76+
emmake make libclang -j $(nproc --all)
77+
emmake make clangInterpreter clangStaticAnalyzerCore -j $(nproc --all)
78+
emmake make lldWasm -j $(nproc --all)
7579
```
7680

7781
Once this finishes building we need to take note of where we built our llvm build. This can be done by executing the following
@@ -97,7 +101,7 @@ export CMAKE_PREFIX_PATH=$PREFIX
97101
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
98102
```
99103

100-
Now to build CppInterOp execute the following
104+
Now to build and test your Emscripten build of CppInterOp by executing the following
101105

102106
```bash
103107
mkdir build
@@ -109,14 +113,15 @@ emcmake cmake -DCMAKE_BUILD_TYPE=Release \
109113
-DBUILD_SHARED_LIBS=ON \
110114
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
111115
-DCMAKE_INSTALL_PREFIX=$PREFIX \
116+
-DSYSROOT_PATH=$SYSROOT_PATH \
112117
../
113-
emmake make -j $(nproc --all) install
118+
emmake make -j $(nproc --all) check-cppinterop
114119
```
115120

116-
Once this finishes building we need to take note of where we built CppInterOp. This can be done by executing the following
121+
Assuming it passes all test you can install by executing the following
117122

118123
```bash
119-
export CPPINTEROP_BUILD_DIR=$PWD
124+
emmake make -j $(nproc --all) install
120125
```
121126

122127
## Xeus-cpp-lite Wasm Build Instructions
@@ -126,7 +131,6 @@ the CppInterOp build folder, you can build the wasm version of xeus-cpp by execu
126131

127132
```bash
128133
cd ../..
129-
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
130134
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
131135
cd ./xeus-cpp
132136
mkdir build
@@ -137,7 +141,6 @@ emcmake cmake \
137141
-DCMAKE_INSTALL_PREFIX=$PREFIX \
138142
-DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON \
139143
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
140-
-DCppInterOp_DIR="$CPPINTEROP_BUILD_DIR/lib/cmake/CppInterOp" \
141144
-DSYSROOT_PATH=$SYSROOT_PATH \
142145
..
143146
emmake make -j $(nproc --all) install

Diff for: interpreter/CppInterOp/cmake/modules/GoogleTest.cmake

+13-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,20 @@ if(WIN32)
1313
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL:PATH=${_gtest_byproduct_binary_dir}/lib/
1414
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE:PATH=${_gtest_byproduct_binary_dir}/lib/
1515
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO:PATH=${_gtest_byproduct_binary_dir}/lib/
16-
-Dgtest_force_shared_crt=ON
17-
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config $<CONFIG>)
16+
-Dgtest_force_shared_crt=ON)
1817
elseif(APPLE)
1918
set(EXTRA_GTEST_OPTS -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT})
2019
endif()
2120

2221
include(ExternalProject)
22+
if (EMSCRIPTEN)
23+
set(config_cmd emcmake cmake)
24+
set(build_cmd emmake make)
25+
else()
26+
set(config_cmd ${CMAKE_COMMAND})
27+
set(build_cmd ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/unittests/googletest-prefix/src/googletest-build/ --config $<CONFIG>)
28+
endif()
29+
2330
ExternalProject_Add(
2431
googletest
2532
GIT_REPOSITORY https://github.com/google/googletest.git
@@ -31,7 +38,9 @@ ExternalProject_Add(
3138
# CMAKE_ARGS -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG:PATH=DebugLibs
3239
# -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE:PATH=ReleaseLibs
3340
# -Dgtest_force_shared_crt=ON
34-
CMAKE_ARGS -G ${CMAKE_GENERATOR}
41+
CONFIGURE_COMMAND ${config_cmd} -G ${CMAKE_GENERATOR}
42+
-S ${CMAKE_BINARY_DIR}/unittests/googletest-prefix/src/googletest/
43+
-B ${CMAKE_BINARY_DIR}/unittests/googletest-prefix/src/googletest-build/
3544
-DCMAKE_BUILD_TYPE=$<CONFIG>
3645
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
3746
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
@@ -40,6 +49,7 @@ ExternalProject_Add(
4049
-DCMAKE_AR=${CMAKE_AR}
4150
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
4251
${EXTRA_GTEST_OPTS}
52+
BUILD_COMMAND ${build_cmd}
4353
# Disable install step
4454
INSTALL_COMMAND ""
4555
BUILD_BYPRODUCTS ${_gtest_byproducts}

Diff for: interpreter/CppInterOp/cppinterop-version.tag

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
27847e4265dd7d1eecf1ce5471034cc2eb6ab7d2

Diff for: interpreter/CppInterOp/docs/Emscripten-build-instructions.rst

+13-11
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ This can be installed by executing (we only currently support version
3535
git clone https://github.com/emscripten-core/emsdk.git
3636
./emsdk/emsdk install 3.1.73
3737
38-
and activate the emsdk environment
38+
and activate the emsdk environment (we are defining SYSROOT_PATH for use later)
3939

4040
.. code:: bash
4141
4242
./emsdk/emsdk activate 3.1.73
4343
source ./emsdk/emsdk_env.sh
44+
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
4445
4546
Now clone the 19.x release of the LLVM project repository and CppInterOp
4647
(the building of the emscripten version of llvm can be avoided by
@@ -84,10 +85,13 @@ executing the following
8485
-DLLVM_INCLUDE_EXAMPLES=OFF \
8586
-DLLVM_INCLUDE_TESTS=OFF \
8687
-DLLVM_ENABLE_THREADS=OFF \
88+
-DLLVM_BUILD_TOOLS=OFF \
89+
-DLLVM_ENABLE_LIBPFM=OFF \
90+
-DCLANG_BUILD_TOOLS=OFF \
8791
../llvm
88-
emmake make clang -j $(nproc --all)
89-
emmake make clang-repl -j $(nproc --all)
90-
emmake make lld -j $(nproc --all)
92+
emmake make libclang -j $(nproc --all)
93+
emmake make clangInterpreter clangStaticAnalyzerCore -j $(nproc --all)
94+
emmake make lldWasm -j $(nproc --all)
9195
9296
Once this finishes building we need to take note of where we built our
9397
llvm build. This can be done by executing the following
@@ -115,7 +119,7 @@ You will also want to set a few environment variables
115119
export CMAKE_PREFIX_PATH=$PREFIX
116120
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
117121
118-
Now to build CppInterOp execute the following
122+
Now to build and test your Emscripten build of CppInterOp by executing the following
119123

120124
.. code:: bash
121125
@@ -128,15 +132,15 @@ Now to build CppInterOp execute the following
128132
-DBUILD_SHARED_LIBS=ON \
129133
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
130134
-DCMAKE_INSTALL_PREFIX=$PREFIX \
135+
-DSYSROOT_PATH=$SYSROOT_PATH \
131136
../
132-
emmake make -j $(nproc --all) install
137+
emmake make -j $(nproc --all) check-cppinterop
133138
134-
Once this finishes building we need to take note of where we built
135-
CppInterOp. This can be done by executing the following
139+
Assuming it passes all test you can install by executing the following.
136140

137141
.. code:: bash
138142
139-
export CPPINTEROP_BUILD_DIR=$PWD
143+
emmake make -j $(nproc --all) install
140144
141145
## Xeus-cpp-lite Wasm Build Instructions
142146

@@ -147,7 +151,6 @@ build folder, you can build the wasm version of xeus-cpp by executing
147151
.. code:: bash
148152
149153
cd ../..
150-
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
151154
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
152155
cd ./xeus-cpp
153156
mkdir build
@@ -158,7 +161,6 @@ build folder, you can build the wasm version of xeus-cpp by executing
158161
-DCMAKE_INSTALL_PREFIX=$PREFIX \
159162
-DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON \
160163
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
161-
-DCppInterOp_DIR="$CPPINTEROP_BUILD_DIR/lib/cmake/CppInterOp" \
162164
-DSYSROOT_PATH=$SYSROOT_PATH \
163165
..
164166
emmake make -j $(nproc --all) install

Diff for: interpreter/CppInterOp/environment-wasm.yml

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ dependencies:
88
- xeus
99
- cpp-argparse
1010
- pugixml
11+
- doctest

Diff for: interpreter/CppInterOp/include/clang/Interpreter/CppInterOp.h

+32-11
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,15 @@ namespace Cpp {
127127
: m_Kind(K), m_DestructorCall(C), m_FD(Dtor) {}
128128

129129
/// Checks if the passed arguments are valid for the given function.
130-
bool AreArgumentsValid(void* result, ArgList args, void* self) const;
130+
CPPINTEROP_API bool AreArgumentsValid(void* result, ArgList args,
131+
void* self) const;
131132

132133
/// This function is used for debugging, it reports when the function was
133134
/// called.
134-
void ReportInvokeStart(void* result, ArgList args, void* self) const;
135-
void ReportInvokeStart(void* object, unsigned long nary,
136-
int withFree) const;
135+
CPPINTEROP_API void ReportInvokeStart(void* result, ArgList args,
136+
void* self) const;
137+
CPPINTEROP_API void ReportInvokeStart(void* object, unsigned long nary,
138+
int withFree) const;
137139
void ReportInvokeEnd() const;
138140
public:
139141
Kind getKind() const { return m_Kind; }
@@ -313,8 +315,8 @@ namespace Cpp {
313315
/// underlying decl is not a class it returns the input unchanged.
314316
CPPINTEROP_API TCppScope_t GetUnderlyingScope(TCppScope_t scope);
315317

316-
/// Gets the namespace or class (by stripping typedefs) for the name
317-
/// passed as a parameter, and if the parent is not passed,
318+
/// Gets the namespace or class (by stripping typedefs) for the name
319+
/// passed as a parameter, and if the parent is not passed,
318320
/// then global scope will be assumed.
319321
CPPINTEROP_API TCppScope_t GetScope(const std::string& name,
320322
TCppScope_t parent = nullptr);
@@ -414,13 +416,27 @@ namespace Cpp {
414416
CPPINTEROP_API bool ExistsFunctionTemplate(const std::string& name,
415417
TCppScope_t parent = nullptr);
416418

419+
/// Sets a list of all the constructor for a scope/class that is
420+
/// supplied as a parameter.
421+
///\param[in] name - This string is used as a constraint, that clients can use
422+
/// to ensure the constructors match the name that they provide
423+
///\param[in] parent - Pointer to the scope/class for which the constructors
424+
/// are being looked up
425+
/// to be retrieved
426+
///\param[out] funcs - vector of handles to all constructors found under the
427+
/// given scope
428+
CPPINTEROP_API void LookupConstructors(const std::string& name,
429+
TCppScope_t parent,
430+
std::vector<TCppFunction_t>& funcs);
431+
417432
/// Sets a list of all the Templated Methods that are in the Class that is
418433
/// supplied as a parameter.
434+
///\returns true if the lookup succeeded, and false if there are no candidates
419435
///\param[in] name - method name
420436
///\param[in] parent - Pointer to the scope/class under which the methods have
421437
/// to be retrieved
422438
///\param[out] funcs - vector of function pointers matching the name
423-
CPPINTEROP_API void
439+
CPPINTEROP_API bool
424440
GetClassTemplatedMethods(const std::string& name, TCppScope_t parent,
425441
std::vector<TCppFunction_t>& funcs);
426442

@@ -563,12 +579,12 @@ namespace Cpp {
563579
TCppIndex_t param_index);
564580

565581
///\returns arity of the operator or kNone
566-
OperatorArity GetOperatorArity(TCppFunction_t op);
582+
CPPINTEROP_API OperatorArity GetOperatorArity(TCppFunction_t op);
567583

568584
///\returns list of operator overloads
569-
void GetOperator(TCppScope_t scope, Operator op,
570-
std::vector<TCppFunction_t>& operators,
571-
OperatorArity kind = kBoth);
585+
CPPINTEROP_API void GetOperator(TCppScope_t scope, Operator op,
586+
std::vector<TCppFunction_t>& operators,
587+
OperatorArity kind = kBoth);
572588

573589
/// Creates an instance of the interpreter we need for the various interop
574590
/// services.
@@ -783,6 +799,11 @@ namespace Cpp {
783799
unsigned complete_line = 1U,
784800
unsigned complete_column = 1U);
785801

802+
/// Reverts the last N operations performed by the interpreter.
803+
///\param[in] N The number of operations to undo. Defaults to 1.
804+
///\returns 0 on success, non-zero on failure.
805+
CPPINTEROP_API int Undo(unsigned N = 1);
806+
786807
} // end namespace Cpp
787808

788809
#endif // CPPINTEROP_CPPINTEROP_H

0 commit comments

Comments
 (0)