Skip to content
This repository was archived by the owner on Aug 5, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
common --enable_bzlmod
test --test_output=errors

# The C++ toolchain (clang from the LLVM tree) and all ABI-critical flags are
# centralized in the cppyy_bazel module, which registers @llvm//:cc_toolchain.
# No per-repo compiler wiring needed.
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.3.1
57 changes: 57 additions & 0 deletions .github/workflows/bazel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Best-effort, NON-GATING Bazel build. CMake is the supported build for
# cppyy-backend; this job is informational only and must never gate CI
# (continue-on-error). The build step runs for real and surfaces a regression as
# a warning, not a false green.
#
# Sibling repos are cloned from the compiler-research default branches. The
# cppyy_bazel module (cppyy/bazel/) and the per-repo MODULE.bazel files are still
# landing across the four repos' Bazel PRs; until all four land this best-effort
# job may fail (non-gating). Cloning the default branches means no follow-up PR
# is needed once they do — the job goes green on its own.
name: bazel

on:
push:
pull_request:

jobs:
bazel-build:
name: bazel (best-effort) llvm${{ matrix.llvm }}
runs-on: ubuntu-24.04
continue-on-error: true
strategy:
fail-fast: false
matrix:
llvm: ["22"]
steps:
# No `path:` -> cppyy-backend is $GITHUB_WORKSPACE; siblings are cloned
# alongside it so the local_path_overrides (../cppyy/bazel, ../CppInterOp)
# resolve.
- name: Checkout cppyy-backend
uses: actions/checkout@v4

- name: Clone sibling repos
run: |
set -eux
cd "$GITHUB_WORKSPACE/.."
for repo in cppyy CppInterOp; do
git clone --depth=1 \
"https://github.com/compiler-research/${repo}.git"
done

- name: Setup LLVM ${{ matrix.llvm }}
uses: compiler-research/ci-workflows/actions/setup-llvm@main
with:
version: ${{ matrix.llvm }}
os: ubuntu-24.04

- name: Point LLVM_DIR at the tree root for the @llvm Bazel extension
run: |
# setup-llvm sets LLVM_DIR=<prefix>/lib/cmake/llvm (CMake convention);
# the @llvm Bazel extension needs the tree root holding bin/llvm-config.
echo "LLVM_DIR=${GITHUB_WORKSPACE}/install" >> "$GITHUB_ENV"

- name: bazel build //:solib //:pylib
run: |
bazelisk build //:solib //:pylib \
|| echo "::warning::bazel build failed (best-effort, non-gating)"
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,10 @@ ENV/
# mypy
.mypy_cache/

.vscode
.vscode
# Bazel convenience symlinks and module lock
/bazel-bin
/bazel-out
/bazel-testlogs
/bazel-cppyy-backend
MODULE.bazel.lock
90 changes: 90 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
load("@cppyy_bazel//:defs.bzl", "BASE_COPTS", "repo_loc", "repo_rloc")
load("@rules_python//python:packaging.bzl", "py_wheel")

# cppyy-backend is a sanitizer boundary: libcppyy-backend.so is dlopen'd by a
# (possibly non-instrumented) host interpreter and works directly with the
# non-sanitized LLVM/clang runtime, so an asan/ubsan-instrumented build would die
# on undefined __asan_* symbols at load. Opt the package out; harmless when the
# consumer build isn't sanitized.
package(
default_visibility = ["//visibility:public"],
features = [
"-asan",
"-ubsan",
],
)

# CppInterOp headers (incl. the generated CppInterOpAPI.inc) live in the
# @cppinterop tree, not an install prefix. Build-time includes resolve against
# the external path; the runtime CPPINTEROP_DIR/{lib,include} the source dlopen's
# resolve against the runfiles path.
_CPPINTEROP_RLOC = repo_rloc("@cppinterop")

