@overmvp/kumi 0.0.0-stage → 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.
Files changed (205) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +14 -2
  3. package/animation/color-transition.ts +196 -0
  4. package/animation/cycle.ts +151 -0
  5. package/animation/ease.ts +29 -0
  6. package/animation/index.ts +13 -0
  7. package/animation/package.json +12 -0
  8. package/animation/presets.ts +376 -0
  9. package/animation/spec.ts +197 -0
  10. package/builder/Cargo.lock +192 -0
  11. package/builder/Cargo.toml +7 -0
  12. package/builder/css-v1.mjs +334 -0
  13. package/builder/css-v1.test.mjs +321 -0
  14. package/builder/generated-output.mjs +61 -0
  15. package/builder/generated-output.test.mjs +132 -0
  16. package/builder/jsx-form.mjs +93 -0
  17. package/builder/jsx-form.test.mjs +48 -0
  18. package/builder/jsx-lists.mjs +209 -0
  19. package/builder/link-addon-package.mjs +86 -0
  20. package/builder/lua-assets.mjs +74 -0
  21. package/builder/lua-builtin-values.mjs +57 -0
  22. package/builder/lua-builtin-values.test.mjs +155 -0
  23. package/builder/lua-loop-closures.mjs +183 -0
  24. package/builder/lua-loop-closures.test.mjs +89 -0
  25. package/builder/lua-truthiness.mjs +61 -0
  26. package/builder/lua-truthiness.test.mjs +113 -0
  27. package/builder/module-declarations.mjs +594 -0
  28. package/builder/module-declarations.test.mjs +444 -0
  29. package/builder/native-kernels.mjs +60 -0
  30. package/builder/native-lua.d.ts +57 -0
  31. package/builder/native-routes.mjs +51 -0
  32. package/builder/no-static-ref-read.mjs +93 -0
  33. package/builder/no-static-ref-read.test.mjs +181 -0
  34. package/builder/secure-snippet.mjs +317 -0
  35. package/builder/secure-snippet.test.mjs +101 -0
  36. package/builder/shared-lua-runtime.mjs +150 -0
  37. package/builder/src/addon-link.lua +29 -0
  38. package/builder/src/arrays.lua +260 -0
  39. package/builder/src/assets.rs +177 -0
  40. package/builder/src/classes.lua +75 -0
  41. package/builder/src/collections.lua +190 -0
  42. package/builder/src/compiler.rs +2164 -0
  43. package/builder/src/config.rs +42 -0
  44. package/builder/src/entries.rs +166 -0
  45. package/builder/src/errors.lua +15 -0
  46. package/builder/src/lua_data.rs +231 -0
  47. package/builder/src/main.rs +367 -0
  48. package/builder/src/native_ir.rs +65 -0
  49. package/builder/src/native_signal.rs +47 -0
  50. package/builder/src/numbers.lua +62 -0
  51. package/builder/src/project-front.mjs +3331 -0
  52. package/builder/src/records.lua +75 -0
  53. package/builder/src/routes.rs +127 -0
  54. package/builder/src/signal-kernel.fingerprint +1 -0
  55. package/builder/src/strings.lua +103 -0
  56. package/builder/src/ts-lower.mjs +68 -0
  57. package/builder/src/wow_client.rs +253 -0
  58. package/builder/src/wow_types.rs +564 -0
  59. package/builder/style-states.mjs +100 -0
  60. package/builder/style-states.test.mjs +103 -0
  61. package/builder/vite-assets.mjs +53 -0
  62. package/builder/vite-project.mjs +10 -0
  63. package/config.ts +17 -0
  64. package/form/index.ts +522 -0
  65. package/form/package.json +13 -0
  66. package/motion/index.ts +2 -0
  67. package/motion/package.json +10 -0
  68. package/package.json +22 -4
  69. package/router/index.ts +43 -0
  70. package/router/package.json +12 -0
  71. package/router/routes.ts +64 -0
  72. package/scripts/kumi-cli.mjs +70 -0
  73. package/scripts/link-addons.mjs +51 -0
  74. package/src/bindings.ts +35 -0
  75. package/src/context.ts +15 -0
  76. package/src/css-tokens.ts +234 -0
  77. package/src/css-v1.ts +58 -0
  78. package/src/cvars.ts +91 -0
  79. package/src/element-node.ts +32 -0
  80. package/src/elements.ts +479 -0
  81. package/src/feature-scope.ts +82 -0
  82. package/src/flex-layout.ts +807 -0
  83. package/src/frame-scheduler.ts +334 -0
  84. package/src/grid-tracks.ts +165 -0
  85. package/src/image-imports.d.ts +24 -0
  86. package/src/images.ts +79 -0
  87. package/src/index.ts +28 -0
  88. package/src/jsx-dev-runtime.ts +2 -0
  89. package/src/jsx-runtime.ts +22 -0
  90. package/src/jsx.d.ts +12 -0
  91. package/src/keyed-list.ts +363 -0
  92. package/src/media-query.ts +144 -0
  93. package/src/module.ts +277 -0
  94. package/src/node-selectors.ts +114 -0
  95. package/src/owned-collections.ts +44 -0
  96. package/src/providers.ts +235 -0
  97. package/src/reactive-scope.ts +34 -0
  98. package/src/reactivity.ts +254 -0
  99. package/src/result.ts +58 -0
  100. package/src/runtime.ts +52 -0
  101. package/src/scheduler.ts +185 -0
  102. package/src/signal-kernel.ts +30 -0
  103. package/src/style-classes.ts +51 -0
  104. package/src/style-states.ts +134 -0
  105. package/src/style-variables.ts +53 -0
  106. package/src/text-children.ts +42 -0
  107. package/src/theme.ts +50 -0
  108. package/src/transition.ts +18 -0
  109. package/state/index.ts +3 -0
  110. package/state/package.json +12 -0
  111. package/state/store-bindings.ts +25 -0
  112. package/state/store.ts +82 -0
  113. package/styles/_layers.scss +14 -0
  114. package/templates/addon/README.md +14 -0
  115. package/templates/addon/__ADDON_NAME__.toc +4 -0
  116. package/templates/addon/eslint.config.mjs +12 -0
  117. package/templates/addon/gitignore +8 -0
  118. package/templates/addon/package.json +21 -0
  119. package/templates/addon/scripts/build.mjs +25 -0
  120. package/templates/addon/src/app/main.tsx +13 -0
  121. package/templates/addon/tsconfig.json +24 -0
  122. package/translate/index.ts +14 -0
  123. package/translate/package.json +9 -0
  124. package/utils/colors.ts +76 -0
  125. package/utils/format.ts +37 -0
  126. package/utils/index.ts +4 -0
  127. package/utils/number.ts +17 -0
  128. package/utils/package.json +7 -0
  129. package/utils/text.ts +6 -0
  130. package/validate/index.ts +119 -0
  131. package/validate/package.json +9 -0
  132. package/wow/absolute-position.ts +142 -0
  133. package/wow/animation.ts +428 -0
  134. package/wow/aura-button.ts +76 -0
  135. package/wow/aura-container.ts +591 -0
  136. package/wow/aura-countdown.ts +201 -0
  137. package/wow/aura-slot.ts +153 -0
  138. package/wow/bar-shade.ts +93 -0
  139. package/wow/borrowed-slot.ts +216 -0
  140. package/wow/button-drag.ts +48 -0
  141. package/wow/cast-clock.ts +153 -0
  142. package/wow/cast-text.ts +83 -0
  143. package/wow/class-colors.ts +126 -0
  144. package/wow/clock.ts +7 -0
  145. package/wow/color-picker.ts +128 -0
  146. package/wow/commands.ts +17 -0
  147. package/wow/contained-frame.ts +128 -0
  148. package/wow/contract.ts +42 -0
  149. package/wow/css-box.ts +110 -0
  150. package/wow/css-color.ts +12 -0
  151. package/wow/css-style.ts +109 -0
  152. package/wow/css-surfaces.ts +398 -0
  153. package/wow/css-text.ts +399 -0
  154. package/wow/cvar-schema.ts +32 -0
  155. package/wow/cvars.ts +98 -0
  156. package/wow/dropdown-art.ts +39 -0
  157. package/wow/element-click.ts +20 -0
  158. package/wow/element-event-coordinator.ts +219 -0
  159. package/wow/element-events.ts +317 -0
  160. package/wow/event-dispatcher.ts +151 -0
  161. package/wow/events.ts +50 -0
  162. package/wow/font-cache.ts +92 -0
  163. package/wow/frame-access.ts +31 -0
  164. package/wow/frame-layer.ts +5 -0
  165. package/wow/frames.ts +236 -0
  166. package/wow/heal-prediction.ts +305 -0
  167. package/wow/image-layers.ts +55 -0
  168. package/wow/index.ts +97 -0
  169. package/wow/layout-view.ts +651 -0
  170. package/wow/lua-string.ts +18 -0
  171. package/wow/lua-table.ts +18 -0
  172. package/wow/macro-book.ts +84 -0
  173. package/wow/map-position.ts +27 -0
  174. package/wow/media-query.ts +65 -0
  175. package/wow/module-events.ts +11 -0
  176. package/wow/native-hooks.ts +168 -0
  177. package/wow/native-placement.ts +88 -0
  178. package/wow/native.ts +135 -0
  179. package/wow/number-format.ts +8 -0
  180. package/wow/number-input.ts +10 -0
  181. package/wow/protect.ts +24 -0
  182. package/wow/protected-layout.ts +133 -0
  183. package/wow/range-art.ts +74 -0
  184. package/wow/reparent-frame.ts +99 -0
  185. package/wow/rounded-texture.ts +156 -0
  186. package/wow/saved-variables.ts +60 -0
  187. package/wow/scroll-view.ts +64 -0
  188. package/wow/secret-ref.ts +14 -0
  189. package/wow/secure-bindings.ts +89 -0
  190. package/wow/secure-clicks.ts +432 -0
  191. package/wow/secure-snippet.ts +235 -0
  192. package/wow/secure-state.ts +130 -0
  193. package/wow/secure-target-visibility.ts +89 -0
  194. package/wow/secure-transaction.ts +331 -0
  195. package/wow/special-window.ts +269 -0
  196. package/wow/start-addon.ts +99 -0
  197. package/wow/state-paint.ts +256 -0
  198. package/wow/transition.ts +86 -0
  199. package/wow/unit-button.ts +39 -0
  200. package/wow/unit-cast.ts +92 -0
  201. package/wow/unit-health-text.ts +47 -0
  202. package/wow/view-nodes.ts +304 -0
  203. package/wow/view.ts +1746 -0
  204. package/wow/visible-frame-job.ts +34 -0
  205. package/wow/width-reserve.ts +108 -0
