Skip to content
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

Enable CppInterOp #16814

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Enable CppInterOp #16814

wants to merge 5 commits into from

Conversation

aaronj0
Copy link
Contributor

@aaronj0 aaronj0 commented Nov 4, 2024

CppInterOp exposes API from Clang and LLVM in a mostly backward compatibe way. The API support downstream tools that utilize interactive C++ by using the compiler as a service.

This PR is the first step in using pure clang based reflection API in meta, and part of eventually integrating the JITCall and DynamicLibraryManager infrastructure.

Adopting more of CppInterOp in ROOT will help simplify the LLVM migration process and allow us to upstream more patches to either CppInterOp or LLVM.

TODO:

  • Add github workflow to diffcheck upstream
  • Improve CMake config
  • Propoagate LLVM_BUILD_TYPE instead of ROOT's config to InterOp's build type

@aaronj0 aaronj0 changed the title Enable interop Enable CppInterOp Nov 4, 2024
@aaronj0 aaronj0 marked this pull request as draft November 4, 2024 14:58
Copy link

github-actions bot commented Nov 4, 2024

Test Results

    18 files      18 suites   3d 22h 13m 24s ⏱️
 2 692 tests  2 692 ✅ 0 💤 0 ❌
46 760 runs  46 760 ✅ 0 💤 0 ❌

Results for commit 34a36e5.

♻️ This comment has been updated with latest results.

Copy link
Member

@hahnjo hahnjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The direction looks good to me! In addition to the test failures that need fixing, some comments inline for consideration

