Skip to content

Commit 16a19a6

Browse files
Smoke test
1 parent e3b265d commit 16a19a6

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

crates/c-api/include/wasmtime/wasi.hh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ public:
102102
return wasi_config_preopen_dir(ptr.get(), path.c_str(), guest_path.c_str(),
103103
dir_perms, file_perms);
104104
}
105+
106+
/// \brief Returns the underlying C API pointer.
107+
[[nodiscard]] wasi_config_t *capi() { return ptr.get(); }
105108
};
106109

107110
} // namespace wasmtime

crates/c-api/tests/wasip2.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <gtest/gtest.h>
2+
#include <string_view>
23
#include <wasmtime/component.hh>
34
#include <wasmtime/store.hh>
45

@@ -20,6 +21,22 @@ TEST(wasip2, smoke) {
2021
auto context = store.context();
2122

2223
wasmtime::WasiConfig config;
24+
25+
wasi_config_set_stdout_custom(
26+
config.capi(),
27+
[](void *, const unsigned char *buf, size_t len) -> ptrdiff_t {
28+
std::cout << std::string_view{(const char *)(buf), len};
29+
return len;
30+
},
31+
nullptr, nullptr);
32+
wasi_config_set_stderr_custom(
33+
config.capi(),
34+
[](void *, const unsigned char *buf, size_t len) -> ptrdiff_t {
35+
std::cerr << std::string_view{(const char *)(buf), len};
36+
return len;
37+
},
38+
nullptr, nullptr);
39+
2340
context.set_wasi(std::move(config)).unwrap();
2441
Component component = Component::compile(engine, component_text).unwrap();
2542

0 commit comments

Comments
 (0)