Skip to content

Commit ba9650c

Browse files
LegNeatoclaude
andcommitted
Remove source/table.h include from context_bridge.cc
context_bridge.cc is compiled by Rust's build.rs, which always defines SPIRV_RUST_TARGET_ENV. However, source/table.h requires generated headers (core_tables_header.inc) that aren't available during the cxx_build phase. Solution: - Remove source/table.h include from context_bridge.cc entirely - Make dispatch_context_message a no-op in context_bridge.cc - Move the actual dispatch_context_message implementation to source/text.cpp (which is compiled by CMake with access to generated headers) This ensures: - Bazel builds: context_bridge.cc compiles without generated headers - CMake builds: source/text.cpp provides working implementations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 68638f6 commit ba9650c

File tree

2 files changed

+41
-46
lines changed

2 files changed

+41
-46
lines changed

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

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

10-
// When building with Rust target env (CMake integration), we have access to
11-
// internal headers for spv_context_t definition. In standalone Rust builds
12-
// (like Bazel), we don't need the full context definition since message
13-
// dispatch to C++ consumers isn't used.
14-
#ifdef SPIRV_RUST_TARGET_ENV
15-
#include "source/table.h"
16-
#endif
17-
1810
// When building with Rust target env, we don't need C++ fallback implementations
1911
// since Rust provides them. This avoids link dependencies on C++ SPIRV-Tools
2012
// libraries (libspirv.hpp, reducer.h) that would create circular dependencies.
@@ -40,53 +32,26 @@ std::string FormatDiagnostic(spv_message_level_t, const spv_position_t& position
4032
} // namespace
4133

4234
namespace spvtools::ffi {
43-
namespace {
44-
spv_position_t ToSpvPosition(MessagePosition position) {
45-
spv_position_t pos = {};
46-
pos.line = position.line;
47-
pos.column = position.column;
48-
pos.index = position.index;
49-
return pos;
50-
}
51-
} // namespace
5235

36+
// In CMake builds with SPIRV_RUST_TARGET_ENV, dispatch_context_message and
37+
// assemble_text_with_context are provided by source/text.cpp using internal APIs.
38+
// In standalone Rust builds (Bazel), we provide them here.
39+
#ifndef SPIRV_RUST_TARGET_ENV
5340
void dispatch_context_message(std::uintptr_t context_ptr, std::uint32_t level,
5441
bool has_source, rust::Str source,
5542
MessagePosition position, rust::Str message) {
56-
#ifdef SPIRV_RUST_TARGET_ENV
57-
// In CMake builds with Rust target env, we have access to spv_context_t
58-
// definition and can dispatch messages to C++ consumers.
59-
auto* context = reinterpret_cast<spv_context>(context_ptr);
60-
if (context == nullptr || !context->consumer) {
61-
return;
62-
}
63-
64-
std::string message_storage(message.data(), message.length());
65-
const char* source_ptr = nullptr;
66-
std::string source_storage;
67-
if (has_source) {
68-
source_storage.assign(source.data(), source.length());
69-
source_ptr = source_storage.c_str();
70-
}
71-
72-
context->consumer(static_cast<spv_message_level_t>(level), source_ptr,
73-
ToSpvPosition(position), message_storage.c_str());
74-
#else
75-
// In standalone Rust builds (like Bazel), message dispatch to C++ consumers
76-
// is not supported since we don't have access to generated headers.
43+
// This function is intentionally a no-op in standalone Rust builds.
44+
// Message dispatch to C++ consumers requires access to spv_context_t internals
45+
// (specifically the `consumer` callback), which requires generated headers
46+
// that are not available when compiling via Rust's build.rs.
7747
(void)context_ptr;
7848
(void)level;
7949
(void)has_source;
8050
(void)source;
8151
(void)position;
8252
(void)message;
83-
#endif
8453
}
8554

86-
// In CMake builds with SPIRV_RUST_TARGET_ENV, this function is provided by
87-
// source/text.cpp using internal APIs. In standalone Rust builds (Bazel),
88-
// we provide it here using the public C API.
89-
#ifndef SPIRV_RUST_TARGET_ENV
9055
AssembleResult assemble_text_with_context(std::size_t context_ptr,
9156
rust::Slice<const std::uint8_t> text,
9257
std::uint32_t options) {

source/text.cpp

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,11 +1071,41 @@ spv_result_t spvTextToBinaryWithOptions(const spv_const_context context,
10711071
sanitized_options, pBinary, pDiagnostic);
10721072
}
10731073

1074-
// FFI bridge for Rust assembler integration. In CMake builds with SPIRV_RUST_TARGET_ENV,
1075-
// we provide this function here using internal C++ APIs. In standalone Rust builds (Bazel),
1076-
// context_bridge.cc provides this using the public C API.
1074+
// FFI bridge functions for Rust integration. In CMake builds with SPIRV_RUST_TARGET_ENV,
1075+
// we provide these functions here using internal C++ APIs. In standalone Rust builds (Bazel),
1076+
// context_bridge.cc provides stubs (since generated headers aren't available there).
10771077
#if defined(SPIRV_RUST_TARGET_ENV)
10781078
namespace spvtools::ffi {
1079+
namespace {
1080+
spv_position_t ToSpvPosition(MessagePosition position) {
1081+
spv_position_t pos = {};
1082+
pos.line = position.line;
1083+
pos.column = position.column;
1084+
pos.index = position.index;
1085+
return pos;
1086+
}
1087+
} // namespace
1088+
1089+
void dispatch_context_message(std::uintptr_t context_ptr, std::uint32_t level,
1090+
bool has_source, rust::Str source,
1091+
MessagePosition position, rust::Str message) {
1092+
auto* context = reinterpret_cast<spv_context>(context_ptr);
1093+
if (context == nullptr || !context->consumer) {
1094+
return;
1095+
}
1096+
1097+
std::string message_storage(message.data(), message.length());
1098+
const char* source_ptr = nullptr;
1099+
std::string source_storage;
1100+
if (has_source) {
1101+
source_storage.assign(source.data(), source.length());
1102+
source_ptr = source_storage.c_str();
1103+
}
1104+
1105+
context->consumer(static_cast<spv_message_level_t>(level), source_ptr,
1106+
ToSpvPosition(position), message_storage.c_str());
1107+
}
1108+
10791109
AssembleResult assemble_text_with_context(std::size_t context_ptr,
10801110
rust::Slice<const std::uint8_t> text,
10811111
std::uint32_t options) {

0 commit comments

Comments
 (0)