Path: blob/main/crates/c-api/tests/component/define_module.cc
3069 views
#include <gtest/gtest.h>1#include <wasmtime/component.hh>2#include <wasmtime/module.hh>3#include <wasmtime/store.hh>45using namespace wasmtime::component;67TEST(component, define_module) {8static constexpr auto module_wat = std::string_view{9R"END(10(module11(func $function (param $x i32) (result i32)12local.get $x)13(export "function" (func $function))14)15)END",16};1718static constexpr auto component_text = std::string_view{19R"END(20(component21(import "x:y/z" (instance22(export "mod" (core module23(export "function" (func (param i32) (result i32)))24))25))26)27)END",28};2930wasmtime::Engine engine;31wasmtime::Module module =32wasmtime::Module::compile(engine, module_wat).unwrap();33wasmtime::Store store(engine);34auto context = store.context();3536Component component = Component::compile(engine, component_text).unwrap();37Linker linker(engine);3839{40auto root = linker.root();41auto xyz = root.add_instance("x:y/z").unwrap();42xyz.add_module("mod", module).unwrap();43}4445linker.instantiate(context, component).unwrap();46}474849