core/metacling/src/CMakeLists.txt Outdated Show resolved Hide resolved
Comment on lines 609 to 611
set(LLVM_DIR "${CMAKE_BINARY_DIR}/interpreter/llvm-project/llvm/lib/cmake/llvm")
set(Clang_DIR "${CMAKE_BINARY_DIR}/interpreter/llvm-project/llvm/tools/clang/lib/cmake/clang")
set(Cling_DIR "${CMAKE_BINARY_DIR}/interpreter/cling")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need adapting for externally built LLVM, Clang, and / or Cling. For LLVM and Clang, I believe this should already be taken care of above, no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment still applies, even if the code was moved: variables related to this are already set above (and will change with #17354)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I will look into improving this config for externally built llvm and cling, and test if the existing variables work

@@ -0,0 +1,372 @@
<div align="center">

# CppInterOp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, we probably want a similar workflow as .github/workflows/llvm-diff.yml to make sure our copies are not diverging

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still strongly recommend implement this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The workflow has been added

core/metacling/src/TClingCallFunc.cxx Outdated Show resolved Hide resolved
@guitargeek guitargeek added the clean build Ask CI to do non-incremental build on PR label Dec 2, 2024
@aaronj0 aaronj0 force-pushed the enable-interop branch 2 times, most recently from ef871f9 to 86246a7 Compare December 2, 2024 10:46
@aaronj0 aaronj0 removed the clean build Ask CI to do non-incremental build on PR label Dec 3, 2024
@aaronj0 aaronj0 force-pushed the enable-interop branch 2 times, most recently from 196c4ff to 9977082 Compare December 3, 2024 14:43
@vgvassilev vgvassilev mentioned this pull request Dec 3, 2024
@aaronj0 aaronj0 force-pushed the enable-interop branch 3 times, most recently from ab52fd8 to 540c6fc Compare December 9, 2024 10:49
@aaronj0 aaronj0 force-pushed the enable-interop branch 2 times, most recently from 6f2ac11 to 7e53b7b Compare January 9, 2025 18:50
@aaronj0 aaronj0 marked this pull request as ready for review January 18, 2025 17:38
Comment on lines 607 to 608
set(USE_CLING ON CACHE BOOL "Use Cling as backend" FORCE)
set(USE_REPL OFF CACHE BOOL "Use Clang-repl as backend" FORCE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhm, can CppInterOp be changed to scope its configuration options? Setting this as a global CACHE variable is not great.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! We can get away by just setting USE_CLING ON

Comment on lines +871 to +874

#ifdef _WIN32
GTEST_SKIP() << "Disabled on Windows (Fails with ROOT win-x64)";
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this done upstream in CppInterOp? We should not start by immediately diverging

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aaronj0, do you remember how this used to fail?

Comment on lines 126 to 130
#ifdef LLVM_BINARY_DIR
TEST(InterpreterTest, DetectResourceDir) {
#else

TEST(InterpreterTest, DISABLED_DetectResourceDir) {
#endif // LLVM_BINARY_DIR
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this done upstream in CppInterOp? We should not start by immediately diverging

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is only required when shipping CppInterOp externally and doesn't work with ROOT since llvm is not externally built, which is why we opted to disable and track this as a patch to the tests..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I think the binary dir is set but it is not what we expect it to be. I think that's part of the problem that LLVM's build system was not designed to be embedded in another build system...

@aaronj0 aaronj0 force-pushed the enable-interop branch 7 times, most recently from be05b00 to ffb1ec6 Compare January 29, 2025 14:05
@aaronj0 aaronj0 requested a review from hahnjo January 30, 2025 09:49
run: |
rm -rf .github
- name: Compare
continue-on-error: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I was already wondering: With this line you just ignore the error and continue even if the two copies have a difference. That renders the check useless...

Copy link
Contributor Author

@aaronj0 aaronj0 Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I will drop the continue-on-error setting. I will note that we may have to keep a patch disabling a unittest, assuming the other failing test on Windows is fixed and no longer disabled

Copy link
Member

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This practically looks good to me...

Comment on lines 126 to 130
#ifdef LLVM_BINARY_DIR
TEST(InterpreterTest, DetectResourceDir) {
#else

TEST(InterpreterTest, DISABLED_DetectResourceDir) {
#endif // LLVM_BINARY_DIR
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I think the binary dir is set but it is not what we expect it to be. I think that's part of the problem that LLVM's build system was not designed to be embedded in another build system...

Comment on lines +871 to +874

#ifdef _WIN32
GTEST_SKIP() << "Disabled on Windows (Fails with ROOT win-x64)";
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aaronj0, do you remember how this used to fail?

@bellenot
Copy link
Member

@vgvassilev about your question, here is the error:

1: [ RUN      ] FunctionReflectionTest.GetFunctionCallWrapper
1: C:\root-dev\github\enable-interop\interpreter\CppInterOp\unittests\CppInterOp\FunctionReflectionTest.cpp(919): error: Expected equality of these values:
1:   output
1:     Which is: ""
1:   s
1:     Which is: "Hello World!\n"
1: C:\root-dev\github\enable-interop\interpreter\CppInterOp\unittests\CppInterOp\FunctionReflectionTest.cpp(944): error: Expected equality of these values:
1:   output
1:     Which is: ""
1:   "Default Ctor Called\n"
1: C:\root-dev\github\enable-interop\interpreter\CppInterOp\unittests\CppInterOp\FunctionReflectionTest.cpp(953): error: Expected equality of these values:
1:   output
1:     Which is: ""
1:   "Dtor Called\n"
1: [  FAILED  ] FunctionReflectionTest.GetFunctionCallWrapper (428 ms)

@vgvassilev
Copy link
Member

@vgvassilev about your question, here is the error:

1: [ RUN      ] FunctionReflectionTest.GetFunctionCallWrapper
1: C:\root-dev\github\enable-interop\interpreter\CppInterOp\unittests\CppInterOp\FunctionReflectionTest.cpp(919): error: Expected equality of these values:
1:   output
1:     Which is: ""
1:   s
1:     Which is: "Hello World!\n"
1: C:\root-dev\github\enable-interop\interpreter\CppInterOp\unittests\CppInterOp\FunctionReflectionTest.cpp(944): error: Expected equality of these values:
1:   output
1:     Which is: ""
1:   "Default Ctor Called\n"
1: C:\root-dev\github\enable-interop\interpreter\CppInterOp\unittests\CppInterOp\FunctionReflectionTest.cpp(953): error: Expected equality of these values:
1:   output
1:     Which is: ""
1:   "Dtor Called\n"
1: [  FAILED  ] FunctionReflectionTest.GetFunctionCallWrapper (428 ms)

Any chance to debug this? Maybe it is the way we capture streams? I doubt this is as broken to not run the constructors on windows…

@bellenot
Copy link
Member

bellenot commented Jan 30, 2025

Any chance to debug this? Maybe it is the way we capture streams? I doubt this is as broken to not run the constructors on windows…

Sure! I can try to take a look when I find some time for it

@vgvassilev
Copy link
Member

Any chance to debug this? Maybe it is the way we capture streams? I doubt this is as broken to not run the constructors on windows…

Sure! I can try to take a look when I find some time for it

In this case let's leave this pending and move forward with the PR.

@aaronj0 aaronj0 force-pushed the enable-interop branch 2 times, most recently from 2a58aa5 to 4ee500d Compare February 5, 2025 08:02
@aaronj0 aaronj0 force-pushed the enable-interop branch 2 times, most recently from cd575d7 to 34a36e5 Compare February 5, 2025 08:20
by linking clangCppInterOp in libCling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants