Skip to content

Commit bc4dbb0

Browse files
committed
fix: ensure wit-bindge test suite compiles
Signed-off-by Gordon Smith <GordonJSmith@gmail.com>
1 parent 3934d24 commit bc4dbb0

18 files changed

Lines changed: 1891 additions & 75 deletions

samples/wamr/generated/sample_wamr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// Generated WAMR bindings for package: example:sample
77
// These symbol arrays can be used with wasm_runtime_register_natives_raw()
8-
// NOTE: You must implement the functions declared in the imports namespace
8+
// NOTE: You must implement the functions declared in the host namespace
99
// (See sample.hpp for declarations, provide implementations in your host code)
1010

1111
using namespace cmcpp;

test/validate_all_wit_bindgen.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,23 @@ def generate_stub(wit_path, stub_name):
6767
except Exception as e:
6868
return False, str(e)
6969

70+
def check_if_empty_stub(stub_name):
71+
"""Check if generated stub only contains empty namespaces"""
72+
stub_file = GENERATED_DIR / f"{stub_name}.hpp"
73+
74+
try:
75+
with open(stub_file, 'r') as f:
76+
content = f.read()
77+
# Check for the marker comment that indicates empty interfaces
78+
if "This WIT file contains no concrete interface definitions" in content:
79+
# Also verify it only has empty namespaces
80+
if "namespace host {}" in content and "namespace guest {}" in content:
81+
return True
82+
except Exception:
83+
pass
84+
85+
return False
86+
7087
def compile_stub(stub_name):
7188
"""Compile a generated stub"""
7289
stub_file = GENERATED_DIR / f"{stub_name}.hpp"
@@ -107,6 +124,10 @@ def process_wit_file(wit_path):
107124
gen_ok, gen_error = generate_stub(wit_path, stub_name)
108125

109126
if gen_ok:
127+
# Check if this generated an empty stub (references external packages only)
128+
if check_if_empty_stub(stub_name):
129+
return rel_path, 'empty_stub', 'Generated empty stub (references external packages only)'
130+
110131
# Compile stub
111132
compile_ok, compile_error = compile_stub(stub_name)
112133

@@ -142,11 +163,13 @@ def main():
142163
'gen_success': 0,
143164
'gen_failed': 0,
144165
'compile_success': 0,
145-
'compile_failed': 0
166+
'compile_failed': 0,
167+
'empty_stubs': 0
146168
}
147169

148170
failed_generation = []
149171
failed_compilation = []
172+
empty_stub_files = []
150173

151174
# Process files in parallel
152175
with ThreadPoolExecutor(max_workers=num_workers) as executor:
@@ -163,6 +186,11 @@ def main():
163186
stats['gen_success'] += 1
164187
stats['compile_success'] += 1
165188
status = f"{GREEN}{RESET}"
189+
elif result == 'empty_stub':
190+
stats['gen_success'] += 1
191+
stats['empty_stubs'] += 1
192+
status = f"{YELLOW}{RESET}"
193+
empty_stub_files.append((rel_path, error))
166194
elif result == 'compile_failed':
167195
stats['gen_success'] += 1
168196
stats['compile_failed'] += 1
@@ -191,9 +219,18 @@ def main():
191219
print(f" Total WIT files: {stats['total']}")
192220
print(f" Generation successful: {stats['gen_success']} ({stats['gen_success']/stats['total']*100:.1f}%)")
193221
print(f" Generation failed: {stats['gen_failed']}")
222+
print(f" Empty stubs (no types): {stats['empty_stubs']}")
194223
print(f" Compilation successful: {stats['compile_success']} ({stats['compile_success']/stats['total']*100:.1f}%)")
195224
print(f" Compilation failed: {stats['compile_failed']}")
196225

226+
if empty_stub_files:
227+
print(f"\n{YELLOW}Empty stubs ({len(empty_stub_files)} files):{RESET}")
228+
print(f"These files only reference external packages and contain no concrete definitions:")
229+
for rel_path, reason in empty_stub_files[:10]:
230+
print(f" - {rel_path}")
231+
if len(empty_stub_files) > 10:
232+
print(f" ... and {len(empty_stub_files) - 10} more")
233+
197234
if failed_generation:
198235
print(f"\n{YELLOW}Failed generation ({len(failed_generation)} files):{RESET}")
199236
for rel_path, error in failed_generation[:10]: # Show first 10

tools/wit-codegen/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ add_executable(wit-codegen
4040
wit_parser.cpp
4141
code_generator.cpp
4242
type_mapper.cpp
43+
package_registry.cpp
44+
dependency_resolver.cpp
4345
${ANTLR_GENERATED_SOURCES}
4446
)
4547

0 commit comments

Comments
 (0)