Skip to content

Commit 5155901

Browse files
LegNeatoclaude
andcommitted
Avoid circular dependency in assemble_text_with_context
When SPIRV_RUST_TARGET_ENV is defined (CMake builds), provide a stub implementation of assemble_text_with_context that returns failure. This avoids calling spvTextToBinaryWithOptions from within libspirv_tools_ffi, which would create a circular dependency since SPIRV-Tools links against spirv-tools-ffi. In CMake builds, the Rust side should use its native assembler instead of calling back into C++. The stub signals this by returning failure. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent da9235a commit 5155901

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ spv_position_t ToSpvPosition(spvtools::ffi::MessagePosition position) {
4646

4747
namespace spvtools::ffi {
4848

49-
// These functions use only the public C API (libspirv.h) and are always provided.
49+
// dispatch_context_message uses only the internal struct definition (table.h)
50+
// and is always provided.
5051
void dispatch_context_message(std::size_t context_ptr, std::uint32_t level,
5152
bool has_source, rust::Str source,
5253
MessagePosition position, rust::Str message) {
@@ -67,6 +68,19 @@ void dispatch_context_message(std::size_t context_ptr, std::uint32_t level,
6768
ToSpvPosition(position), message_storage.c_str());
6869
}
6970

71+
// assemble_text_with_context needs different implementations:
72+
// - In standalone Rust builds: call through to C++ SPIRV-Tools assembler
73+
// - In CMake builds (SPIRV_RUST_TARGET_ENV): Rust should use its native
74+
// assembler, so this returns failure to signal the C++ path is unavailable
75+
#ifdef SPIRV_RUST_TARGET_ENV
76+
AssembleResult assemble_text_with_context(std::size_t, rust::Slice<const std::uint8_t>,
77+
std::uint32_t) {
78+
// In CMake builds with Rust target env, the Rust side should use its native
79+
// assembler instead of calling back into C++. Return failure to signal this.
80+
AssembleResult result{false, ::rust::Vec<std::uint32_t>()};
81+
return result;
82+
}
83+
#else
7084
AssembleResult assemble_text_with_context(std::size_t context_ptr,
7185
rust::Slice<const std::uint8_t> text,
7286
std::uint32_t options) {
@@ -97,6 +111,7 @@ AssembleResult assemble_text_with_context(std::size_t context_ptr,
97111

98112
return result;
99113
}
114+
#endif
100115

101116
ValidateResult validate_binary_with_options(
102117
std::uint32_t env, rust::Slice<const std::uint32_t> words,

0 commit comments

Comments
 (0)