MCPcopy Create free account
hub / github.com/bytecodealliance/wit-bindgen / finish

Method finish

crates/cpp/src/lib.rs:667–774  ·  view source on GitHub ↗
(
        &mut self,
        resolve: &Resolve,
        world_id: WorldId,
        files: &mut Files,
    )

Source from the content-addressed store, hash-verified

665 }
666
667 fn finish(
668 &mut self,
669 resolve: &Resolve,
670 world_id: WorldId,
671 files: &mut Files,
672 ) -> std::result::Result<(), anyhow::Error> {
673 let world = &resolve.worlds[world_id];
674 let snake = world.name.to_snake_case();
675 let linking_symbol = wit_bindgen_c::component_type_object::linking_symbol(&world.name);
676
677 let mut h_str = SourceWithState::default();
678 let mut c_str = SourceWithState::default();
679
680 let version = env!("CARGO_PKG_VERSION");
681 uwriteln!(
682 h_str.src,
683 "// Generated by `wit-bindgen` {version}. DO NOT EDIT!"
684 );
685
686 uwrite!(
687 h_str.src,
688 "#ifndef __CPP_GUEST_BINDINGS_{0}_H
689 #define __CPP_GUEST_BINDINGS_{0}_H\n",
690 world.name.to_shouty_snake_case(),
691 );
692 self.finish_includes();
693
694 for include in self.includes.iter() {
695 uwriteln!(h_str.src, "#include {include}");
696 }
697
698 uwriteln!(
699 c_str.src,
700 "// Generated by `wit-bindgen` {version}. DO NOT EDIT!"
701 );
702 uwriteln!(
703 c_str.src,
704 "\n// Ensure that the *_component_type.o object is linked in"
705 );
706 uwrite!(
707 c_str.src,
708 "#ifdef __wasm32__
709 extern \"C\" void {linking_symbol}(void);
710 __attribute__((used))
711 void {linking_symbol}_public_use_in_this_compilation_unit(void) {{
712 {linking_symbol}();
713 }}
714 #endif
715 ",
716 );
717 if self.dependencies.needs_assert {
718 uwriteln!(c_str.src, "#include <assert.h>");
719 }
720
721 h_str.change_namespace(&Vec::default());
722
723 self.c_src.change_namespace(&Vec::default());
724 c_str.src.push_str(&self.c_src_head);

Callers

nothing calls this directly

Calls 9

linking_symbolFunction · 0.85
objectFunction · 0.85
finish_includesMethod · 0.80
change_namespaceMethod · 0.80
as_mut_stringMethod · 0.80
joinMethod · 0.80
iterMethod · 0.45
push_strMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected