Skip to content

Commit 59f2f49

Browse files
LegNeatoclaude
andcommitted
Avoid internal headers in Bazel FFI builds
When SPIRV_RUST_TARGET_ENV is defined, avoid including source/table.h and other internal headers that depend on generated files like core_tables_header.inc. Instead, provide stub implementations for all FFI functions including dispatch_context_message. This fixes the Bazel build which doesn't have the generated headers available when building the Rust FFI library. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9e82d27 commit 59f2f49

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

rust/spirv-tools-ffi/src/context_bridge.cc

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,16 @@
77
#include "rust/cxxbridge/spirv-tools-ffi/src/context_bridge.h"
88
#include "spirv-tools/libspirv.h"
99

10-
// Always include table.h for spv_context_t struct definition and libspirv.hpp
11-
// for MessageConsumer. These have no Reducer dependencies.
12-
#include "source/table.h"
13-
#include "spirv-tools/libspirv.hpp"
14-
1510
// When building with Rust target env (SPIRV_RUST_TARGET_ENV defined), we skip
16-
// C++ implementations that depend on the Reducer library to avoid circular
17-
// dependencies.
11+
// C++ implementations entirely and provide stubs. This avoids dependencies on
12+
// generated headers (core_tables_header.inc) that aren't available in Bazel.
1813
#ifndef SPIRV_RUST_TARGET_ENV
14+
#include "source/table.h"
15+
#include "spirv-tools/libspirv.hpp"
1916
#include "source/reduce/reducer.h"
2017
#include "source/spirv_reducer_options.h"
21-
#endif
2218

2319
namespace {
24-
#ifndef SPIRV_RUST_TARGET_ENV
2520
std::string FormatDiagnostic(spv_message_level_t, const spv_position_t& position,
2621
const char* message) {
2722
std::ostringstream oss;
@@ -32,9 +27,8 @@ std::string FormatDiagnostic(spv_message_level_t, const spv_position_t& position
3227
oss << ": " << message;
3328
return oss.str();
3429
}
35-
#endif
3630

37-
// Helper to convert FFI MessagePosition to spv_position_t (always needed)
31+
// Helper to convert FFI MessagePosition to spv_position_t
3832
spv_position_t ToSpvPosition(spvtools::ffi::MessagePosition position) {
3933
spv_position_t pos = {};
4034
pos.line = position.line;
@@ -43,11 +37,19 @@ spv_position_t ToSpvPosition(spvtools::ffi::MessagePosition position) {
4337
return pos;
4438
}
4539
} // namespace
40+
#endif // SPIRV_RUST_TARGET_ENV
4641

4742
namespace spvtools::ffi {
4843

49-
// dispatch_context_message uses only the internal struct definition (table.h)
50-
// and is always provided.
44+
// dispatch_context_message dispatches messages to C++ contexts.
45+
// In SPIRV_RUST_TARGET_ENV mode, this is a no-op stub since we don't have
46+
// access to the internal spv_context_t structure.
47+
#ifdef SPIRV_RUST_TARGET_ENV
48+
void dispatch_context_message(std::size_t, std::uint32_t, bool, rust::Str,
49+
MessagePosition, rust::Str) {
50+
// Stub: In Bazel/Rust-only builds, message dispatch is handled in Rust.
51+
}
52+
#else
5153
void dispatch_context_message(std::size_t context_ptr, std::uint32_t level,
5254
bool has_source, rust::Str source,
5355
MessagePosition position, rust::Str message) {
@@ -67,6 +69,7 @@ void dispatch_context_message(std::size_t context_ptr, std::uint32_t level,
6769
context->consumer(static_cast<spv_message_level_t>(level), source_ptr,
6870
ToSpvPosition(position), message_storage.c_str());
6971
}
72+
#endif
7073

7174
// assemble_text_with_context needs different implementations:
7275
// - In standalone Rust builds: call through to C++ SPIRV-Tools assembler

0 commit comments

Comments
 (0)