@@ -0,0 +1,367 @@
1
+ use std::env;
2
+ use std::fs;
3
+ use std::io::{self, Write};
4
+ use std::path::{absolute, Path, PathBuf};
5
+ use std::process::{Command, ExitCode, Output, Stdio};
6
+ use std::thread;
7
+
8
+ mod assets;
9
+ mod compiler;
10
+ mod config;
11
+ mod entries;
12
+ mod lua_data;
13
+ mod native_ir;
14
+ mod native_signal;
15
+ mod routes;
16
+ mod wow_client;
17
+ mod wow_types;
18
+
19
+ fn modules(directory: &Path) -> io::Result<Vec<String>> {
20
+ let mut names = Vec::new();
21
+ for entry in fs::read_dir(directory)? {
22
+ let path = entry?.path();
23
+ if let Some(file) = path.file_name().and_then(|name| name.to_str()) {
24
+ if let Some(name) = file.strip_suffix(".module.json") {
25
+ names.push(name.to_owned());
26
+ }
27
+ }
28
+ }
29
+ names.sort();
30
+ Ok(names)
31
+ }
32
+
33
+ fn wait_for_node_output(
34
+ worker: io::Result<thread::ScopedJoinHandle<'_, io::Result<Output>>>,
35
+ ) -> io::Result<Output> {
36
+ worker?
37
+ .join()
38
+ .unwrap_or_else(|_| Err(io::Error::other("Node build worker panicked")))
39
+ }
40
+
41
+ fn build() -> Result<bool, Box<dyn std::error::Error>> {
42
+ let root = env::current_dir()?;
43
+ let mut workspace = root.clone();
44
+ let mut selected = Vec::new();
45
+ let mut check = false;
46
+ let mut dev = false;
47
+ let mut api_only = false;
48
+ let mut diff = false;
49
+ let mut lua_only = false;
50
+ let mut jobs = 1;
51
+ let mut routes_only = false;
52
+ let mut routes_dir = None;
53
+ let mut compile_source = None;
54
+ let mut compile_config = None;
55
+ let mut compile_sdk = None;
56
+ let mut compile_addon = false;
57
+ let mut compile_link = None;
58
+ let mut compile_assets = None;
59
+ let mut compile_output = None;
60
+ let mut compile_fragments = false;
61
+ let mut compile_plugin = None;
62
+ let mut native_emission = false;
63
+ let mut native_ir = None;
64
+ let mut native_out = None;
65
+ let mut native_kernels = "none";
66
+ let mut image_source = None;
67
+ let mut image_output = None;
68
+ let mut image_input_tga = false;
69
+ let mut packager = None;
70
+ let mut addons_dir = None;
71
+ let mut source = wow_client::Source {
72
+ docs: wow_client::path_option("KUMI_WOW_DOCS"),
73
+ install: wow_client::path_option("KUMI_WOW_INSTALL"),
74
+ product: env::var("KUMI_WOW_PRODUCT").unwrap_or_else(|_| "wow".to_owned()),
75
+ extractor: wow_client::path_option("KUMI_WOW_EXTRACTOR"),
76
+ listfile: wow_client::path_option("KUMI_WOW_LISTFILE"),
77
+ };
78
+ let mut args = env::args().skip(1);
79
+ while let Some(arg) = args.next() {
80
+ let value = || format!("Expected a value after {arg}");
81
+ match arg.as_str() {
82
+ "build" => {}
83
+ "wow-api" => api_only = true,
84
+ "routes" => routes_only = true,
85
+ "compile" => compile_source = Some(PathBuf::from(args.next().ok_or_else(value)?)),
86
+ "--tsconfig" => compile_config = Some(PathBuf::from(args.next().ok_or_else(value)?)),
87
+ "--sdk-root" => compile_sdk = Some(PathBuf::from(args.next().ok_or_else(value)?)),
88
+ "--addon-entry" => compile_addon = true,
89
+ "--addon-link" => compile_link = Some(args.next().ok_or_else(value)?),
90
+ "--addon-fragments" => compile_fragments = true,
91
+ "--compile-output" => {
92
+ compile_output = Some(PathBuf::from(args.next().ok_or_else(value)?))
93
+ }
94
+ "--addon-plugin" => {
95
+ compile_plugin = Some(match args.next().as_deref() {
96
+ Some("external") => compiler::AddonPlugin::External,
97
+ Some("embeddable") => compiler::AddonPlugin::Embeddable,
98
+ _ => return Err("Expected --addon-plugin external or embeddable".into()),
99
+ });
100
+ }
101
+ "--addon-assets-dir" => {
102
+ compile_assets = Some(PathBuf::from(args.next().ok_or_else(value)?))
103
+ }
104
+ "emit-native" => native_emission = true,
105
+ "--ir" => native_ir = Some(PathBuf::from(args.next().ok_or_else(value)?)),
106
+ "--out" => native_out = Some(PathBuf::from(args.next().ok_or_else(value)?)),
107
+ "--native-kernels" => {
108
+ native_kernels = match args.next().as_deref() {
109
+ Some("none") => "none",
110
+ Some("signal") => "signal",
111
+ _ => return Err("Expected --native-kernels none or signal".into()),
112
+ };
113
+ }
114
+ "image" => image_source = Some(PathBuf::from(args.next().ok_or_else(value)?)),
115
+ "--image-output" => image_output = Some(PathBuf::from(args.next().ok_or_else(value)?)),
116
+ "--image-input-tga" => image_input_tga = true,
117
+ "--routes-dir" => routes_dir = Some(PathBuf::from(args.next().ok_or_else(value)?)),
118
+ "--check" => check = true,
119
+ "--diff" => diff = true,
120
+ "--dev" => dev = true,
121
+ "--lua-only" => lua_only = true,
122
+ "--jobs" => {
123
+ jobs = match args.next().as_deref() {
124
+ Some("1") => 1,
125
+ Some("2") => 2,
126
+ Some(value) => {
127
+ return Err(
128
+ format!("Invalid --jobs value {value:?}. Expected 1 or 2.").into()
129
+ )
130
+ }
131
+ None => return Err("Expected 1 or 2 after --jobs".into()),
132
+ };
133
+ }
134
+ "--workspace" => workspace = absolute(args.next().ok_or_else(value)?)?,
135
+ "--packager" => packager = Some(absolute(args.next().ok_or_else(value)?)?),
136
+ "--addons-dir" => addons_dir = Some(PathBuf::from(args.next().ok_or_else(value)?)),
137
+ "--docs" => source.docs = Some(PathBuf::from(args.next().ok_or_else(value)?)),
138
+ "--wow" => source.install = Some(PathBuf::from(args.next().ok_or_else(value)?)),
139
+ "--product" => source.product = args.next().ok_or_else(value)?,
140
+ "--extractor" => source.extractor = Some(PathBuf::from(args.next().ok_or_else(value)?)),
141
+ "--listfile" => source.listfile = Some(PathBuf::from(args.next().ok_or_else(value)?)),
142
+ _ if !arg.starts_with('-') => {
143
+ if !selected.contains(&arg) {
144
+ selected.push(arg);
145
+ }
146
+ }
147
+ _ => return Err(format!("Unknown option {arg}").into()),
148
+ }
149
+ }
150
+ let output = workspace.join(if dev { ".kumi" } else { "build" });
151
+ if native_emission {
152
+ let input = native_ir.ok_or("emit-native requires --ir")?;
153
+ let target = native_out.ok_or("emit-native requires --out")?;
154
+ compiler::emit_native(&workspace.join(input), &workspace.join(target))?;
155
+ return Ok(true);
156
+ }
157
+ if native_ir.is_some() || native_out.is_some() {
158
+ return Err("--ir and --out require emit-native".into());
159
+ }
160
+ if native_kernels == "signal" && !lua_only {
161
+ return Err("--native-kernels signal requires --lua-only".into());
162
+ }
163
+ if let Some(input) = image_source {
164
+ let output = image_output.ok_or("Expected --image-output for image")?;
165
+ let source = if input == Path::new("-") {
166
+ input
167
+ } else {
168
+ workspace.join(input)
169
+ };
170
+ assets::build(&source, &workspace.join(output), check, image_input_tga)?;
171
+ return Ok(true);
172
+ }
173
+ if image_output.is_some() {
174
+ return Err("--image-output requires the image command".into());
175
+ }
176
+ if image_input_tga {
177
+ return Err("--image-input-tga requires the image command".into());
178
+ }
179
+ if let Some(input) = compile_source {
180
+ if compile_link
181
+ .as_ref()
182
+ .is_some_and(|stamp| !compile_addon || stamp.trim().is_empty())
183
+ {
184
+ return Err("--addon-link requires --addon-entry and a build stamp".into());
185
+ }
186
+ if compile_assets.is_some() && !compile_addon {
187
+ return Err("--addon-assets-dir requires --addon-entry".into());
188
+ }
189
+ if compile_plugin.is_some() && !compile_addon {
190
+ return Err("--addon-plugin requires --addon-entry".into());
191
+ }
192
+ if compile_fragments && (compile_link.is_none() || compile_output.is_none()) {
193
+ return Err("--addon-fragments requires --addon-link and --compile-output".into());
194
+ }
195
+ let input = absolute(workspace.join(input))?;
196
+ let stem = input
197
+ .file_stem()
198
+ .and_then(|stem| stem.to_str())
199
+ .ok_or("Invalid TypeScript filename")?;
200
+ let sdk = compile_sdk.map_or_else(|| workspace.clone(), |path| workspace.join(path));
201
+ let config = compile_config.map(|path| workspace.join(path));
202
+ let assets = compile_assets.map(|path| workspace.join(path));
203
+ let output = compile_output.map_or_else(
204
+ || output.join("compiler").join(format!("{stem}.lua")),
205
+ |path| workspace.join(path),
206
+ );
207
+ compiler::compile(
208
+ &root,
209
+ compiler::ProjectCompile {
210
+ workspace: &workspace,
211
+ sdk: &sdk,
212
+ config: config.as_deref(),
213
+ source: &input,
214
+ output: &output,
215
+ check,
216
+ addon: compile_addon,
217
+ link: compile_link.as_deref(),
218
+ assets: assets.as_deref(),
219
+ plugin: compile_plugin,
220
+ fragments: compile_fragments,
221
+ },
222
+ )?;
223
+ return Ok(true);
224
+ }
225
+ if compile_config.is_some()
226
+ || compile_sdk.is_some()
227
+ || compile_addon
228
+ || compile_link.is_some()
229
+ || compile_assets.is_some()
230
+ || compile_output.is_some()
231
+ || compile_plugin.is_some()
232
+ || compile_fragments
233
+ {
234
+ return Err("Native compiler options require compile".into());
235
+ }
236
+ if routes_only || routes_dir.is_some() {
237
+ let root = workspace.join(routes_dir.unwrap_or_else(|| PathBuf::from("routes")));
238
+ routes::generate(&workspace, &root, &output, check)?;
239
+ if routes_only {
240
+ return Ok(true);
241
+ }
242
+ }
243
+ let package = !check && !dev && !lua_only && !api_only && selected.is_empty();
244
+ let install = if package {
245
+ match addons_dir {
246
+ Some(path) => Some(path),
247
+ None => config::addons_dir(&root)?,
248
+ }
249
+ } else if addons_dir.is_some() {
250
+ return Err("--addons-dir requires a complete addon build".into());
251
+ } else {
252
+ None
253
+ };
254
+ source.generate(&workspace, &output.join("types/wow-api.d.ts"), check, diff)?;
255
+ if api_only {
256
+ return Ok(true);
257
+ }
258
+ let available = modules(&root.join("modules"))?;
259
+ for module in &selected {
260
+ if !available.contains(module) {
261
+ return Err(
262
+ format!("Unknown module {module}. Modules: {}", available.join(", ")).into(),
263
+ );
264
+ }
265
+ }
266
+ if selected.is_empty() {
267
+ selected = available;
268
+ }
269
+ if selected.is_empty() {
270
+ return Err("No module configurations found".into());
271
+ }
272
+
273
+ let entries = entries::generate(&workspace, &root, &output, &selected, check)?;
274
+ let executable = env::current_exe()?;
275
+ let mut succeeded = true;
276
+ for batch in selected.chunks(jobs) {
277
+ let outputs = thread::scope(|scope| {
278
+ let children: Vec<_> = batch
279
+ .iter()
280
+ .map(|module| {
281
+ let mut command = Command::new("node");
282
+ command
283
+ .current_dir(&root)
284
+ .args(["--v8-pool-size=1", "scripts/build.mjs", module])
285
+ .env("KUMI_OUTPUT", &output)
286
+ .env("KUMI_PACK_BIN", &executable)
287
+ .env("KUMI_NATIVE_KERNELS", native_kernels)
288
+ .env("UV_THREADPOOL_SIZE", "1")
289
+ .stdin(Stdio::inherit());
290
+ if let Some(entry) = entries.get(module) {
291
+ command.env("KUMI_BUNDLE_ENTRY", entry);
292
+ }
293
+ if check {
294
+ command.arg("--check");
295
+ }
296
+ thread::Builder::new().spawn_scoped(scope, move || command.output())
297
+ })
298
+ .collect();
299
+ children
300
+ .into_iter()
301
+ .map(wait_for_node_output)
302
+ .collect::<Vec<_>>()
303
+ });
304
+ for (module, result) in batch.iter().zip(outputs) {
305
+ match result {
306
+ Ok(output) => {
307
+ io::stdout().write_all(&output.stdout)?;
308
+ io::stderr().write_all(&output.stderr)?;
309
+ succeeded &= output.status.success();
310
+ }
311
+ Err(error) => {
312
+ eprintln!("{module}: {error}");
313
+ succeeded = false;
314
+ }
315
+ }
316
+ }
317
+ }
318
+ if succeeded && package {
319
+ if let Some(packager) = packager {
320
+ let mut command = Command::new("node");
321
+ command
322
+ .current_dir(&root)
323
+ .arg("--v8-pool-size=1")
324
+ .arg(packager)
325
+ .env("UV_THREADPOOL_SIZE", "1")
326
+ .env("KUMI_OUTPUT", &output);
327
+ if let Some(target) = install {
328
+ command.env("KUMI_ADDONS_DIR", workspace.join(target));
329
+ }
330
+ succeeded = command.status()?.success();
331
+ }
332
+ }
333
+ Ok(succeeded)
334
+ }
335
+
336
+ fn main() -> ExitCode {
337
+ match build() {
338
+ Ok(true) => ExitCode::SUCCESS,
339
+ Ok(false) => ExitCode::FAILURE,
340
+ Err(error) => {
341
+ eprintln!("{error}");
342
+ ExitCode::FAILURE
343
+ }
344
+ }
345
+ }
346
+
347
+ #[cfg(test)]
348
+ mod tests {
349
+ use super::*;
350
+
351
+ #[test]
352
+ fn node_worker_failures_are_reported_as_io_errors() {
353
+ let denied = io::Error::from(io::ErrorKind::PermissionDenied);
354
+ assert_eq!(
355
+ wait_for_node_output(Err(denied)).unwrap_err().kind(),
356
+ io::ErrorKind::PermissionDenied
357
+ );
358
+
359
+ thread::scope(|scope| {
360
+ let worker = thread::Builder::new().spawn_scoped(scope, || panic!("worker failed"));
361
+ assert_eq!(
362
+ wait_for_node_output(worker).unwrap_err().to_string(),
363
+ "Node build worker panicked"
364
+ );
365
+ });
366
+ }
367
+ }
@@ -0,0 +1,65 @@
1
+ use std::io::Read;
2
+ use std::path::Path;
3
+
4
+ type Compile<T> = Result<T, Box<dyn std::error::Error>>;
5
+ const LIMIT: u64 = 4096;
6
+ const FINGERPRINT: &str = include_str!("signal-kernel.fingerprint");
7
+
8
+ pub struct SignalFactory {
9
+ pub source_hash: String,
10
+ }
11
+
12
+ fn hash(value: &str) -> bool {
13
+ value.len() == 64
14
+ && value
15
+ .bytes()
16
+ .all(|byte| matches!(byte, b'0'..=b'9' | b'a'..=b'f'))
17
+ }
18
+
19
+ pub fn signal_from_hashes(source: &str, fingerprint: &str) -> Compile<SignalFactory> {
20
+ if !hash(source) || fingerprint != FINGERPRINT.trim() {
21
+ return Err("Unsupported native Signal source hash or fingerprint".into());
22
+ }
23
+ Ok(SignalFactory {
24
+ source_hash: source.to_owned(),
25
+ })
26
+ }
27
+
28
+ pub fn read_signal(path: &Path) -> Compile<SignalFactory> {
29
+ let mut input = String::new();
30
+ std::fs::File::open(path)?
31
+ .take(LIMIT + 1)
32
+ .read_to_string(&mut input)?;
33
+ if input.len() as u64 > LIMIT {
34
+ return Err("Native IR exceeds the size limit".into());
35
+ }
36
+ let records: Vec<_> = input.lines().collect();
37
+ let ["kumi-native-1", "target\t5.1", "module\tsrc/signal-kernel", "intrinsic\tSignalFactoryV1", source, fingerprint, span, "export\tcreateSignalFactory\tno-self\t3\tscalar", "imports\t0", "end"] =
38
+ records.as_slice()
39
+ else {
40
+ return Err("Unsupported native IR schema, target, module, or ABI".into());
41
+ };
42
+ let source_hash = source
43
+ .strip_prefix("source\t")
44
+ .ok_or("Missing source hash")?;
45
+ let fingerprint = fingerprint
46
+ .strip_prefix("fingerprint\t")
47
+ .ok_or("Missing fingerprint")?;
48
+ let coordinates: Vec<_> = span
49
+ .strip_prefix("span\t")
50
+ .ok_or("Missing source span")?
51
+ .split('\t')
52
+ .collect();
53
+ if coordinates.len() != 4
54
+ || coordinates.iter().any(|value| {
55
+ value
56
+ .parse::<u32>()
57
+ .ok()
58
+ .filter(|value| *value > 0)
59
+ .is_none()
60
+ })
61
+ {
62
+ return Err("Invalid native IR source span".into());
63
+ }
64
+ signal_from_hashes(source_hash, fingerprint)
65
+ }
@@ -0,0 +1,47 @@
1
+ use crate::native_ir::SignalFactory;
2
+
3
+ pub fn emit(ir: SignalFactory) -> String {
4
+ // Missing current falls through the non-value branch of __index.
5
+ // A first write to that slot falls through to rawset in __newindex.
6
+ format!(
7
+ r#"-- kumi-native-1 / SignalFactoryV1 / {source}
8
+ local module = {{}}
9
+ function module.createSignalFactory(track, notify, makeDependency)
10
+ local meta = {{}}
11
+ meta.__index = function(cell, key)
12
+ if key == "value" then
13
+ track(cell.observers)
14
+ return cell.current
15
+ end
16
+ return nil
17
+ end
18
+ meta.__newindex = function(cell, key, next)
19
+ if key ~= "value" then
20
+ rawset(cell, key, next)
21
+ return
22
+ end
23
+ local current = cell.current
24
+ local equals = cell.equals
25
+ if equals == true then
26
+ if next == current then return end
27
+ elseif equals ~= false and equals(current, next) then
28
+ return
29
+ end
30
+ cell.current = next
31
+ notify(cell.observers)
32
+ end
33
+ return function(initial, equals)
34
+ if equals == nil then equals = true end
35
+ local cell = {{
36
+ current = initial,
37
+ equals = equals,
38
+ observers = makeDependency(),
39
+ }}
40
+ return (setmetatable(cell, meta))
41
+ end
42
+ end
43
+ return module
44
+ "#,
45
+ source = ir.source_hash
46
+ )
47
+ }
@@ -0,0 +1,62 @@
1
+ local function numberFinite(value)
2
+ return type(value) == "number" and value > -math.huge and value < math.huge
3
+ end
4
+
5
+ local function numberNaN(value)
6
+ return type(value) == "number" and value ~= value
7
+ end
8
+
9
+ local function numberInteger(value)
10
+ return numberFinite(value) and value % 1 == 0
11
+ end
12
+
13
+ local function numberRound(value)
14
+ if not numberFinite(value) or value == 0 then return value end
15
+ local result = math.floor(value)
16
+ if value - result >= 0.5 then result = result + 1 end
17
+ if result == 0 and value < 0 then return -1 / math.huge end
18
+ return result
19
+ end
20
+
21
+ local function numberFixed(value, digits)
22
+ if value ~= value or value <= -1e21 or value >= 1e21 then return tostring(value) end
23
+ local precision = math.floor(digits or 0)
24
+ if precision < 0 or precision > 99 then
25
+ error("toFixed() digits argument must be between 0 and 99", 0)
26
+ end
27
+ return string.format("%." .. precision .. "f", value)
28
+ end
29
+
30
+ local function numberValue(value)
31
+ local kind = type(value)
32
+ if kind == "number" then return value end
33
+ if kind == "boolean" then return value and 1 or 0 end
34
+ if kind == "string" then
35
+ local numeric = tonumber(value)
36
+ if numeric ~= nil then return numeric end
37
+ if value == "Infinity" then return math.huge end
38
+ if value == "-Infinity" then return -math.huge end
39
+ if value:match("^%s*$") then return 0 end
40
+ end
41
+ return 0 / 0
42
+ end
43
+
44
+ local function numberMin(...)
45
+ local best = math.huge
46
+ for index = 1, select("#", ...) do
47
+ local value = select(index, ...)
48
+ if value ~= value then return value end
49
+ if value < best or value == 0 and best == 0 and 1 / value < 0 then best = value end
50
+ end
51
+ return best
52
+ end
53
+
54
+ local function numberMax(...)
55
+ local best = -math.huge
56
+ for index = 1, select("#", ...) do
57
+ local value = select(index, ...)
58
+ if value ~= value then return value end
59
+ if value > best or value == 0 and best == 0 and 1 / value > 0 then best = value end
60
+ end
61
+ return best
62
+ end