@pkmn/engine 0.1.0-dev.645b4750 → 0.1.0-dev.6ba42cd5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +12 -31
- package/build/pkg/addon/wasm.js.map +1 -1
- package/build/pkg/addon.d.ts +4 -4
- package/build/pkg/addon.js.map +1 -1
- package/build/tools/debug.js +19 -1
- package/build/tools/debug.js.map +1 -1
- package/build/tools/display/ui.jsx +1 -1
- package/build/tools/display/ui.jsx.map +1 -1
- package/build.zig +135 -225
- package/package.json +23 -21
- package/src/bin/install-pkmn-engine +22 -7
- package/src/lib/bindings/c.zig +27 -82
- package/src/lib/bindings/node.zig +7 -11
- package/src/lib/bindings/wasm.zig +6 -15
- package/src/lib/common/array.zig +5 -12
- package/src/lib/common/debug.zig +11 -21
- package/src/lib/common/js.zig +3 -9
- package/src/lib/common/optional.zig +11 -21
- package/src/lib/common/protocol.zig +176 -163
- package/src/lib/common/rational.zig +91 -173
- package/src/lib/common/util.zig +14 -46
- package/src/lib/gen1/calc.zig +46 -52
- package/src/lib/gen1/chance.zig +17 -32
- package/src/lib/gen1/data/types.zig +2 -2
- package/src/lib/gen1/data.zig +5 -5
- package/src/lib/gen1/helpers.zig +8 -10
- package/src/lib/gen1/mechanics.zig +23 -14
- package/src/lib/gen2/calc.zig +3 -6
- package/src/lib/gen2/chance.zig +12 -18
- package/src/lib/gen2/data/types.zig +6 -3
- package/src/lib/gen2/data.zig +8 -7
- package/src/lib/gen2/helpers.zig +4 -6
- package/src/lib/gen2/mechanics.zig +9 -9
- package/src/lib/napi.h +2 -0
- package/src/lib/node.zig +1 -5
- package/src/lib/pkmn.zig +91 -17
- package/src/lib/wasm.zig +2 -6
package/build.zig
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
const builtin = @import("builtin");
|
|
2
2
|
const std = @import("std");
|
|
3
3
|
|
|
4
|
+
fn ArrayList(comptime T: type) type {
|
|
5
|
+
return std.array_list.Aligned(T, null);
|
|
6
|
+
}
|
|
7
|
+
|
|
4
8
|
pub const Options = struct {
|
|
5
9
|
showdown: ?bool = null,
|
|
6
10
|
log: ?bool = null,
|
|
@@ -8,17 +12,6 @@ pub const Options = struct {
|
|
|
8
12
|
calc: ?bool = null,
|
|
9
13
|
};
|
|
10
14
|
|
|
11
|
-
const Step = if (@hasDecl(std.Build, "Step")) std.Build.Step else .{
|
|
12
|
-
.Compile = std.Build.CompileStep,
|
|
13
|
-
.Options = std.Build.OptionsStep,
|
|
14
|
-
.Run = std.Build.RunStep,
|
|
15
|
-
};
|
|
16
|
-
const has_path = @hasField(std.Build.LazyPath, "path");
|
|
17
|
-
const root_module = @hasField(Step.Compile, "root_module");
|
|
18
|
-
const force_pic = !@hasField(std.Build.SharedLibraryOptions, "pic");
|
|
19
|
-
const ResolvedTarget =
|
|
20
|
-
if (@hasDecl(std.Build, "ResolvedTarget")) std.Build.ResolvedTarget else std.zig.CrossTarget;
|
|
21
|
-
|
|
22
15
|
pub fn module(b: *std.Build, options: Options) *std.Build.Module {
|
|
23
16
|
const dirname = comptime std.fs.path.dirname(@src().file) orelse ".";
|
|
24
17
|
const build_options = b.addOptions();
|
|
@@ -29,27 +22,19 @@ pub fn module(b: *std.Build, options: Options) *std.Build.Module {
|
|
|
29
22
|
|
|
30
23
|
const root_source_file: std.Build.LazyPath =
|
|
31
24
|
.{ .cwd_relative = dirname ++ "/src/lib/pkmn.zig" };
|
|
32
|
-
const
|
|
33
|
-
std.Build.Module.Import
|
|
34
|
-
else
|
|
35
|
-
std.Build.ModuleDependency;
|
|
36
|
-
const imports: []const Import =
|
|
25
|
+
const imports: []const std.Build.Module.Import =
|
|
37
26
|
&.{.{ .name = "build_options", .module = build_options.createModule() }};
|
|
38
|
-
return b.createModule(
|
|
39
|
-
.{ .source_file = root_source_file, .dependencies = imports }
|
|
40
|
-
else
|
|
41
|
-
.{ .root_source_file = root_source_file, .imports = imports });
|
|
27
|
+
return b.createModule(.{ .root_source_file = root_source_file, .imports = imports });
|
|
42
28
|
}
|
|
43
29
|
|
|
44
30
|
pub fn build(b: *std.Build) !void {
|
|
45
31
|
const target = b.standardTargetOptions(.{});
|
|
46
32
|
const optimize = b.standardOptimizeOption(.{});
|
|
47
33
|
|
|
48
|
-
const default: ?bool = if (force_pic) false else null;
|
|
49
34
|
const node_headers = b.option([]const u8, "node-headers", "Path to node-headers");
|
|
50
35
|
const node_import_lib =
|
|
51
36
|
b.option([]const u8, "node-import-library", "Path to node import library (Windows)");
|
|
52
|
-
const demo = if (try exists("src/tools/demo.zig"))
|
|
37
|
+
const demo = if (try exists(b, "src/tools/demo.zig"))
|
|
53
38
|
b.option(bool, "demo", "Build the demo library") orelse false
|
|
54
39
|
else
|
|
55
40
|
false;
|
|
@@ -57,8 +42,8 @@ pub fn build(b: *std.Build) !void {
|
|
|
57
42
|
const wasm_stack_size =
|
|
58
43
|
b.option(u64, "wasm-stack-size", "The size of WASM stack") orelse std.wasm.page_size;
|
|
59
44
|
const dynamic = b.option(bool, "dynamic", "Build a dynamic library") orelse false;
|
|
60
|
-
const strip = b.option(bool, "strip", "Strip debugging symbols from binary")
|
|
61
|
-
const pic = b.option(bool, "pic", "Force position independent code")
|
|
45
|
+
const strip = b.option(bool, "strip", "Strip debugging symbols from binary");
|
|
46
|
+
const pic = b.option(bool, "pic", "Force position independent code");
|
|
62
47
|
const emit_asm = b.option(bool, "emit-asm", "Output .s (assembly code)") orelse false;
|
|
63
48
|
const emit_ll = b.option(bool, "emit-ll", "Output .ll (LLVM IR)") orelse false;
|
|
64
49
|
|
|
@@ -72,12 +57,6 @@ pub fn build(b: *std.Build) !void {
|
|
|
72
57
|
var repository = std.mem.splitSequence(u8, parsed.value.object.get("repository").?.string, ":");
|
|
73
58
|
std.debug.assert(std.mem.eql(u8, repository.first(), "github"));
|
|
74
59
|
|
|
75
|
-
const fast = try std.SemanticVersion.parse("0.12.0-dev.866+3a47bc715");
|
|
76
|
-
if (optimize != .Debug and fast.order(builtin.zig_version) == .lt) {
|
|
77
|
-
std.log.warn("Release builds are ~10-20% slower than before Zig " ++
|
|
78
|
-
"v0.12.0-dev.866+3a47bc715 due to ziglang/zig#17768", .{});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
60
|
const showdown =
|
|
82
61
|
b.option(bool, "showdown", "Enable Pokémon Showdown compatibility mode") orelse false;
|
|
83
62
|
const log = b.option(bool, "log", "Enable protocol message logging") orelse false;
|
|
@@ -110,48 +89,46 @@ pub fn build(b: *std.Build) !void {
|
|
|
110
89
|
|
|
111
90
|
const name = if (showdown) "pkmn-showdown" else "pkmn";
|
|
112
91
|
|
|
113
|
-
const pkmn:
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
else
|
|
120
|
-
b.path("src/lib/pkmn.zig"),
|
|
121
|
-
.optimize = optimize,
|
|
122
|
-
.target = target,
|
|
123
|
-
.imports = &.{.{ .name = "build_options", .module = options.createModule() }},
|
|
124
|
-
});
|
|
92
|
+
const pkmn: *std.Build.Module = b.addModule("pkmn", .{
|
|
93
|
+
.root_source_file = b.path("src/lib/pkmn.zig"),
|
|
94
|
+
.optimize = optimize,
|
|
95
|
+
.target = target,
|
|
96
|
+
.imports = &.{.{ .name = "build_options", .module = options.createModule() }},
|
|
97
|
+
});
|
|
125
98
|
|
|
126
99
|
var c = false;
|
|
127
100
|
if (node_headers) |headers| {
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
const lib = b.addSharedLibrary(if (force_pic) .{
|
|
131
|
-
.name = addon,
|
|
132
|
-
.root_source_file = path,
|
|
133
|
-
.optimize = optimize,
|
|
101
|
+
const translate_c = b.addTranslateC(.{
|
|
102
|
+
.root_source_file = b.path("src/lib/napi.h"),
|
|
134
103
|
.target = target,
|
|
135
|
-
} else .{
|
|
136
|
-
.name = addon,
|
|
137
|
-
.root_source_file = path,
|
|
138
104
|
.optimize = optimize,
|
|
139
|
-
.target = target,
|
|
140
|
-
.strip = strip,
|
|
141
|
-
.pic = pic,
|
|
142
105
|
});
|
|
143
|
-
(
|
|
144
|
-
|
|
145
|
-
lib.
|
|
106
|
+
translate_c.addSystemIncludePath(b.path(headers));
|
|
107
|
+
const addon = b.fmt("{s}.node", .{name});
|
|
108
|
+
const path = b.path("src/lib/node.zig");
|
|
109
|
+
const lib = b.addLibrary(.{
|
|
110
|
+
.linkage = .dynamic,
|
|
111
|
+
.name = addon,
|
|
112
|
+
.root_module = b.createModule(.{
|
|
113
|
+
.root_source_file = path,
|
|
114
|
+
.optimize = optimize,
|
|
115
|
+
.target = target,
|
|
116
|
+
.strip = strip,
|
|
117
|
+
.pic = pic,
|
|
118
|
+
}),
|
|
119
|
+
});
|
|
120
|
+
lib.root_module.addOptions("build_options", options);
|
|
121
|
+
lib.root_module.addImport("napi", translate_c.createModule());
|
|
122
|
+
lib.root_module.link_libc = true;
|
|
146
123
|
if (node_import_lib) |il| {
|
|
147
|
-
lib.addObjectFile(
|
|
148
|
-
} else if (
|
|
149
|
-
|
|
124
|
+
lib.root_module.addObjectFile(b.path(il));
|
|
125
|
+
} else if (target.result.os.tag == .windows) {
|
|
126
|
+
var err = std.Io.File.stderr().writer(b.graph.io, &.{});
|
|
127
|
+
try err.interface.writeAll("Must provide --node-import-library path on Windows\n");
|
|
150
128
|
std.process.exit(1);
|
|
151
129
|
}
|
|
152
130
|
lib.linker_allow_shlib_undefined = true;
|
|
153
131
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
154
|
-
if (force_pic and pic orelse false) lib.force_pic = pic;
|
|
155
132
|
// Always emit to build/lib because this is where the driver code expects to find it
|
|
156
133
|
// TODO: ziglang/zig#2231 - using the following used to work (though was hacky):
|
|
157
134
|
//
|
|
@@ -167,56 +144,43 @@ pub fn build(b: *std.Build) !void {
|
|
|
167
144
|
} else if (demo) {
|
|
168
145
|
const path = "src/tools/demo.zig";
|
|
169
146
|
const n = if (showdown) "demo-showdown" else "demo";
|
|
170
|
-
const mod = pkmn
|
|
171
|
-
.showdown = showdown,
|
|
172
|
-
.log = log,
|
|
173
|
-
.chance = chance,
|
|
174
|
-
.calc = calc,
|
|
175
|
-
});
|
|
147
|
+
const mod = pkmn;
|
|
176
148
|
try buildWasm(b, n, path, optimize, strip, pic, wasm_stack_size, mod, options);
|
|
177
149
|
} else if (dynamic) {
|
|
178
|
-
const path =
|
|
179
|
-
const lib = b.
|
|
180
|
-
.
|
|
181
|
-
.root_source_file = path,
|
|
182
|
-
.version = try std.SemanticVersion.parse(version),
|
|
183
|
-
.optimize = optimize,
|
|
184
|
-
.target = target,
|
|
185
|
-
} else .{
|
|
150
|
+
const path = b.path("src/lib/c.zig");
|
|
151
|
+
const lib = b.addLibrary(.{
|
|
152
|
+
.linkage = .dynamic,
|
|
186
153
|
.name = name,
|
|
187
|
-
.
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
154
|
+
.root_module = b.createModule(.{
|
|
155
|
+
.root_source_file = path,
|
|
156
|
+
.optimize = optimize,
|
|
157
|
+
.target = target,
|
|
158
|
+
.strip = strip,
|
|
159
|
+
.pic = pic,
|
|
160
|
+
}),
|
|
193
161
|
});
|
|
194
|
-
|
|
195
|
-
lib.addIncludePath(
|
|
162
|
+
lib.root_module.addOptions("build_options", options);
|
|
163
|
+
lib.root_module.addIncludePath(b.path("src/include"));
|
|
196
164
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
197
|
-
if (force_pic and pic orelse false) lib.force_pic = pic;
|
|
198
165
|
b.installArtifact(lib);
|
|
199
166
|
c = true;
|
|
200
167
|
} else {
|
|
201
|
-
const path =
|
|
202
|
-
const lib = b.
|
|
203
|
-
.
|
|
204
|
-
.root_source_file = path,
|
|
205
|
-
.optimize = optimize,
|
|
206
|
-
.target = target,
|
|
207
|
-
} else .{
|
|
168
|
+
const path = b.path("src/lib/c.zig");
|
|
169
|
+
const lib = b.addLibrary(.{
|
|
170
|
+
.linkage = .static,
|
|
208
171
|
.name = name,
|
|
209
|
-
.
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
172
|
+
.root_module = b.createModule(.{
|
|
173
|
+
.root_source_file = path,
|
|
174
|
+
.optimize = optimize,
|
|
175
|
+
.target = target,
|
|
176
|
+
.strip = strip,
|
|
177
|
+
.pic = pic,
|
|
178
|
+
}),
|
|
214
179
|
});
|
|
215
|
-
|
|
216
|
-
lib.addIncludePath(
|
|
180
|
+
lib.root_module.addOptions("build_options", options);
|
|
181
|
+
lib.root_module.addIncludePath(b.path("src/include"));
|
|
217
182
|
lib.bundle_compiler_rt = true;
|
|
218
183
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
219
|
-
if (force_pic and pic orelse false) lib.force_pic = pic;
|
|
220
184
|
if (emit_asm) {
|
|
221
185
|
b.getInstallStep().dependOn(&b.addInstallFileWithDir(
|
|
222
186
|
lib.getEmittedAsm(),
|
|
@@ -236,22 +200,25 @@ pub fn build(b: *std.Build) !void {
|
|
|
236
200
|
}
|
|
237
201
|
|
|
238
202
|
if (c) {
|
|
239
|
-
const path =
|
|
240
|
-
if (has_path) .{ .path = "src/include/pkmn.h" } else b.path("src/include/pkmn.h");
|
|
203
|
+
const path = b.path("src/include/pkmn.h");
|
|
241
204
|
const header = b.addInstallFileWithDir(path, .header, "pkmn.h");
|
|
242
205
|
b.getInstallStep().dependOn(&header.step);
|
|
243
206
|
|
|
244
207
|
const pc = b.fmt("lib{s}.pc", .{name});
|
|
245
|
-
const
|
|
208
|
+
const cwd = try std.process.getCwdAlloc(b.allocator);
|
|
209
|
+
const file = try std.Io.Dir.path.relative(
|
|
246
210
|
b.allocator,
|
|
247
211
|
try std.process.getCwdAlloc(b.allocator),
|
|
212
|
+
&b.graph.environ_map,
|
|
213
|
+
cwd,
|
|
248
214
|
try b.cache_root.join(b.allocator, &.{pc}),
|
|
249
215
|
);
|
|
250
|
-
const pkgconfig_file = try std.
|
|
216
|
+
const pkgconfig_file = try std.Io.Dir.cwd().createFile(b.graph.io, file, .{});
|
|
217
|
+
defer pkgconfig_file.close(b.graph.io);
|
|
251
218
|
|
|
252
219
|
const dirname = comptime std.fs.path.dirname(@src().file) orelse ".";
|
|
253
|
-
|
|
254
|
-
try writer.print(
|
|
220
|
+
var writer = pkgconfig_file.writer(b.graph.io, &.{});
|
|
221
|
+
try writer.interface.print(
|
|
255
222
|
\\prefix={0s}/{1s}
|
|
256
223
|
\\includedir=${{prefix}}/include
|
|
257
224
|
\\libdir=${{prefix}}/lib
|
|
@@ -263,7 +230,6 @@ pub fn build(b: *std.Build) !void {
|
|
|
263
230
|
\\Cflags: -I${{includedir}}
|
|
264
231
|
\\Libs: -L${{libdir}} -l{2s}
|
|
265
232
|
, .{ dirname, b.install_path, name, repository.next().?, description, version });
|
|
266
|
-
defer pkgconfig_file.close();
|
|
267
233
|
|
|
268
234
|
b.installFile(file, b.fmt("share/pkgconfig/{s}", .{pc}));
|
|
269
235
|
}
|
|
@@ -279,7 +245,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
279
245
|
// TODO: tests can be run multiple times due to @imports
|
|
280
246
|
const tests = TestStep.create(b, options, config);
|
|
281
247
|
|
|
282
|
-
var exes
|
|
248
|
+
var exes: ArrayList(*std.Build.Step.Compile) = .empty;
|
|
283
249
|
const tools: ToolConfig = .{
|
|
284
250
|
.options = .{
|
|
285
251
|
.showdown = showdown,
|
|
@@ -337,7 +303,6 @@ fn buildWasm(
|
|
|
337
303
|
import: ?*std.Build.Module,
|
|
338
304
|
options: anytype,
|
|
339
305
|
) !void {
|
|
340
|
-
const entry = @hasDecl(Step.Compile, "Entry");
|
|
341
306
|
const mode = switch (optimize) {
|
|
342
307
|
.ReleaseFast, .ReleaseSafe => .ReleaseSmall,
|
|
343
308
|
else => optimize,
|
|
@@ -361,92 +326,58 @@ fn buildWasm(
|
|
|
361
326
|
if (builtin.zig_version.order(try std.SemanticVersion.parse("0.12.0")) != .lt) {
|
|
362
327
|
features.addFeature(@intFromEnum(std.Target.wasm.Feature.multivalue));
|
|
363
328
|
}
|
|
364
|
-
const freestanding =
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
.os_tag = .freestanding,
|
|
374
|
-
.cpu_features_add = features,
|
|
375
|
-
};
|
|
376
|
-
const path = if (has_path) .{ .path = root_src_file } else b.path(root_src_file);
|
|
377
|
-
const bin = if (entry) bin: {
|
|
378
|
-
const exe = b.addExecutable(if (force_pic) .{
|
|
379
|
-
.name = name,
|
|
380
|
-
.root_source_file = path,
|
|
381
|
-
.optimize = mode,
|
|
382
|
-
.target = freestanding,
|
|
383
|
-
} else .{
|
|
384
|
-
.name = name,
|
|
329
|
+
const freestanding = b.resolveTargetQuery(.{
|
|
330
|
+
.cpu_arch = .wasm32,
|
|
331
|
+
.os_tag = .freestanding,
|
|
332
|
+
.cpu_features_add = features,
|
|
333
|
+
});
|
|
334
|
+
const path = b.path(root_src_file);
|
|
335
|
+
const exe = b.addExecutable(.{
|
|
336
|
+
.name = name,
|
|
337
|
+
.root_module = b.createModule(.{
|
|
385
338
|
.root_source_file = path,
|
|
386
339
|
.optimize = mode,
|
|
387
340
|
.target = freestanding,
|
|
388
341
|
.strip = strip,
|
|
389
342
|
.pic = pic,
|
|
390
|
-
})
|
|
343
|
+
}),
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
var file = try std.Io.Dir.cwd().openFile(b.graph.io, root_src_file, .{});
|
|
347
|
+
defer file.close(b.graph.io);
|
|
348
|
+
var reader = file.reader(b.graph.io, &.{});
|
|
349
|
+
const bytes = try reader.interface.allocRemaining(b.allocator, .unlimited);
|
|
350
|
+
exe.root_module.export_symbol_names = try exports(b, bytes);
|
|
351
|
+
exe.entry = .disabled;
|
|
391
352
|
|
|
392
|
-
var file = try std.fs.cwd().openFile(root_src_file, .{});
|
|
393
|
-
defer file.close();
|
|
394
|
-
const bytes = try file.readToEndAlloc(b.allocator, std.math.maxInt(usize));
|
|
395
|
-
(if (root_module) exe.root_module else exe).export_symbol_names = try exports(b, bytes);
|
|
396
|
-
exe.entry = .disabled;
|
|
397
|
-
break :bin exe;
|
|
398
|
-
} else bin: {
|
|
399
|
-
const lib = b.addSharedLibrary(.{
|
|
400
|
-
.name = name,
|
|
401
|
-
.root_source_file = path,
|
|
402
|
-
.optimize = mode,
|
|
403
|
-
.target = freestanding,
|
|
404
|
-
});
|
|
405
|
-
lib.rdynamic = true;
|
|
406
|
-
break :bin lib;
|
|
407
|
-
};
|
|
408
353
|
if (import) |i| {
|
|
409
|
-
|
|
410
|
-
bin.root_module.addImport("pkmn", i);
|
|
411
|
-
} else {
|
|
412
|
-
bin.addModule("pkmn", i);
|
|
413
|
-
}
|
|
354
|
+
exe.root_module.addImport("pkmn", i);
|
|
414
355
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
if (force_pic and pic orelse false) bin.force_pic = pic;
|
|
418
|
-
(if (root_module) bin.root_module else bin).addOptions("build_options", options);
|
|
356
|
+
exe.stack_size = wasm_stack_size;
|
|
357
|
+
exe.root_module.addOptions("build_options", options);
|
|
419
358
|
|
|
420
359
|
const opt = b.findProgram(&.{"wasm-opt"}, &.{"./node_modules/.bin"}) catch null;
|
|
421
360
|
if (optimize != .Debug and opt != null) {
|
|
422
361
|
const out = b.fmt("build/lib/{s}.wasm", .{name});
|
|
423
362
|
const sh = b.addSystemCommand(&.{ opt.?, "--enable-bulk-memory", "--enable-simd", "-O4" });
|
|
424
|
-
sh.addArtifactArg(
|
|
363
|
+
sh.addArtifactArg(exe);
|
|
425
364
|
sh.addArg("-o");
|
|
426
|
-
|
|
427
|
-
sh.addFileSourceArg(if (has_path) .{ .path = out } else b.path(out));
|
|
428
|
-
} else {
|
|
429
|
-
sh.addFileArg(if (has_path) .{ .path = out } else b.path(out));
|
|
430
|
-
}
|
|
365
|
+
sh.addFileArg(b.path(out));
|
|
431
366
|
b.getInstallStep().dependOn(&sh.step);
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
b.getInstallStep().dependOn(&b.addInstallArtifact(bin, .{
|
|
367
|
+
} else {
|
|
368
|
+
b.getInstallStep().dependOn(&b.addInstallArtifact(exe, .{
|
|
435
369
|
.dest_dir = .{ .override = std.Build.InstallDir{ .lib = {} } },
|
|
436
370
|
}).step);
|
|
437
|
-
} else {
|
|
438
|
-
b.installArtifact(bin);
|
|
439
371
|
}
|
|
440
372
|
}
|
|
441
373
|
|
|
442
374
|
fn maybeStrip(
|
|
443
375
|
b: *std.Build,
|
|
444
|
-
artifact: *Step.Compile,
|
|
376
|
+
artifact: *std.Build.Step.Compile,
|
|
445
377
|
step: *std.Build.Step,
|
|
446
378
|
strip: ?bool,
|
|
447
379
|
cmd: ?[]const u8,
|
|
448
380
|
) void {
|
|
449
|
-
if (@hasDecl(@TypeOf(artifact.*), "strip")) artifact.strip = strip orelse false;
|
|
450
381
|
if (!(strip orelse false) or cmd == null) return;
|
|
451
382
|
// Using `strip -r -u` for dynamic libraries is supposed to work on macOS but doesn't...
|
|
452
383
|
const mac = builtin.os.tag == .macos;
|
|
@@ -459,7 +390,7 @@ fn maybeStrip(
|
|
|
459
390
|
}
|
|
460
391
|
|
|
461
392
|
const Config = struct {
|
|
462
|
-
target: ResolvedTarget,
|
|
393
|
+
target: std.Build.ResolvedTarget,
|
|
463
394
|
optimize: std.builtin.OptimizeMode,
|
|
464
395
|
pic: ?bool,
|
|
465
396
|
strip: ?bool,
|
|
@@ -470,7 +401,7 @@ const TestStep = struct {
|
|
|
470
401
|
step: std.Build.Step,
|
|
471
402
|
build: bool,
|
|
472
403
|
|
|
473
|
-
pub fn create(b: *std.Build, options: *Step.Options, config: Config) *TestStep {
|
|
404
|
+
pub fn create(b: *std.Build, options: *std.Build.Step.Options, config: Config) *TestStep {
|
|
474
405
|
const coverage = b.option([]const u8, "test-coverage", "Generate test coverage");
|
|
475
406
|
const test_filter =
|
|
476
407
|
b.option([]const u8, "test-filter", "Skip tests that do not match filter");
|
|
@@ -479,28 +410,21 @@ const TestStep = struct {
|
|
|
479
410
|
const step = std.Build.Step.init(.{ .id = .custom, .name = "Run all tests", .owner = b });
|
|
480
411
|
self.* = .{ .step = step, .build = test_filter == null };
|
|
481
412
|
|
|
482
|
-
const path =
|
|
483
|
-
const tests = b.addTest(
|
|
484
|
-
.
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
.
|
|
493
|
-
.single_threaded = true,
|
|
494
|
-
.strip = config.strip,
|
|
495
|
-
.pic = config.pic,
|
|
413
|
+
const path = b.path("src/lib/test.zig");
|
|
414
|
+
const tests = b.addTest(.{
|
|
415
|
+
.root_module = b.createModule(.{
|
|
416
|
+
.root_source_file = path,
|
|
417
|
+
.optimize = config.optimize,
|
|
418
|
+
.target = config.target,
|
|
419
|
+
.single_threaded = true,
|
|
420
|
+
.strip = config.strip,
|
|
421
|
+
.pic = config.pic,
|
|
422
|
+
}),
|
|
423
|
+
.filters = if (test_filter) |filter| &.{filter} else &.{},
|
|
496
424
|
});
|
|
497
|
-
|
|
425
|
+
tests.root_module.addOptions("build_options", options);
|
|
498
426
|
|
|
499
427
|
maybeStrip(b, tests, &tests.step, config.strip, config.cmd);
|
|
500
|
-
if (force_pic) {
|
|
501
|
-
tests.single_threaded = true;
|
|
502
|
-
if (config.pic orelse false) tests.force_pic = config.pic;
|
|
503
|
-
}
|
|
504
428
|
if (coverage) |c| {
|
|
505
429
|
tests.setExecCmd(&.{ "kcov", "--include-pattern=src/lib", c, null });
|
|
506
430
|
}
|
|
@@ -517,45 +441,36 @@ const ToolConfig = struct {
|
|
|
517
441
|
tool: struct {
|
|
518
442
|
tests: ?*TestStep,
|
|
519
443
|
name: ?[]const u8 = null,
|
|
520
|
-
exes: *
|
|
444
|
+
exes: *ArrayList(*std.Build.Step.Compile),
|
|
521
445
|
},
|
|
522
446
|
};
|
|
523
447
|
|
|
524
|
-
fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*Step.Run {
|
|
525
|
-
if (!try exists(path)) return null;
|
|
448
|
+
fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*std.Build.Step.Run {
|
|
449
|
+
if (!try exists(b, path)) return null;
|
|
526
450
|
var name = config.tool.name orelse std.fs.path.basename(path);
|
|
527
451
|
const index = std.mem.lastIndexOfScalar(u8, name, '.');
|
|
528
452
|
if (index) |i| name = name[0..i];
|
|
529
453
|
if (config.options.showdown orelse false) name = b.fmt("{s}-showdown", .{name});
|
|
530
454
|
|
|
531
|
-
const exe = b.addExecutable(
|
|
532
|
-
.name = name,
|
|
533
|
-
.root_source_file = if (has_path) .{ .path = path } else b.path(path),
|
|
534
|
-
.target = config.general.target,
|
|
535
|
-
.optimize = config.general.optimize,
|
|
536
|
-
} else .{
|
|
455
|
+
const exe = b.addExecutable(.{
|
|
537
456
|
.name = name,
|
|
538
|
-
.
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
457
|
+
.root_module = b.createModule(.{
|
|
458
|
+
.root_source_file = b.path(path),
|
|
459
|
+
.target = config.general.target,
|
|
460
|
+
.optimize = config.general.optimize,
|
|
461
|
+
.strip = config.general.strip,
|
|
462
|
+
.pic = config.general.pic,
|
|
463
|
+
}),
|
|
544
464
|
});
|
|
545
465
|
|
|
546
|
-
if (
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
exe.addModule("pkmn", module(b, config.options));
|
|
466
|
+
const import = if (config.module) |m| m else module(b, config.options);
|
|
467
|
+
exe.root_module.addImport("pkmn", import);
|
|
468
|
+
if (config.general.target.result.os.tag == .windows) {
|
|
469
|
+
exe.root_module.linkSystemLibrary("advapi32", .{});
|
|
551
470
|
}
|
|
552
471
|
|
|
553
|
-
if (force_pic) {
|
|
554
|
-
exe.single_threaded = true;
|
|
555
|
-
if (config.general.pic orelse false) exe.force_pic = config.general.pic;
|
|
556
|
-
}
|
|
557
472
|
if (config.tool.tests) |ts| ts.step.dependOn(&exe.step);
|
|
558
|
-
config.tool.exes.append(exe) catch @panic("OOM");
|
|
473
|
+
config.tool.exes.append(b.allocator, exe) catch @panic("OOM");
|
|
559
474
|
|
|
560
475
|
const run = b.addRunArtifact(exe);
|
|
561
476
|
maybeStrip(b, exe, &run.step, config.general.strip, config.general.cmd);
|
|
@@ -564,8 +479,8 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*Step.Run {
|
|
|
564
479
|
return run;
|
|
565
480
|
}
|
|
566
481
|
|
|
567
|
-
fn exists(path: []const u8) !bool {
|
|
568
|
-
std.
|
|
482
|
+
fn exists(b: *std.Build, path: []const u8) !bool {
|
|
483
|
+
std.Io.Dir.cwd().access(b.graph.io, path, .{}) catch |err| switch (err) {
|
|
569
484
|
error.FileNotFound => return false,
|
|
570
485
|
else => |e| return e,
|
|
571
486
|
};
|
|
@@ -575,7 +490,7 @@ fn exists(path: []const u8) !bool {
|
|
|
575
490
|
const ToolsStep = struct {
|
|
576
491
|
step: std.Build.Step,
|
|
577
492
|
|
|
578
|
-
pub fn create(b: *std.Build, exes: *
|
|
493
|
+
pub fn create(b: *std.Build, exes: *ArrayList(*std.Build.Step.Compile)) *ToolsStep {
|
|
579
494
|
const self = b.allocator.create(ToolsStep) catch @panic("OOM");
|
|
580
495
|
const step = std.Build.Step.init(.{ .id = .custom, .name = "Install tools", .owner = b });
|
|
581
496
|
self.* = .{ .step = step };
|
|
@@ -584,23 +499,18 @@ const ToolsStep = struct {
|
|
|
584
499
|
}
|
|
585
500
|
};
|
|
586
501
|
|
|
587
|
-
fn detect(target: anytype) std.Target {
|
|
588
|
-
if (@hasField(@TypeOf(target), "result")) return target.result;
|
|
589
|
-
return (std.zig.system.NativeTargetInfo.detect(target) catch unreachable).target;
|
|
590
|
-
}
|
|
591
|
-
|
|
592
502
|
pub fn exports(b: *std.Build, bytes: []const u8) ![][]const u8 {
|
|
593
|
-
var symbols
|
|
503
|
+
var symbols: ArrayList([]const u8) = .empty;
|
|
594
504
|
|
|
595
505
|
var it = std.mem.splitSequence(u8, bytes, "export ");
|
|
596
506
|
_ = it.next();
|
|
597
507
|
while (it.next()) |s| {
|
|
598
508
|
if (std.mem.startsWith(u8, s, "const ")) {
|
|
599
509
|
const i = std.mem.indexOf(u8, s[6..], " ").?;
|
|
600
|
-
try symbols.append(s[6 .. 6 + i]);
|
|
510
|
+
try symbols.append(b.allocator, s[6 .. 6 + i]);
|
|
601
511
|
} else { // "fn "
|
|
602
512
|
const i = std.mem.indexOf(u8, s[3..], "(").?;
|
|
603
|
-
try symbols.append(s[3 .. 3 + i]);
|
|
513
|
+
try symbols.append(b.allocator, s[3 .. 3 + i]);
|
|
604
514
|
}
|
|
605
515
|
}
|
|
606
516
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pkmn/engine",
|
|
3
|
-
"version": "0.1.0-dev.
|
|
3
|
+
"version": "0.1.0-dev.6ba42cd5",
|
|
4
4
|
"description": "A minimal, complete, Pokémon battle simulation engine optimized for performance",
|
|
5
5
|
"repository": "github:pkmn/engine",
|
|
6
6
|
"license": "MIT",
|
|
@@ -81,6 +81,7 @@
|
|
|
81
81
|
"src/lib/gen2/generated.zig",
|
|
82
82
|
"src/lib/gen2/helpers.zig",
|
|
83
83
|
"src/lib/gen2/mechanics.zig",
|
|
84
|
+
"src/lib/napi.h",
|
|
84
85
|
"src/lib/node.zig",
|
|
85
86
|
"src/lib/pkmn.zig",
|
|
86
87
|
"src/lib/wasm.zig",
|
|
@@ -98,38 +99,39 @@
|
|
|
98
99
|
"access": "public"
|
|
99
100
|
},
|
|
100
101
|
"dependencies": {
|
|
101
|
-
"@pkmn/data": "
|
|
102
|
-
"@pkmn/protocol": "^0.
|
|
102
|
+
"@pkmn/data": "0.9.35",
|
|
103
|
+
"@pkmn/protocol": "^0.7.2"
|
|
103
104
|
},
|
|
104
105
|
"devDependencies": {
|
|
105
|
-
"@pkmn/
|
|
106
|
-
"@pkmn/
|
|
107
|
-
"@pkmn/
|
|
106
|
+
"@pkmn/dex-types": "0.9.35",
|
|
107
|
+
"@pkmn/eslint-config": "^9.21.0",
|
|
108
|
+
"@pkmn/img": "^0.3.3",
|
|
109
|
+
"@pkmn/sets": "^5.2.0",
|
|
108
110
|
"@pkmn/sim": "0.9.31",
|
|
109
|
-
"@pkmn/smogon": "
|
|
110
|
-
"@types/html-minifier": "^4.0.
|
|
111
|
-
"@types/jest": "^
|
|
111
|
+
"@pkmn/smogon": "0.5.21",
|
|
112
|
+
"@types/html-minifier": "^4.0.6",
|
|
113
|
+
"@types/jest": "^30.0.0",
|
|
112
114
|
"@types/minimist": "^1.2.5",
|
|
113
|
-
"@types/mustache": "^4.2.
|
|
114
|
-
"@types/node": "^
|
|
115
|
+
"@types/mustache": "^4.2.6",
|
|
116
|
+
"@types/node": "^25.0.6",
|
|
115
117
|
"@types/react": "<=18",
|
|
116
|
-
"@types/semver": "^7.
|
|
117
|
-
"@types/vscode": "^1.
|
|
118
|
-
"@vitest/coverage-v8": "^
|
|
119
|
-
"@vscode/vsce": "^3.
|
|
120
|
-
"binaryen": "^
|
|
121
|
-
"esbuild": "^0.
|
|
122
|
-
"eslint": "^9.
|
|
118
|
+
"@types/semver": "^7.7.1",
|
|
119
|
+
"@types/vscode": "^1.108.1",
|
|
120
|
+
"@vitest/coverage-v8": "^4.0.17",
|
|
121
|
+
"@vscode/vsce": "^3.7.1",
|
|
122
|
+
"binaryen": "^125.0.0",
|
|
123
|
+
"esbuild": "^0.27.2",
|
|
124
|
+
"eslint": "^9.39.2",
|
|
123
125
|
"html-minifier": "^4.0.0",
|
|
124
126
|
"json-stringify-pretty-compact": "3.0.0",
|
|
125
127
|
"minimist": "^1.2.8",
|
|
126
128
|
"mustache": "^4.2.0",
|
|
127
|
-
"semver": "^7.7.
|
|
129
|
+
"semver": "^7.7.3",
|
|
128
130
|
"source-map-support": "^0.5.21",
|
|
129
131
|
"table": "^6.9.0",
|
|
130
132
|
"trakr": "^0.2.0",
|
|
131
|
-
"typescript": "^5.
|
|
132
|
-
"vitest": "^
|
|
133
|
+
"typescript": "^5.9.3",
|
|
134
|
+
"vitest": "^4.0.17"
|
|
133
135
|
},
|
|
134
136
|
"scripts": {
|
|
135
137
|
"lint": "eslint --cache src",
|