craft-native 0.0.409 → 0.0.410

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/dist/cli.js CHANGED
@@ -3047,7 +3047,7 @@ function pinCraftNativeDependency(packagePath, craftVersion) {
3047
3047
  `);
3048
3048
  }
3049
3049
  // package.json
3050
- var version = "0.0.409";
3050
+ var version = "0.0.410";
3051
3051
 
3052
3052
  // bin/cli.ts
3053
3053
  var spawnedFrom = process6.env[CRAFT_CLI_SPAWN_MARKER];
package/dist/index.cjs CHANGED
@@ -375,7 +375,7 @@ function craftBinaryNotFoundMessage(triedPath) {
375
375
  `);
376
376
  }
377
377
  // package.json
378
- var version = "0.0.409";
378
+ var version = "0.0.410";
379
379
 
380
380
  // src/sdk-version.ts
381
381
  var SDK_VERSION = version;
package/dist/index.js CHANGED
@@ -117,7 +117,7 @@ function craftBinaryNotFoundMessage(triedPath) {
117
117
  `);
118
118
  }
119
119
  // package.json
120
- var version = "0.0.409";
120
+ var version = "0.0.410";
121
121
 
122
122
  // src/sdk-version.ts
123
123
  var SDK_VERSION = version;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Screens run on zig-js, and only on zig-js. zig-js exports JavaScriptCore's C
3
+ * API under the same names, and a host built with `webkit` sits one framework
4
+ * away from Apple's JavaScriptCore. So a `JS*` function zig-js does not define,
5
+ * or a Swift import that autolinks JavaScriptCore, would quietly bind part of
6
+ * the screen's engine to the system one, and fail far from the cause (a value
7
+ * from one engine handed to the other). The build checks the linked host.
8
+ */
9
+ /** What in a host's imports would run on the system's JavaScriptCore; empty when everything is zig-js. */
10
+ export declare function systemEngineUse(undefinedSymbols: string[], linkedLibraries: string[]): string[];
11
+ /** Fails when the linked host would run any script on the system's JavaScriptCore. */
12
+ export declare function assertZigJsEngine(executable: string): Promise<void>;
@@ -1,3 +1,4 @@
1
+ export { assertZigJsEngine, systemEngineUse } from './engine.js';
1
2
  export { macosToolchain, pantryExecutable, resolveMacOSToolchain, resolveZig, toolchainCacheDir } from './toolchain.js';
2
3
  export type { MacOSToolchain } from './toolchain.js';
3
4
  export interface MacOSNativeBuildOptions {
@@ -5,6 +5,36 @@ import { existsSync as existsSync2 } from "fs";
5
5
  import { join as join2, resolve } from "path";
6
6
  import process2 from "process";
7
7
 
8
+ // ../macos/src/engine.ts
9
+ var SYSTEM_ENGINE_SYMBOL = /^_(?:kJS[A-Z]|JS(?:Value|Object|String|BigInt|Context|GlobalContext|Class|PropertyName|EvaluateScript|CheckScriptSyntax|GarbageCollect|Script|Weak|ReportExtraMemoryCost|Synchronous)|OBJC_CLASS_\$_JS(?:Context|Value|ManagedValue|VirtualMachine)$)/;
10
+ function systemEngineUse(undefinedSymbols, linkedLibraries) {
11
+ return [
12
+ ...linkedLibraries.filter((library) => library.includes("/JavaScriptCore.framework/")),
13
+ ...undefinedSymbols.filter((symbol) => SYSTEM_ENGINE_SYMBOL.test(symbol))
14
+ ];
15
+ }
16
+ async function lines(args) {
17
+ const child = Bun.spawn(args, { stdout: "pipe", stderr: "inherit" });
18
+ const text = await new Response(child.stdout).text();
19
+ if (await child.exited !== 0)
20
+ throw new Error(`Could not inspect the host: ${args.join(" ")}`);
21
+ return text.split(`
22
+ `).map((line) => line.trim()).filter(Boolean);
23
+ }
24
+ async function assertZigJsEngine(executable) {
25
+ const [undefinedSymbols, linked] = await Promise.all([
26
+ lines(["xcrun", "nm", "-u", "-j", executable]),
27
+ lines(["xcrun", "otool", "-L", executable])
28
+ ]);
29
+ const leaks = systemEngineUse(undefinedSymbols, linked.slice(1).map((line) => line.split(" (")[0]));
30
+ if (leaks.length) {
31
+ throw new Error(`The host would run scripts on the system's JavaScriptCore instead of zig-js:
32
+ ${leaks.join(`
33
+ `)}
34
+ Define the missing functions in zig-js, or keep JavaScriptCore out of the Swift imports.`);
35
+ }
36
+ }
37
+
8
38
  // ../macos/src/toolchain.ts
9
39
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
10
40
  import { homedir } from "os";
@@ -157,16 +187,19 @@ async function buildMacOSNative(options) {
157
187
  "-o",
158
188
  executable
159
189
  ]);
190
+ await assertZigJsEngine(executable);
160
191
  const bundle = join2(outdir, "native-screen.js");
161
192
  if (resolve(options.nativeBundle) !== bundle)
162
193
  await cp(options.nativeBundle, bundle);
163
194
  return { executable, bundle };
164
195
  }
165
196
  export {
197
+ assertZigJsEngine,
166
198
  buildMacOSNative,
167
199
  macosToolchain,
168
200
  pantryExecutable,
169
201
  resolveMacOSToolchain,
170
202
  resolveZig,
203
+ systemEngineUse,
171
204
  toolchainCacheDir
172
205
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "craft-native",
3
- "version": "0.0.409",
3
+ "version": "0.0.410",
4
4
  "type": "module",
5
5
  "description": "Build desktop apps with web languages - TypeScript SDK for Craft",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",