Skip to content

Commit 63ccd87

Browse files
committed
WIP
1 parent 0b9ebc6 commit 63ccd87

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

samples/wamr/generated/sample_wamr.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef GENERATED_WAMR_BINDINGS_HPP
2-
#define GENERATED_WAMR_BINDINGS_HPP
1+
#ifndef GENERATED_SAMPLE_WAMR_HPP_HPP
2+
#define GENERATED_SAMPLE_WAMR_HPP_HPP
33

44
// Generated WAMR helper functions for package: example:sample
55
// This header provides utility functions for initializing and using WAMR with Component Model bindings
@@ -150,4 +150,4 @@ inline auto option_func(const wasm_module_inst_t& module_inst, const wasm_exec_e
150150

151151
} // namespace guest_wrappers
152152

153-
#endif // GENERATED_WAMR_BINDINGS_HPP
153+
#endif // GENERATED_SAMPLE_WAMR_HPP_HPP

tools/wit-codegen/code_generator.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ void CodeGenerator::generateHeader(const std::vector<InterfaceInfo> &interfaces,
2121
throw std::runtime_error("Cannot create header file: " + filename);
2222
}
2323

24-
// Generate header guard
25-
std::string guard = "GENERATED_" + sanitize_identifier(filename) + "_HPP";
24+
// Generate header guard using just the filename (not full path)
25+
std::filesystem::path filepath(filename);
26+
std::string guard = "GENERATED_" + sanitize_identifier(filepath.filename().string()) + "_HPP";
2627
std::transform(guard.begin(), guard.end(), guard.begin(), ::toupper);
2728

2829
out << "#pragma once\n\n";
@@ -893,8 +894,10 @@ void CodeGenerator::generateWAMRHeader(const std::vector<InterfaceInfo> &interfa
893894
throw std::runtime_error("Cannot create WAMR header file: " + filename);
894895
}
895896

896-
// Header guard
897-
std::string guard = "GENERATED_WAMR_BINDINGS_HPP";
897+
// Header guard using just the filename (not full path)
898+
std::filesystem::path filepath(filename);
899+
std::string guard = "GENERATED_" + sanitize_identifier(filepath.filename().string()) + "_HPP";
900+
std::transform(guard.begin(), guard.end(), guard.begin(), ::toupper);
898901
out << "#ifndef " << guard << "\n";
899902
out << "#define " << guard << "\n\n";
900903

@@ -1871,8 +1874,7 @@ void CodeGenerator::generateExternalPackageStubs(std::ofstream &out,
18711874
auto *iface_ptr = package->get_interface(iface_name);
18721875
if (!iface_ptr)
18731876
{
1874-
out << " // Interface not found: " << iface_name << "\n";
1875-
continue;
1877+
throw std::runtime_error("Interface '" + iface_name + "' not found in package '" + package_spec + "'");
18761878
}
18771879

18781880
out << " namespace " << sanitize_identifier(iface_name) << " {\n";

tools/wit-codegen/package_registry.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,11 @@ bool PackageRegistry::load_package(const std::filesystem::path &path)
124124
// Parse the WIT file
125125
auto parse_result = WitGrammarParser::parse(path.string());
126126

127-
// Skip if no package name defined
127+
// Skip if no package name defined (these are interface-only files that will be
128+
// loaded as part of their parent package)
128129
if (parse_result.packageName.empty())
129130
{
130-
return false;
131+
return true; // Not an error - just skip interface-only files
131132
}
132133

133134
// Parse package ID from package name

tools/wit-codegen/wit-codegen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ int main(int argc, char *argv[])
105105
std::cout << "Loading dependency: " << dep_file << "\n";
106106
if (!registry.load_package(dep_file))
107107
{
108-
std::cerr << "Warning: Failed to load dependency: " << dep_file << "\n";
108+
throw std::runtime_error("Failed to load dependency: " + dep_file.string());
109109
}
110110
}
111111
}
@@ -163,7 +163,7 @@ int main(int argc, char *argv[])
163163
std::cout << "Loading dependency: " << dep_file << "\n";
164164
if (!registry.load_package(dep_file))
165165
{
166-
std::cerr << "Warning: Failed to load dependency: " << dep_file << "\n";
166+
throw std::runtime_error("Failed to load dependency: " + dep_file.string());
167167
}
168168
}
169169
}

0 commit comments

Comments
 (0)