Skip to content

Commit 1899a1d

Browse files
authored
gen-guest-c: Print private types to the .c file (#448)
Print private types to the .c file instead of the .h file.
1 parent 23bce90 commit 1899a1d

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

crates/gen-guest-c/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ impl WorldGenerator for C {
222222
if c_str.len() > 0 {
223223
c_str.push_str("\n");
224224
}
225+
c_str.push_str(&self.src.c_defs);
225226
c_str.push_str(&self.src.c_fns);
226227

227228
if self.needs_string {
@@ -848,8 +849,10 @@ impl InterfaceGenerator<'_> {
848849
for id in self.iface.topological_types() {
849850
if let Some(ty) = self.types.get(&id) {
850851
if private_types.contains(&id) {
851-
self.src.h_defs(ty);
852+
// It's private; print it in the .c file.
853+
self.src.c_defs(ty);
852854
} else {
855+
// It's public; print it in the .h file.
853856
self.src.h_defs(ty);
854857
self.print_dtor(id);
855858
}
@@ -2325,6 +2328,7 @@ enum SourceType {
23252328
HDefs,
23262329
HFns,
23272330
HHelpers,
2331+
// CDefs,
23282332
// CFns,
23292333
// CHelpers,
23302334
// CAdapters,
@@ -2335,6 +2339,7 @@ struct Source {
23352339
h_defs: wit_bindgen_core::Source,
23362340
h_fns: wit_bindgen_core::Source,
23372341
h_helpers: wit_bindgen_core::Source,
2342+
c_defs: wit_bindgen_core::Source,
23382343
c_fns: wit_bindgen_core::Source,
23392344
c_helpers: wit_bindgen_core::Source,
23402345
c_adapters: wit_bindgen_core::Source,
@@ -2346,6 +2351,7 @@ impl Source {
23462351
SourceType::HDefs => self.h_defs(s),
23472352
SourceType::HFns => self.h_fns(s),
23482353
SourceType::HHelpers => self.h_helpers(s),
2354+
// SourceType::CDefs => self.c_defs(s),
23492355
// SourceType::CFns => self.c_fns(s),
23502356
// SourceType::CHelpers => self.c_helpers(s),
23512357
// SourceType::CAdapters => self.c_adapters(s),
@@ -2355,6 +2361,7 @@ impl Source {
23552361
self.h_defs.push_str(&append_src.h_defs);
23562362
self.h_fns.push_str(&append_src.h_fns);
23572363
self.h_helpers.push_str(&append_src.h_helpers);
2364+
self.c_defs.push_str(&append_src.c_defs);
23582365
self.c_fns.push_str(&append_src.c_fns);
23592366
self.c_helpers.push_str(&append_src.c_helpers);
23602367
self.c_adapters.push_str(&append_src.c_adapters);
@@ -2368,6 +2375,9 @@ impl Source {
23682375
fn h_helpers(&mut self, s: &str) {
23692376
self.h_helpers.push_str(s);
23702377
}
2378+
fn c_defs(&mut self, s: &str) {
2379+
self.c_defs.push_str(s);
2380+
}
23712381
fn c_fns(&mut self, s: &str) {
23722382
self.c_fns.push_str(s);
23732383
}

0 commit comments

Comments
 (0)