Skip to content

Commit 83dfd7e

Browse files
LegNeatoclaude
andcommitted
Always provide dispatch_context_message and assemble_text_with_context
These FFI functions only depend on the public C API and table.h struct definitions, not on the Reducer library. Move table.h and libspirv.hpp includes outside the SPIRV_RUST_TARGET_ENV guard so these functions are always compiled. Only the Reducer-specific headers (reducer.h, spirv_reducer_options.h) remain guarded since they're only needed by reduce_with_cpp. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent edcb0a7 commit 83dfd7e

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
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, we don't need C++ fallback implementations
11-
// since Rust provides them. This avoids link dependencies on C++ SPIRV-Tools
12-
// libraries (libspirv.hpp, reducer.h) that would create circular dependencies.
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+
15+
// 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.
1318
#ifndef SPIRV_RUST_TARGET_ENV
1419
#include "source/reduce/reducer.h"
1520
#include "source/spirv_reducer_options.h"
16-
#include "source/table.h"
17-
#include "spirv-tools/libspirv.hpp"
1821
#endif
1922

2023
namespace {
@@ -30,16 +33,9 @@ std::string FormatDiagnostic(spv_message_level_t, const spv_position_t& position
3033
return oss.str();
3134
}
3235
#endif
33-
} // namespace
3436

35-
namespace spvtools::ffi {
36-
37-
// In CMake builds with SPIRV_RUST_TARGET_ENV, dispatch_context_message and
38-
// assemble_text_with_context are provided by source/text.cpp using internal APIs.
39-
// In standalone Rust builds (Bazel), we provide them here.
40-
#ifndef SPIRV_RUST_TARGET_ENV
41-
namespace {
42-
spv_position_t ToSpvPosition(MessagePosition position) {
37+
// Helper to convert FFI MessagePosition to spv_position_t (always needed)
38+
spv_position_t ToSpvPosition(spvtools::ffi::MessagePosition position) {
4339
spv_position_t pos = {};
4440
pos.line = position.line;
4541
pos.column = position.column;
@@ -48,6 +44,9 @@ spv_position_t ToSpvPosition(MessagePosition position) {
4844
}
4945
} // namespace
5046

47+
namespace spvtools::ffi {
48+
49+
// These functions use only the public C API (libspirv.h) and are always provided.
5150
void dispatch_context_message(std::size_t context_ptr, std::uint32_t level,
5251
bool has_source, rust::Str source,
5352
MessagePosition position, rust::Str message) {
@@ -98,7 +97,6 @@ AssembleResult assemble_text_with_context(std::size_t context_ptr,
9897

9998
return result;
10099
}
101-
#endif
102100

103101
ValidateResult validate_binary_with_options(
104102
std::uint32_t env, rust::Slice<const std::uint32_t> words,

0 commit comments

Comments
 (0)