wickra-compile 0.1.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.
- package/LICENSE-APACHE +201 -0
- package/LICENSE-MIT +21 -0
- package/README.md +278 -0
- package/index.d.ts +15 -0
- package/index.js +702 -0
- package/package.json +67 -0
- package/wickra-compile.darwin-arm64.node +0 -0
- package/wickra-compile.darwin-x64.node +0 -0
- package/wickra-compile.linux-arm64-gnu.node +0 -0
- package/wickra-compile.linux-x64-gnu.node +0 -0
- package/wickra-compile.win32-arm64-msvc.node +0 -0
- package/wickra-compile.win32-x64-msvc.node +0 -0
package/LICENSE-APACHE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 kingchenc and the Wickra contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kingchenc and the Wickra contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://wickra.org"><img src="https://raw.githubusercontent.com/wickra-lib/.github/main/profile/wickra-banner.webp?v=514" alt="Wickra Compile — compile a strategy spec into a standalone deployable" width="100%"></a>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
[](https://github.com/wickra-lib/wickra)
|
|
6
|
+
[](https://github.com/wickra-lib/wickra-compile)
|
|
7
|
+
[](https://github.com/wickra-lib/wickra-compile/actions/workflows/ci.yml)
|
|
8
|
+
[](https://github.com/wickra-lib/wickra-compile/actions/workflows/codeql.yml)
|
|
9
|
+
[](https://codecov.io/gh/wickra-lib/wickra-compile)
|
|
10
|
+
[](https://github.com/wickra-lib/wickra-compile/releases/latest)
|
|
11
|
+
[](https://crates.io/crates/wickra-compile)
|
|
12
|
+
[](https://pypi.org/project/wickra-compile/)
|
|
13
|
+
[](https://www.npmjs.com/package/wickra-compile)
|
|
14
|
+
[](https://www.nuget.org/packages/Wickra.Compile)
|
|
15
|
+
[](https://central.sonatype.com/artifact/org.wickra/wickra-compile)
|
|
16
|
+
[](https://pkg.go.dev/github.com/wickra-lib/wickra-compile-go)
|
|
17
|
+
[](https://wickra-lib.r-universe.dev)
|
|
18
|
+
[](#license)
|
|
19
|
+
[](https://scorecard.dev/viewer/?uri=github.com/wickra-lib/wickra-compile)
|
|
20
|
+
[](https://www.bestpractices.dev)
|
|
21
|
+
[](https://github.com/wickra-lib/wickra-compile/attestations)
|
|
22
|
+
[](https://wickra.org)
|
|
23
|
+
[](golden/)
|
|
24
|
+
[](#determinism)
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
# Wickra Compile
|
|
29
|
+
|
|
30
|
+
**Compile a strategy spec into a standalone deployable: a WASM module, a
|
|
31
|
+
self-contained binary, or a `no_std` artifact for microcontrollers. Write once
|
|
32
|
+
as data, deploy anywhere.**
|
|
33
|
+
|
|
34
|
+
> **Part of the [Wickra ecosystem](https://github.com/wickra-lib):** the same data-driven core and ten-language binding surface also power [wickra-exchange](https://github.com/wickra-lib/wickra-exchange), [wickra-backtest](https://github.com/wickra-lib/wickra-backtest), [wickra-terminal](https://github.com/wickra-lib/wickra-terminal) and 20 more — see [the full list](https://github.com/wickra-lib).
|
|
35
|
+
> same [`StrategySpec`](https://github.com/wickra-lib/wickra-backtest) that
|
|
36
|
+
> `wickra-backtest` runs and emits a self-contained project that embeds the spec
|
|
37
|
+
> and calls the Wickra engine — no interpreter, no runtime spec parsing.
|
|
38
|
+
|
|
39
|
+
Wickra Compile is the **output** side of strategy authoring: instead of wrestling
|
|
40
|
+
a Pine-like input language, you write your strategy as a `StrategySpec` (data),
|
|
41
|
+
and the compiler generates a standalone Rust project that embeds it verbatim and
|
|
42
|
+
targets WASM, a native binary, or bare metal. The generated **manifest** — the
|
|
43
|
+
list of files with their hashes plus the canonical spec hash — is
|
|
44
|
+
**byte-identical across all ten language bindings** and reproducible across runs.
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# Print the deterministic manifest for a strategy spec — no toolchain needed.
|
|
48
|
+
cargo run -p wickra-compile -- --spec golden/specs/sma_cross.json --manifest
|
|
49
|
+
|
|
50
|
+
# Generate the project without building it, then inspect it.
|
|
51
|
+
cargo run -p wickra-compile -- --spec golden/specs/sma_cross.json --dry-run --out ./out
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Status
|
|
55
|
+
|
|
56
|
+
Early development (0.1.0). The codegen core, the reference CLI, the
|
|
57
|
+
ten-language binding surface, the golden corpus and the full CI matrix are in
|
|
58
|
+
place; 0.1.0 is the first published release.
|
|
59
|
+
|
|
60
|
+
## How it works
|
|
61
|
+
|
|
62
|
+
A `CompileSpec` names a `StrategySpec`, a `target` (`wasm` / `binary` /
|
|
63
|
+
`no_std`), an optimisation level and optional embedded data. The codegen core:
|
|
64
|
+
|
|
65
|
+
1. validates the spec (the strategy round-trips as a `wickra_backtest::StrategySpec`;
|
|
66
|
+
the crate name and MCU triple are checked against an allowlist);
|
|
67
|
+
2. renders a generated Rust project from embedded templates (the spec is embedded
|
|
68
|
+
as **data**, never run through the template engine);
|
|
69
|
+
3. emits a deterministic **manifest** — every file's SHA-256 and length, the
|
|
70
|
+
canonical spec hash, and the project hash — in stable path order;
|
|
71
|
+
4. optionally invokes `cargo` (argv, never a shell) to build the artifact.
|
|
72
|
+
|
|
73
|
+
## Determinism
|
|
74
|
+
|
|
75
|
+
The manifest is the golden moat: `BTreeMap` everywhere in the output path, stable
|
|
76
|
+
path-sorted file lists, no RNG, no timestamps, canonical spec serialisation
|
|
77
|
+
before hashing. The same `CompileSpec` + `target` produces a byte-identical
|
|
78
|
+
manifest on every run and in every language binding. (The compiled *binary*
|
|
79
|
+
bytes are only reproducible with a reproducible-build toolchain — that is
|
|
80
|
+
best-effort and separate from the manifest guarantee.)
|
|
81
|
+
|
|
82
|
+
## Quickstart
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Print the deterministic manifest for a strategy spec — no toolchain needed.
|
|
86
|
+
wickra-compile --spec golden/specs/sma_cross.json --manifest
|
|
87
|
+
|
|
88
|
+
# Generate the project without building it, then inspect it.
|
|
89
|
+
wickra-compile --spec golden/specs/sma_cross.json --dry-run --out ./out
|
|
90
|
+
|
|
91
|
+
# Retarget the same spec without editing it.
|
|
92
|
+
wickra-compile --spec golden/specs/sma_cross.json --target wasm --opt size
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Use in any language
|
|
96
|
+
|
|
97
|
+
The same handle + `command_json` + `version` surface ships for Rust, Python,
|
|
98
|
+
Node.js, WASM, and — over a C ABI hub — C, C++, C#, Go, Java and R. Each binding
|
|
99
|
+
passes the command string through verbatim, so the manifest they return is
|
|
100
|
+
identical.
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
import json
|
|
104
|
+
from wickra_compile import Compiler
|
|
105
|
+
|
|
106
|
+
spec = open("golden/specs/sma_cross.json").read()
|
|
107
|
+
out = json.loads(Compiler().command(f'{{"cmd":"compile","dry_run":true,"spec":{spec}}}'))
|
|
108
|
+
print(out["manifest"]["project_hash"]) # identical in every binding
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
See [`examples/`](examples/) for the same program in all ten languages.
|
|
112
|
+
|
|
113
|
+
## Documentation
|
|
114
|
+
|
|
115
|
+
- [ARCHITECTURE.md](docs/ARCHITECTURE.md) — the crates and the codegen pipeline.
|
|
116
|
+
- [COMPILESPEC.md](docs/COMPILESPEC.md) — the input schema.
|
|
117
|
+
- [TARGETS.md](docs/TARGETS.md) — WASM / binary / `no_std` and the MCU allowlist.
|
|
118
|
+
- [DETERMINISM.md](docs/DETERMINISM.md) — why the manifest is reproducible.
|
|
119
|
+
- [TEMPLATES.md](docs/TEMPLATES.md) — codegen and injection safety.
|
|
120
|
+
- [Cookbook.md](docs/Cookbook.md) — practical recipes.
|
|
121
|
+
|
|
122
|
+
## Project layout
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
crates/compile-core the library: spec, canonical JSON, codegen, manifest
|
|
126
|
+
crates/compile-cli the wickra-compile CLI
|
|
127
|
+
crates/compile-bench criterion micro-benchmarks
|
|
128
|
+
bindings/* ten language surfaces (c, python, node, wasm, csharp, go, java, r)
|
|
129
|
+
golden/ specs + blessed manifests (the cross-language corpus)
|
|
130
|
+
examples/ one runnable example per language
|
|
131
|
+
docs/ architecture, spec, targets, determinism, templates, cookbook
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Building everything from source
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
cargo build --workspace
|
|
138
|
+
cargo test --workspace --all-features
|
|
139
|
+
cargo clippy --workspace --all-targets --all-features -- -D warnings
|
|
140
|
+
cargo run -p wickra-compile -- --spec golden/specs/sma_cross.json --manifest
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Each binding builds from its own directory — see the per-binding READMEs under
|
|
144
|
+
`bindings/`. The operating-mode test builds the generated `no_std` project for
|
|
145
|
+
real, so `rustup target add thumbv7em-none-eabihf` before `cargo test`.
|
|
146
|
+
|
|
147
|
+
## Testing
|
|
148
|
+
|
|
149
|
+
Run the suites with the commands in
|
|
150
|
+
[Building everything from source](#building-everything-from-source).
|
|
151
|
+
|
|
152
|
+
- **`wickra-compile-core`** — unit tests per template and target, canonical
|
|
153
|
+
determinism (a spec in any key order hashes the same), property tests over
|
|
154
|
+
specs and the command envelope, and the operating-mode check: the manifest a
|
|
155
|
+
dry run describes is the manifest a real build builds (the `no_std` project,
|
|
156
|
+
which has no dependencies and compiles in seconds). The golden fixtures in
|
|
157
|
+
`golden/` are the anchor: every spec must produce the same manifest bytes
|
|
158
|
+
here as in every binding.
|
|
159
|
+
- **Every binding** asserts the *same* golden manifest and the same
|
|
160
|
+
operating-mode equivalence (the WASM build, which carries no toolchain,
|
|
161
|
+
checks key-order independence instead of a real build). That is the whole
|
|
162
|
+
cross-language claim, so it is checked the same way in each one rather than
|
|
163
|
+
approximated per language: Python with pytest (and a plain runner on 3.9),
|
|
164
|
+
Node with `node --test`, WASM through the nodejs build, C and C++ through
|
|
165
|
+
`ctest`, C# with `dotnet test`, Go with `go test`, Java with JUnit, and R
|
|
166
|
+
with the shipped `tests/smoke.R` plus the repository's `run_tests.R`.
|
|
167
|
+
- **Examples** — every example under `examples/` runs in CI and is held to the
|
|
168
|
+
version and the `project_hash` it prints.
|
|
169
|
+
- **Real builds** — the nightly build-targets job cross-compiles a generated
|
|
170
|
+
project per target family (wasm32, thumbv7em) with the CLI.
|
|
171
|
+
- **Fuzz** — `fuzz/` holds libFuzzer targets over spec and target parsing, the
|
|
172
|
+
canonical hash and the codegen; CI runs each for a short smoke.
|
|
173
|
+
|
|
174
|
+
## Benchmarks
|
|
175
|
+
|
|
176
|
+
Codegen is pure data templating and hashing — tens of microseconds, no
|
|
177
|
+
compilation. See [BENCHMARKS.md](BENCHMARKS.md); reproduce with
|
|
178
|
+
`cargo bench -p compile-bench`.
|
|
179
|
+
|
|
180
|
+
## Requirements
|
|
181
|
+
|
|
182
|
+
- **Rust 1.86+** — the workspace MSRV; the Node binding needs **Rust 1.88**.
|
|
183
|
+
Building a generated artifact additionally needs its target toolchain
|
|
184
|
+
(`wasm32-unknown-unknown` for WASM, a `thumbv*` target for `no_std`).
|
|
185
|
+
- **Python 3.9+** — the Python binding.
|
|
186
|
+
- **Node 22+** — the Node binding.
|
|
187
|
+
- **Go 1.23+** — the Go binding.
|
|
188
|
+
- **Java 22+** — the Java binding.
|
|
189
|
+
- **R 4.1+** — the R package.
|
|
190
|
+
- **.NET 8+** — the C# binding.
|
|
191
|
+
- A **C11 / C++17** compiler with CMake 3.15+ for the C and C++ examples.
|
|
192
|
+
|
|
193
|
+
See each `bindings/<lang>/README.md` for the per-language build and install.
|
|
194
|
+
|
|
195
|
+
## Security
|
|
196
|
+
|
|
197
|
+
See [SECURITY.md](SECURITY.md) and [THREAT_MODEL.md](THREAT_MODEL.md). The
|
|
198
|
+
compiler generates code and can invoke `cargo` on it — run it only on trusted
|
|
199
|
+
specs.
|
|
200
|
+
|
|
201
|
+
## Ecosystem
|
|
202
|
+
|
|
203
|
+
Part of the [Wickra](https://github.com/wickra-lib/wickra) family — each one a
|
|
204
|
+
data-driven core with a CLI and the same ten-language binding surface:
|
|
205
|
+
|
|
206
|
+
- [**wickra**](https://github.com/wickra-lib/wickra) — main library (Rust core + Python / Node.js / WASM bindings + a C ABI for C / C++ / C# / Go / Java / R)
|
|
207
|
+
- [**wickra-playground**](https://github.com/wickra-lib/wickra-playground) — a polyglot strategy playground: one StrategySpec live side by side in Python, Rust, JS and Go, entirely in the browser
|
|
208
|
+
- [**wickra-exchange**](https://github.com/wickra-lib/wickra-exchange) — unified market-data + execution across ten crypto exchanges
|
|
209
|
+
- [**wickra-backtest**](https://github.com/wickra-lib/wickra-backtest) — event-driven backtester over the Wickra core
|
|
210
|
+
- [**wickra-terminal**](https://github.com/wickra-lib/wickra-terminal) — the trading terminal: a TUI and a browser renderer over the stack
|
|
211
|
+
- [**wickra-screener**](https://github.com/wickra-lib/wickra-screener) — parallel multi-symbol screening over 514 streaming indicators
|
|
212
|
+
- [**wickra-xray**](https://github.com/wickra-lib/wickra-xray) — market-microstructure explorer: footprint, order-book heatmap, liquidation map, funding/OI divergence
|
|
213
|
+
- [**wickra-copilot**](https://github.com/wickra-lib/wickra-copilot) — local market copilot grounded in real order-book, liquidation and funding microstructure
|
|
214
|
+
- [**wickra-shazam**](https://github.com/wickra-lib/wickra-shazam) — match an asset's current microstructure fingerprint against its entire history
|
|
215
|
+
- [**wickra-benchmark**](https://github.com/wickra-lib/wickra-benchmark) — reproducible, golden-verified benchmark suite — recompute any (strategy, dataset, report) in ten languages and confirm it byte-for-byte
|
|
216
|
+
- [**wickra-strategy-ci**](https://github.com/wickra-lib/wickra-strategy-ci) — Jest for trading strategies: golden-pin the report, catch regressions in CI, property-test against fuzzed data
|
|
217
|
+
- [**wickra-verify**](https://github.com/wickra-lib/wickra-verify) — confirm or refute a claimed backtest report against its strategy and data, in ten languages
|
|
218
|
+
- [**wickra-proof**](https://github.com/wickra-lib/wickra-proof) — Proof-of-Backtest: deterministic (spec, data) → report + blake3 hash, recomputable byte-for-byte in ten languages
|
|
219
|
+
- [**wickra-zk**](https://github.com/wickra-lib/wickra-zk) — prove a backtest zero-knowledge — on-chain-verifiable performance without revealing the data or the strategy
|
|
220
|
+
- [**wickra-impact**](https://github.com/wickra-lib/wickra-impact) — the backtester that knows you would have moved the market: agent-based fills on the real historical L2 order book
|
|
221
|
+
- [**wickra-darwin**](https://github.com/wickra-lib/wickra-darwin) — evolutionary strategy search at millions of backtests per second, mutating and crossing JSON specs across the 514-indicator space
|
|
222
|
+
- [**wickra-gym**](https://github.com/wickra-lib/wickra-gym) — a Gymnasium-compatible, microstructure-aware backtest environment with O(1) steps for deterministic RL rollouts
|
|
223
|
+
- [**wickra-feature-store**](https://github.com/wickra-lib/wickra-feature-store) — OHLCV and microstructure streams into ML-ready feature matrices over 514 O(1) streaming indicators
|
|
224
|
+
- [**wickra-genome**](https://github.com/wickra-lib/wickra-genome) — a vector database of the whole market: every asset a 514-dim live vector, for similarity search, clustering and anomaly detection
|
|
225
|
+
- [**wickra-timemachine**](https://github.com/wickra-lib/wickra-timemachine) — scrub the whole market like a video — every symbol, full order book, rewound to any moment via deterministic re-fold
|
|
226
|
+
- [**wickra-synth**](https://github.com/wickra-lib/wickra-synth) — deterministic synthetic market microstructure: OHLCV, order book, trades and funding from a single seed
|
|
227
|
+
- [**wickra-radar**](https://github.com/wickra-lib/wickra-radar) — a liquidation-cascade early-warning radar over 514 streaming indicators
|
|
228
|
+
- [**wickra-embed**](https://github.com/wickra-lib/wickra-embed) — allocation-free, `no_std` streaming indicators for bare-metal and HFT, byte-for-byte identical to the core
|
|
229
|
+
- [**wickra-pico**](https://github.com/wickra-lib/wickra-pico) — the O(1) indicator core running bare-metal on a $5 Raspberry Pi Pico — the LED blinks on the EMA cross
|
|
230
|
+
|
|
231
|
+
Docs at [docs.wickra.org](https://docs.wickra.org); the marketing site and
|
|
232
|
+
in-browser demo at [wickra.org](https://wickra.org).
|
|
233
|
+
|
|
234
|
+
## Contributing
|
|
235
|
+
|
|
236
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
237
|
+
|
|
238
|
+
## License
|
|
239
|
+
|
|
240
|
+
Dual-licensed under either of
|
|
241
|
+
|
|
242
|
+
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE))
|
|
243
|
+
- MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
244
|
+
|
|
245
|
+
at your option. Unless you explicitly state otherwise, any contribution
|
|
246
|
+
intentionally submitted for inclusion in this work, as defined in the Apache-2.0
|
|
247
|
+
license, shall be dual-licensed as above, without any additional terms or
|
|
248
|
+
conditions.
|
|
249
|
+
|
|
250
|
+
## Disclaimer
|
|
251
|
+
|
|
252
|
+
Wickra Compile is a code-generation tool, provided "as is" without warranty of
|
|
253
|
+
any kind. It generates projects and can invoke `cargo` to build them — run it
|
|
254
|
+
only on specs you trust. Nothing here is financial advice; compiled strategies
|
|
255
|
+
are your responsibility, and trading carries risk of loss.
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
<p align="center">
|
|
260
|
+
<a href="https://github.com/wickra-lib/wickra-compile">
|
|
261
|
+
<img alt="GitHub stars" src="https://raw.githubusercontent.com/wickra-lib/.github/main/profile/badges/wickra-compile/stars.svg">
|
|
262
|
+
</a>
|
|
263
|
+
<a href="https://github.com/wickra-lib/wickra-compile/network/members">
|
|
264
|
+
<img alt="GitHub forks" src="https://raw.githubusercontent.com/wickra-lib/.github/main/profile/badges/wickra-compile/forks.svg">
|
|
265
|
+
</a>
|
|
266
|
+
<a href="https://github.com/wickra-lib/wickra-compile/issues">
|
|
267
|
+
<img alt="GitHub issues" src="https://raw.githubusercontent.com/wickra-lib/.github/main/profile/badges/wickra-compile/issues.svg">
|
|
268
|
+
</a>
|
|
269
|
+
</p>
|
|
270
|
+
|
|
271
|
+
<p align="center">
|
|
272
|
+
Built on <a href="https://github.com/wickra-lib/wickra">Wickra</a>. If it saved you time, the cheapest way to say thanks is to ⭐ the repo.
|
|
273
|
+
</p>
|
|
274
|
+
|
|
275
|
+
<p align="center">
|
|
276
|
+
<img alt="wickra-compile star history" width="640"
|
|
277
|
+
src="https://raw.githubusercontent.com/wickra-lib/.github/main/profile/badges/wickra-compile/star-history.svg">
|
|
278
|
+
</p>
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/** A compiler driven by JSON commands. */
|
|
5
|
+
export declare class Compiler {
|
|
6
|
+
/** Construct a compiler handle. */
|
|
7
|
+
constructor()
|
|
8
|
+
/**
|
|
9
|
+
* Apply a command envelope (`{"cmd":"...", ...}`) and return the response
|
|
10
|
+
* JSON. Domain errors are reported in-band as `{"ok":false,"error":...}`.
|
|
11
|
+
*/
|
|
12
|
+
command(cmdJson: string): string
|
|
13
|
+
/** The crate version. */
|
|
14
|
+
version(): string
|
|
15
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,702 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
/* auto-generated by NAPI-RS */
|
|
4
|
+
|
|
5
|
+
const { readFileSync } = require('fs')
|
|
6
|
+
let nativeBinding = null
|
|
7
|
+
const loadErrors = []
|
|
8
|
+
|
|
9
|
+
const isMusl = () => {
|
|
10
|
+
let musl = false
|
|
11
|
+
if (process.platform === 'linux') {
|
|
12
|
+
musl = isMuslFromFilesystem()
|
|
13
|
+
if (musl === null) {
|
|
14
|
+
musl = isMuslFromReport()
|
|
15
|
+
}
|
|
16
|
+
if (musl === null) {
|
|
17
|
+
musl = isMuslFromChildProcess()
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return musl
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
|
24
|
+
|
|
25
|
+
const isMuslFromFilesystem = () => {
|
|
26
|
+
try {
|
|
27
|
+
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
|
28
|
+
} catch {
|
|
29
|
+
return null
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const isMuslFromReport = () => {
|
|
34
|
+
let report = null
|
|
35
|
+
if (process.report && typeof process.report.getReport === 'function') {
|
|
36
|
+
process.report.excludeNetwork = true
|
|
37
|
+
report = process.report.getReport()
|
|
38
|
+
}
|
|
39
|
+
if (!report) {
|
|
40
|
+
return null
|
|
41
|
+
}
|
|
42
|
+
if (report.header && report.header.glibcVersionRuntime) {
|
|
43
|
+
return false
|
|
44
|
+
}
|
|
45
|
+
if (Array.isArray(report.sharedObjects)) {
|
|
46
|
+
if (report.sharedObjects.some(isFileMusl)) {
|
|
47
|
+
return true
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return false
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const isMuslFromChildProcess = () => {
|
|
54
|
+
try {
|
|
55
|
+
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
56
|
+
} catch (e) {
|
|
57
|
+
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
58
|
+
return false
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function requireNative() {
|
|
63
|
+
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
64
|
+
try {
|
|
65
|
+
return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH)
|
|
66
|
+
} catch (err) {
|
|
67
|
+
loadErrors.push(err)
|
|
68
|
+
}
|
|
69
|
+
} else if (process.platform === 'android') {
|
|
70
|
+
if (process.arch === 'arm64') {
|
|
71
|
+
try {
|
|
72
|
+
return require('./wickra-compile.android-arm64.node')
|
|
73
|
+
} catch (e) {
|
|
74
|
+
loadErrors.push(e)
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
const binding = require('wickra-compile-android-arm64')
|
|
78
|
+
const bindingPackageVersion = require('wickra-compile-android-arm64/package.json').version
|
|
79
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
80
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
81
|
+
}
|
|
82
|
+
return binding
|
|
83
|
+
} catch (e) {
|
|
84
|
+
loadErrors.push(e)
|
|
85
|
+
}
|
|
86
|
+
} else if (process.arch === 'arm') {
|
|
87
|
+
try {
|
|
88
|
+
return require('./wickra-compile.android-arm-eabi.node')
|
|
89
|
+
} catch (e) {
|
|
90
|
+
loadErrors.push(e)
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
const binding = require('wickra-compile-android-arm-eabi')
|
|
94
|
+
const bindingPackageVersion = require('wickra-compile-android-arm-eabi/package.json').version
|
|
95
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
96
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
97
|
+
}
|
|
98
|
+
return binding
|
|
99
|
+
} catch (e) {
|
|
100
|
+
loadErrors.push(e)
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
|
|
104
|
+
}
|
|
105
|
+
} else if (process.platform === 'win32') {
|
|
106
|
+
if (process.arch === 'x64') {
|
|
107
|
+
if ((process.config && process.config.variables && process.config.variables.shlib_suffix === 'dll.a') || (process.config && process.config.variables && process.config.variables.node_target_type === 'shared_library')) {
|
|
108
|
+
try {
|
|
109
|
+
return require('./wickra-compile.win32-x64-gnu.node')
|
|
110
|
+
} catch (e) {
|
|
111
|
+
loadErrors.push(e)
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
const binding = require('wickra-compile-win32-x64-gnu')
|
|
115
|
+
const bindingPackageVersion = require('wickra-compile-win32-x64-gnu/package.json').version
|
|
116
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
117
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
118
|
+
}
|
|
119
|
+
return binding
|
|
120
|
+
} catch (e) {
|
|
121
|
+
loadErrors.push(e)
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
try {
|
|
125
|
+
return require('./wickra-compile.win32-x64-msvc.node')
|
|
126
|
+
} catch (e) {
|
|
127
|
+
loadErrors.push(e)
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
const binding = require('wickra-compile-win32-x64-msvc')
|
|
131
|
+
const bindingPackageVersion = require('wickra-compile-win32-x64-msvc/package.json').version
|
|
132
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
133
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
134
|
+
}
|
|
135
|
+
return binding
|
|
136
|
+
} catch (e) {
|
|
137
|
+
loadErrors.push(e)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
} else if (process.arch === 'ia32') {
|
|
141
|
+
try {
|
|
142
|
+
return require('./wickra-compile.win32-ia32-msvc.node')
|
|
143
|
+
} catch (e) {
|
|
144
|
+
loadErrors.push(e)
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
const binding = require('wickra-compile-win32-ia32-msvc')
|
|
148
|
+
const bindingPackageVersion = require('wickra-compile-win32-ia32-msvc/package.json').version
|
|
149
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
150
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
151
|
+
}
|
|
152
|
+
return binding
|
|
153
|
+
} catch (e) {
|
|
154
|
+
loadErrors.push(e)
|
|
155
|
+
}
|
|
156
|
+
} else if (process.arch === 'arm64') {
|
|
157
|
+
try {
|
|
158
|
+
return require('./wickra-compile.win32-arm64-msvc.node')
|
|
159
|
+
} catch (e) {
|
|
160
|
+
loadErrors.push(e)
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
const binding = require('wickra-compile-win32-arm64-msvc')
|
|
164
|
+
const bindingPackageVersion = require('wickra-compile-win32-arm64-msvc/package.json').version
|
|
165
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
166
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
167
|
+
}
|
|
168
|
+
return binding
|
|
169
|
+
} catch (e) {
|
|
170
|
+
loadErrors.push(e)
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
|
|
174
|
+
}
|
|
175
|
+
} else if (process.platform === 'darwin') {
|
|
176
|
+
try {
|
|
177
|
+
return require('./wickra-compile.darwin-universal.node')
|
|
178
|
+
} catch (e) {
|
|
179
|
+
loadErrors.push(e)
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
const binding = require('wickra-compile-darwin-universal')
|
|
183
|
+
const bindingPackageVersion = require('wickra-compile-darwin-universal/package.json').version
|
|
184
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
185
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
186
|
+
}
|
|
187
|
+
return binding
|
|
188
|
+
} catch (e) {
|
|
189
|
+
loadErrors.push(e)
|
|
190
|
+
}
|
|
191
|
+
if (process.arch === 'x64') {
|
|
192
|
+
try {
|
|
193
|
+
return require('./wickra-compile.darwin-x64.node')
|
|
194
|
+
} catch (e) {
|
|
195
|
+
loadErrors.push(e)
|
|
196
|
+
}
|
|
197
|
+
try {
|
|
198
|
+
const binding = require('wickra-compile-darwin-x64')
|
|
199
|
+
const bindingPackageVersion = require('wickra-compile-darwin-x64/package.json').version
|
|
200
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
201
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
202
|
+
}
|
|
203
|
+
return binding
|
|
204
|
+
} catch (e) {
|
|
205
|
+
loadErrors.push(e)
|
|
206
|
+
}
|
|
207
|
+
} else if (process.arch === 'arm64') {
|
|
208
|
+
try {
|
|
209
|
+
return require('./wickra-compile.darwin-arm64.node')
|
|
210
|
+
} catch (e) {
|
|
211
|
+
loadErrors.push(e)
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
const binding = require('wickra-compile-darwin-arm64')
|
|
215
|
+
const bindingPackageVersion = require('wickra-compile-darwin-arm64/package.json').version
|
|
216
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
217
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
218
|
+
}
|
|
219
|
+
return binding
|
|
220
|
+
} catch (e) {
|
|
221
|
+
loadErrors.push(e)
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
|
|
225
|
+
}
|
|
226
|
+
} else if (process.platform === 'freebsd') {
|
|
227
|
+
if (process.arch === 'x64') {
|
|
228
|
+
try {
|
|
229
|
+
return require('./wickra-compile.freebsd-x64.node')
|
|
230
|
+
} catch (e) {
|
|
231
|
+
loadErrors.push(e)
|
|
232
|
+
}
|
|
233
|
+
try {
|
|
234
|
+
const binding = require('wickra-compile-freebsd-x64')
|
|
235
|
+
const bindingPackageVersion = require('wickra-compile-freebsd-x64/package.json').version
|
|
236
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
237
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
238
|
+
}
|
|
239
|
+
return binding
|
|
240
|
+
} catch (e) {
|
|
241
|
+
loadErrors.push(e)
|
|
242
|
+
}
|
|
243
|
+
} else if (process.arch === 'arm64') {
|
|
244
|
+
try {
|
|
245
|
+
return require('./wickra-compile.freebsd-arm64.node')
|
|
246
|
+
} catch (e) {
|
|
247
|
+
loadErrors.push(e)
|
|
248
|
+
}
|
|
249
|
+
try {
|
|
250
|
+
const binding = require('wickra-compile-freebsd-arm64')
|
|
251
|
+
const bindingPackageVersion = require('wickra-compile-freebsd-arm64/package.json').version
|
|
252
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
253
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
254
|
+
}
|
|
255
|
+
return binding
|
|
256
|
+
} catch (e) {
|
|
257
|
+
loadErrors.push(e)
|
|
258
|
+
}
|
|
259
|
+
} else {
|
|
260
|
+
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
|
|
261
|
+
}
|
|
262
|
+
} else if (process.platform === 'linux') {
|
|
263
|
+
if (process.arch === 'x64') {
|
|
264
|
+
if (isMusl()) {
|
|
265
|
+
try {
|
|
266
|
+
return require('./wickra-compile.linux-x64-musl.node')
|
|
267
|
+
} catch (e) {
|
|
268
|
+
loadErrors.push(e)
|
|
269
|
+
}
|
|
270
|
+
try {
|
|
271
|
+
const binding = require('wickra-compile-linux-x64-musl')
|
|
272
|
+
const bindingPackageVersion = require('wickra-compile-linux-x64-musl/package.json').version
|
|
273
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
274
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
275
|
+
}
|
|
276
|
+
return binding
|
|
277
|
+
} catch (e) {
|
|
278
|
+
loadErrors.push(e)
|
|
279
|
+
}
|
|
280
|
+
} else {
|
|
281
|
+
try {
|
|
282
|
+
return require('./wickra-compile.linux-x64-gnu.node')
|
|
283
|
+
} catch (e) {
|
|
284
|
+
loadErrors.push(e)
|
|
285
|
+
}
|
|
286
|
+
try {
|
|
287
|
+
const binding = require('wickra-compile-linux-x64-gnu')
|
|
288
|
+
const bindingPackageVersion = require('wickra-compile-linux-x64-gnu/package.json').version
|
|
289
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
290
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
291
|
+
}
|
|
292
|
+
return binding
|
|
293
|
+
} catch (e) {
|
|
294
|
+
loadErrors.push(e)
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
} else if (process.arch === 'arm64') {
|
|
298
|
+
if (isMusl()) {
|
|
299
|
+
try {
|
|
300
|
+
return require('./wickra-compile.linux-arm64-musl.node')
|
|
301
|
+
} catch (e) {
|
|
302
|
+
loadErrors.push(e)
|
|
303
|
+
}
|
|
304
|
+
try {
|
|
305
|
+
const binding = require('wickra-compile-linux-arm64-musl')
|
|
306
|
+
const bindingPackageVersion = require('wickra-compile-linux-arm64-musl/package.json').version
|
|
307
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
308
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
309
|
+
}
|
|
310
|
+
return binding
|
|
311
|
+
} catch (e) {
|
|
312
|
+
loadErrors.push(e)
|
|
313
|
+
}
|
|
314
|
+
} else {
|
|
315
|
+
try {
|
|
316
|
+
return require('./wickra-compile.linux-arm64-gnu.node')
|
|
317
|
+
} catch (e) {
|
|
318
|
+
loadErrors.push(e)
|
|
319
|
+
}
|
|
320
|
+
try {
|
|
321
|
+
const binding = require('wickra-compile-linux-arm64-gnu')
|
|
322
|
+
const bindingPackageVersion = require('wickra-compile-linux-arm64-gnu/package.json').version
|
|
323
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
324
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
325
|
+
}
|
|
326
|
+
return binding
|
|
327
|
+
} catch (e) {
|
|
328
|
+
loadErrors.push(e)
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
} else if (process.arch === 'arm') {
|
|
332
|
+
if (isMusl()) {
|
|
333
|
+
try {
|
|
334
|
+
return require('./wickra-compile.linux-arm-musleabihf.node')
|
|
335
|
+
} catch (e) {
|
|
336
|
+
loadErrors.push(e)
|
|
337
|
+
}
|
|
338
|
+
try {
|
|
339
|
+
const binding = require('wickra-compile-linux-arm-musleabihf')
|
|
340
|
+
const bindingPackageVersion = require('wickra-compile-linux-arm-musleabihf/package.json').version
|
|
341
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
342
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
343
|
+
}
|
|
344
|
+
return binding
|
|
345
|
+
} catch (e) {
|
|
346
|
+
loadErrors.push(e)
|
|
347
|
+
}
|
|
348
|
+
} else {
|
|
349
|
+
try {
|
|
350
|
+
return require('./wickra-compile.linux-arm-gnueabihf.node')
|
|
351
|
+
} catch (e) {
|
|
352
|
+
loadErrors.push(e)
|
|
353
|
+
}
|
|
354
|
+
try {
|
|
355
|
+
const binding = require('wickra-compile-linux-arm-gnueabihf')
|
|
356
|
+
const bindingPackageVersion = require('wickra-compile-linux-arm-gnueabihf/package.json').version
|
|
357
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
358
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
359
|
+
}
|
|
360
|
+
return binding
|
|
361
|
+
} catch (e) {
|
|
362
|
+
loadErrors.push(e)
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
} else if (process.arch === 'loong64') {
|
|
366
|
+
if (isMusl()) {
|
|
367
|
+
try {
|
|
368
|
+
return require('./wickra-compile.linux-loong64-musl.node')
|
|
369
|
+
} catch (e) {
|
|
370
|
+
loadErrors.push(e)
|
|
371
|
+
}
|
|
372
|
+
try {
|
|
373
|
+
const binding = require('wickra-compile-linux-loong64-musl')
|
|
374
|
+
const bindingPackageVersion = require('wickra-compile-linux-loong64-musl/package.json').version
|
|
375
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
376
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
377
|
+
}
|
|
378
|
+
return binding
|
|
379
|
+
} catch (e) {
|
|
380
|
+
loadErrors.push(e)
|
|
381
|
+
}
|
|
382
|
+
} else {
|
|
383
|
+
try {
|
|
384
|
+
return require('./wickra-compile.linux-loong64-gnu.node')
|
|
385
|
+
} catch (e) {
|
|
386
|
+
loadErrors.push(e)
|
|
387
|
+
}
|
|
388
|
+
try {
|
|
389
|
+
const binding = require('wickra-compile-linux-loong64-gnu')
|
|
390
|
+
const bindingPackageVersion = require('wickra-compile-linux-loong64-gnu/package.json').version
|
|
391
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
392
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
393
|
+
}
|
|
394
|
+
return binding
|
|
395
|
+
} catch (e) {
|
|
396
|
+
loadErrors.push(e)
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
} else if (process.arch === 'riscv64') {
|
|
400
|
+
if (isMusl()) {
|
|
401
|
+
try {
|
|
402
|
+
return require('./wickra-compile.linux-riscv64-musl.node')
|
|
403
|
+
} catch (e) {
|
|
404
|
+
loadErrors.push(e)
|
|
405
|
+
}
|
|
406
|
+
try {
|
|
407
|
+
const binding = require('wickra-compile-linux-riscv64-musl')
|
|
408
|
+
const bindingPackageVersion = require('wickra-compile-linux-riscv64-musl/package.json').version
|
|
409
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
410
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
411
|
+
}
|
|
412
|
+
return binding
|
|
413
|
+
} catch (e) {
|
|
414
|
+
loadErrors.push(e)
|
|
415
|
+
}
|
|
416
|
+
} else {
|
|
417
|
+
try {
|
|
418
|
+
return require('./wickra-compile.linux-riscv64-gnu.node')
|
|
419
|
+
} catch (e) {
|
|
420
|
+
loadErrors.push(e)
|
|
421
|
+
}
|
|
422
|
+
try {
|
|
423
|
+
const binding = require('wickra-compile-linux-riscv64-gnu')
|
|
424
|
+
const bindingPackageVersion = require('wickra-compile-linux-riscv64-gnu/package.json').version
|
|
425
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
426
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
427
|
+
}
|
|
428
|
+
return binding
|
|
429
|
+
} catch (e) {
|
|
430
|
+
loadErrors.push(e)
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
} else if (process.arch === 'ppc64') {
|
|
434
|
+
try {
|
|
435
|
+
return require('./wickra-compile.linux-ppc64-gnu.node')
|
|
436
|
+
} catch (e) {
|
|
437
|
+
loadErrors.push(e)
|
|
438
|
+
}
|
|
439
|
+
try {
|
|
440
|
+
const binding = require('wickra-compile-linux-ppc64-gnu')
|
|
441
|
+
const bindingPackageVersion = require('wickra-compile-linux-ppc64-gnu/package.json').version
|
|
442
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
443
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
444
|
+
}
|
|
445
|
+
return binding
|
|
446
|
+
} catch (e) {
|
|
447
|
+
loadErrors.push(e)
|
|
448
|
+
}
|
|
449
|
+
} else if (process.arch === 's390x') {
|
|
450
|
+
try {
|
|
451
|
+
return require('./wickra-compile.linux-s390x-gnu.node')
|
|
452
|
+
} catch (e) {
|
|
453
|
+
loadErrors.push(e)
|
|
454
|
+
}
|
|
455
|
+
try {
|
|
456
|
+
const binding = require('wickra-compile-linux-s390x-gnu')
|
|
457
|
+
const bindingPackageVersion = require('wickra-compile-linux-s390x-gnu/package.json').version
|
|
458
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
459
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
460
|
+
}
|
|
461
|
+
return binding
|
|
462
|
+
} catch (e) {
|
|
463
|
+
loadErrors.push(e)
|
|
464
|
+
}
|
|
465
|
+
} else {
|
|
466
|
+
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
|
|
467
|
+
}
|
|
468
|
+
} else if (process.platform === 'openharmony') {
|
|
469
|
+
if (process.arch === 'arm64') {
|
|
470
|
+
try {
|
|
471
|
+
return require('./wickra-compile.openharmony-arm64.node')
|
|
472
|
+
} catch (e) {
|
|
473
|
+
loadErrors.push(e)
|
|
474
|
+
}
|
|
475
|
+
try {
|
|
476
|
+
const binding = require('wickra-compile-openharmony-arm64')
|
|
477
|
+
const bindingPackageVersion = require('wickra-compile-openharmony-arm64/package.json').version
|
|
478
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
479
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
480
|
+
}
|
|
481
|
+
return binding
|
|
482
|
+
} catch (e) {
|
|
483
|
+
loadErrors.push(e)
|
|
484
|
+
}
|
|
485
|
+
} else if (process.arch === 'x64') {
|
|
486
|
+
try {
|
|
487
|
+
return require('./wickra-compile.openharmony-x64.node')
|
|
488
|
+
} catch (e) {
|
|
489
|
+
loadErrors.push(e)
|
|
490
|
+
}
|
|
491
|
+
try {
|
|
492
|
+
const binding = require('wickra-compile-openharmony-x64')
|
|
493
|
+
const bindingPackageVersion = require('wickra-compile-openharmony-x64/package.json').version
|
|
494
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
495
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
496
|
+
}
|
|
497
|
+
return binding
|
|
498
|
+
} catch (e) {
|
|
499
|
+
loadErrors.push(e)
|
|
500
|
+
}
|
|
501
|
+
} else if (process.arch === 'arm') {
|
|
502
|
+
try {
|
|
503
|
+
return require('./wickra-compile.openharmony-arm.node')
|
|
504
|
+
} catch (e) {
|
|
505
|
+
loadErrors.push(e)
|
|
506
|
+
}
|
|
507
|
+
try {
|
|
508
|
+
const binding = require('wickra-compile-openharmony-arm')
|
|
509
|
+
const bindingPackageVersion = require('wickra-compile-openharmony-arm/package.json').version
|
|
510
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
511
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
512
|
+
}
|
|
513
|
+
return binding
|
|
514
|
+
} catch (e) {
|
|
515
|
+
loadErrors.push(e)
|
|
516
|
+
}
|
|
517
|
+
} else {
|
|
518
|
+
loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
|
|
519
|
+
}
|
|
520
|
+
} else {
|
|
521
|
+
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function createLoadErrorChain(errors) {
|
|
526
|
+
return errors.reduce((previous, current) => {
|
|
527
|
+
let message
|
|
528
|
+
try {
|
|
529
|
+
message =
|
|
530
|
+
current && typeof current.message === 'string'
|
|
531
|
+
? current.message
|
|
532
|
+
: String(current)
|
|
533
|
+
} catch {
|
|
534
|
+
message = 'Unknown error'
|
|
535
|
+
}
|
|
536
|
+
const error = new Error(message)
|
|
537
|
+
error.cause = previous
|
|
538
|
+
return error
|
|
539
|
+
}, null)
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// NAPI_RS_FORCE_WASI is a tri-state flag:
|
|
543
|
+
// unset / any other value → native binding preferred, WASI is only a fallback
|
|
544
|
+
// 'true' → prefer WASI, but retain native as a lazy fallback
|
|
545
|
+
// 'error' → require WASI without initializing a native fallback
|
|
546
|
+
// Treating any non-empty string as truthy (the historical behavior) meant
|
|
547
|
+
// NAPI_RS_FORCE_WASI=false, NAPI_RS_FORCE_WASI=0, etc. inadvertently triggered
|
|
548
|
+
// the WASI path, causing ENOENT for packages shipped without a .wasi.cjs file.
|
|
549
|
+
//
|
|
550
|
+
// NAPI_RS_WASI_FLAVOR selects one exact generated flavor and implies strict
|
|
551
|
+
// WASI loading. It never crosses into another flavor or falls back to native.
|
|
552
|
+
const __napiWasiFlavors = ['wasm32-wasi']
|
|
553
|
+
const __napiWasiFlavor = process.env.NAPI_RS_WASI_FLAVOR
|
|
554
|
+
const __napiWasiFlavorRequested =
|
|
555
|
+
typeof __napiWasiFlavor === 'string' && __napiWasiFlavor.length > 0
|
|
556
|
+
if (
|
|
557
|
+
__napiWasiFlavorRequested &&
|
|
558
|
+
__napiWasiFlavors.indexOf(__napiWasiFlavor) === -1
|
|
559
|
+
) {
|
|
560
|
+
throw new Error(
|
|
561
|
+
'Unsupported WASI flavor "' +
|
|
562
|
+
__napiWasiFlavor +
|
|
563
|
+
'". Available flavors: ' +
|
|
564
|
+
__napiWasiFlavors.join(', '),
|
|
565
|
+
)
|
|
566
|
+
}
|
|
567
|
+
const forceWasiError = process.env.NAPI_RS_FORCE_WASI === 'error'
|
|
568
|
+
const forceWasi =
|
|
569
|
+
process.env.NAPI_RS_FORCE_WASI === 'true' ||
|
|
570
|
+
forceWasiError ||
|
|
571
|
+
__napiWasiFlavorRequested
|
|
572
|
+
|
|
573
|
+
if (!forceWasi) {
|
|
574
|
+
nativeBinding = requireNative()
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
if (!nativeBinding || forceWasi) {
|
|
578
|
+
let wasiBinding = null
|
|
579
|
+
let wasiBindingLoaded = false
|
|
580
|
+
const wasiBindingErrors = []
|
|
581
|
+
const __napiWasiResolveCandidate = (specifier, isPackage, localArtifacts) => {
|
|
582
|
+
try {
|
|
583
|
+
require.resolve(specifier)
|
|
584
|
+
} catch (resolveError) {
|
|
585
|
+
if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
|
|
586
|
+
throw resolveError
|
|
587
|
+
}
|
|
588
|
+
if (isPackage) {
|
|
589
|
+
try {
|
|
590
|
+
require.resolve(specifier + '/package.json')
|
|
591
|
+
} catch (packageError) {
|
|
592
|
+
if (packageError && packageError.code === 'MODULE_NOT_FOUND') {
|
|
593
|
+
return resolveError
|
|
594
|
+
}
|
|
595
|
+
// An exports restriction proves the package exists even when its
|
|
596
|
+
// package.json is not public. Preserve the root resolution failure.
|
|
597
|
+
throw resolveError
|
|
598
|
+
}
|
|
599
|
+
// The package exists but its main/export target is broken.
|
|
600
|
+
throw resolveError
|
|
601
|
+
}
|
|
602
|
+
return resolveError
|
|
603
|
+
}
|
|
604
|
+
if (localArtifacts) {
|
|
605
|
+
let artifactError = null
|
|
606
|
+
for (let i = 0; i < localArtifacts.length; i++) {
|
|
607
|
+
try {
|
|
608
|
+
require.resolve(localArtifacts[i])
|
|
609
|
+
return null
|
|
610
|
+
} catch (resolveError) {
|
|
611
|
+
if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
|
|
612
|
+
throw resolveError
|
|
613
|
+
}
|
|
614
|
+
artifactError = resolveError
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
return artifactError
|
|
618
|
+
}
|
|
619
|
+
return null
|
|
620
|
+
}
|
|
621
|
+
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
|
|
622
|
+
let candidateError = null
|
|
623
|
+
let candidateFailed = false
|
|
624
|
+
try {
|
|
625
|
+
candidateError = __napiWasiResolveCandidate('./wickra-compile.wasi.cjs', false, ['./wickra-compile.wasm32-wasi.debug.wasm', './wickra-compile.wasm32-wasi.wasm'])
|
|
626
|
+
candidateFailed = candidateError !== null
|
|
627
|
+
if (!candidateFailed) {
|
|
628
|
+
wasiBinding = require('./wickra-compile.wasi.cjs')
|
|
629
|
+
nativeBinding = wasiBinding
|
|
630
|
+
wasiBindingLoaded = true
|
|
631
|
+
}
|
|
632
|
+
} catch (err) {
|
|
633
|
+
candidateError = err
|
|
634
|
+
candidateFailed = true
|
|
635
|
+
}
|
|
636
|
+
if (candidateFailed) {
|
|
637
|
+
wasiBindingErrors.push(candidateError)
|
|
638
|
+
loadErrors.push(candidateError)
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
|
|
642
|
+
let candidateError = null
|
|
643
|
+
let candidateFailed = false
|
|
644
|
+
try {
|
|
645
|
+
candidateError = __napiWasiResolveCandidate('wickra-compile-wasm32-wasi', true, undefined)
|
|
646
|
+
candidateFailed = candidateError !== null
|
|
647
|
+
if (!candidateFailed) {
|
|
648
|
+
if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
649
|
+
const bindingPackageVersion = require('wickra-compile-wasm32-wasi/package.json').version
|
|
650
|
+
if (bindingPackageVersion !== '0.1.0') {
|
|
651
|
+
throw new Error(`WASI binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
wasiBinding = require('wickra-compile-wasm32-wasi')
|
|
655
|
+
nativeBinding = wasiBinding
|
|
656
|
+
wasiBindingLoaded = true
|
|
657
|
+
}
|
|
658
|
+
} catch (err) {
|
|
659
|
+
candidateError = err
|
|
660
|
+
candidateFailed = true
|
|
661
|
+
}
|
|
662
|
+
if (candidateFailed) {
|
|
663
|
+
wasiBindingErrors.push(candidateError)
|
|
664
|
+
loadErrors.push(candidateError)
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
if (
|
|
668
|
+
!wasiBindingLoaded &&
|
|
669
|
+
forceWasi &&
|
|
670
|
+
!forceWasiError &&
|
|
671
|
+
!__napiWasiFlavorRequested
|
|
672
|
+
) {
|
|
673
|
+
nativeBinding = requireNative()
|
|
674
|
+
}
|
|
675
|
+
if ((forceWasiError || __napiWasiFlavorRequested) && !wasiBindingLoaded) {
|
|
676
|
+
const error = new Error(
|
|
677
|
+
__napiWasiFlavorRequested
|
|
678
|
+
? 'WASI binding for flavor "' + __napiWasiFlavor + '" not found'
|
|
679
|
+
: 'WASI binding not found and NAPI_RS_FORCE_WASI is set to error',
|
|
680
|
+
)
|
|
681
|
+
error.cause = createLoadErrorChain(wasiBindingErrors)
|
|
682
|
+
throw error
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
if (!nativeBinding) {
|
|
687
|
+
if (loadErrors.length > 0) {
|
|
688
|
+
const error = new Error(
|
|
689
|
+
`Cannot find native binding. ` +
|
|
690
|
+
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
|
|
691
|
+
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
|
|
692
|
+
)
|
|
693
|
+
// assign instead of the `new Error(message, { cause })` options form,
|
|
694
|
+
// which Node < 16.9 silently ignores
|
|
695
|
+
error.cause = createLoadErrorChain(loadErrors)
|
|
696
|
+
throw error
|
|
697
|
+
}
|
|
698
|
+
throw new Error(`Failed to load native binding`)
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
module.exports = nativeBinding
|
|
702
|
+
module.exports.Compiler = nativeBinding.Compiler
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wickra-compile",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Compile a Wickra strategy spec into a standalone deployable (WASM, binary, or no_std) with a deterministic manifest. Node bindings powered by Rust.",
|
|
5
|
+
"author": "kingchenc <support@wickra.org>",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"license": "MIT OR Apache-2.0",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"trading",
|
|
11
|
+
"strategy",
|
|
12
|
+
"compiler",
|
|
13
|
+
"wasm",
|
|
14
|
+
"codegen",
|
|
15
|
+
"rust"
|
|
16
|
+
],
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/wickra-lib/wickra-compile"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/wickra-lib/wickra-compile/issues"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/wickra-lib/wickra-compile",
|
|
25
|
+
"files": [
|
|
26
|
+
"index.js",
|
|
27
|
+
"index.d.ts",
|
|
28
|
+
"*.node",
|
|
29
|
+
"LICENSE-MIT",
|
|
30
|
+
"LICENSE-APACHE"
|
|
31
|
+
],
|
|
32
|
+
"napi": {
|
|
33
|
+
"name": "wickra-compile",
|
|
34
|
+
"triples": {
|
|
35
|
+
"defaults": false,
|
|
36
|
+
"additional": [
|
|
37
|
+
"x86_64-unknown-linux-gnu",
|
|
38
|
+
"aarch64-unknown-linux-gnu",
|
|
39
|
+
"x86_64-apple-darwin",
|
|
40
|
+
"aarch64-apple-darwin",
|
|
41
|
+
"x86_64-pc-windows-msvc",
|
|
42
|
+
"aarch64-pc-windows-msvc"
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">= 22"
|
|
48
|
+
},
|
|
49
|
+
"optionalDependencies": {
|
|
50
|
+
"wickra-compile-linux-x64-gnu": "0.1.0",
|
|
51
|
+
"wickra-compile-linux-arm64-gnu": "0.1.0",
|
|
52
|
+
"wickra-compile-darwin-x64": "0.1.0",
|
|
53
|
+
"wickra-compile-darwin-arm64": "0.1.0",
|
|
54
|
+
"wickra-compile-win32-x64-msvc": "0.1.0",
|
|
55
|
+
"wickra-compile-win32-arm64-msvc": "0.1.0"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "napi build --platform --release",
|
|
59
|
+
"build:debug": "napi build --platform",
|
|
60
|
+
"artifacts": "napi artifacts",
|
|
61
|
+
"version": "napi version",
|
|
62
|
+
"test": "node --test"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@napi-rs/cli": "^3.9.0"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|