Skip to content

Commit b44f9f6

Browse files
committed
wasm: remove deprecated wasi APIs
1 parent 9184e28 commit b44f9f6

File tree

2 files changed

+13
-92
lines changed

2 files changed

+13
-92
lines changed

src/wasm.zig

Lines changed: 8 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,6 @@ pub const Module = opaque {
7373
var byte_vec = ByteVec.initWithCapacity(bytes.len);
7474
defer byte_vec.deinit();
7575

76-
// var i: usize = 0;
77-
// var ptr = byte_vec.data;
78-
// while (i < bytes.len) : (i += 1) {
79-
// ptr.* = bytes[i];
80-
// ptr += 1;
81-
// }
82-
// TODO: remove it
83-
8476
var ptr = byte_vec.data;
8577
var i: usize = 0;
8678
while (i < bytes.len) : (i += 1) {
@@ -109,7 +101,7 @@ pub const Module = opaque {
109101
fn cb(params: ?*const Valtype, results: ?*Valtype) callconv(.C) ?*Trap {
110102
_ = params;
111103
_ = results;
112-
const func = @as(fn () void, @ptrFromInt(CALLBACK));
104+
const func = @as(*const fn () void, @ptrFromInt(CALLBACK));
113105
func();
114106
return null;
115107
}
@@ -135,13 +127,16 @@ pub const Func = opaque {
135127
const cb_meta = @typeInfo(@TypeOf(callback));
136128
switch (cb_meta) {
137129
.Fn => {
138-
if (cb_meta.Fn.args.len > 0 or cb_meta.Fn.return_type.? != void) {
130+
if (cb_meta.Fn.params.len > 0 or cb_meta.Fn.return_type.? != void) {
139131
@compileError("only callbacks with no input args and no results are currently supported");
140132
}
141133
},
142134
else => @compileError("only functions can be used as callbacks into Wasm"),
143135
}
144-
CALLBACK = @intFromPtr(callback);
136+
137+
const func_ptr: *const fn () void = @ptrCast(&callback);
138+
139+
CALLBACK = @intFromPtr(func_ptr);
145140

146141
var args = ValtypeVec.empty();
147142
var results = ValtypeVec.empty();
@@ -296,7 +291,7 @@ pub const Func = opaque {
296291
wasm_func_delete(self);
297292
}
298293

299-
/// Returns tue if the given `kind` of `Valkind` can coerce to type `T`
294+
/// Returns true if the given `kind` of `Valkind` can coerce to type `T`
300295
pub fn matchesKind(comptime T: type, kind: Valkind) bool {
301296
return switch (T) {
302297
i32, u32 => kind == .i32,
@@ -309,7 +304,7 @@ pub const Func = opaque {
309304
};
310305
}
311306

312-
extern "c" fn wasm_func_new(*Store, ?*anyopaque, Callback) ?*Func;
307+
extern "c" fn wasm_func_new(*Store, ?*anyopaque, *const Callback) ?*Func;
313308
extern "c" fn wasm_func_delete(*Func) void;
314309
extern "c" fn wasm_func_as_extern(*Func) ?*Extern;
315310
extern "c" fn wasm_func_copy(*const Func) ?*Func;
@@ -327,13 +322,6 @@ pub const Instance = opaque {
327322
var imports = ExternVec.initWithCapacity(import.len);
328323
defer imports.deinit();
329324

330-
// var ptr = imports.data;
331-
// for (import) |func| {
332-
// ptr.* = func.asExtern();
333-
// ptr += 1;
334-
// }
335-
// TODO: remove it
336-
337325
var ptr = imports.data;
338326
var i: usize = 0;
339327
while (i < import.len) : (i += 1) {
@@ -795,78 +783,6 @@ pub const ValVec = extern struct {
795783
pub extern "c" fn wasm_functype_new(args: *ValtypeVec, results: *ValtypeVec) ?*anyopaque;
796784
pub extern "c" fn wasm_functype_delete(functype: *anyopaque) void;
797785

798-
pub const WasiConfig = opaque {
799-
/// Options to inherit when inherriting configs
800-
/// By default all is `true` as you often want to
801-
/// inherit everything rather than something specifically.
802-
const InheritOptions = struct {
803-
argv: bool = true,
804-
env: bool = true,
805-
std_in: bool = true,
806-
std_out: bool = true,
807-
std_err: bool = true,
808-
};
809-
810-
pub fn init() !*WasiConfig {
811-
return wasi_config_new() orelse error.ConfigInit;
812-
}
813-
814-
pub fn deinit(self: *WasiConfig) void {
815-
wasi_config_delete(self);
816-
}
817-
818-
/// Allows to inherit the native environment into the current config.
819-
/// Inherits everything by default.
820-
pub fn inherit(self: *WasiConfig, options: InheritOptions) void {
821-
if (options.argv) self.inheritArgv();
822-
if (options.env) self.inheritEnv();
823-
if (options.std_in) self.inheritStdIn();
824-
if (options.std_out) self.inheritStdOut();
825-
if (options.std_err) self.inheritStdErr();
826-
}
827-
828-
pub fn inheritArgv(self: *WasiConfig) void {
829-
wasi_config_inherit_argv(self);
830-
}
831-
832-
pub fn inheritEnv(self: *WasiConfig) void {
833-
wasi_config_inherit_env(self);
834-
}
835-
836-
pub fn inheritStdIn(self: *WasiConfig) void {
837-
wasi_config_inherit_stdin(self);
838-
}
839-
840-
pub fn inheritStdOut(self: *WasiConfig) void {
841-
wasi_config_inherit_stdout(self);
842-
}
843-
844-
pub fn inheritStdErr(self: *WasiConfig) void {
845-
wasi_config_inherit_stderr(self);
846-
}
847-
848-
extern "c" fn wasi_config_new() ?*WasiConfig;
849-
extern "c" fn wasi_config_delete(?*WasiConfig) void;
850-
extern "c" fn wasi_config_inherit_argv(?*WasiConfig) void;
851-
extern "c" fn wasi_config_inherit_env(?*WasiConfig) void;
852-
extern "c" fn wasi_config_inherit_stdin(?*WasiConfig) void;
853-
extern "c" fn wasi_config_inherit_stdout(?*WasiConfig) void;
854-
extern "c" fn wasi_config_inherit_stderr(?*WasiConfig) void;
855-
};
856-
857-
pub const WasiInstance = opaque {
858-
pub fn init(store: *Store, name: [*:0]const u8, config: ?*WasiConfig, trap: *?*Trap) !*WasiInstance {
859-
return wasi_instance_new(store, name, config, trap) orelse error.InstanceInit;
860-
}
861-
862-
pub fn deinit(self: *WasiInstance) void {
863-
wasm_instance_delete(self);
864-
}
865-
866-
extern "c" fn wasi_instance_new(?*Store, [*:0]const u8, ?*WasiConfig, *?*Trap) ?*WasiInstance;
867-
extern "c" fn wasm_instance_delete(?*WasiInstance) void;
868-
};
869-
870786
test "run_tests" {
871787
testing.refAllDecls(@This());
872788
}

src/wasmer.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const std = @import("std");
22
const builtin = @import("builtin");
33
pub const wasm = @import("./wasm.zig");
4+
pub const wasi = @import("./wasi.zig");
45

56
// Re-exports
67
pub const ByteVec = wasm.ByteVec;
@@ -10,6 +11,10 @@ pub const Module = wasm.Module;
1011
pub const Instance = wasm.Instance;
1112
pub const Extern = wasm.Extern;
1213
pub const Func = wasm.Func;
14+
pub const Memory = wasm.Memory;
15+
pub const MemoryType = wasm.MemoryType;
16+
pub const Limits = wasm.Limits;
17+
pub const WasiConfig = wasi.WasiConfig;
1318

1419
const OS_PATH_MAX: usize = switch (builtin.os.tag) {
1520
.windows => std.os.windows.MAX_PATH,

0 commit comments

Comments
 (0)