Skip to content

Commit 313f23d

Browse files
authored
Test C/C++ headers can be included in isolation (#10694)
* Test C/C++ headers can be included in isolation I frequently make mistakes about this, so I figure it's good to at least try to test this. It's not possible to fully test AFAIK but this is hopefully at least something. * Fix header discovery location * Don't test `conf.h.in` * Try to fix windows CI
1 parent 2cd52b7 commit 313f23d

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

crates/c-api/include/wasmtime/error.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <memory>
99
#include <optional>
10+
#include <ostream>
1011
#include <string>
1112
#include <variant>
1213
#include <wasmtime/error.h>

crates/c-api/include/wasmtime/linker.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <wasmtime/conf.h>
1212
#include <wasmtime/error.h>
1313
#include <wasmtime/extern.h>
14+
#include <wasmtime/func.h>
15+
#include <wasmtime/instance.h>
1416
#include <wasmtime/store.h>
1517

1618
#ifdef __cplusplus

crates/c-api/include/wasmtime/profiling.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <wasm.h>
1111
#include <wasmtime/conf.h>
1212
#include <wasmtime/error.h>
13+
#include <wasmtime/module.h>
14+
#include <wasmtime/store.h>
1315

1416
#ifdef WASMTIME_FEATURE_PROFILING
1517

crates/c-api/include/wasmtime/span.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
#endif
1313

1414
#ifndef __cpp_lib_span
15+
#include <cstddef>
1516
#include <limits>
17+
#include <type_traits>
1618
#endif
1719

1820
namespace wasmtime {

crates/c-api/tests/CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,34 @@ add_capi_test(tests FILES
5050
linker.cc
5151
)
5252

53+
# Create a list of all wasmtime headers with `GLOB_RECURSE`, then emit a file
54+
# into the current binary directory which tests that if the header is included
55+
# that the file compiles correctly.
56+
#
57+
# Gather everything into a list and then create a test which links all these
58+
# compilations together. This binary doesn't actually run any tests itself but
59+
# it does test that all headers compile in isolation at least. Not perfect but
60+
# hopefully at least something.
61+
cmake_path(APPEND CMAKE_CURRENT_SOURCE_DIR "../include" OUTPUT_VARIABLE header_root)
62+
file(GLOB_RECURSE cpp_headers "${header_root}/*.h*")
63+
foreach(header IN LISTS cpp_headers)
64+
cmake_path(GET header EXTENSION header_extension)
65+
if(header_extension STREQUAL ".h.in")
66+
continue()
67+
endif()
68+
cmake_path(GET header FILENAME header_filename)
69+
cmake_path(APPEND CMAKE_CURRENT_BINARY_DIR "header-test" "${header_filename}.cc"
70+
OUTPUT_VARIABLE test_filename)
71+
list(APPEND header_tests ${test_filename})
72+
73+
cmake_path(
74+
RELATIVE_PATH header
75+
BASE_DIRECTORY ${header_root}
76+
OUTPUT_VARIABLE rel_header)
77+
file(WRITE ${test_filename} "#include <${rel_header}>")
78+
endforeach()
79+
add_capi_test(standalone-headers FILES ${header_tests})
80+
5381
# Add a custom test where two files include `wasmtime.hh` and are compiled into
5482
# the same executable (basically makes sure any defined functions in the header
5583
# are tagged with `inline`).

0 commit comments

Comments
 (0)