-
Notifications
You must be signed in to change notification settings - Fork 62
Add self-containment link probe for CppInterOpTypes.h. #1075
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
vgvassilev
wants to merge
1
commit into
compiler-research:main
Choose a base branch
from
vgvassilev:cppinterop-types-test-infra
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
42 changes: 42 additions & 0 deletions
42
unittests/CppInterOp/TypesSelfContainedTest/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Regression guard for CppInterOpTypes.h staying header-only. This | ||
| # executable includes only CppInterOpTypes.h, exercises every helper, | ||
| # and DELIBERATELY does not link libclangCppInterOp or any LLVM library | ||
| # — if any header helper needs an out-of-line symbol, the link fails. | ||
| # See TypesSelfContainedTest.cpp for the full rationale. | ||
| # | ||
| # Not a runtime test — the built binary is not invoked. Success is | ||
| # purely that the link stage completes; ctest just runs it to confirm | ||
| # the process starts. | ||
|
|
||
| add_executable(CppInterOpTypesSelfContainedTest EXCLUDE_FROM_ALL | ||
| TypesSelfContainedTest.cpp) | ||
|
|
||
| # The one and only include CppInterOpTypes.h needs is its own header | ||
| # directory. NOTHING from libclangCppInterOp or LLVM. | ||
| target_include_directories(CppInterOpTypesSelfContainedTest PRIVATE | ||
| ${CMAKE_SOURCE_DIR}/include) | ||
|
|
||
| # Match the Release-ish flags real Dispatch consumers see so any | ||
| # NDEBUG-guarded regressions surface here too. | ||
| target_compile_definitions(CppInterOpTypesSelfContainedTest PRIVATE NDEBUG) | ||
|
|
||
| # Route the executable to the same bin dir the other cppinterop | ||
| # unittests land in, so ctest's default search path finds it. Follow | ||
| # the pattern from add_cppinterop_unittest (see unittests/CMakeLists.txt). | ||
| set_output_directory(CppInterOpTypesSelfContainedTest | ||
| BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/../bin/$<CONFIG>/ | ||
| LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/../bin/$<CONFIG>/ | ||
| ) | ||
|
|
||
| # Register with ctest — the invocation just checks the process | ||
| # launches; the load-bearing signal is that the link succeeded at | ||
| # build time. | ||
| add_test(NAME cppinterop-CppInterOpTypesSelfContainedTest | ||
| COMMAND CppInterOpTypesSelfContainedTest) | ||
|
|
||
| # Ensure the target is built as part of CppInterOpUnitTests (parallel | ||
| # to how add_cppinterop_unittest chains dependencies). | ||
| add_dependencies(CppInterOpUnitTests CppInterOpTypesSelfContainedTest) | ||
|
|
||
| set_target_properties(CppInterOpTypesSelfContainedTest PROPERTIES | ||
| FOLDER "Tests") |
67 changes: 67 additions & 0 deletions
67
unittests/CppInterOp/TypesSelfContainedTest/TypesSelfContainedTest.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| // Regression guard: CppInterOpTypes.h must stay a fully self-contained | ||
| // header — every helper's implementation lives either inline in the | ||
| // header or in a plain-libc-shaped body. If a future contributor adds | ||
| // a helper backed by an out-of-line .cpp definition in | ||
| // libclangCppInterOp, this translation unit will fail to LINK | ||
| // (undefined symbol at ld time) because the executable deliberately | ||
| // does not link against libclangCppInterOp. | ||
| // | ||
| // Consumers reaching the CppInterOp API through Dispatch.h | ||
| // (cppyy-backend, xeus-cpp) do not link against libclangCppInterOp — | ||
| // they dlopen it lazily via LoadDispatchAPI. A CppInterOpTypes.h that | ||
| // referenced an out-of-line symbol from libclangCppInterOp would | ||
| // either force those consumers into a DT_NEEDED against the full | ||
| // library (the exact class of hazard we hit with | ||
| // Cpp::ResultAbort_UncheckedOnDtor) or require routing the helper | ||
| // through the dispatch table. | ||
| // | ||
| // This binary is not run — it's a compile-and-link probe. Success == | ||
| // build succeeded. Failure looks like: | ||
| // undefined reference to `some_new_helper_that_snuck_in' | ||
| // | ||
| // If you land such a symbol here, either (a) make it a static inline | ||
| // in the header, (b) route it through the dispatch table, or (c) split | ||
| // the ABI-helper prelude into a truly no-op runtime archive that | ||
| // downstream Dispatch consumers can link cheaply. | ||
| // | ||
| // Follow-up commits extend the probe body as new helpers land in | ||
| // CppInterOpTypes.h. Today only the pre-existing types are exercised: | ||
| // the opaque handles, TemplateArgInfo, and the CppInterOp{Array, | ||
| // StringArray} PODs. | ||
|
|
||
| #include "CppInterOp/CppInterOpTypes.h" | ||
|
|
||
| #include <cstddef> | ||
|
|
||
| // Force ODR-use of every currently-provided CppInterOpTypes.h helper | ||
| // so the linker resolves each one. If any helper picks up an | ||
| // out-of-line dependency, this function fails to link. | ||
| extern "C" int cppinterop_types_self_contained_probe(int seed) { | ||
| // Handle types (Cpp::DeclRef etc.) — POD trivially copyable; a | ||
| // default-constructed handle compares equal to nullptr and yields | ||
| // false in a bool context. All inline, no external symbols. | ||
| Cpp::DeclRef d; | ||
| if (d) | ||
| return -1; | ||
|
|
||
| // TemplateArgInfo — standard-layout POD with a #ifdef __cplusplus | ||
| // constructor. Instantiation touches the ctor without pulling any | ||
| // implementation symbol. | ||
| Cpp::TemplateArgInfo tai(nullptr); | ||
| (void)tai; | ||
|
|
||
| // Array/StringArray helpers — pure PODs. No methods, no ctors that | ||
| // reach out-of-line code. | ||
| Cpp::CppInterOpArray arr = {nullptr, 0}; | ||
| Cpp::CppInterOpStringArray sarr = {nullptr, 0}; | ||
| return static_cast<int>(seed + arr.size + sarr.size); | ||
| } | ||
|
|
||
| int main(int argc, char** /*argv*/) { | ||
| // Volatile / argc mixing keeps the compiler from optimizing the probe | ||
| // call away in a Release build. The returned value is uninteresting; | ||
| // the load-bearing signal is that the link succeeded. | ||
| volatile int r = cppinterop_types_self_contained_probe(argc); | ||
| (void)r; | ||
| return 0; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: included header cstddef is not used directly [misc-include-cleaner]