Skip to content

Commit 4a3163d

Browse files
authored
fix(go): do not generate component type object file from C (#770)
We don't want to generate the C object file because 1. we aren't even using it in Go / TinyGo 2. we don't want to check in an opaque C object file for where we check in the generated code Signed-off-by: Jiaxiao Zhou (Mossaka) <[email protected]>
1 parent 6d6c315 commit 4a3163d

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

crates/c/src/lib.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ pub struct Opts {
4949
// Skip optional null pointer and boolean result argument signature flattening
5050
#[cfg_attr(feature = "clap", arg(long, default_value_t = false))]
5151
pub no_sig_flattening: bool,
52+
// Skip generating C object file
53+
#[cfg_attr(feature = "clap", arg(long, default_value_t = false))]
54+
pub no_object_file: bool,
5255
}
5356

5457
impl Opts {
@@ -372,14 +375,16 @@ impl WorldGenerator for C {
372375
#endif"
373376
);
374377

375-
files.push(&format!("{snake}.c"), c_str.as_bytes());
376378
files.push(&format!("{snake}.h"), h_str.as_bytes());
377-
files.push(
378-
&format!("{snake}_component_type.o",),
379-
component_type_object::object(resolve, id, self.opts.string_encoding)
380-
.unwrap()
381-
.as_slice(),
382-
);
379+
files.push(&format!("{snake}.c"), c_str.as_bytes());
380+
if !self.opts.no_object_file {
381+
files.push(
382+
&format!("{snake}_component_type.o",),
383+
component_type_object::object(resolve, id, self.opts.string_encoding)
384+
.unwrap()
385+
.as_slice(),
386+
);
387+
}
383388
}
384389

385390
fn pre_export_interface(&mut self, resolve: &Resolve, _files: &mut Files) -> Result<()> {

crates/go/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ impl WorldGenerator for TinyGo {
346346

347347
let mut opts = wit_bindgen_c::Opts::default();
348348
opts.no_sig_flattening = true;
349+
opts.no_object_file = true;
349350
opts.build()
350351
.generate(resolve, id, files)
351352
.expect("C generator should be infallible")

0 commit comments

Comments
 (0)