Skip to content
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ jobs:
run: |
cmake -S lang/cpp -B build \
-DCMAKE_BUILD_TYPE=Debug \
-DVORTEX_DEBUG_INFO=0 \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DVORTEX_SANITIZER=asan \
Expand Down
2 changes: 2 additions & 0 deletions lang/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ option(VORTEX_WARNINGS_AS_ERRORS
"Treat warnings in Vortex-owned sources as errors"
"${_vortex_top_level}")

include(../../vortex-ffi/cmake/DebugInfo.cmake)

# The Rust FFI archive comes from vortex-ffi. A standalone configure of this
# directory adds it here; the repository root or a parent may already have.
if(NOT TARGET Vortex::ffi_static)
Expand Down
1 change: 1 addition & 0 deletions lang/cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ options. Defaults below are for standalone builds.
| `VORTEX_RUSTUP_TOOLCHAIN` | Inferred | [Rust toolchain override](#toolchain-and-build-behavior). |
| `VORTEX_SANITIZER` | Empty | [Sanitizers](#sanitizers): `asan`, `lsan`, `ubsan`, `tsan`. |
| `VORTEX_SANITIZE_RUST_STD` | `OFF` | Also instrument Rust's standard library. |
| `VORTEX_DEBUG_INFO` | `2` | C/C++ and Rust debug info: `0` none, `1` limited, `2` full. |
| `VORTEX_ENABLE_CUDA` | `OFF` | Linux-only [CUDA build](#cuda). |

Embedded builds default `VORTEX_WARNINGS_AS_ERRORS` to `OFF`. Parents must call
Expand Down
12 changes: 8 additions & 4 deletions vortex-ffi/cmake/Configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
include_guard(GLOBAL)

include("${CMAKE_CURRENT_LIST_DIR}/Cuda.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/DebugInfo.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/Helpers.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/RustToolchain.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/SystemDependencies.cmake")
Expand Down Expand Up @@ -184,7 +185,6 @@ function(_vortex_resolve_sanitizer
list(APPEND _rustflags
-A warnings
-Cunsafe-allow-abi-mismatch=sanitizer
-C debuginfo=2
-C opt-level=0
# Use the sanitizer runtime linked by the final C++ target for both languages.
-Zexternal-clangrt
Expand Down Expand Up @@ -239,8 +239,9 @@ function(_vortex_native_flags
endif()

# Native dependencies become part of the archive embedded in shared parents.
list(APPEND _cflags -fPIC)
list(APPEND _cxxflags -fPIC)
# Match CMake targets even when cc-rs or parent flags enable debug info.
list(APPEND _cflags -fPIC -g${VORTEX_DEBUG_INFO})
list(APPEND _cxxflags -fPIC -g${VORTEX_DEBUG_INFO})

set(${cflags_output} "${_cflags}" PARENT_SCOPE)
set(${cxxflags_output} "${_cxxflags}" PARENT_SCOPE)
Expand Down Expand Up @@ -282,7 +283,10 @@ block(SCOPE_FOR VARIABLES)
_native_cxx_flags)
# Mirror .cargo/config.toml's Unix rustflags, which CARGO_ENCODED_RUSTFLAGS overrides.
# Keep them in sync; PIC additionally allows embedding in shared libraries.
set(_rustflags ${_sanitizer_rustflags} -C force-frame-pointers=yes -C relocation-model=pic)
set(_rustflags ${_sanitizer_rustflags}
-C force-frame-pointers=yes
-C relocation-model=pic
-C "debuginfo=${VORTEX_DEBUG_INFO}")

# Cargo owns incremental invalidation inside this CMake-build-local cache.
# Registering the directory as additional clean state gives the standard
Expand Down
15 changes: 15 additions & 0 deletions vortex-ffi/cmake/DebugInfo.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright the Vortex contributors

include_guard(DIRECTORY)

set(VORTEX_DEBUG_INFO "2" CACHE STRING
"Debug information for C, C++, and Rust: 0 (none), 1 (limited), 2 (full)")
set_property(CACHE VORTEX_DEBUG_INFO PROPERTY STRINGS 0 1 2)
if(NOT VORTEX_DEBUG_INFO MATCHES "^[012]$")
message(FATAL_ERROR "VORTEX_DEBUG_INFO must be 0, 1, or 2")
endif()

# Keep the override in Vortex's directories, including fetched dependencies,
# without changing unrelated targets in an embedding parent.
add_compile_options("$<$<COMPILE_LANGUAGE:C,CXX>:-g${VORTEX_DEBUG_INFO}>")
14 changes: 12 additions & 2 deletions vortex-ffi/cmake/tests/test_compiler_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,20 @@ def setUp(self) -> None:
self.command("cargo", "generate-lockfile", "--offline", cwd=self.source)

def configure(
self, value=7, argument=7, policy=True, instrumentation=False, generator="Ninja", build_name=None
self,
value=7,
argument=7,
policy=True,
instrumentation=False,
generator="Ninja",
build_name=None,
debug_info=None,
) -> None:
self.build_dir = self.work / (build_name or f"{generator} build directory's")
self.target_dir = self.build_dir / "ffi/cargo-target"
options = []
if debug_info is not None:
options.append(f"-DVORTEX_DEBUG_INFO={debug_info}")
include = self.source / "native-helper/include directory's"
errors = ["-Werror", "-Werror=unused-variable", "-pedantic-errors"] if policy else []
for language, compiler in (("C", "clang"), ("CXX", "clang++")):
Expand Down Expand Up @@ -151,12 +160,13 @@ def test_host_target_instrumentation_and_cache_boundary(self) -> None:
os.execv(sys.argv[1], sys.argv[1:])
""",
)
self.configure(instrumentation=True)
self.configure(instrumentation=True, debug_info=0)
self.build()
calls = [json.loads(line) for line in log.read_text().splitlines()]
self.assertEqual(sorted(target for target, _ in calls), [False, False, True, True])
for target, args in calls:
self.assertIn(Path(args[0]).name, ("clang", "clang++"))
self.assertEqual([arg for arg in args if arg.startswith("-g")][-1:], ["-g0"], args)
for flag in ("--coverage", "-fsanitize=undefined"):
self.assertEqual(flag in args, target, args)
objects = sorted(self.target_dir.rglob("out/*-native.o"))
Expand Down
7 changes: 7 additions & 0 deletions vortex-ffi/cmake/tests/test_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def test_standalone_defaults_and_ffi_default_build(self) -> None:
self.assertEqual(settings[:2], ["Debug", "ON"])
if len(settings) == 3:
self.assertIn("-Werror", settings[2].split(";"))
self.assertIn("$<$<COMPILE_LANGUAGE:C,CXX>:-g2>", settings[2].split(";"))

build = self.work / "ffi"
self.cmake_build(build)
Expand All @@ -76,8 +77,14 @@ def test_standalone_defaults_and_ffi_default_build(self) -> None:
self.assertEqual(recorded["args"][recorded["args"].index("--profile") + 1], "dev")
config = tomllib.loads((self.repo / ".cargo/config.toml").read_text())
expected = config["target"]['cfg(target_family="unix")']["rustflags"] + ["-C", "relocation-model=pic"]
expected += ["-C", "debuginfo=2"]
self.assertEqual(recorded["env"]["CARGO_ENCODED_RUSTFLAGS"].split("\x1f"), expected)

self.configure("ffi", "-DVORTEX_DEBUG_INFO=0")
self.cmake_build(build)
recorded = self.cargo_recording(build / "cargo-target")
self.assertEqual(recorded["env"]["CARGO_ENCODED_RUSTFLAGS"].split("\x1f"), expected[:-1] + ["debuginfo=0"])

def test_embedded_root_preserves_parent_variables(self) -> None:
source = self.write(
"parent/CMakeLists.txt",
Expand Down
Loading