cc_library(
name = "lib",
srcs = glob(["clingwrapper/src/*.cxx"]),
hdrs = glob(["clingwrapper/src/*.h"]) + ["@cppinterop//:headers"],
copts = BASE_COPTS + [
# BASE_COPTS sets -fno-exceptions/-fno-rtti; clingwrapper needs both
# (throw std::runtime_error, typeid for AutoCastRTTI).
"-fexceptions",
"-frtti",
# CppInterOp headers are <CppInterOp/...>; include root is the source
# tree plus the genfiles tree where the tblgen'd .inc headers land.
"-I" + repo_loc("@cppinterop") + "/include",
"-I$(GENDIR)/" + repo_loc("@cppinterop") + "/include",
# CMAKE: CPPINTEROP_DIR drives the runtime dlopen path
# CPPINTEROP_DIR "/lib/libclangCppInterOp" CMAKE_SHARED_LIBRARY_SUFFIX.
"-DCPPINTEROP_DIR='\"" + _CPPINTEROP_RLOC + "\"'",
# CMAKE: CMAKE_SHARED_LIBRARY_SUFFIX, .so on Linux.
"-DCMAKE_SHARED_LIBRARY_SUFFIX='\".so\"'",
# clingwrapper has an unused var and a non-canonical dtor name; demote
# so a consumer toolchain with -Werror (e.g. nebula) doesn't fail.
"-Wno-error=unused-variable",
"-Wno-unused-variable",
"-Wno-error=dtor-name",
"-Wno-dtor-name",
"-Wno-error=unused-parameter",
"-Wno-unused-parameter",
],
data = ["@cppinterop//:headers"],
# CMAKE: target_include_directories PRIVATE clingwrapper/src.
includes = ["clingwrapper/src"],
)

cc_shared_library(
name = "solib",
additional_linker_inputs = ["@llvm//:lib_files"],
dynamic_deps = ["@cppinterop//:solib"],
shared_lib_name = "python/cppyy_backend/lib/libcppyy-backend.so",
deps = [":lib"],
)

py_library(
name = "pylib",
srcs = glob(["python/cppyy_backend/**/*.py"]),
# Carry the runtime libs so anything depending on the python package (e.g.
# cppyy -> @cppyy//:lib) gets libcppyy-backend.so + libclangCppInterOp.so in
# its runfiles, not just the headers.
data = [
":solib",
"@cppinterop//:headers",
"@cppinterop//:solib",
],
imports = ["python"],
)

# strip_path_prefixes drops the python/ source root and the solib's python/
# wrapper so both land under cppyy_backend/ (the .so at cppyy_backend/lib/),
# matching where setup.py ships them.
py_wheel(
name = "cppyy_backend_wheel",
distribution = "cppyy-backend",
python_tag = "py3",
strip_path_prefixes = ["python"],
version = "0.1.0.dev0",
deps = [
":pylib",
":solib",
],
)
24 changes: 24 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module(
name = "cppyy_backend",
version = "0.1.0",
)

bazel_dep(name = "cppyy_bazel", version = "0.1.0")
local_path_override(
module_name = "cppyy_bazel",
path = "../cppyy/bazel",
)

bazel_dep(name = "cppinterop", version = "0.1.0")
local_path_override(
module_name = "cppinterop",
path = "../CppInterOp",
)

bazel_dep(name = "rules_python", version = "1.5.1")

llvm = use_extension("@cppyy_bazel//:llvm.bzl", "llvm")
use_repo(llvm, llvm = "cppjit_llvm")

# Opt in to the centralized clang toolchain from cppyy_bazel (standalone build).
register_toolchains("@llvm//:cc_toolchain")
34 changes: 34 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,37 @@ Find the cppyy documentation here:
http://cppyy.readthedocs.io/

Please report bugs in the `cppyy issue tracker <https://bitbucket.org/wlav/cppyy/issues>`_.

----

Building with Bazel (experimental)
----------------------------------

CMake is the supported build for cppyy-backend. A best-effort Bazel build is
also provided and is **not** a replacement for CMake; it may lag behind. A
non-gating CI job builds it against an upstream LLVM 22 release (via
``compiler-research/ci-workflows``'s ``setup-llvm``), so a failure warns rather
than blocking a PR.

It builds the ``libcppyy-backend`` shared library and the ``cppyy_backend``
Python package against a local LLVM/Clang tree and a sibling CppInterOp.

Requirements:

- An LLVM/Clang build or release install tree (LLVM 20-22), pointed at by the
``LLVM_DIR`` env var.
- Sibling checkouts laid out next to this repo (the bzlmod
``local_path_override``\ s expect them)::

<workspace>/
cppyy-backend/ (this repo)
cppyy/ (provides cppyy/bazel, the shared Bazel module)
CppInterOp/

Build::

LLVM_DIR=/path/to/llvm bazelisk build //:solib //:pylib

Build the wheel::

LLVM_DIR=/path/to/llvm bazelisk build //:cppyy_backend_wheel
Loading