FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Support consuming an external CppInterOp via CppInterOp_DIR by guitargeek · Pull Request #48 · compiler-research/cppjit · GitHub

Support consuming an external CppInterOp via CppInterOp_DIR - #48

Open
guitargeek wants to merge 1 commit into
compiler-research:mainfrom
guitargeek:external-cppinterop
Open

Support consuming an external CppInterOp via CppInterOp_DIR#48
guitargeek wants to merge 1 commit into
compiler-research:mainfrom
guitargeek:external-cppinterop

Conversation

guitargeek commented Aug 29, 2026
edited
Loading

Copy link
Copy Markdown
Collaborator

Providing CppInterOp_DIR selects external mode: cppjit consumes that CppInterOp install through find_package(CppInterOp) instead of building one with ExternalProject and bundling it into the wheel.

In this mode nothing is bundled: the library and include paths from the package config are baked into the wrapper as absolute paths, which works because cppinterop_paths() joins with std::filesystem's operator/, where an absolute right-hand side replaces the anchor. The clang major comes from CPPINTEROP_LLVM_VERSION_MAJOR in the config, so no LLVM is needed to build the wrapper itself; the LLVM discovery and version gate only run in the default bundled mode, since compatibility was already enforced when the external CppInterOp was built.

The mode is keyed to the explicitly provided CppInterOp_DIR variable, not to find_package succeeding through ambient search paths: otherwise a pip install inside e.g. a conda environment that happens to carry CppInterOp would silently produce a wheel that does not bundle its interpreter, making the wheel's composition depend on what the build environment has lying around.

An external CppInterOp carries no clang builtin headers, and clang's compiled-in resource dir default resolves relative to the library location, so CPPJIT_CLANG_RESOURCE_DIR should point at the resource dir matching the CppInterOp's clang. It is optional: when unset, CMake warns and the wrapper falls back to the existing runtime DetectResourceDir("clang-") probe, which works wherever a versioned clang is on PATH (e.g. conda environments). Distributions where it is not (e.g. NixOS) pass the resource dir explicitly.

The config file's CPPINTEROP_INSTALL_PREFIX is captured immediately after find_package, before the site-packages staging logic reuses that variable name.

Intended for distribution packaging (e.g. Nix), where CppInterOp is a separate package and duplicating its build in every consumer is wasted work (e.g. for the matrix of different LLVM and Python versions supported by Nix).

Copy link
Copy Markdown
Contributor

I’d think providing just CPPINTEROP_DIR should make this use case work…

guitargeek force-pushed the external-cppinterop branch from 51352db to 13499e1 Compare August 29, 2026 10:23

Copy link
Copy Markdown
Collaborator Author

That's also possible. I have rewritten the logic such that the external CpInterOp path is triggered when the CppInterOp_DIR variable is set (not CPPINTEROP_DIR, to be consistent with CppInterOps CppInterOpConfig.cmake).

guitargeek changed the title Add CPPJIT_USE_EXTERNAL_CPPINTEROP build option Support consuming an external CppInterOp via CppInterOp_DIR Aug 29, 2026
Comment thread CMakeLists.txt Outdated
# the LLVM version the library embeds, so no LLVM is needed to build the
# wrapper itself; version compatibility was already enforced when that
# CppInterOp was built.
find_package(CppInterOp CONFIG REQUIRED)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think we don't need the extra _cppjit_external_cppinterop but we can provide a HINT or an extra PATH and find_package will do the rest..

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Right! I updated the PR.

Providing CppInterOp_DIR selects external mode: cppjit consumes that
CppInterOp install through find_package(CppInterOp) instead of building
one with ExternalProject and bundling it into the wheel.

In this mode nothing is bundled: the library and include paths from the
package config are baked into the wrapper as absolute paths, which
works because cppinterop_paths() joins with std::filesystem's
operator/, where an absolute right-hand side replaces the anchor. The
clang major comes from CPPINTEROP_LLVM_VERSION_MAJOR in the config, so
no LLVM is needed to build the wrapper itself; the LLVM discovery and
version gate only run in the default bundled mode, since compatibility
was already enforced when the external CppInterOp was built.

The mode is keyed to the explicitly provided CppInterOp_DIR variable,
not to find_package succeeding through ambient search paths: otherwise
a pip install inside e.g. a conda environment that happens to carry
CppInterOp would silently produce a wheel that does not bundle its
interpreter, making the wheel's composition depend on what the build
environment has lying around.

An external CppInterOp carries no clang builtin headers, and clang's
compiled-in resource dir default resolves relative to the library
location, so CPPJIT_CLANG_RESOURCE_DIR should point at the resource dir
matching the CppInterOp's clang. It is optional: when unset, CMake
warns and the wrapper falls back to the existing runtime
DetectResourceDir("clang-<major>") probe, which works wherever a
versioned clang is on PATH (e.g. conda environments). Distributions
where it is not (e.g. NixOS) pass the resource dir explicitly.

The config file's CPPINTEROP_INSTALL_PREFIX is captured immediately
after find_package, before the site-packages staging logic reuses that
variable name.

Intended for distribution packaging (e.g. Nix), where CppInterOp is a
separate package and duplicating its build in every consumer is wasted
work (e.g. for the matrix of different LLVM and Python versions
supported by Nix).
guitargeek force-pushed the external-cppinterop branch from 13499e1 to 986f057 Compare August 29, 2026 12:55
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
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.

2 participants


Back | FazBrowse Home | New Git URL