@thi.ng/wasm-api 1.4.69 → 1.5.0

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.
Files changed (69) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/package.json +2 -2
  3. package/zig/build-v0.11.zig +126 -0
  4. package/zig/build.zig +29 -25
  5. package/zig/lib.zig +1 -1
  6. package/zig/managed-index.zig +2 -2
  7. package/zig/zig-cache/h/bc052b73addda9fe899d4556c8f21a5c.txt +0 -0
  8. package/zig/zig-cache/h/timestamp +0 -0
  9. package/zig/zig-cache/o/20f8f8362ac39302905d03992fa818bc/dependencies.zig +2 -0
  10. package/zig/zig-cache/tmp/0696373596682bd9/build +0 -0
  11. package/zig/zig-cache/tmp/06fd7da717810606/build +0 -0
  12. package/zig/zig-cache/tmp/0a39f7dbdddbea21/build +0 -0
  13. package/zig/zig-cache/tmp/0f72c6fd825322f3/build +0 -0
  14. package/zig/zig-cache/tmp/119286fc10b777f9/build +0 -0
  15. package/zig/zig-cache/tmp/1891fd08324fa403/build +0 -0
  16. package/zig/zig-cache/tmp/1eb500fac3d5ce62/build +0 -0
  17. package/zig/zig-cache/tmp/2043d7dd4743109c/build +0 -0
  18. package/zig/zig-cache/tmp/224ea1ba9258bfe3/build +0 -0
  19. package/zig/zig-cache/tmp/25343e986edbd1ad/build +0 -0
  20. package/zig/zig-cache/tmp/2d366ba992d14d5f/build +0 -0
  21. package/zig/zig-cache/tmp/2ddcd2b8d14b81eb/build +0 -0
  22. package/zig/zig-cache/tmp/3b7519b048bc31f6/build +0 -0
  23. package/zig/zig-cache/tmp/4b5e6a399cb5aee9/build +0 -0
  24. package/zig/zig-cache/tmp/4fb96aef1e2a7ae7/build +0 -0
  25. package/zig/zig-cache/tmp/527925617da9c3dd/build +0 -0
  26. package/zig/zig-cache/tmp/56dbc6d60b6441e9/build +0 -0
  27. package/zig/zig-cache/tmp/57954e69e2d9522f/build +0 -0
  28. package/zig/zig-cache/tmp/57cb18f507029d64/build +0 -0
  29. package/zig/zig-cache/tmp/5d8fe28f3373c9ca/build +0 -0
  30. package/zig/zig-cache/tmp/65c1c50c9b1018bd/build +0 -0
  31. package/zig/zig-cache/tmp/6977aca430f59bc9/build +0 -0
  32. package/zig/zig-cache/tmp/6c0722b71c685402/build +0 -0
  33. package/zig/zig-cache/tmp/6c4ec579c09d1f80/build +0 -0
  34. package/zig/zig-cache/tmp/6eae82521f2631ac/build +0 -0
  35. package/zig/zig-cache/tmp/6f62ac363f21537f/build +0 -0
  36. package/zig/zig-cache/tmp/7ae3fef48d8f3ada/build +0 -0
  37. package/zig/zig-cache/tmp/7fd336b7694ba54b/build +0 -0
  38. package/zig/zig-cache/tmp/899150dbae119836/build +0 -0
  39. package/zig/zig-cache/tmp/913281630cad1c0a/build +0 -0
  40. package/zig/zig-cache/tmp/927255f410775c17/build +0 -0
  41. package/zig/zig-cache/tmp/956b7aafe87eed23/build +0 -0
  42. package/zig/zig-cache/tmp/97e4f8c36515e21c/build +0 -0
  43. package/zig/zig-cache/tmp/9de1ed1e5e51add9/build +0 -0
  44. package/zig/zig-cache/tmp/a051bffb2bb19130/build +0 -0
  45. package/zig/zig-cache/tmp/a2d24144aa720ff5/build +0 -0
  46. package/zig/zig-cache/tmp/a6450c98790914aa/build +0 -0
  47. package/zig/zig-cache/tmp/a7851baacd09b97e/build +0 -0
  48. package/zig/zig-cache/tmp/a9620e90f7f21f27/build +0 -0
  49. package/zig/zig-cache/tmp/a9d0ae4a598bbae7/build +0 -0
  50. package/zig/zig-cache/tmp/adc434dfc8cff980/build +0 -0
  51. package/zig/zig-cache/tmp/b92139a1c898f577/build +0 -0
  52. package/zig/zig-cache/tmp/bae01421ea15bdba/build +0 -0
  53. package/zig/zig-cache/tmp/bb366772a50163c4/build +0 -0
  54. package/zig/zig-cache/tmp/c2d91fef7812604a/build +0 -0
  55. package/zig/zig-cache/tmp/ca6f88cc7990ad70/build +0 -0
  56. package/zig/zig-cache/tmp/ce13ae17f06e2897/build +0 -0
  57. package/zig/zig-cache/tmp/d24e82056000cd3c/build +0 -0
  58. package/zig/zig-cache/tmp/d2d6630e2babce19/build +0 -0
  59. package/zig/zig-cache/tmp/d64ec8b30efbd39c/build +0 -0
  60. package/zig/zig-cache/tmp/dfc96c446ee3d83c/build +0 -0
  61. package/zig/zig-cache/tmp/e1245d4f3790795e/build +0 -0
  62. package/zig/zig-cache/tmp/e680fd8b7b04a063/build +0 -0
  63. package/zig/zig-cache/tmp/ed7c14c98bd9f25f/build +0 -0
  64. package/zig/zig-cache/tmp/f26e509f102208e6/build +0 -0
  65. package/zig/zig-cache/tmp/f8720cafd74033d4/build +0 -0
  66. package/zig/zig-cache/tmp/fac1b43e1ee19272/build +0 -0
  67. package/zig/zig-cache/tmp/fb98957abd64e116/build +0 -0
  68. package/zig/zig-cache/tmp/fc4e6e1289006215/build +0 -0
  69. package/zig/zig-cache/tmp/fcb97051d8caa0cc/build +0 -0
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-04-20T14:42:45Z
3
+ - **Last updated**: 2024-04-22T09:56:21Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,21 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ## [1.5.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/wasm-api@1.5.0) (2024-04-22)
13
+
14
+ #### 🚀 Features
15
+
16
+ - update build script for zig v0.12.0 (incomplete) ([99a1916](https://github.com/thi-ng/umbrella/commit/99a1916))
17
+ - store existing script as build-v0.11.zig
18
+
19
+ #### 🩹 Bug fixes
20
+
21
+ - re-add -rdynamic flag in build.zig ([f509d1e](https://github.com/thi-ng/umbrella/commit/f509d1e))
22
+
23
+ #### ♻️ Refactoring
24
+
25
+ - minor zig v0.12.0 updates ([4a0751c](https://github.com/thi-ng/umbrella/commit/4a0751c))
26
+
12
27
  ### [1.4.69](https://github.com/thi-ng/umbrella/tree/@thi.ng/wasm-api@1.4.69) (2024-04-20)
13
28
 
14
29
  #### ♻️ Refactoring
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/wasm-api",
3
- "version": "1.4.69",
3
+ "version": "1.5.0",
4
4
  "description": "Generic, modular, extensible API bridge and infrastructure for hybrid JS & WebAssembly projects",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -116,5 +116,5 @@
116
116
  "status": "alpha",
117
117
  "year": 2022
118
118
  },
119
- "gitHead": "8339d05ecc857e529c7325a9839c0063b89e728d\n"
119
+ "gitHead": "4e2bf6b12e35192e678b525fa699429370e357d3\n"
120
120
  }
@@ -0,0 +1,126 @@
1
+ //! Build helpers for using modules/packages distributed via NPM
2
+ //! Intended for use with https://thi.ng/wasm-api and support packages
3
+ //!
4
+ //! This version of the script is only compatible with:
5
+ //! Zig 0.11.0-dev.3857+7322aa118 or newer
6
+ //!
7
+ //! Use build.zig (in this same directory) for earlier Zig versions
8
+
9
+ const std = @import("std");
10
+ const Build = std.Build;
11
+
12
+ /// Config options
13
+ pub const WasmLibOpts = struct {
14
+ /// Base path to common node_modules directory under which
15
+ /// all to be imported modules are located
16
+ base: []const u8 = "node_modules",
17
+ /// Relative path to root source file
18
+ root: []const u8 = "zig/main.zig",
19
+ /// Additional WASM API support modules.
20
+ /// Only need to specify custom/extra modules
21
+ /// `wasm-api` and `wasm-api-bindgen` are auto-added as dependency for all...
22
+ modules: ?[]const ModuleSpec = null,
23
+ /// Build mode override (else allows config via CLI args)
24
+ optimize: ?std.builtin.Mode = null,
25
+ /// Additional WASM target features, e.g. `.simd128` to enable SIMD
26
+ features: ?[]const std.Target.wasm.Feature = null,
27
+ /// Initial memory (in bytes, MUST be multiple of 0x10000)
28
+ initialMemory: ?u64 = null,
29
+ /// Max memory (in bytes, MUST be multiple of 0x10000)
30
+ maxMemory: ?u64 = null,
31
+ // If true, build will also generate docs
32
+ // docs: bool = false,
33
+ };
34
+
35
+ /// WASM API sub-module declaration
36
+ pub const ModuleSpec = struct {
37
+ /// module import name/ID
38
+ name: []const u8,
39
+ /// Relative path to configured base path
40
+ path: []const u8,
41
+ /// Module IDs of other modules this module depends on
42
+ /// Only need to specify custom/extra modules
43
+ /// `wasm-api` and `wasm-api-bindgen` are auto-added as dependency for all...
44
+ dependencies: ?[]const []const u8 = null,
45
+ };
46
+
47
+ const wasmapi = "wasm-api";
48
+ const wasmbind = "wasm-api-bindgen";
49
+
50
+ /// Creates and returns a build step to build a dynamic WASM library, configured
51
+ /// with given options and package declarations. The given package specs will be inserted
52
+ pub fn wasmLib(b: *Build, opts: WasmLibOpts) *Build.Step.Compile {
53
+ const lib = b.addSharedLibrary(.{
54
+ .name = "main",
55
+ .root_source_file = .{ .path = opts.root },
56
+ .target = .{
57
+ .cpu_arch = .wasm32,
58
+ .os_tag = .freestanding,
59
+ .cpu_features_add = if (opts.features) |features| std.Target.wasm.featureSet(features) else std.Target.Cpu.Feature.Set.empty,
60
+ },
61
+ .optimize = if (opts.optimize) |m| m else b.standardOptimizeOption(.{}),
62
+ });
63
+ if (lib.optimize == .ReleaseSmall or lib.optimize == .ReleaseFast) lib.strip = true;
64
+
65
+ // build flags
66
+ lib.rdynamic = true;
67
+ lib.import_symbols = true;
68
+ lib.initial_memory = opts.initialMemory;
69
+ lib.max_memory = opts.maxMemory;
70
+
71
+ // add default dependencies
72
+ lib.addModule(
73
+ wasmapi,
74
+ b.createModule(.{
75
+ .source_file = modulePath(b.allocator, opts.base, "@thi.ng/wasm-api/zig/lib.zig"),
76
+ }),
77
+ );
78
+ lib.addModule(
79
+ wasmbind,
80
+ b.createModule(.{
81
+ .source_file = modulePath(b.allocator, opts.base, "@thi.ng/wasm-api-bindgen/zig/lib.zig"),
82
+ }),
83
+ );
84
+ if (opts.modules) |modules| {
85
+ for (modules) |mod| {
86
+ register(lib, mod, opts);
87
+ }
88
+ }
89
+ return lib;
90
+ }
91
+
92
+ /// Registers a single package and its deps (also injects core wasm-api deps)
93
+ pub fn register(step: *Build.Step.Compile, mod: ModuleSpec, opts: WasmLibOpts) void {
94
+ const num = if (mod.dependencies) |ids| ids.len else 0;
95
+ var dpkgs = step.step.owner.allocator.alloc(Build.ModuleDependency, num + 2) catch unreachable;
96
+ dpkgs[0] = if (step.modules.get(wasmapi)) |m| .{ .name = wasmapi, .module = m } else unreachable;
97
+ dpkgs[1] = if (step.modules.get(wasmbind)) |m| .{ .name = wasmbind, .module = m } else unreachable;
98
+ var i: usize = 2;
99
+ if (mod.dependencies) |ids| {
100
+ for (ids) |id| {
101
+ if (step.modules.get(id)) |m| {
102
+ if (isDuplicateId(dpkgs[0..i], id)) {
103
+ std.log.info("ignoring duplicate dependency: {s}", .{id});
104
+ continue;
105
+ }
106
+ dpkgs[i] = .{ .name = id, .module = m };
107
+ i += 1;
108
+ } else @panic("unknown dependency");
109
+ }
110
+ }
111
+ step.addModule(mod.name, step.step.owner.createModule(.{
112
+ .source_file = modulePath(step.step.owner.allocator, opts.base, mod.path),
113
+ .dependencies = dpkgs[0..i],
114
+ }));
115
+ }
116
+
117
+ fn isDuplicateId(deps: []Build.ModuleDependency, name: []const u8) bool {
118
+ for (deps) |d| {
119
+ if (std.mem.eql(u8, d.name, name)) return true;
120
+ }
121
+ return false;
122
+ }
123
+
124
+ fn modulePath(allocator: std.mem.Allocator, base: []const u8, path: []const u8) Build.FileSource {
125
+ return .{ .path = std.fs.path.join(allocator, &.{ base, path }) catch unreachable };
126
+ }
package/zig/build.zig CHANGED
@@ -50,55 +50,59 @@ const wasmbind = "wasm-api-bindgen";
50
50
  /// Creates and returns a build step to build a dynamic WASM library, configured
51
51
  /// with given options and package declarations. The given package specs will be inserted
52
52
  pub fn wasmLib(b: *Build, opts: WasmLibOpts) *Build.Step.Compile {
53
- const lib = b.addSharedLibrary(.{
53
+ const optimize = if (opts.optimize) |m| m else b.standardOptimizeOption(.{});
54
+ const lib = b.addExecutable(.{
54
55
  .name = "main",
55
56
  .root_source_file = .{ .path = opts.root },
56
- .target = .{
57
- .cpu_arch = .wasm32,
58
- .os_tag = .freestanding,
59
- .cpu_features_add = if (opts.features) |features| std.Target.wasm.featureSet(features) else std.Target.Cpu.Feature.Set.empty,
60
- },
61
- .optimize = if (opts.optimize) |m| m else b.standardOptimizeOption(.{}),
57
+ .target = b.resolveTargetQuery(
58
+ .{
59
+ .cpu_arch = .wasm32,
60
+ .os_tag = .freestanding,
61
+ .cpu_features_add = if (opts.features) |features| std.Target.wasm.featureSet(features) else std.Target.Cpu.Feature.Set.empty,
62
+ },
63
+ ),
64
+ .optimize = optimize,
65
+ .strip = (optimize == .ReleaseSmall or optimize == .ReleaseFast),
62
66
  });
63
- if (lib.optimize == .ReleaseSmall or lib.optimize == .ReleaseFast) lib.strip = true;
64
67
 
65
68
  // build flags
69
+ // https://github.com/ziglang/zig/pull/17815
70
+ lib.entry = .disabled;
66
71
  lib.rdynamic = true;
67
72
  lib.import_symbols = true;
68
73
  lib.initial_memory = opts.initialMemory;
69
74
  lib.max_memory = opts.maxMemory;
70
75
 
71
76
  // add default dependencies
72
- lib.addModule(
77
+ // https://ziggit.dev/t/what-happened-to-addmodule/2908/3
78
+ _ = lib.root_module.addImport(
73
79
  wasmapi,
74
80
  b.createModule(.{
75
- .source_file = modulePath(b.allocator, opts.base, "@thi.ng/wasm-api/zig/lib.zig"),
81
+ .root_source_file = modulePath(b.allocator, opts.base, "@thi.ng/wasm-api/zig/lib.zig"),
76
82
  }),
77
83
  );
78
- lib.addModule(
84
+ _ = lib.root_module.addImport(
79
85
  wasmbind,
80
86
  b.createModule(.{
81
- .source_file = modulePath(b.allocator, opts.base, "@thi.ng/wasm-api-bindgen/zig/lib.zig"),
87
+ .root_source_file = modulePath(b.allocator, opts.base, "@thi.ng/wasm-api-bindgen/zig/lib.zig"),
82
88
  }),
83
89
  );
84
90
  if (opts.modules) |modules| {
85
- for (modules) |mod| {
86
- register(lib, mod, opts);
87
- }
91
+ for (modules) |mod| register(lib, mod, opts);
88
92
  }
89
93
  return lib;
90
94
  }
91
95
 
92
96
  /// Registers a single package and its deps (also injects core wasm-api deps)
93
- pub fn register(step: *Build.Step.Compile, mod: ModuleSpec, opts: WasmLibOpts) void {
97
+ pub fn register(lib: *Build.Step.Compile, mod: ModuleSpec, opts: WasmLibOpts) void {
94
98
  const num = if (mod.dependencies) |ids| ids.len else 0;
95
- var dpkgs = step.step.owner.allocator.alloc(Build.ModuleDependency, num + 2) catch unreachable;
96
- dpkgs[0] = if (step.modules.get(wasmapi)) |m| .{ .name = wasmapi, .module = m } else unreachable;
97
- dpkgs[1] = if (step.modules.get(wasmbind)) |m| .{ .name = wasmbind, .module = m } else unreachable;
99
+ var dpkgs = lib.step.owner.allocator.alloc(Build.Module.Import, num + 2) catch unreachable;
100
+ dpkgs[0] = if (lib.root_module.import_table.get(wasmapi)) |m| .{ .name = wasmapi, .module = m } else unreachable;
101
+ dpkgs[1] = if (lib.root_module.import_table.get(wasmbind)) |m| .{ .name = wasmbind, .module = m } else unreachable;
98
102
  var i: usize = 2;
99
103
  if (mod.dependencies) |ids| {
100
104
  for (ids) |id| {
101
- if (step.modules.get(id)) |m| {
105
+ if (lib.root_module.import_table.get(id)) |m| {
102
106
  if (isDuplicateId(dpkgs[0..i], id)) {
103
107
  std.log.info("ignoring duplicate dependency: {s}", .{id});
104
108
  continue;
@@ -108,19 +112,19 @@ pub fn register(step: *Build.Step.Compile, mod: ModuleSpec, opts: WasmLibOpts) v
108
112
  } else @panic("unknown dependency");
109
113
  }
110
114
  }
111
- step.addModule(mod.name, step.step.owner.createModule(.{
112
- .source_file = modulePath(step.step.owner.allocator, opts.base, mod.path),
113
- .dependencies = dpkgs[0..i],
115
+ _ = lib.root_module.addImport(mod.name, lib.step.owner.createModule(.{
116
+ .root_source_file = modulePath(lib.step.owner.allocator, opts.base, mod.path),
117
+ .imports = dpkgs[0..i],
114
118
  }));
115
119
  }
116
120
 
117
- fn isDuplicateId(deps: []Build.ModuleDependency, name: []const u8) bool {
121
+ fn isDuplicateId(deps: []Build.Module.Import, name: []const u8) bool {
118
122
  for (deps) |d| {
119
123
  if (std.mem.eql(u8, d.name, name)) return true;
120
124
  }
121
125
  return false;
122
126
  }
123
127
 
124
- fn modulePath(allocator: std.mem.Allocator, base: []const u8, path: []const u8) Build.FileSource {
128
+ fn modulePath(allocator: std.mem.Allocator, base: []const u8, path: []const u8) Build.LazyPath {
125
129
  return .{ .path = std.fs.path.join(allocator, &.{ base, path }) catch unreachable };
126
130
  }
package/zig/lib.zig CHANGED
@@ -51,7 +51,7 @@ pub inline fn allocator() ?std.mem.Allocator {
51
51
  /// Note: For SIMD compatibility all allocations are aligned to 16 bytes
52
52
  pub export fn _wasm_allocate(numBytes: usize) usize {
53
53
  if (allocator()) |alloc| {
54
- var mem = alloc.alignedAlloc(u8, 16, numBytes) catch return 0;
54
+ const mem = alloc.alignedAlloc(u8, 16, numBytes) catch return 0;
55
55
  return @intFromPtr(mem.ptr);
56
56
  }
57
57
  return 0;
@@ -200,7 +200,7 @@ test "ManagedIndex" {
200
200
  list.remove(1);
201
201
  list.remove(2);
202
202
 
203
- var ids = try list.freeIndicesAsSlice(allocator);
203
+ const ids = try list.freeIndicesAsSlice(allocator);
204
204
  defer allocator.free(ids);
205
205
  try expectEqualSlices(u8, &[_]u8{ 2, 1 }, ids);
206
206
 
@@ -224,7 +224,7 @@ test "ManagedIndex" {
224
224
  list.remove(2);
225
225
  list.remove(1);
226
226
 
227
- var ids2 = try list.freeIndicesAsSlice(allocator);
227
+ const ids2 = try list.freeIndicesAsSlice(allocator);
228
228
  defer allocator.free(ids2);
229
229
  try expectEqualSlices(u8, &[_]u8{ 1, 2, 0 }, ids2);
230
230
  }
File without changes
@@ -0,0 +1,2 @@
1
+ pub const packages = struct {};
2
+ pub const root_deps: []const struct { []const u8, []const u8 } = &.{};
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes