@pkmn/engine 0.1.0-dev.90d6c14c → 0.1.0-dev.9257876b
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 -3
- package/README.md +52 -21
- package/build/pkg/addon.js.map +1 -1
- package/build/pkg/data/ids.json +12 -12
- package/build/pkg/data/layout.json +2 -2
- package/build/pkg/data/protocol.json +69 -12
- package/build/pkg/data.d.ts +3 -2
- package/build/pkg/data.js.map +1 -1
- package/build/pkg/gen1.js +2 -2
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.d.ts +2 -1
- package/build/pkg/index.js.map +1 -1
- package/build/pkg/protocol.js +57 -38
- package/build/pkg/protocol.js.map +1 -1
- package/build/test/display.js.map +1 -1
- package/build/tools/debug.js +3 -1
- package/build/tools/debug.js.map +1 -1
- package/build.zig +125 -102
- package/package.json +43 -23
- package/src/bin/install-pkmn-engine +27 -19
- package/src/lib/common/data.zig +12 -24
- package/src/lib/common/optional.zig +9 -2
- package/src/lib/common/protocol.zig +805 -327
- package/src/lib/common/rational.zig +12 -8
- package/src/lib/common/rng.zig +26 -17
- package/src/lib/gen1/calc.zig +9 -10
- package/src/lib/gen1/chance.zig +83 -66
- package/src/lib/gen1/data/moves.zig +192 -180
- package/src/lib/gen1/data/species.zig +3 -3
- package/src/lib/gen1/data/types.zig +7 -7
- package/src/lib/gen1/data.zig +60 -67
- package/src/lib/gen1/helpers.zig +261 -123
- package/src/lib/gen1/mechanics.zig +370 -403
- package/src/lib/gen2/calc.zig +143 -0
- package/src/lib/gen2/chance.zig +1315 -0
- package/src/lib/gen2/data/items.zig +12 -18
- package/src/lib/gen2/data/moves.zig +663 -569
- package/src/lib/gen2/data/species.zig +1 -1
- package/src/lib/gen2/data/types.zig +134 -31
- package/src/lib/gen2/data.zig +106 -79
- package/src/lib/gen2/generated.zig +806 -0
- package/src/lib/gen2/helpers.zig +8 -12
- package/src/lib/gen2/mechanics.zig +3587 -9
- package/src/lib/{binding/node.zig → node.zig} +10 -13
- package/src/lib/pkmn.zig +26 -3
- package/src/lib/{binding/wasm.zig → wasm.zig} +2 -1
- package/src/lib/gen1/README.md +0 -812
- package/src/lib/gen2/README.md +0 -308
package/build.zig
CHANGED
|
@@ -16,8 +16,8 @@ pub fn module(b: *std.Build, options: Options) *std.Build.Module {
|
|
|
16
16
|
build_options.addOption(?bool, "chance", options.chance);
|
|
17
17
|
build_options.addOption(?bool, "calc", options.calc);
|
|
18
18
|
return b.createModule(.{
|
|
19
|
-
.
|
|
20
|
-
.
|
|
19
|
+
.root_source_file = .{ .cwd_relative = dirname ++ "/src/lib/pkmn.zig" },
|
|
20
|
+
.imports = &.{.{ .name = "build_options", .module = build_options.createModule() }},
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -32,9 +32,10 @@ pub fn build(b: *std.Build) !void {
|
|
|
32
32
|
const wasm_stack_size =
|
|
33
33
|
b.option(u64, "wasm-stack-size", "The size of WASM stack") orelse std.wasm.page_size;
|
|
34
34
|
const dynamic = b.option(bool, "dynamic", "Build a dynamic library") orelse false;
|
|
35
|
-
const strip = b.option(bool, "strip", "Strip debugging symbols from binary")
|
|
36
|
-
const pic = b.option(bool, "pic", "Force position independent code")
|
|
35
|
+
const strip = b.option(bool, "strip", "Strip debugging symbols from binary");
|
|
36
|
+
const pic = b.option(bool, "pic", "Force position independent code");
|
|
37
37
|
const emit_asm = b.option(bool, "emit-asm", "Output .s (assembly code)") orelse false;
|
|
38
|
+
const emit_ll = b.option(bool, "emit-ll", "Output .ll (LLVM IR)") orelse false;
|
|
38
39
|
|
|
39
40
|
const cmd = b.findProgram(&.{"strip"}, &.{}) catch null;
|
|
40
41
|
|
|
@@ -43,7 +44,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
43
44
|
defer parsed.deinit();
|
|
44
45
|
const version = parsed.value.object.get("version").?.string;
|
|
45
46
|
const description = parsed.value.object.get("description").?.string;
|
|
46
|
-
var repository = std.mem.
|
|
47
|
+
var repository = std.mem.splitSequence(u8, parsed.value.object.get("repository").?.string, ":");
|
|
47
48
|
std.debug.assert(std.mem.eql(u8, repository.first(), "github"));
|
|
48
49
|
|
|
49
50
|
const showdown =
|
|
@@ -65,25 +66,25 @@ pub fn build(b: *std.Build) !void {
|
|
|
65
66
|
const addon = b.fmt("{s}.node", .{name});
|
|
66
67
|
const lib = b.addSharedLibrary(.{
|
|
67
68
|
.name = addon,
|
|
68
|
-
.root_source_file = .
|
|
69
|
+
.root_source_file = b.path("src/lib/node.zig"),
|
|
69
70
|
.optimize = optimize,
|
|
70
71
|
.target = target,
|
|
72
|
+
.strip = strip,
|
|
73
|
+
.pic = pic,
|
|
71
74
|
});
|
|
72
|
-
lib.addOptions("build_options", options);
|
|
73
|
-
lib.
|
|
74
|
-
lib.addSystemIncludePath(headers);
|
|
75
|
+
lib.root_module.addOptions("build_options", options);
|
|
76
|
+
lib.addSystemIncludePath(b.path(headers));
|
|
75
77
|
lib.linkLibC();
|
|
76
78
|
if (node_import_lib) |il| {
|
|
77
|
-
lib.addObjectFile(il);
|
|
78
|
-
} else if (
|
|
79
|
+
lib.addObjectFile(b.path(il));
|
|
80
|
+
} else if (target.result.os.tag == .windows) {
|
|
79
81
|
try std.io.getStdErr().writeAll("Must provide --node-import-library path on Windows\n");
|
|
80
82
|
std.process.exit(1);
|
|
81
83
|
}
|
|
82
84
|
lib.linker_allow_shlib_undefined = true;
|
|
83
85
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
84
|
-
if (pic) lib.force_pic = pic;
|
|
85
86
|
// Always emit to build/lib because this is where the driver code expects to find it
|
|
86
|
-
// TODO
|
|
87
|
+
// TODO: ziglang/zig#2231 - using the following used to work (though was hacky):
|
|
87
88
|
//
|
|
88
89
|
// lib.emit_bin = .{ .emit_to = b.fmt("build/lib/{s}", .{addon}) };
|
|
89
90
|
// b.getInstallStep().dependOn(&lib.step);
|
|
@@ -92,74 +93,101 @@ pub fn build(b: *std.Build) !void {
|
|
|
92
93
|
// rename the file ourself in install-pkmn-engine
|
|
93
94
|
b.installArtifact(lib);
|
|
94
95
|
} else if (wasm) {
|
|
95
|
-
const
|
|
96
|
+
const exe = b.addExecutable(.{
|
|
96
97
|
.name = name,
|
|
97
|
-
.root_source_file = .
|
|
98
|
+
.root_source_file = b.path("src/lib/wasm.zig"),
|
|
98
99
|
.optimize = switch (optimize) {
|
|
99
100
|
.ReleaseFast, .ReleaseSafe => .ReleaseSmall,
|
|
100
101
|
else => optimize,
|
|
101
102
|
},
|
|
102
|
-
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
|
|
103
|
+
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
|
|
104
|
+
.strip = strip,
|
|
105
|
+
.pic = pic,
|
|
103
106
|
});
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
exe.root_module.addOptions("build_options", options);
|
|
108
|
+
exe.root_module.export_symbol_names = &[_][]const u8{
|
|
109
|
+
"SHOWDOWN",
|
|
110
|
+
"LOG",
|
|
111
|
+
"CHANCE",
|
|
112
|
+
"CALC",
|
|
113
|
+
"GEN1_CHOICES_SIZE",
|
|
114
|
+
"GEN1_LOGS_SIZE",
|
|
115
|
+
};
|
|
116
|
+
exe.entry = .disabled;
|
|
117
|
+
exe.stack_size = wasm_stack_size;
|
|
110
118
|
const opt = b.findProgram(&.{"wasm-opt"}, &.{"./node_modules/.bin"}) catch null;
|
|
111
119
|
if (optimize != .Debug and opt != null) {
|
|
112
120
|
const out = b.fmt("build/lib/{s}.wasm", .{name});
|
|
113
121
|
const sh = b.addSystemCommand(&.{ opt.?, "-O4" });
|
|
114
|
-
sh.addArtifactArg(
|
|
122
|
+
sh.addArtifactArg(exe);
|
|
115
123
|
sh.addArg("-o");
|
|
116
|
-
sh.
|
|
124
|
+
sh.addFileArg(b.path(out));
|
|
117
125
|
b.getInstallStep().dependOn(&sh.step);
|
|
126
|
+
} else {
|
|
127
|
+
b.getInstallStep().dependOn(&b.addInstallArtifact(exe, .{
|
|
128
|
+
.dest_dir = .{ .override = std.Build.InstallDir{ .lib = {} } },
|
|
129
|
+
}).step);
|
|
118
130
|
}
|
|
119
|
-
b.installArtifact(lib);
|
|
120
131
|
} else if (dynamic) {
|
|
121
132
|
const lib = b.addSharedLibrary(.{
|
|
122
133
|
.name = name,
|
|
123
|
-
.root_source_file = .
|
|
134
|
+
.root_source_file = b.path("src/lib/c.zig"),
|
|
124
135
|
.version = try std.SemanticVersion.parse(version),
|
|
125
136
|
.optimize = optimize,
|
|
126
137
|
.target = target,
|
|
138
|
+
.strip = strip,
|
|
139
|
+
.pic = pic,
|
|
127
140
|
});
|
|
128
|
-
lib.addOptions("build_options", options);
|
|
129
|
-
lib.
|
|
130
|
-
lib.addIncludePath("src/include");
|
|
141
|
+
lib.root_module.addOptions("build_options", options);
|
|
142
|
+
lib.addIncludePath(b.path("src/include"));
|
|
131
143
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
132
|
-
if (pic) lib.force_pic = pic;
|
|
133
144
|
b.installArtifact(lib);
|
|
134
145
|
c = true;
|
|
135
146
|
} else {
|
|
136
147
|
const lib = b.addStaticLibrary(.{
|
|
137
148
|
.name = name,
|
|
138
|
-
.root_source_file = .
|
|
149
|
+
.root_source_file = b.path("src/lib/c.zig"),
|
|
139
150
|
.optimize = optimize,
|
|
140
151
|
.target = target,
|
|
152
|
+
.strip = strip,
|
|
153
|
+
.pic = pic,
|
|
141
154
|
});
|
|
142
|
-
lib.addOptions("build_options", options);
|
|
143
|
-
lib.
|
|
144
|
-
lib.addIncludePath("src/include");
|
|
155
|
+
lib.root_module.addOptions("build_options", options);
|
|
156
|
+
lib.addIncludePath(b.path("src/include"));
|
|
145
157
|
lib.bundle_compiler_rt = true;
|
|
146
158
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
147
|
-
if (
|
|
148
|
-
|
|
159
|
+
if (emit_asm) {
|
|
160
|
+
b.getInstallStep().dependOn(&b.addInstallFileWithDir(
|
|
161
|
+
lib.getEmittedAsm(),
|
|
162
|
+
.prefix,
|
|
163
|
+
b.fmt("{s}.s", .{name}),
|
|
164
|
+
).step);
|
|
165
|
+
}
|
|
166
|
+
if (emit_ll) {
|
|
167
|
+
b.getInstallStep().dependOn(&b.addInstallFileWithDir(
|
|
168
|
+
lib.getEmittedLlvmIr(),
|
|
169
|
+
.prefix,
|
|
170
|
+
b.fmt("{s}.ll", .{name}),
|
|
171
|
+
).step);
|
|
172
|
+
}
|
|
149
173
|
b.installArtifact(lib);
|
|
150
174
|
c = true;
|
|
151
175
|
}
|
|
152
176
|
|
|
153
177
|
if (c) {
|
|
154
178
|
const header = b.addInstallFileWithDir(
|
|
155
|
-
.
|
|
179
|
+
b.path("src/include/pkmn.h"),
|
|
156
180
|
.header,
|
|
157
181
|
"pkmn.h",
|
|
158
182
|
);
|
|
159
183
|
b.getInstallStep().dependOn(&header.step);
|
|
160
184
|
|
|
161
185
|
const pc = b.fmt("lib{s}.pc", .{name});
|
|
162
|
-
const file = try
|
|
186
|
+
const file = try std.fs.path.relative(
|
|
187
|
+
b.allocator,
|
|
188
|
+
try std.process.getCwdAlloc(b.allocator),
|
|
189
|
+
try b.cache_root.join(b.allocator, &.{pc}),
|
|
190
|
+
);
|
|
163
191
|
const pkgconfig_file = try std.fs.cwd().createFile(file, .{});
|
|
164
192
|
|
|
165
193
|
const dirname = comptime std.fs.path.dirname(@src().file) orelse ".";
|
|
@@ -192,7 +220,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
192
220
|
// TODO: tests can be run multiple times due to @imports
|
|
193
221
|
const tests = TestStep.create(b, options, config);
|
|
194
222
|
|
|
195
|
-
var exes = std.ArrayList(*std.Build.
|
|
223
|
+
var exes = std.ArrayList(*std.Build.Step.Compile).init(b.allocator);
|
|
196
224
|
const tools: ToolConfig = .{
|
|
197
225
|
.options = .{
|
|
198
226
|
.showdown = showdown,
|
|
@@ -210,41 +238,42 @@ pub fn build(b: *std.Build) !void {
|
|
|
210
238
|
var benchmark_config = tools;
|
|
211
239
|
benchmark_config.general.optimize = .ReleaseFast;
|
|
212
240
|
benchmark_config.general.strip = true;
|
|
213
|
-
const benchmark = tool(b, "src/test/benchmark.zig", benchmark_config);
|
|
241
|
+
const benchmark = try tool(b, "src/test/benchmark.zig", benchmark_config);
|
|
214
242
|
|
|
215
243
|
var fuzz_config = tools;
|
|
216
244
|
fuzz_config.general.strip = false;
|
|
217
245
|
fuzz_config.tool.name = "fuzz";
|
|
218
|
-
const fuzz = tool(b, "src/test/fuzz.zig", fuzz_config);
|
|
219
|
-
|
|
220
|
-
const
|
|
221
|
-
const
|
|
222
|
-
const transitions = tool(b, "src/tools/transitions.zig", tools);
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
if (
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
b.step("
|
|
230
|
-
b.step("
|
|
231
|
-
b.step("
|
|
232
|
-
b.step("
|
|
233
|
-
b.step("serde", "Run serialization/deserialization tool").dependOn(&
|
|
246
|
+
const fuzz = try tool(b, "src/test/fuzz.zig", fuzz_config);
|
|
247
|
+
|
|
248
|
+
const analyze = try tool(b, "src/tools/analyze.zig", tools);
|
|
249
|
+
const dump = try tool(b, "src/tools/dump.zig", tools);
|
|
250
|
+
const transitions = try tool(b, "src/tools/transitions.zig", tools);
|
|
251
|
+
|
|
252
|
+
// FIXME: serde randomly fails to build in some release configurations
|
|
253
|
+
var hack = tools;
|
|
254
|
+
if (optimize != .Debug) hack.tool.tests = null;
|
|
255
|
+
const serde = try tool(b, "src/tools/serde.zig", hack);
|
|
256
|
+
|
|
257
|
+
if (analyze) |t| b.step("analyze", "Run LLVM analysis tool").dependOn(&t.step);
|
|
258
|
+
if (benchmark) |t| b.step("benchmark", "Run benchmark code").dependOn(&t.step);
|
|
259
|
+
if (dump) |t| b.step("dump", "Run protocol dump tool").dependOn(&t.step);
|
|
260
|
+
if (fuzz) |t| b.step("fuzz", "Run fuzz tester").dependOn(&t.step);
|
|
261
|
+
if (serde) |t| b.step("serde", "Run serialization/deserialization tool").dependOn(&t.step);
|
|
234
262
|
b.step("test", "Run all tests").dependOn(&tests.step);
|
|
235
263
|
b.step("tools", "Install tools").dependOn(&ToolsStep.create(b, &exes).step);
|
|
236
|
-
|
|
264
|
+
if (transitions) |t| {
|
|
265
|
+
b.step("transitions", "Visualize transitions algorithm search").dependOn(&t.step);
|
|
266
|
+
}
|
|
237
267
|
}
|
|
238
268
|
|
|
239
269
|
fn maybeStrip(
|
|
240
270
|
b: *std.Build,
|
|
241
|
-
artifact: *std.Build.
|
|
271
|
+
artifact: *std.Build.Step.Compile,
|
|
242
272
|
step: *std.Build.Step,
|
|
243
|
-
strip: bool,
|
|
273
|
+
strip: ?bool,
|
|
244
274
|
cmd: ?[]const u8,
|
|
245
275
|
) void {
|
|
246
|
-
|
|
247
|
-
if (!strip or cmd == null) return;
|
|
276
|
+
if (!(strip orelse false) or cmd == null) return;
|
|
248
277
|
// Using `strip -r -u` for dynamic libraries is supposed to work on macOS but doesn't...
|
|
249
278
|
const mac = builtin.os.tag == .macos;
|
|
250
279
|
if (mac and artifact.isDynamicLibrary()) return;
|
|
@@ -256,53 +285,42 @@ fn maybeStrip(
|
|
|
256
285
|
}
|
|
257
286
|
|
|
258
287
|
const Config = struct {
|
|
259
|
-
target: std.
|
|
288
|
+
target: std.Build.ResolvedTarget,
|
|
260
289
|
optimize: std.builtin.OptimizeMode,
|
|
261
|
-
pic: bool,
|
|
262
|
-
strip: bool,
|
|
290
|
+
pic: ?bool,
|
|
291
|
+
strip: ?bool,
|
|
263
292
|
cmd: ?[]const u8,
|
|
264
293
|
};
|
|
265
294
|
|
|
266
|
-
const TESTS = .{
|
|
267
|
-
"src/lib/common/test.zig",
|
|
268
|
-
"src/lib/gen1/test.zig",
|
|
269
|
-
"src/lib/gen2/test.zig",
|
|
270
|
-
};
|
|
271
|
-
|
|
272
295
|
const TestStep = struct {
|
|
273
296
|
step: std.Build.Step,
|
|
274
297
|
build: bool,
|
|
275
298
|
|
|
276
|
-
pub fn create(b: *std.Build, options: *std.Build.
|
|
299
|
+
pub fn create(b: *std.Build, options: *std.Build.Step.Options, config: Config) *TestStep {
|
|
277
300
|
const coverage = b.option([]const u8, "test-coverage", "Generate test coverage");
|
|
278
|
-
const test_file = b.option([]const u8, "test-file", "Input file for test");
|
|
279
301
|
const test_filter =
|
|
280
302
|
b.option([]const u8, "test-filter", "Skip tests that do not match filter");
|
|
281
303
|
|
|
282
304
|
const self = b.allocator.create(TestStep) catch @panic("OOM");
|
|
283
305
|
const step = std.Build.Step.init(.{ .id = .custom, .name = "Run all tests", .owner = b });
|
|
284
|
-
self.* =
|
|
285
|
-
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
tests.
|
|
299
|
-
maybeStrip(b, tests, &tests.step, config.strip, config.cmd);
|
|
300
|
-
if (config.pic) tests.force_pic = config.pic;
|
|
301
|
-
if (coverage) |c| {
|
|
302
|
-
tests.setExecCmd(&.{ "kcov", "--include-pattern=src/lib", c, null });
|
|
303
|
-
}
|
|
304
|
-
self.step.dependOn(&b.addRunArtifact(tests).step);
|
|
306
|
+
self.* = .{ .step = step, .build = test_filter == null };
|
|
307
|
+
|
|
308
|
+
const tests = b.addTest(.{
|
|
309
|
+
.root_source_file = b.path("src/lib/test.zig"),
|
|
310
|
+
.optimize = config.optimize,
|
|
311
|
+
.target = config.target,
|
|
312
|
+
.filter = test_filter,
|
|
313
|
+
.single_threaded = true,
|
|
314
|
+
.strip = config.strip,
|
|
315
|
+
.pic = config.pic,
|
|
316
|
+
});
|
|
317
|
+
tests.root_module.addOptions("build_options", options);
|
|
318
|
+
maybeStrip(b, tests, &tests.step, config.strip, config.cmd);
|
|
319
|
+
if (coverage) |c| {
|
|
320
|
+
tests.setExecCmd(&.{ "kcov", "--include-pattern=src/lib", c, null });
|
|
305
321
|
}
|
|
322
|
+
self.step.dependOn(&b.addRunArtifact(tests).step);
|
|
323
|
+
|
|
306
324
|
return self;
|
|
307
325
|
}
|
|
308
326
|
};
|
|
@@ -313,11 +331,15 @@ const ToolConfig = struct {
|
|
|
313
331
|
tool: struct {
|
|
314
332
|
tests: ?*TestStep,
|
|
315
333
|
name: ?[]const u8 = null,
|
|
316
|
-
exes: *std.ArrayList(*std.Build.
|
|
334
|
+
exes: *std.ArrayList(*std.Build.Step.Compile),
|
|
317
335
|
},
|
|
318
336
|
};
|
|
319
337
|
|
|
320
|
-
fn tool(b: *std.Build, path: []const u8, config: ToolConfig)
|
|
338
|
+
fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*std.Build.Step.Run {
|
|
339
|
+
std.fs.cwd().access(path, .{}) catch |err| switch (err) {
|
|
340
|
+
error.FileNotFound => return null,
|
|
341
|
+
else => |e| return e,
|
|
342
|
+
};
|
|
321
343
|
var name = config.tool.name orelse std.fs.path.basename(path);
|
|
322
344
|
const index = std.mem.lastIndexOfScalar(u8, name, '.');
|
|
323
345
|
if (index) |i| name = name[0..i];
|
|
@@ -325,14 +347,15 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) *std.Build.RunStep
|
|
|
325
347
|
|
|
326
348
|
const exe = b.addExecutable(.{
|
|
327
349
|
.name = name,
|
|
328
|
-
.root_source_file = .
|
|
350
|
+
.root_source_file = b.path(path),
|
|
329
351
|
.target = config.general.target,
|
|
330
352
|
.optimize = config.general.optimize,
|
|
353
|
+
.single_threaded = true,
|
|
354
|
+
.strip = config.general.strip,
|
|
355
|
+
.pic = config.general.pic,
|
|
331
356
|
});
|
|
332
|
-
exe.
|
|
357
|
+
exe.root_module.addImport("pkmn", module(b, config.options));
|
|
333
358
|
|
|
334
|
-
exe.single_threaded = true;
|
|
335
|
-
if (config.general.pic) exe.force_pic = config.general.pic;
|
|
336
359
|
if (config.tool.tests) |ts| ts.step.dependOn(&exe.step);
|
|
337
360
|
config.tool.exes.append(exe) catch @panic("OOM");
|
|
338
361
|
|
|
@@ -346,11 +369,11 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) *std.Build.RunStep
|
|
|
346
369
|
const ToolsStep = struct {
|
|
347
370
|
step: std.Build.Step,
|
|
348
371
|
|
|
349
|
-
pub fn create(b: *std.Build, exes: *std.ArrayList(*std.Build.
|
|
372
|
+
pub fn create(b: *std.Build, exes: *std.ArrayList(*std.Build.Step.Compile)) *ToolsStep {
|
|
350
373
|
const self = b.allocator.create(ToolsStep) catch @panic("OOM");
|
|
351
374
|
const step = std.Build.Step.init(.{ .id = .custom, .name = "Install tools", .owner = b });
|
|
352
|
-
self.* =
|
|
353
|
-
for (exes.items) |t| self.step.dependOn(&b.addInstallArtifact(t).step);
|
|
375
|
+
self.* = .{ .step = step };
|
|
376
|
+
for (exes.items) |t| self.step.dependOn(&b.addInstallArtifact(t, .{}).step);
|
|
354
377
|
return self;
|
|
355
378
|
}
|
|
356
379
|
};
|
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.9257876b",
|
|
4
4
|
"description": "A minimal, complete, Pokémon battle simulation engine optimized for performance",
|
|
5
5
|
"repository": "github:pkmn/engine",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,9 +31,6 @@
|
|
|
31
31
|
"build/test/display.js",
|
|
32
32
|
"build/tools/debug.js.map",
|
|
33
33
|
"build/tools/debug.js",
|
|
34
|
-
"src/bin/install-pkmn-engine",
|
|
35
|
-
"src/lib/binding/node.zig",
|
|
36
|
-
"src/lib/binding/wasm.zig",
|
|
37
34
|
"src/lib/common/battle.zig",
|
|
38
35
|
"src/lib/common/data.zig",
|
|
39
36
|
"src/lib/common/debug.zig",
|
|
@@ -52,14 +49,19 @@
|
|
|
52
49
|
"src/lib/gen1/data/types.zig",
|
|
53
50
|
"src/lib/gen1/helpers.zig",
|
|
54
51
|
"src/lib/gen1/mechanics.zig",
|
|
52
|
+
"src/lib/gen2/calc.zig",
|
|
53
|
+
"src/lib/gen2/chance.zig",
|
|
55
54
|
"src/lib/gen2/data.zig",
|
|
56
55
|
"src/lib/gen2/data/items.zig",
|
|
57
56
|
"src/lib/gen2/data/moves.zig",
|
|
58
57
|
"src/lib/gen2/data/species.zig",
|
|
59
58
|
"src/lib/gen2/data/types.zig",
|
|
59
|
+
"src/lib/gen2/generated.zig",
|
|
60
60
|
"src/lib/gen2/helpers.zig",
|
|
61
61
|
"src/lib/gen2/mechanics.zig",
|
|
62
|
+
"src/lib/node.zig",
|
|
62
63
|
"src/lib/pkmn.zig",
|
|
64
|
+
"src/lib/wasm.zig",
|
|
63
65
|
"src/test/display/pkmn.html.tmpl"
|
|
64
66
|
],
|
|
65
67
|
"engines": {
|
|
@@ -73,30 +75,31 @@
|
|
|
73
75
|
"access": "public"
|
|
74
76
|
},
|
|
75
77
|
"dependencies": {
|
|
76
|
-
"@pkmn/data": "^0.7
|
|
77
|
-
"@pkmn/protocol": "^0.6.
|
|
78
|
+
"@pkmn/data": "^0.9.7",
|
|
79
|
+
"@pkmn/protocol": "^0.6.25"
|
|
78
80
|
},
|
|
79
81
|
"devDependencies": {
|
|
80
|
-
"@pkmn/eslint-config": "^
|
|
81
|
-
"@pkmn/img": "^0.2.
|
|
82
|
-
"@pkmn/sets": "^5.
|
|
83
|
-
"@pkmn/sim": "0.7
|
|
84
|
-
"@types/html-minifier": "^4.0.
|
|
85
|
-
"@types/jest": "^29.5.
|
|
86
|
-
"@types/minimist": "^1.2.
|
|
87
|
-
"@types/mustache": "^4.2.
|
|
88
|
-
"@types/node": "^20.
|
|
89
|
-
"@vitest/coverage-
|
|
90
|
-
"binaryen": "^
|
|
91
|
-
"eslint": "
|
|
82
|
+
"@pkmn/eslint-config": "^7.4.0",
|
|
83
|
+
"@pkmn/img": "^0.2.29",
|
|
84
|
+
"@pkmn/sets": "^5.1.2",
|
|
85
|
+
"@pkmn/sim": "0.9.7",
|
|
86
|
+
"@types/html-minifier": "^4.0.5",
|
|
87
|
+
"@types/jest": "^29.5.12",
|
|
88
|
+
"@types/minimist": "^1.2.5",
|
|
89
|
+
"@types/mustache": "^4.2.5",
|
|
90
|
+
"@types/node": "^20.14.5",
|
|
91
|
+
"@vitest/coverage-v8": "^1.6.0",
|
|
92
|
+
"binaryen": "^117.0.0",
|
|
93
|
+
"eslint": "<=8",
|
|
92
94
|
"html-minifier": "^4.0.0",
|
|
93
|
-
"json-stringify-pretty-compact": "
|
|
95
|
+
"json-stringify-pretty-compact": "4.0.0",
|
|
94
96
|
"minimist": "^1.2.8",
|
|
95
97
|
"mustache": "^4.2.0",
|
|
96
98
|
"source-map-support": "^0.5.21",
|
|
99
|
+
"table": "^6.8.2",
|
|
97
100
|
"trakr": "^0.2.0",
|
|
98
|
-
"typescript": "^5.
|
|
99
|
-
"vitest": "^
|
|
101
|
+
"typescript": "^5.4.5",
|
|
102
|
+
"vitest": "^1.6.0"
|
|
100
103
|
},
|
|
101
104
|
"scripts": {
|
|
102
105
|
"lint": "eslint --cache src --ext ts,js && eslint src/bin/*",
|
|
@@ -118,7 +121,7 @@
|
|
|
118
121
|
"ignorePatterns": [
|
|
119
122
|
"dist/",
|
|
120
123
|
"node_modules/",
|
|
121
|
-
"
|
|
124
|
+
"examples/zig",
|
|
122
125
|
"build/"
|
|
123
126
|
],
|
|
124
127
|
"env": {
|
|
@@ -134,10 +137,18 @@
|
|
|
134
137
|
"parserOptions": {
|
|
135
138
|
"project": [
|
|
136
139
|
"./tsconfig.json",
|
|
137
|
-
"./
|
|
140
|
+
"./examples/js/tsconfig.json"
|
|
138
141
|
]
|
|
139
142
|
}
|
|
140
143
|
},
|
|
144
|
+
{
|
|
145
|
+
"files": [
|
|
146
|
+
"src/test/display.ts"
|
|
147
|
+
],
|
|
148
|
+
"rules": {
|
|
149
|
+
"@typescript-eslint/no-unnecessary-type-assertion": "off"
|
|
150
|
+
}
|
|
151
|
+
},
|
|
141
152
|
{
|
|
142
153
|
"files": [
|
|
143
154
|
"src/pkg/index.ts",
|
|
@@ -168,6 +179,15 @@
|
|
|
168
179
|
"@typescript-eslint/no-redundant-type-constituents": "off"
|
|
169
180
|
}
|
|
170
181
|
},
|
|
182
|
+
{
|
|
183
|
+
"files": [
|
|
184
|
+
"src/pkg/protocol.test.ts"
|
|
185
|
+
],
|
|
186
|
+
"rules": {
|
|
187
|
+
"jest/no-standalone-expect": "off",
|
|
188
|
+
"jest/no-conditional-expect": "off"
|
|
189
|
+
}
|
|
190
|
+
},
|
|
171
191
|
{
|
|
172
192
|
"files": [
|
|
173
193
|
"src/test/*.test.ts",
|
|
@@ -10,7 +10,7 @@ const path = require('path');
|
|
|
10
10
|
const {pipeline} = require('stream/promises');
|
|
11
11
|
const tty = require('tty');
|
|
12
12
|
|
|
13
|
-
const ZIG_VERSION = {major: 0, minor:
|
|
13
|
+
const ZIG_VERSION = {major: 0, minor: 13, patch: 0};
|
|
14
14
|
const DEV = ZIG_VERSION.dev ? `-dev.${ZIG_VERSION.dev}` : '';
|
|
15
15
|
const VERSION = `${ZIG_VERSION.major}.${ZIG_VERSION.minor}.${ZIG_VERSION.patch}${DEV}`;
|
|
16
16
|
const INDEX = 'https://ziglang.org/download/index.json';
|
|
@@ -283,19 +283,19 @@ const downloadImportLib = async () => {
|
|
|
283
283
|
let error = false;
|
|
284
284
|
for (let i = 2; i < process.argv.length; i++) {
|
|
285
285
|
switch (process.argv[i]) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
286
|
+
case "--silent": {
|
|
287
|
+
SILENT = true;
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
case "--zig": {
|
|
291
|
+
if (options || only) error = true;
|
|
292
|
+
only = true;
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
default: {
|
|
296
|
+
if (options || only || !process.argv[i].startsWith('--options=')) error = true;
|
|
297
|
+
options = process.argv[i].slice(10).split(' ');
|
|
298
|
+
}
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
301
|
if (error) {
|
|
@@ -358,7 +358,7 @@ const downloadImportLib = async () => {
|
|
|
358
358
|
// either the default options or whatever was passed in
|
|
359
359
|
if (!configs.size) {
|
|
360
360
|
node = true;
|
|
361
|
-
const DEFAULT = ['-Dshowdown'
|
|
361
|
+
const DEFAULT = ['-Dshowdown'];
|
|
362
362
|
configs.set('node', {type: 'node', options: options || DEFAULT});
|
|
363
363
|
configs.set('wasm', {type: 'wasm', options: options || DEFAULT});
|
|
364
364
|
}
|
|
@@ -370,8 +370,10 @@ const downloadImportLib = async () => {
|
|
|
370
370
|
const args = ['build', '-p', 'build', ...opts];
|
|
371
371
|
if (!process.env.DEBUG_PKMN_ENGINE) args.push('-Doptimize=ReleaseFast', '-Dstrip');
|
|
372
372
|
if (config.type === 'node') {
|
|
373
|
-
args.push(`-Dnode-headers=${headers}`);
|
|
374
|
-
if (process.platform === 'win32')
|
|
373
|
+
args.push(`-Dnode-headers=${path.relative(ROOT, headers)}`);
|
|
374
|
+
if (process.platform === 'win32') {
|
|
375
|
+
args.push(`-Dnode-import-library=${path.relative(ROOT, lib)}`);
|
|
376
|
+
}
|
|
375
377
|
} else {
|
|
376
378
|
args.push('-Dwasm');
|
|
377
379
|
}
|
|
@@ -386,8 +388,14 @@ const downloadImportLib = async () => {
|
|
|
386
388
|
const prefix = process.platform === 'win32' ? '' : 'lib';
|
|
387
389
|
const ext = process.platform === 'darwin'
|
|
388
390
|
? 'dylib' : process.platform === 'win32' ? 'dll' : 'so';
|
|
389
|
-
|
|
390
|
-
|
|
391
|
+
try {
|
|
392
|
+
const actual = path.join('build', 'lib', `${prefix}pkmn${suffix}.node.${ext}`);
|
|
393
|
+
fs.renameSync(actual, artifact);
|
|
394
|
+
} catch (err) {
|
|
395
|
+
// ziglang/zig#19743 changed this path
|
|
396
|
+
const actual = path.join('build', 'bin', `${prefix}pkmn${suffix}.node.${ext}`);
|
|
397
|
+
fs.renameSync(actual, artifact);
|
|
398
|
+
}
|
|
391
399
|
}
|
|
392
400
|
}
|
|
393
401
|
})().catch(e => {
|