1 #include <gtest/gtest.h>
2 #include <wasmtime/component.hh>
3 #include <wasmtime/module.hh>
4 #include <wasmtime/store.hh>
5 
6 using namespace wasmtime::component;
7 
8 TEST(component, define_module) {
9   static constexpr auto module_wat = std::string_view{
10       R"END(
11 (module
12     (func $function (param $x i32) (result i32)
13         local.get $x)
14     (export "function" (func $function))
15 )
16       )END",
17   };
18 
19   static constexpr auto component_text = std::string_view{
20       R"END(
21 (component
22     (import "x:y/z" (instance
23         (export "mod" (core module
24             (export "function" (func (param i32) (result i32)))
25         ))
26     ))
27 )
28       )END",
29   };
30 
31   wasmtime::Engine engine;
32   wasmtime::Module module =
33       wasmtime::Module::compile(engine, module_wat).unwrap();
34   wasmtime::Store store(engine);
35   auto context = store.context();
36 
37   Component component = Component::compile(engine, component_text).unwrap();
38   Linker linker(engine);
39 
40   {
41     auto root = linker.root();
42     auto xyz = root.add_instance("x:y/z").unwrap();
43     xyz.add_module("mod", module).unwrap();
44   }
45 
46   linker.instantiate(context, component).unwrap();
47 }
48