Skip to content

Commit f2b9dc5

Browse files
LegNeatoclaude
andcommitted
Move assemble_text_with_context to context_bridge.cc to fix link order
The function was defined in source/text.cpp (guarded by SPIRV_RUST_TARGET_ENV) and called by lib.rs.cc in spirv-tools-ffi. This created a circular link dependency: spirv-tools-ffi needed the symbol from SPIRV-Tools, but SPIRV-Tools linked spirv-tools-ffi. On Linux, the single-pass linker couldn't resolve this. Fix by moving the function to context_bridge.cc (part of spirv-tools-ffi) and using the public API spvTextToBinaryWithOptions instead of the internal AssembleTextWithDiagnostics function. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b711a24 commit f2b9dc5

2 files changed

Lines changed: 31 additions & 37 deletions

File tree

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,37 @@ void dispatch_context_message(std::uintptr_t context_ptr, std::uint32_t level,
6363
ToSpvPosition(position), message_storage.c_str());
6464
}
6565

66+
AssembleResult assemble_text_with_context(std::size_t context_ptr,
67+
rust::Slice<const std::uint8_t> text,
68+
std::uint32_t options) {
69+
AssembleResult result{false, ::rust::Vec<std::uint32_t>()};
70+
auto* context = reinterpret_cast<spv_context>(context_ptr);
71+
if (context == nullptr) {
72+
return result;
73+
}
74+
75+
spv_binary binary = nullptr;
76+
spv_diagnostic diagnostic = nullptr;
77+
const char* text_ptr = reinterpret_cast<const char*>(text.data());
78+
const spv_result_t status =
79+
spvTextToBinaryWithOptions(context, text_ptr, text.size(), options,
80+
&binary, &diagnostic);
81+
if (diagnostic) {
82+
spvDiagnosticDestroy(diagnostic);
83+
}
84+
85+
if (status == SPV_SUCCESS && binary != nullptr) {
86+
result.success = true;
87+
result.binary.reserve(binary->wordCount);
88+
for (size_t i = 0; i < binary->wordCount; ++i) {
89+
result.binary.push_back(binary->code[i]);
90+
}
91+
spvBinaryDestroy(binary);
92+
}
93+
94+
return result;
95+
}
96+
6697
ValidateResult validate_binary_with_options(
6798
std::uint32_t env, rust::Slice<const std::uint32_t> words,
6899
const ValidatorOptions& options) {

source/text.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,43 +1071,6 @@ spv_result_t spvTextToBinaryWithOptions(const spv_const_context context,
10711071
sanitized_options, pBinary, pDiagnostic);
10721072
}
10731073

1074-
#if defined(SPIRV_RUST_TARGET_ENV)
1075-
namespace spvtools::ffi {
1076-
1077-
AssembleResult assemble_text_with_context(std::size_t context_ptr,
1078-
::rust::Slice<const std::uint8_t> text,
1079-
std::uint32_t options) {
1080-
AssembleResult result{
1081-
/*success=*/false,
1082-
/*binary=*/{}};
1083-
1084-
if (context_ptr == 0 || text.data() == nullptr) {
1085-
return result;
1086-
}
1087-
1088-
auto* context = reinterpret_cast<spv_const_context>(context_ptr);
1089-
if (!context) {
1090-
return result;
1091-
}
1092-
1093-
spv_binary binary = nullptr;
1094-
spv_result_t status = AssembleTextWithDiagnostics(
1095-
context, reinterpret_cast<const char*>(text.data()), text.size(), options,
1096-
&binary, nullptr);
1097-
if (status == SPV_SUCCESS && binary != nullptr) {
1098-
result.success = true;
1099-
result.binary.reserve(binary->wordCount);
1100-
for (std::size_t i = 0; i < binary->wordCount; ++i) {
1101-
result.binary.push_back(binary->code[i]);
1102-
}
1103-
}
1104-
spvBinaryDestroy(binary);
1105-
return result;
1106-
}
1107-
1108-
} // namespace spvtools::ffi
1109-
#endif
1110-
11111074
void spvTextDestroy(spv_text text) {
11121075
if (text) {
11131076
if (text->str) delete[] text->str;

0 commit comments

Comments
 (0)