Skip to content

Commit 4f5add2

Browse files
LegNeatoclaude
andcommitted
Fix circular dependency in CMake Rust FFI build
When building via CMake (SPIRV_TOOLS_FFI_SKIP_CPP_LINK=1), don't define SPIRV_RUST_TARGET_ENV in the Rust FFI build. This allows context_bridge.cc to include its own implementations of dispatch_context_message and assemble_text_with_context, avoiding a circular dependency between SPIRV-Tools and spirv-tools-ffi at link time. Previously, SPIRV_RUST_TARGET_ENV was always defined, which caused the stub implementations in context_bridge.cc to be skipped, expecting text.cpp to provide them. But since spirv-tools-ffi is linked into SPIRV-Tools, and text.cpp is part of SPIRV-Tools, this created a circular dependency that the linker couldn't resolve. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 1aee011 commit 4f5add2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

rust/spirv-tools-ffi/build.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ fn main() {
2929
.expect("failed to copy context bridge header");
3030

3131
let mut bridge_builder = cxx_build::bridge("src/lib.rs");
32-
bridge_builder.define("SPIRV_RUST_TARGET_ENV", None);
32+
// Only define SPIRV_RUST_TARGET_ENV when NOT building via CMake.
33+
// When building via CMake, the FFI library should include its own implementations
34+
// of dispatch_context_message and assemble_text_with_context (from context_bridge.cc)
35+
// to avoid circular dependency issues at link time.
36+
// CMake sets SPIRV_TOOLS_FFI_SKIP_CPP_LINK=1 when invoking cargo.
37+
if env::var("SPIRV_TOOLS_FFI_SKIP_CPP_LINK").is_err() {
38+
bridge_builder.define("SPIRV_RUST_TARGET_ENV", None);
39+
}
3340
bridge_builder
3441
.file("src/context_bridge.cc")
3542
.include(repo_root)

0 commit comments

Comments
 (0)