Skip to content

Commit ec2c2be

Browse files
LegNeatoclaude
andcommitted
Always define SPIRV_RUST_TARGET_ENV in context_bridge.cc compilation
When compiling context_bridge.cc via cargo (build.rs), we must always define SPIRV_RUST_TARGET_ENV. This ensures: 1. We skip C++ includes that need generated headers (reducer.h, libspirv.hpp) 2. We delegate to Rust implementations (validate_binary_rust, etc.) 3. We don't provide duplicate implementations of dispatch_context_message and assemble_text_with_context (text.cpp provides these in CMake builds when SPIRV_RUST_TARGET_ENV is defined there too) The previous conditional logic caused multiple definition errors because in CMake builds, both context_bridge.cc and text.cpp were providing implementations of the same functions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent efca9f1 commit ec2c2be

1 file changed

Lines changed: 8 additions & 16 deletions

File tree

rust/spirv-tools-ffi/build.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +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-
// Define SPIRV_RUST_TARGET_ENV to use Rust-only implementations in context_bridge.cc.
33-
// This avoids dependencies on generated SPIRV-Tools headers (like core_tables_header.inc)
34-
// and C++ libraries (libspirv.hpp, reducer.h) that may not be available.
35-
//
36-
// Build scenarios:
37-
// - Standalone cargo build (no env vars): Define SPIRV_RUST_TARGET_ENV, use Rust stubs
38-
// - Bazel build (SPIRV_RUST_TARGET_ENV_DEFINE=1): Define SPIRV_RUST_TARGET_ENV, use Rust stubs
39-
// - CMake build (SPIRV_TOOLS_FFI_SKIP_CPP_LINK=1 only): Don't define, use C++ implementations
40-
//
41-
// Both Bazel and CMake set SPIRV_TOOLS_FFI_SKIP_CPP_LINK=1 to skip link directives,
42-
// but only Bazel sets SPIRV_RUST_TARGET_ENV_DEFINE=1 to use Rust-only implementations.
43-
let use_rust_implementations = env::var("SPIRV_RUST_TARGET_ENV_DEFINE").is_ok()
44-
|| env::var("SPIRV_TOOLS_FFI_SKIP_CPP_LINK").is_err();
45-
if use_rust_implementations {
46-
bridge_builder.define("SPIRV_RUST_TARGET_ENV", None);
47-
}
32+
// Always define SPIRV_RUST_TARGET_ENV when compiling context_bridge.cc via cargo.
33+
// This ensures:
34+
// 1. We skip C++ includes that need generated headers (reducer.h, libspirv.hpp)
35+
// 2. We delegate to Rust implementations (validate_binary_rust, etc.)
36+
// 3. We don't provide duplicate implementations of dispatch_context_message
37+
// and assemble_text_with_context (text.cpp provides these in CMake builds
38+
// when SPIRV_RUST_TARGET_ENV is defined there too)
39+
bridge_builder.define("SPIRV_RUST_TARGET_ENV", None);
4840
bridge_builder
4941
.file("src/context_bridge.cc")
5042
.include(repo_root)

0 commit comments

Comments
 (0)