@pkmn/engine 0.1.0-dev.30c63015 → 0.1.0-dev.32adfe77

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/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
- .source_file = .{ .path = dirname ++ "/src/lib/pkmn.zig" },
20
- .dependencies = &.{.{ .name = "build_options", .module = build_options.createModule() }},
19
+ .root_source_file = .{ .path = dirname ++ "/src/lib/pkmn.zig" },
20
+ .imports = &.{.{ .name = "build_options", .module = build_options.createModule() }},
21
21
  });
22
22
  }
23
23
 
@@ -32,8 +32,8 @@ 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") orelse false;
36
- const pic = b.option(bool, "pic", "Force position independent code") 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");
37
37
  const emit_asm = b.option(bool, "emit-asm", "Output .s (assembly code)") orelse false;
38
38
  const emit_ll = b.option(bool, "emit-ll", "Output .ll (LLVM IR)") orelse false;
39
39
 
@@ -66,25 +66,25 @@ pub fn build(b: *std.Build) !void {
66
66
  const addon = b.fmt("{s}.node", .{name});
67
67
  const lib = b.addSharedLibrary(.{
68
68
  .name = addon,
69
- .main_pkg_path = .{ .path = "." },
70
- .root_source_file = .{ .path = "src/lib/binding/node.zig" },
69
+ .root_source_file = .{ .path = "src/lib/node.zig" },
71
70
  .optimize = optimize,
72
71
  .target = target,
72
+ .strip = strip,
73
+ .pic = pic,
73
74
  });
74
- lib.addOptions("build_options", options);
75
+ lib.root_module.addOptions("build_options", options);
75
76
  lib.addSystemIncludePath(.{ .path = headers });
76
77
  lib.linkLibC();
77
78
  if (node_import_lib) |il| {
78
79
  lib.addObjectFile(.{ .path = il });
79
- } else if ((try std.zig.system.NativeTargetInfo.detect(target)).target.os.tag == .windows) {
80
+ } else if (target.result.os.tag == .windows) {
80
81
  try std.io.getStdErr().writeAll("Must provide --node-import-library path on Windows\n");
81
82
  std.process.exit(1);
82
83
  }
83
84
  lib.linker_allow_shlib_undefined = true;
84
85
  maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
85
- if (pic) lib.force_pic = pic;
86
86
  // Always emit to build/lib because this is where the driver code expects to find it
87
- // TODO(ziglang/zig#2231): using the following used to work (though was hacky):
87
+ // TODO: ziglang/zig#2231 - using the following used to work (though was hacky):
88
88
  //
89
89
  // lib.emit_bin = .{ .emit_to = b.fmt("build/lib/{s}", .{addon}) };
90
90
  // b.getInstallStep().dependOn(&lib.step);
@@ -93,59 +93,69 @@ pub fn build(b: *std.Build) !void {
93
93
  // rename the file ourself in install-pkmn-engine
94
94
  b.installArtifact(lib);
95
95
  } else if (wasm) {
96
- const lib = b.addSharedLibrary(.{
96
+ const exe = b.addExecutable(.{
97
97
  .name = name,
98
- .main_pkg_path = .{ .path = "." },
99
- .root_source_file = .{ .path = "src/lib/binding/wasm.zig" },
98
+ .root_source_file = .{ .path = "src/lib/wasm.zig" },
100
99
  .optimize = switch (optimize) {
101
100
  .ReleaseFast, .ReleaseSafe => .ReleaseSmall,
102
101
  else => optimize,
103
102
  },
104
- .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
103
+ .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
104
+ .strip = strip,
105
+ .pic = pic,
105
106
  });
106
- lib.addOptions("build_options", options);
107
- lib.stack_size = wasm_stack_size;
108
- lib.rdynamic = true;
109
- lib.strip = strip;
110
- if (pic) lib.force_pic = pic;
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;
111
118
  const opt = b.findProgram(&.{"wasm-opt"}, &.{"./node_modules/.bin"}) catch null;
112
119
  if (optimize != .Debug and opt != null) {
113
120
  const out = b.fmt("build/lib/{s}.wasm", .{name});
114
121
  const sh = b.addSystemCommand(&.{ opt.?, "-O4" });
115
- sh.addArtifactArg(lib);
122
+ sh.addArtifactArg(exe);
116
123
  sh.addArg("-o");
117
- sh.addFileSourceArg(.{ .path = out });
124
+ sh.addFileArg(.{ .path = out });
118
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);
119
130
  }
120
- b.installArtifact(lib);
121
131
  } else if (dynamic) {
122
132
  const lib = b.addSharedLibrary(.{
123
133
  .name = name,
124
- .main_pkg_path = .{ .path = "." },
125
- .root_source_file = .{ .path = "src/lib/binding/c.zig" },
134
+ .root_source_file = .{ .path = "src/lib/c.zig" },
126
135
  .version = try std.SemanticVersion.parse(version),
127
136
  .optimize = optimize,
128
137
  .target = target,
138
+ .strip = strip,
139
+ .pic = pic,
129
140
  });
130
- lib.addOptions("build_options", options);
141
+ lib.root_module.addOptions("build_options", options);
131
142
  lib.addIncludePath(.{ .path = "src/include" });
132
143
  maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
133
- if (pic) lib.force_pic = pic;
134
144
  b.installArtifact(lib);
135
145
  c = true;
136
146
  } else {
137
147
  const lib = b.addStaticLibrary(.{
138
148
  .name = name,
139
- .main_pkg_path = .{ .path = "." },
140
- .root_source_file = .{ .path = "src/lib/binding/c.zig" },
149
+ .root_source_file = .{ .path = "src/lib/c.zig" },
141
150
  .optimize = optimize,
142
151
  .target = target,
152
+ .strip = strip,
153
+ .pic = pic,
143
154
  });
144
- lib.addOptions("build_options", options);
155
+ lib.root_module.addOptions("build_options", options);
145
156
  lib.addIncludePath(.{ .path = "src/include" });
146
157
  lib.bundle_compiler_rt = true;
147
158
  maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
148
- if (pic) lib.force_pic = pic;
149
159
  if (emit_asm) {
150
160
  b.getInstallStep().dependOn(&b.addInstallFileWithDir(
151
161
  lib.getEmittedAsm(),
@@ -206,7 +216,7 @@ pub fn build(b: *std.Build) !void {
206
216
  // TODO: tests can be run multiple times due to @imports
207
217
  const tests = TestStep.create(b, options, config);
208
218
 
209
- var exes = std.ArrayList(*std.Build.CompileStep).init(b.allocator);
219
+ var exes = std.ArrayList(*std.Build.Step.Compile).init(b.allocator);
210
220
  const tools: ToolConfig = .{
211
221
  .options = .{
212
222
  .showdown = showdown,
@@ -254,13 +264,12 @@ pub fn build(b: *std.Build) !void {
254
264
 
255
265
  fn maybeStrip(
256
266
  b: *std.Build,
257
- artifact: *std.Build.CompileStep,
267
+ artifact: *std.Build.Step.Compile,
258
268
  step: *std.Build.Step,
259
- strip: bool,
269
+ strip: ?bool,
260
270
  cmd: ?[]const u8,
261
271
  ) void {
262
- artifact.strip = strip;
263
- if (!strip or cmd == null) return;
272
+ if (!(strip orelse false) or cmd == null) return;
264
273
  // Using `strip -r -u` for dynamic libraries is supposed to work on macOS but doesn't...
265
274
  const mac = builtin.os.tag == .macos;
266
275
  if (mac and artifact.isDynamicLibrary()) return;
@@ -272,10 +281,10 @@ fn maybeStrip(
272
281
  }
273
282
 
274
283
  const Config = struct {
275
- target: std.zig.CrossTarget,
284
+ target: std.Build.ResolvedTarget,
276
285
  optimize: std.builtin.OptimizeMode,
277
- pic: bool,
278
- strip: bool,
286
+ pic: ?bool,
287
+ strip: ?bool,
279
288
  cmd: ?[]const u8,
280
289
  };
281
290
 
@@ -283,9 +292,8 @@ const TestStep = struct {
283
292
  step: std.Build.Step,
284
293
  build: bool,
285
294
 
286
- pub fn create(b: *std.Build, options: *std.Build.OptionsStep, config: Config) *TestStep {
295
+ pub fn create(b: *std.Build, options: *std.Build.Step.Options, config: Config) *TestStep {
287
296
  const coverage = b.option([]const u8, "test-coverage", "Generate test coverage");
288
- const test_file = b.option([]const u8, "test-file", "Input file for test");
289
297
  const test_filter =
290
298
  b.option([]const u8, "test-filter", "Skip tests that do not match filter");
291
299
 
@@ -293,22 +301,17 @@ const TestStep = struct {
293
301
  const step = std.Build.Step.init(.{ .id = .custom, .name = "Run all tests", .owner = b });
294
302
  self.* = .{ .step = step, .build = test_filter == null };
295
303
 
296
- const path = test_file orelse "src/lib/test.zig";
297
304
  const tests = b.addTest(.{
298
- .name = b.fmt("{s}-{s}", .{
299
- std.fs.path.basename(std.fs.path.dirname(path).?),
300
- std.fs.path.stem(std.fs.path.basename(path)),
301
- }),
302
- .main_pkg_path = .{ .path = "." },
303
- .root_source_file = .{ .path = path },
305
+ .root_source_file = .{ .path = "src/lib/test.zig" },
304
306
  .optimize = config.optimize,
305
307
  .target = config.target,
306
308
  .filter = test_filter,
309
+ .single_threaded = true,
310
+ .strip = config.strip,
311
+ .pic = config.pic,
307
312
  });
308
- tests.addOptions("build_options", options);
309
- tests.single_threaded = true;
313
+ tests.root_module.addOptions("build_options", options);
310
314
  maybeStrip(b, tests, &tests.step, config.strip, config.cmd);
311
- if (config.pic) tests.force_pic = config.pic;
312
315
  if (coverage) |c| {
313
316
  tests.setExecCmd(&.{ "kcov", "--include-pattern=src/lib", c, null });
314
317
  }
@@ -324,11 +327,11 @@ const ToolConfig = struct {
324
327
  tool: struct {
325
328
  tests: ?*TestStep,
326
329
  name: ?[]const u8 = null,
327
- exes: *std.ArrayList(*std.Build.CompileStep),
330
+ exes: *std.ArrayList(*std.Build.Step.Compile),
328
331
  },
329
332
  };
330
333
 
331
- fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*std.Build.RunStep {
334
+ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*std.Build.Step.Run {
332
335
  std.fs.cwd().access(path, .{}) catch |err| switch (err) {
333
336
  error.FileNotFound => return null,
334
337
  else => |e| return e,
@@ -343,11 +346,12 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*std.Build.RunSte
343
346
  .root_source_file = .{ .path = path },
344
347
  .target = config.general.target,
345
348
  .optimize = config.general.optimize,
349
+ .single_threaded = true,
350
+ .strip = config.general.strip,
351
+ .pic = config.general.pic,
346
352
  });
347
- exe.addModule("pkmn", module(b, config.options));
353
+ exe.root_module.addImport("pkmn", module(b, config.options));
348
354
 
349
- exe.single_threaded = true;
350
- if (config.general.pic) exe.force_pic = config.general.pic;
351
355
  if (config.tool.tests) |ts| ts.step.dependOn(&exe.step);
352
356
  config.tool.exes.append(exe) catch @panic("OOM");
353
357
 
@@ -361,7 +365,7 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*std.Build.RunSte
361
365
  const ToolsStep = struct {
362
366
  step: std.Build.Step,
363
367
 
364
- pub fn create(b: *std.Build, exes: *std.ArrayList(*std.Build.CompileStep)) *ToolsStep {
368
+ pub fn create(b: *std.Build, exes: *std.ArrayList(*std.Build.Step.Compile)) *ToolsStep {
365
369
  const self = b.allocator.create(ToolsStep) catch @panic("OOM");
366
370
  const step = std.Build.Step.init(.{ .id = .custom, .name = "Install tools", .owner = b });
367
371
  self.* = .{ .step = step };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pkmn/engine",
3
- "version": "0.1.0-dev.30c63015",
3
+ "version": "0.1.0-dev.32adfe77",
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",
@@ -62,7 +59,9 @@
62
59
  "src/lib/gen2/generated.zig",
63
60
  "src/lib/gen2/helpers.zig",
64
61
  "src/lib/gen2/mechanics.zig",
62
+ "src/lib/node.zig",
65
63
  "src/lib/pkmn.zig",
64
+ "src/lib/wasm.zig",
66
65
  "src/test/display/pkmn.html.tmpl"
67
66
  ],
68
67
  "engines": {
@@ -76,30 +75,31 @@
76
75
  "access": "public"
77
76
  },
78
77
  "dependencies": {
79
- "@pkmn/data": "^0.7.53",
80
- "@pkmn/protocol": "^0.6.16"
78
+ "@pkmn/data": "^0.8.9",
79
+ "@pkmn/protocol": "^0.6.19"
81
80
  },
82
81
  "devDependencies": {
83
- "@pkmn/eslint-config": "^5.3.0",
84
- "@pkmn/img": "^0.2.18",
85
- "@pkmn/sets": "^5.1.0",
86
- "@pkmn/sim": "0.7.53",
87
- "@types/html-minifier": "^4.0.3",
88
- "@types/jest": "^29.5.5",
89
- "@types/minimist": "^1.2.3",
90
- "@types/mustache": "^4.2.3",
91
- "@types/node": "^20.8.2",
92
- "@vitest/coverage-c8": "^0.33.0",
93
- "binaryen": "^114.0.0",
94
- "eslint": "^8.51.0",
82
+ "@pkmn/eslint-config": "^7.1.0",
83
+ "@pkmn/img": "^0.2.25",
84
+ "@pkmn/sets": "^5.1.2",
85
+ "@pkmn/sim": "0.8.9",
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.11.25",
91
+ "@vitest/coverage-v8": "^1.3.1",
92
+ "binaryen": "^116.0.0",
93
+ "eslint": "^8.57.0",
95
94
  "html-minifier": "^4.0.0",
96
- "json-stringify-pretty-compact": "3.0.0",
95
+ "json-stringify-pretty-compact": "4.0.0",
97
96
  "minimist": "^1.2.8",
98
97
  "mustache": "^4.2.0",
99
98
  "source-map-support": "^0.5.21",
99
+ "table": "^6.8.1",
100
100
  "trakr": "^0.2.0",
101
- "typescript": "^5.2.2",
102
- "vitest": "^0.34.6"
101
+ "typescript": "^5.4.2",
102
+ "vitest": "^1.3.1"
103
103
  },
104
104
  "scripts": {
105
105
  "lint": "eslint --cache src --ext ts,js && eslint src/bin/*",
@@ -141,6 +141,14 @@
141
141
  ]
142
142
  }
143
143
  },
144
+ {
145
+ "files": [
146
+ "src/test/display.ts"
147
+ ],
148
+ "rules": {
149
+ "@typescript-eslint/no-unnecessary-type-assertion": "off"
150
+ }
151
+ },
144
152
  {
145
153
  "files": [
146
154
  "src/pkg/index.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: 11, patch: 0};
13
+ const ZIG_VERSION = {major: 0, minor: 12, patch: 0, dev: 2036};
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
- 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
- }
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) {
@@ -22,8 +22,8 @@ pub const Player = enum(u1) {
22
22
 
23
23
  test Player {
24
24
  try expectEqual(Player.P2, Player.P1.foe());
25
- try expectEqual(@as(u8, 0b0001), @as(u8, @bitCast(Player.P1.ident(1))));
26
- try expectEqual(@as(u8, 0b1101), @as(u8, @bitCast(Player.P2.ident(5))));
25
+ try expectEqual(0b0001, @as(u8, @bitCast(Player.P1.ident(1))));
26
+ try expectEqual(0b1101, @as(u8, @bitCast(Player.P2.ident(5))));
27
27
  }
28
28
 
29
29
  /// An identifier for a specific Pokémon in battle.
@@ -46,8 +46,8 @@ pub const ID = packed struct(u8) {
46
46
  };
47
47
 
48
48
  test ID {
49
- try expectEqual(@as(u8, 0b0001), @as(u8, @bitCast(ID{ .player = .P1, .id = 1 })));
50
- try expectEqual(@as(u8, 0b1101), @as(u8, @bitCast(ID{ .player = .P2, .id = 5 })));
49
+ try expectEqual(0b0001, @as(u8, @bitCast(ID{ .player = .P1, .id = 1 })));
50
+ try expectEqual(0b1101, @as(u8, @bitCast(ID{ .player = .P2, .id = 5 })));
51
51
  const id: ID = .{ .player = .P2, .id = 4 };
52
52
  try expectEqual(id, ID.from(id.int()));
53
53
  }
@@ -46,7 +46,7 @@ test Optional {
46
46
  try expect(b != .true);
47
47
  try expect(b != .false);
48
48
 
49
- const Player = @import("./data.zig").Player;
49
+ const Player = @import("data.zig").Player;
50
50
  try expect(@bitSizeOf(Optional(Player)) == 2);
51
51
 
52
52
  const p: Optional(Player) = .P2;