Skip to content

Commit f054e50

Browse files
authored
Merge pull request #7 from zig-wasm/fix-wasi-config
wasmer-zig-api v0.4.0
2 parents 346484c + 96b7d4f commit f054e50

4 files changed

Lines changed: 20 additions & 19 deletions

File tree

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ All WASI APIs are also implemented.
88

99
All tests from the "wasmer" lib C repository are also reimplemented on zig. You can learn more about the API of this module through rich examples.
1010

11-
The current module works with Zig 0.14.0+.
11+
The current module works with Zig 0.15.x.
1212

1313
## Wasmer C API test examples [WIP]
1414

@@ -41,25 +41,26 @@ zig build run -Dexamples=true
4141
In your zig project folder (where build.zig is located), run:
4242

4343
```bash
44-
zig fetch --save "git+https://github.com/Afirium/wasmer-zig-api#v0.3.0"
44+
zig fetch --save "git+https://github.com/Afirium/wasmer-zig-api#v0.4.0"
4545
```
4646

4747
Then, in your `build.zig`'s `build` function, add the following before
4848
`b.installArtifact(exe)`:
4949

5050
```zig
51-
const wasmerZigAPI= b.dependency("wasmer_zig_api", .{
52-
.target = target,
53-
.optimize = optimize,
54-
});
55-
exe.root_module.addImport("wasmer", wasmerZigAPI.module("wasmer"));
56-
exe.linkLibC();
57-
exe.addLibraryPath(.{ .cwd_relative = "/home/path_to_your_wasmer/.wasmer/lib" });
58-
exe.linkSystemLibrary("wasmer");
51+
const wasmer_zig_api = b.dependency("wasmer_zig_api", .{
52+
.target = target,
53+
.optimize = optimize,
54+
});
55+
56+
exe.root_module.addImport("wasmer", wasmer_zig_api.module("wasmer"));
57+
exe.root_module.link_libc = true;
58+
exe.root_module.addLibraryPath(.{ .cwd_relative = "/home/path_to_your_wasmer/.wasmer/lib" });
59+
exe.root_module.linkSystemLibrary("wasmer", .{});
5960
```
6061

6162
## Status
6263

63-
| Refname | Wasmer runtime version | Zig `0.12.x` | Zig `0.13.x` | Zig `0.14.x` | Zig `0.15.0-dev` |
64-
|:----------|:-----------------------|:------------:|:------------:|:------------:|:----------------:|
65-
| `v0.3.0` | `v4.0.0+`, `v5.0.0+` | ||| |
64+
| Refname | Wasmer runtime version | Zig `0.15.x` |
65+
|:----------|:-----------------------|:----------------:|
66+
| `v0.4.0` | `v4.0.0+`, `v5.0.0+` | |

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.{
22
.fingerprint = 0xadae4aecca466a13,
33
.name = .wasmer_zig_api,
4-
.version = "0.3.0",
4+
.version = "0.4.0",
55
.minimum_zig_version = "0.15.0",
66
.paths = .{
77
"build.zig",

examples/wasi.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn run() !void {
4444

4545
std.log.info("setting up WASI...", .{});
4646

47-
const wasi_config = try wasmer.WasiConfig.init();
47+
const wasi_config = try wasmer.WasiConfig.init("example_program");
4848

4949
const js_string =
5050
\\function greet(name) {

src/wasi.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ pub const WasiConfig = opaque {
2525
std_err: bool = true,
2626
};
2727

28-
/// Initialize a new WASI configuration
29-
pub fn init() !*WasiConfig {
30-
return wasi_config_new() orelse WasiError.ConfigInit;
28+
/// Initialize a new WASI configuration with a program name
29+
pub fn init(program_name: [:0]const u8) !*WasiConfig {
30+
return wasi_config_new(program_name.ptr) orelse WasiError.ConfigInit;
3131
}
3232

3333
/// Clean up WASI configuration
@@ -102,7 +102,7 @@ pub const WasiConfig = opaque {
102102
}
103103

104104
// External C function declarations
105-
extern "c" fn wasi_config_new() ?*WasiConfig;
105+
extern "c" fn wasi_config_new([*:0]const u8) ?*WasiConfig;
106106
extern "c" fn wasi_config_delete(?*WasiConfig) void;
107107
extern "c" fn wasi_config_inherit_argv(?*WasiConfig) void;
108108
extern "c" fn wasi_config_inherit_env(?*WasiConfig) void;

0 commit comments

Comments
 (0)