Skip to content

Commit 542d668

Browse files
Validate that C ABI in CMakeLists.txt matches code.
1 parent 45a36ad commit 542d668

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,10 @@ if (SPIRV_CROSS_CLI)
431431
target_compile_options(spirv-cross-c-api-test PRIVATE -std=c89 -Wall -Wextra)
432432
endif()
433433
add_test(NAME spirv-cross-c-api-test
434-
COMMAND $<TARGET_FILE:spirv-cross-c-api-test> ${CMAKE_CURRENT_SOURCE_DIR}/tests-other/c_api_test.spv)
434+
COMMAND $<TARGET_FILE:spirv-cross-c-api-test> ${CMAKE_CURRENT_SOURCE_DIR}/tests-other/c_api_test.spv
435+
${spirv-cross-abi-major}
436+
${spirv-cross-abi-minor}
437+
${spirv-cross-abi-patch})
435438
add_test(NAME spirv-cross-small-vector-test
436439
COMMAND $<TARGET_FILE:spirv-cross-small-vector-test>)
437440
add_test(NAME spirv-cross-test

tests-other/c_api_test.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,32 @@ int main(int argc, char **argv)
116116
SpvId *buffer = NULL;
117117
size_t word_count = 0;
118118

119-
if (argc != 2)
119+
if (argc != 5)
120120
return 1;
121121

122122
if (read_file(argv[1], &buffer, &word_count) < 0)
123123
return 1;
124124

125+
unsigned abi_major, abi_minor, abi_patch;
126+
spvc_get_version(&abi_major, &abi_minor, &abi_patch);
127+
if (abi_major != strtoul(argv[2], NULL, 0))
128+
{
129+
fprintf(stderr, "VERSION_MAJOR mismatch!\n");
130+
return 1;
131+
}
132+
133+
if (abi_minor != strtoul(argv[3], NULL, 0))
134+
{
135+
fprintf(stderr, "VERSION_MINOR mismatch!\n");
136+
return 1;
137+
}
138+
139+
if (abi_patch != strtoul(argv[4], NULL, 0))
140+
{
141+
fprintf(stderr, "VERSION_PATCH mismatch!\n");
142+
return 1;
143+
}
144+
125145
SPVC_CHECKED_CALL(spvc_context_create(&context));
126146
spvc_context_set_error_callback(context, error_callback, NULL);
127147
SPVC_CHECKED_CALL(spvc_context_parse_spirv(context, buffer, word_count, &ir));

0 commit comments

Comments
 (0)