@thi.ng/wasm-api 0.17.1 → 0.17.3
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/CHANGELOG.md +10 -1
- package/README.md +30 -13
- package/api.d.ts +8 -4
- package/package.json +2 -2
- package/zig/{wasmapi.zig → lib.zig} +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2022-10-
|
|
3
|
+
- **Last updated**: 2022-10-31T09:19:33Z
|
|
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,15 @@ 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
|
+
### [0.17.3](https://github.com/thi-ng/umbrella/tree/@thi.ng/wasm-api@0.17.3) (2022-10-31)
|
|
13
|
+
|
|
14
|
+
#### ♻️ Refactoring
|
|
15
|
+
|
|
16
|
+
- restructure/rename zig files, update readdme ([c63ca10](https://github.com/thi-ng/umbrella/commit/c63ca10))
|
|
17
|
+
- enforce uniform project structure for all `[@thi.ng/wasm-api-](https://github.com/thi-ng/umbrella/tree/main/packages/wasm-api-)*` packages
|
|
18
|
+
- rename /zig/wasmapi.zig => /zig/lib.zig
|
|
19
|
+
- update readme w/ further info
|
|
20
|
+
|
|
12
21
|
### [0.17.1](https://github.com/thi-ng/umbrella/tree/@thi.ng/wasm-api@0.17.1) (2022-10-30)
|
|
13
22
|
|
|
14
23
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
|
@@ -17,6 +17,7 @@ This project is part of the
|
|
|
17
17
|
- [String handling](#string-handling)
|
|
18
18
|
- [Memory allocations](#memory-allocations)
|
|
19
19
|
- [Custom API modules](#custom-api-modules)
|
|
20
|
+
- [Building Zig projects with these hybrid API modules](#building-zig-projects-with-these-hybrid-api-modules)
|
|
20
21
|
- [Object indices & handles](#object-indices--handles)
|
|
21
22
|
- [Status](#status)
|
|
22
23
|
- [Support packages](#support-packages)
|
|
@@ -450,7 +451,7 @@ The actual allocator is implementation specific and suitable generic mechanisms
|
|
|
450
451
|
are defined for both the included Zig & C bindings. Please see for further
|
|
451
452
|
reference:
|
|
452
453
|
|
|
453
|
-
- [`/zig/
|
|
454
|
+
- [`/zig/lib.zig`](https://github.com/thi-ng/umbrella/blob/develop/packages/wasm-api/zig/lib.zig#L64):
|
|
454
455
|
comments about WASM-side allocator handling in Zig
|
|
455
456
|
- [`/include/wasmapi.h`](https://github.com/thi-ng/umbrella/blob/develop/packages/wasm-api/include/wasmapi.h#L18):
|
|
456
457
|
comments about WASM-side allocator handling in C/C++
|
|
@@ -541,9 +542,8 @@ export const bridge = new WasmBridge({ custom: new CustomAPI() });
|
|
|
541
542
|
```
|
|
542
543
|
|
|
543
544
|
In Zig (or any other language of your choice) we can then utilize this custom
|
|
544
|
-
API like so (Please also see
|
|
545
|
-
|
|
546
|
-
& other examples in this readme):
|
|
545
|
+
API like so (Please also see [example projects](https://github.com/thi-ng/umbrella/tree/develop/examples/zig-canvas/)
|
|
546
|
+
& other example snippets in this readme):
|
|
547
547
|
|
|
548
548
|
Bindings file / lib:
|
|
549
549
|
|
|
@@ -579,6 +579,19 @@ export fn test_randomVec4() void {
|
|
|
579
579
|
}
|
|
580
580
|
```
|
|
581
581
|
|
|
582
|
+
### Building Zig projects with these hybrid API modules
|
|
583
|
+
|
|
584
|
+
Some example projects (see [list below](#usage-examples)) provide custom
|
|
585
|
+
[`build.zig`](https://github.com/thi-ng/umbrella/blob/develop/examples/zig-canvas/build.zig)
|
|
586
|
+
&
|
|
587
|
+
[`npm.zig`](https://github.com/thi-ng/umbrella/blob/develop/examples/zig-canvas/npm.zig)
|
|
588
|
+
build scripts to easily integrate these hybrid TS/Zig packages into users'
|
|
589
|
+
development processes.
|
|
590
|
+
|
|
591
|
+
To avoid guesswork about the internals of these API modules, all of them are
|
|
592
|
+
using an overall uniform structure, with the main Zig entry point in
|
|
593
|
+
`/zig/lib.zig`...
|
|
594
|
+
|
|
582
595
|
### Object indices & handles
|
|
583
596
|
|
|
584
597
|
Since only numeric values can be exchanged between the WASM module and the JS
|
|
@@ -630,7 +643,9 @@ Since v0.15.0, the supplied Zig core bindings lib also includes a
|
|
|
630
643
|
[`ManagedIndex`](https://github.com/thi-ng/umbrella/blob/develop/packages/wasm-api/zig/managed-index.zig)
|
|
631
644
|
for similar dealings on the Zig side of the application. For example, in the
|
|
632
645
|
[@thi.ng/wasm-api-dom](https://github.com/thi-ng/umbrella/blob/develop/packages/wasm-api-dom/)
|
|
633
|
-
|
|
646
|
+
&
|
|
647
|
+
[@thi.ng/wasm-api-timer](https://github.com/thi-ng/umbrella/blob/develop/packages/wasm-api-timer/)
|
|
648
|
+
modules this is used to manage Zig event listeners.
|
|
634
649
|
|
|
635
650
|
## Status
|
|
636
651
|
|
|
@@ -640,7 +655,8 @@ module this is used to manage Zig event listeners.
|
|
|
640
655
|
|
|
641
656
|
## Support packages
|
|
642
657
|
|
|
643
|
-
- [@thi.ng/wasm-api-dom](https://github.com/thi-ng/umbrella/tree/develop/packages/wasm-api-dom) - Browser DOM bridge API for hybrid TypeScript & Zig applications
|
|
658
|
+
- [@thi.ng/wasm-api-dom](https://github.com/thi-ng/umbrella/tree/develop/packages/wasm-api-dom) - Browser DOM bridge API for hybrid TypeScript & WASM (Zig) applications
|
|
659
|
+
- [@thi.ng/wasm-api-timer](https://github.com/thi-ng/umbrella/tree/develop/packages/wasm-api-timer) - Delayed & scheduled function execution (via setTimeout() etc.) for hybrid WASM apps
|
|
644
660
|
|
|
645
661
|
## Installation
|
|
646
662
|
|
|
@@ -665,10 +681,10 @@ node --experimental-repl-await
|
|
|
665
681
|
> const wasmApi = await import("@thi.ng/wasm-api");
|
|
666
682
|
```
|
|
667
683
|
|
|
668
|
-
Package sizes (gzipped, pre-treeshake): ESM:
|
|
684
|
+
Package sizes (gzipped, pre-treeshake): ESM: 7.06 KB
|
|
669
685
|
|
|
670
|
-
**IMPORTANT:** The package includes code generators
|
|
671
|
-
|
|
686
|
+
**IMPORTANT:** The package includes multiple language code generators which are
|
|
687
|
+
**not** required for normal use of the API bridge. Hence, the actual package
|
|
672
688
|
size in production will be MUCH smaller than what's stated here!
|
|
673
689
|
|
|
674
690
|
## Dependencies
|
|
@@ -695,9 +711,10 @@ directory are using this package.
|
|
|
695
711
|
|
|
696
712
|
A selection:
|
|
697
713
|
|
|
698
|
-
| Screenshot
|
|
699
|
-
|
|
700
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/zig-canvas.png" width="240"/>
|
|
714
|
+
| Screenshot | Description | Live demo | Source |
|
|
715
|
+
|:-------------------------------------------------------------------------------------------------------------------|:--------------------------------------------|:--------------------------------------------------|:-------------------------------------------------------------------------------|
|
|
716
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/zig-canvas.png" width="240"/> | Zig-based DOM creation & canvas drawing app | [Demo](https://demo.thi.ng/umbrella/zig-canvas/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/zig-canvas) |
|
|
717
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/zig-counter.png" width="240"/> | Simple Zig/WASM click counter DOM component | [Demo](https://demo.thi.ng/umbrella/zig-counter/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/zig-counter) |
|
|
701
718
|
|
|
702
719
|
## API
|
|
703
720
|
|
|
@@ -756,7 +773,7 @@ folder):
|
|
|
756
773
|
```bash
|
|
757
774
|
# compile WASM binary
|
|
758
775
|
zig build-lib \
|
|
759
|
-
--pkg-begin wasmapi node_modules/@thi.ng/wasm-api/zig/
|
|
776
|
+
--pkg-begin wasmapi node_modules/@thi.ng/wasm-api/zig/lib.zig --pkg-end \
|
|
760
777
|
-target wasm32-freestanding \
|
|
761
778
|
-O ReleaseSmall -dynamic --strip \
|
|
762
779
|
hello.zig
|
package/api.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ export interface WasmExports {
|
|
|
53
53
|
* @remarks
|
|
54
54
|
* #### Zig
|
|
55
55
|
*
|
|
56
|
-
* Using the supplied Zig bindings (see `/zig/
|
|
56
|
+
* Using the supplied Zig bindings (see `/zig/lib.zig`), it's the
|
|
57
57
|
* user's responsibility to define a public `WASM_ALLOCATOR` in the root
|
|
58
58
|
* source file to enable allocations, e.g. using the
|
|
59
59
|
* [`std.heap.GeneralPurposeAllocator`](https://ziglang.org/documentation/master/#Choosing-an-Allocator)
|
|
@@ -161,12 +161,12 @@ export interface IWasmMemoryAccess {
|
|
|
161
161
|
}
|
|
162
162
|
/**
|
|
163
163
|
* Core API of WASM imports defined by the {@link WasmBridge}. The same
|
|
164
|
-
* functions are declared as bindings in `/zig/
|
|
164
|
+
* functions are declared as bindings in `/zig/lib.zig`. **Also see this
|
|
165
165
|
* file for documentation of each function...**
|
|
166
166
|
*
|
|
167
167
|
* @remarks
|
|
168
168
|
* Zig API:
|
|
169
|
-
* https://github.com/thi-ng/umbrella/blob/develop/packages/wasm-api/zig/
|
|
169
|
+
* https://github.com/thi-ng/umbrella/blob/develop/packages/wasm-api/zig/lib.zig
|
|
170
170
|
*/
|
|
171
171
|
export interface CoreAPI extends WebAssembly.ModuleImports {
|
|
172
172
|
printI8: Fn<number, void>;
|
|
@@ -458,7 +458,11 @@ export interface CodeGenOpts extends CodeGenOptsBase {
|
|
|
458
458
|
*/
|
|
459
459
|
stringType: "slice" | "ptr";
|
|
460
460
|
/**
|
|
461
|
-
* If true (default), forces uppercase enum identifiers
|
|
461
|
+
* If true (default), forces uppercase enum identifiers.
|
|
462
|
+
*
|
|
463
|
+
* @remarks
|
|
464
|
+
* This option is ignored in {@link ZIG} since it's idiomatic for that
|
|
465
|
+
* language to only use lowercase/camelCase enum IDs.
|
|
462
466
|
*
|
|
463
467
|
* @defaultValue true
|
|
464
468
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/wasm-api",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.3",
|
|
4
4
|
"description": "Generic, modular, extensible API bridge, polyglot glue code and bindings code generators for hybrid JS & WebAssembly projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -141,5 +141,5 @@
|
|
|
141
141
|
"status": "alpha",
|
|
142
142
|
"year": 2022
|
|
143
143
|
},
|
|
144
|
-
"gitHead": "
|
|
144
|
+
"gitHead": "7c5c0cb37ff88c2fa5dd77dd78bf3a5ceb5c62c6\n"
|
|
145
145
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//!
|
|
1
|
+
//! Zig API for https://thi.ng/wasm-api
|
|
2
2
|
|
|
3
3
|
const std = @import("std");
|
|
4
4
|
const root = @import("root");
|
|
@@ -72,7 +72,7 @@ pub fn panic(msg: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn {
|
|
|
72
72
|
/// Note: The type for this var is purposefully chosen as an optional,
|
|
73
73
|
/// effectively disabling allocations from the WASM host side if no
|
|
74
74
|
/// `WASM_ALLOCATOR` is set (or set to null).
|
|
75
|
-
pub fn allocator() ?std.mem.Allocator {
|
|
75
|
+
pub inline fn allocator() ?std.mem.Allocator {
|
|
76
76
|
return if (@hasDecl(root, "WASM_ALLOCATOR")) root.WASM_ALLOCATOR else null;
|
|
77
77
|
}
|
|
78
78
|
|