Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ test/spec/static_tests.zig
.yarn
node_modules/
lib/
.zig-cache/
zig-pkg/
47 changes: 3 additions & 44 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// This file is generated by zbuild. Do not edit manually.

const std = @import("std");

pub fn build(b: *std.Build) void {
Expand All @@ -15,33 +13,12 @@ pub fn build(b: *std.Build) void {
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
module_napi.addIncludePath(b.path("include"));
module_napi.addImport("build_options", options_module_build_options);
b.modules.put(b.dupe("napi"), module_napi) catch @panic("OOM");

const module_example_hello_world = b.createModule(.{
.root_source_file = b.path("examples/hello_world/mod.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
b.modules.put(b.dupe("example_hello_world"), module_example_hello_world) catch @panic("OOM");

const lib_example_hello_world = b.addLibrary(.{
.name = "example_hello_world",
.root_module = module_example_hello_world,
.linkage = .dynamic,
});

lib_example_hello_world.linker_allow_shlib_undefined = true;
const install_lib_example_hello_world = b.addInstallArtifact(lib_example_hello_world, .{
.dest_sub_path = "example_hello_world.node",
});

const tls_install_lib_example_hello_world = b.step("build-lib:example_hello_world", "Install the example_hello_world library");
tls_install_lib_example_hello_world.dependOn(&install_lib_example_hello_world.step);
b.getInstallStep().dependOn(&install_lib_example_hello_world.step);

const module_example_type_tag = b.createModule(.{
.root_source_file = b.path("examples/type_tag/mod.zig"),
.target = target,
Expand Down Expand Up @@ -72,28 +49,12 @@ pub fn build(b: *std.Build) void {
.root_module = module_napi,
.filters = b.option([][]const u8, "napi.filters", "napi test filters") orelse &[_][]const u8{},
});
const install_test_napi = b.addInstallArtifact(test_napi, .{});
const tls_install_test_napi = b.step("build-test:napi", "Install the napi test");
tls_install_test_napi.dependOn(&install_test_napi.step);

const run_test_napi = b.addRunArtifact(test_napi);
const tls_run_test_napi = b.step("test:napi", "Run the napi test");
tls_run_test_napi.dependOn(&run_test_napi.step);
tls_run_test.dependOn(&run_test_napi.step);

const test_example_hello_world = b.addTest(.{
.name = "example_hello_world",
.root_module = module_example_hello_world,
.filters = b.option([][]const u8, "example_hello_world.filters", "example_hello_world test filters") orelse &[_][]const u8{},
});
const install_test_example_hello_world = b.addInstallArtifact(test_example_hello_world, .{});
const tls_install_test_example_hello_world = b.step("build-test:example_hello_world", "Install the example_hello_world test");
tls_install_test_example_hello_world.dependOn(&install_test_example_hello_world.step);

const run_test_example_hello_world = b.addRunArtifact(test_example_hello_world);
const tls_run_test_example_hello_world = b.step("test:example_hello_world", "Run the example_hello_world test");
tls_run_test_example_hello_world.dependOn(&run_test_example_hello_world.step);
tls_run_test.dependOn(&run_test_example_hello_world.step);
// TODO: example_hello_world needs std.time.Timer/sleep migration (moved to std.Io)

const test_example_type_tag = b.addTest(.{
.name = "example_type_tag",
Expand All @@ -111,7 +72,5 @@ pub fn build(b: *std.Build) void {

module_napi.addImport("build_options", options_module_build_options);

module_example_hello_world.addImport("napi", module_napi);

module_example_type_tag.addImport("napi", module_napi);
}
2 changes: 1 addition & 1 deletion src/AsyncContext.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const c = @import("c.zig");
const c = @import("c.zig").c;
const status = @import("status.zig");
const NapiError = @import("status.zig").NapiError;
const Value = @import("Value.zig");
Expand Down
2 changes: 1 addition & 1 deletion src/Deferred.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const c = @import("c.zig");
const c = @import("c.zig").c;
const status = @import("status.zig");
const NapiError = @import("status.zig").NapiError;
const Value = @import("Value.zig");
Expand Down
2 changes: 1 addition & 1 deletion src/Env.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const c = @import("c.zig");
const c = @import("c.zig").c;
const status = @import("status.zig");
const NapiError = status.NapiError;
const TypedarrayType = @import("value_types.zig").TypedarrayType;
Expand Down
2 changes: 1 addition & 1 deletion src/EscapableHandleScope.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const c = @import("c.zig");
const c = @import("c.zig").c;
const status = @import("status.zig");
const NapiError = @import("status.zig").NapiError;
const Value = @import("Value.zig");
Expand Down
2 changes: 1 addition & 1 deletion src/HandleScope.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const c = @import("c.zig");
const c = @import("c.zig").c;
const status = @import("status.zig");
const NapiError = @import("status.zig").NapiError;

Expand Down
2 changes: 1 addition & 1 deletion src/NodeVersion.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const c = @import("c.zig");
const c = @import("c.zig").c;

version: c.napi_node_version,

Expand Down
2 changes: 1 addition & 1 deletion src/Ref.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const c = @import("c.zig");
const c = @import("c.zig").c;
const status = @import("status.zig");
const NapiError = @import("status.zig").NapiError;
const Value = @import("Value.zig");
Expand Down
2 changes: 1 addition & 1 deletion src/Value.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const c = @import("c.zig");
const c = @import("c.zig").c;
const status = @import("status.zig");
const NapiError = @import("status.zig").NapiError;
const TypedarrayType = @import("value_types.zig").TypedarrayType;
Expand Down
2 changes: 1 addition & 1 deletion src/args.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const c = @import("c.zig");
const c = @import("c.zig").c;
const Value = @import("Value.zig");

pub fn tupleToRaw(args: anytype) [@typeInfo(@TypeOf(args)).@"struct".fields.len]c.napi_value {
Expand Down
4 changes: 2 additions & 2 deletions src/async_cleanup_hook.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const c = @import("c.zig");
const c = @import("c.zig").c;

pub fn AsyncCleanupHookCallback(comptime Data: type) type {
return *const fn (c.napi_async_cleanup_hook_handle, *Data) void;
Expand All @@ -10,7 +10,7 @@ pub fn wrapAsyncCleanupHook(
comptime cb: AsyncCleanupHookCallback(Data),
) c.napi_async_cleanup_hook {
const wrapper = struct {
fn f(handle: c.napi_async_cleanup_hook_handle, arg: ?*anyopaque) callconv(.C) void {
fn f(handle: c.napi_async_cleanup_hook_handle, arg: ?*anyopaque) callconv(.c) void {
if (arg == null) return;
cb(handle, @ptrCast(@alignCast(arg)));
}
Expand Down
6 changes: 3 additions & 3 deletions src/async_work.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const c = @import("c.zig");
const c = @import("c.zig").c;
const status = @import("status.zig");
const NapiError = @import("status.zig").NapiError;
const Env = @import("Env.zig");
Expand All @@ -18,7 +18,7 @@ pub fn wrapAsyncExecuteCallback(
pub fn f(
raw_env: c.napi_env,
raw_data: ?*anyopaque,
) callconv(.C) void {
) callconv(.c) void {
if (raw_data == null) return;
const env = Env{ .env = raw_env };
const data: *Data = @ptrCast(@alignCast(raw_data));
Expand All @@ -41,7 +41,7 @@ pub fn wrapAsyncCompleteCallback(
raw_env: c.napi_env,
raw_status: c.napi_status,
raw_data: ?*anyopaque,
) callconv(.C) void {
) callconv(.c) void {
if (raw_data == null) return;
const env = Env{ .env = raw_env };
const stat: Status = @enumFromInt(raw_status);
Expand Down
2 changes: 1 addition & 1 deletion src/c.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const napi_version = @import("build_options").napi_version;

pub usingnamespace @cImport({
pub const c = @cImport({
@cDefine("NAPI_VERSION", napi_version);
@cInclude("node_api.h");
});
4 changes: 2 additions & 2 deletions src/callback.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const c = @import("c.zig");
const c = @import("c.zig").c;
const status = @import("status.zig");
const Env = @import("Env.zig");
const CallbackInfo = @import("callback_info.zig").CallbackInfo;
Expand All @@ -18,7 +18,7 @@ pub fn wrapCallback(
pub fn f(
env: c.napi_env,
info: c.napi_callback_info,
) callconv(.C) c.napi_value {
) callconv(.c) c.napi_value {
const e = Env{ .env = env };
const cb_info = CallbackInfo(argc_cap).init(env, info) catch |err| {
e.throwError(@errorName(err), "CallbackInfo initialization failed") catch {};
Expand Down
2 changes: 1 addition & 1 deletion src/callback_info.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const c = @import("c.zig");
const c = @import("c.zig").c;
const status = @import("status.zig");
const NapiError = @import("status.zig").NapiError;
const Value = @import("Value.zig");
Expand Down
6 changes: 3 additions & 3 deletions src/cleanup_hook.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const c = @import("c.zig");
const c = @import("c.zig").c;

pub fn CleanupHookCallback(comptime Data: type) type {
return *const fn (*Data) void;
Expand All @@ -8,9 +8,9 @@ pub fn CleanupHookCallback(comptime Data: type) type {
pub fn wrapCleanupHook(
comptime Data: type,
comptime cb: CleanupHookCallback(Data),
) *const fn (?*anyopaque) callconv(.C) void {
) *const fn (?*anyopaque) callconv(.c) void {
const wrapper = struct {
fn f(arg: ?*anyopaque) callconv(.C) void {
fn f(arg: ?*anyopaque) callconv(.c) void {
if (arg == null) return;
cb(@ptrCast(@alignCast(arg)));
}
Expand Down
4 changes: 2 additions & 2 deletions src/finalize_callback.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const c = @import("c.zig");
const c = @import("c.zig").c;
const Env = @import("Env.zig");

pub fn FinalizeCallback(comptime Data: type) type {
Expand All @@ -15,7 +15,7 @@ pub fn wrapFinalizeCallback(
env: c.napi_env,
data: ?*anyopaque,
hint: ?*anyopaque,
) callconv(.C) void {
) callconv(.c) void {
if (data == null) return;
return finalize_cb(
Env{ .env = env },
Expand Down
4 changes: 2 additions & 2 deletions src/module.zig
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const c = @import("c.zig");
const c = @import("c.zig").c;
const Env = @import("Env.zig");
const Value = @import("Value.zig");

extern fn napi_register_module_v1(env: c.napi_env, module: c.napi_value) c.napi_status;

pub fn register(comptime f: fn (Env, Value) anyerror!void) void {
const wrapper = opaque {
fn napi_register_module_v1(env: c.napi_env, module: c.napi_value) callconv(.C) c.napi_value {
fn napi_register_module_v1(env: c.napi_env, module: c.napi_value) callconv(.c) c.napi_value {
const e = Env{
.env = env,
};
Expand Down
2 changes: 1 addition & 1 deletion src/root.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");

pub const c = @import("c.zig");
pub const c = @import("c.zig").c;
pub const AsyncContext = @import("AsyncContext.zig");
pub const Env = @import("Env.zig");
pub const Value = @import("Value.zig");
Expand Down
2 changes: 1 addition & 1 deletion src/status.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const c = @import("c.zig");
const c = @import("c.zig").c;

/// https://nodejs.org/api/n-api.html#napi_status
pub const Status = enum(c.napi_status) {
Expand Down
6 changes: 3 additions & 3 deletions src/threadsafe_function.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const c = @import("c.zig");
const c = @import("c.zig").c;
const status = @import("status.zig");
const NapiError = status.NapiError;
const Env = @import("Env.zig");
Expand Down Expand Up @@ -30,7 +30,7 @@ pub fn wrapCallJsCallback(
raw_js_callback: c.napi_value,
raw_context: ?*anyopaque,
raw_data: ?*anyopaque,
) callconv(.C) void {
) callconv(.c) void {
// If raw_env is null, the TSFN is being torn down.
if (raw_env == null) return;
// Context should be present if we customized it
Expand Down Expand Up @@ -58,7 +58,7 @@ pub fn wrapFinalizeCallback(
raw_env: c.napi_env,
raw_data: ?*anyopaque,
hint: ?*anyopaque,
) callconv(.C) void {
) callconv(.c) void {
_ = hint;
if (raw_data == null and Context != void) return;
const env = Env{ .env = raw_env };
Expand Down
2 changes: 1 addition & 1 deletion src/value_types.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const c = @import("c.zig");
const c = @import("c.zig").c;

/// https://nodejs.org/api/n-api.html#napi_key_collection_mode
pub const KeyCollectionMode = enum(c.napi_key_collection_mode) {
Expand Down