wasm-idle 1.0.8 → 1.0.10

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 (79) hide show
  1. package/README.md +60 -26
  2. package/dist/playground/applicationAssets.js +18 -0
  3. package/dist/playground/assetBridge.d.ts +1 -1
  4. package/dist/playground/assetBridge.js +172 -117
  5. package/dist/playground/assets.d.ts +74 -4
  6. package/dist/playground/assets.js +127 -4
  7. package/dist/playground/cachedClang.js +44 -5
  8. package/dist/playground/clang.d.ts +5 -0
  9. package/dist/playground/clang.js +100 -0
  10. package/dist/playground/clangWorkerProtocol.d.ts +13 -1
  11. package/dist/playground/fennel.d.ts +9 -0
  12. package/dist/playground/fennel.js +30 -0
  13. package/dist/playground/fennelBootstrap.d.ts +31 -0
  14. package/dist/playground/fennelBootstrap.js +118 -0
  15. package/dist/playground/grain.d.ts +9 -0
  16. package/dist/playground/grain.js +127 -0
  17. package/dist/playground/hy.d.ts +21 -0
  18. package/dist/playground/hy.js +24 -0
  19. package/dist/playground/index.d.ts +1 -1
  20. package/dist/playground/index.js +49 -0
  21. package/dist/playground/lua.d.ts +19 -0
  22. package/dist/playground/lua.js +64 -39
  23. package/dist/playground/objectivec.d.ts +3 -1
  24. package/dist/playground/objectivec.js +6 -2
  25. package/dist/playground/options.js +1 -1
  26. package/dist/playground/postgresql.d.ts +36 -0
  27. package/dist/playground/postgresql.js +543 -0
  28. package/dist/playground/python.d.ts +5 -0
  29. package/dist/playground/python.js +13 -0
  30. package/dist/playground/rescript.d.ts +5 -0
  31. package/dist/playground/rescript.js +58 -0
  32. package/dist/playground/rescriptPreflight.d.ts +26 -0
  33. package/dist/playground/rescriptPreflight.js +381 -0
  34. package/dist/playground/runtimeAssetCache.d.ts +6 -0
  35. package/dist/playground/runtimeAssetCache.js +109 -0
  36. package/dist/playground/staticRuntimeModuleVersion.d.ts +1 -1
  37. package/dist/playground/staticRuntimeModuleVersion.js +1 -1
  38. package/dist/playground/staticRuntimePreflightExecute.d.ts +2 -1
  39. package/dist/playground/staticRuntimePreflightExecute.js +9 -0
  40. package/dist/playground/staticRuntimePreflightProtocol.d.ts +1 -1
  41. package/dist/playground/v.d.ts +46 -0
  42. package/dist/playground/v.js +703 -0
  43. package/dist/playground/wasmBashVersion.d.ts +25 -25
  44. package/dist/playground/wasmBashVersion.js +12 -12
  45. package/dist/playground/wasmElixirVersion.d.ts +9 -9
  46. package/dist/playground/wasmElixirVersion.js +9 -9
  47. package/dist/playground/wasmFennelVersion.d.ts +23 -0
  48. package/dist/playground/wasmFennelVersion.js +16 -0
  49. package/dist/playground/wasmGrainVersion.d.ts +24 -0
  50. package/dist/playground/wasmGrainVersion.js +25 -0
  51. package/dist/playground/wasmHaskellVersion.d.ts +1 -1
  52. package/dist/playground/wasmHaskellVersion.js +1 -1
  53. package/dist/playground/wasmHyVersion.d.ts +7 -0
  54. package/dist/playground/wasmHyVersion.js +15 -0
  55. package/dist/playground/wasmLispVersion.d.ts +1 -1
  56. package/dist/playground/wasmLispVersion.js +1 -1
  57. package/dist/playground/wasmOcamlVersion.d.ts +4 -4
  58. package/dist/playground/wasmOcamlVersion.js +3 -3
  59. package/dist/playground/wasmPrologVersion.d.ts +19 -19
  60. package/dist/playground/wasmPrologVersion.js +18 -18
  61. package/dist/playground/wasmReScriptVersion.d.ts +20 -0
  62. package/dist/playground/wasmReScriptVersion.js +20 -0
  63. package/dist/playground/wasmTypeScriptVersion.d.ts +5 -5
  64. package/dist/playground/wasmTypeScriptVersion.js +5 -5
  65. package/dist/playground/worker/cachedClangCompile.js +44 -5
  66. package/dist/playground/worker/clang.js +44 -11
  67. package/dist/playground/worker/clangStreaming.js +6 -0
  68. package/dist/playground/worker/lua.js +48 -11
  69. package/dist/playground/worker/postgresql.d.ts +1 -0
  70. package/dist/playground/worker/postgresql.js +205 -0
  71. package/dist/playground/worker/python.js +113 -12
  72. package/dist/playground/worker/runtimeModule.d.ts +1 -1
  73. package/dist/playground/worker/runtimeModule.js +1 -1
  74. package/dist/playground/worker/staticRuntimePreflight.js +2 -1
  75. package/dist/playground/worker/v.d.ts +1 -0
  76. package/dist/playground/worker/v.js +106 -0
  77. package/dist/testPublicEnv.d.ts +2 -0
  78. package/dist/testPublicEnv.js +8 -0
  79. package/package.json +59 -48
@@ -103,6 +103,9 @@ export interface WatRuntimeAssetConfig {
103
103
  export interface LuaRuntimeAssetConfig {
104
104
  moduleUrl?: string;
105
105
  }
106
+ export interface FennelRuntimeAssetConfig {
107
+ compilerUrl?: string;
108
+ }
106
109
  export interface HaskellRuntimeAssetConfig {
107
110
  moduleUrl?: string;
108
111
  rootfsUrl?: string;
@@ -122,6 +125,9 @@ export interface FortranRuntimeAssetConfig {
122
125
  export interface CobolRuntimeAssetConfig {
123
126
  baseUrl?: string;
124
127
  }
128
+ export interface VRuntimeAssetConfig {
129
+ baseUrl?: string;
130
+ }
125
131
  export interface ObjectiveCRuntimeAssetConfig {
126
132
  baseUrl?: string;
127
133
  libobjcUrl?: string;
@@ -493,6 +499,35 @@ export interface ClojureScriptRuntimePreflightProfile {
493
499
  uncompressedSha256?: string;
494
500
  }>;
495
501
  }
502
+ export interface ReScriptRuntimeAssetConfig {
503
+ baseUrl?: string;
504
+ workerUrl?: string;
505
+ manifestUrl?: string;
506
+ manifestFingerprint?: string;
507
+ profileId?: string;
508
+ sourceRevision?: string;
509
+ manifestReceipt?: RuntimeAssetIntegrityEntry;
510
+ compilerReceipt?: RuntimeAssetIntegrityEntry;
511
+ workerReceipt?: Readonly<{
512
+ bytes: number;
513
+ sha256: string;
514
+ }>;
515
+ }
516
+ export interface ReScriptRuntimePreflightProfile {
517
+ readonly profileId: string;
518
+ readonly sourceRevision: string;
519
+ readonly manifestFingerprint: string;
520
+ readonly manifestReceipt?: Readonly<{
521
+ bytes?: number;
522
+ sha256: string;
523
+ }>;
524
+ readonly compilerReceipt?: Readonly<{
525
+ bytes?: number;
526
+ sha256: string;
527
+ uncompressedBytes?: number;
528
+ uncompressedSha256?: string;
529
+ }>;
530
+ }
496
531
  export interface SwiftRuntimeAssetConfig {
497
532
  baseUrl?: string;
498
533
  workerUrl?: string;
@@ -508,6 +543,9 @@ export interface AssemblyScriptRuntimeAssetConfig {
508
543
  export interface DuckDbRuntimeAssetConfig {
509
544
  moduleUrl?: string;
510
545
  }
546
+ export interface PostgresqlRuntimeAssetConfig {
547
+ moduleUrl?: string;
548
+ }
511
549
  export interface PhpRuntimeAssetConfig {
512
550
  moduleUrl?: string;
513
551
  }
@@ -528,9 +566,11 @@ export interface PlaygroundRuntimeAssets extends RuntimeAssetKeySource {
528
566
  typescript?: TypeScriptRuntimeAssetConfig;
529
567
  wat?: WatRuntimeAssetConfig;
530
568
  lua?: LuaRuntimeAssetConfig;
569
+ fennel?: FennelRuntimeAssetConfig;
531
570
  haskell?: HaskellRuntimeAssetConfig;
532
571
  fortran?: FortranRuntimeAssetConfig;
533
572
  cobol?: CobolRuntimeAssetConfig;
573
+ v?: VRuntimeAssetConfig;
534
574
  objectivec?: ObjectiveCRuntimeAssetConfig;
535
575
  zig?: ZigRuntimeAssetConfig;
536
576
  lisp?: LispRuntimeAssetConfig;
@@ -551,12 +591,20 @@ export interface PlaygroundRuntimeAssets extends RuntimeAssetKeySource {
551
591
  c3?: {
552
592
  baseUrl?: string;
553
593
  };
594
+ grain?: {
595
+ baseUrl?: string;
596
+ };
597
+ hy?: {
598
+ baseUrl?: string;
599
+ };
554
600
  nim?: NimRuntimeAssetConfig;
555
601
  bash?: BashRuntimeAssetConfig;
556
602
  clojurescript?: ClojureScriptRuntimeAssetConfig;
603
+ rescript?: ReScriptRuntimeAssetConfig;
557
604
  swift?: SwiftRuntimeAssetConfig;
558
605
  assemblyscript?: AssemblyScriptRuntimeAssetConfig;
559
606
  duckdb?: DuckDbRuntimeAssetConfig;
607
+ postgresql?: PostgresqlRuntimeAssetConfig;
560
608
  sqlite?: SqliteRuntimeAssetConfig;
561
609
  php?: PhpRuntimeAssetConfig;
562
610
  }
@@ -605,15 +653,15 @@ export interface ResolvedZigRuntimeAssetConfig {
605
653
  stdlibUrl: string;
606
654
  integrity: ZigExecutionAssetReceipts;
607
655
  }
608
- export declare const PYTHON_RUNTIME_LOAD_ASSETS: readonly ["pyodide.mjs", "pyodide.asm.js", "pyodide-lock.json", "pyodide.asm.wasm", "python_stdlib.zip"];
656
+ export declare const PYTHON_RUNTIME_LOAD_ASSETS: readonly ["pyodide.mjs", "pyodide.asm.mjs", "pyodide-lock.json", "pyodide.asm.wasm", "python_stdlib.zip"];
609
657
  export declare const JAVA_RUNTIME_LOAD_ASSETS: readonly ["compiler.wasm-runtime.js", "compiler.wasm", "compile-classlib-teavm.bin", "runtime-classlib-teavm.bin"];
610
658
  export declare const CLANG_RUNTIME_LOAD_ASSETS: readonly ["runtime-manifest.v1.json", "bin/memfs.wasm.gz", "bin/clang.wasm.gz", "bin/lld.wasm.gz", "bin/sysroot.tar.gz"];
611
- export declare const CLANGD_RUNTIME_LOAD_ASSETS: readonly ["clangd.js", "clangd.wasm.gz"];
659
+ export declare const CLANGD_RUNTIME_LOAD_ASSETS: readonly ["clangd.js", "clangd.wasm.gz", "clangd.headers.json.gz"];
612
660
  export declare const RUNTIME_LOAD_ASSETS: {
613
- python: readonly ["pyodide.mjs", "pyodide.asm.js", "pyodide-lock.json", "pyodide.asm.wasm", "python_stdlib.zip"];
661
+ python: readonly ["pyodide.mjs", "pyodide.asm.mjs", "pyodide-lock.json", "pyodide.asm.wasm", "python_stdlib.zip"];
614
662
  java: readonly ["compiler.wasm-runtime.js", "compiler.wasm", "compile-classlib-teavm.bin", "runtime-classlib-teavm.bin"];
615
663
  clang: readonly ["runtime-manifest.v1.json", "bin/memfs.wasm.gz", "bin/clang.wasm.gz", "bin/lld.wasm.gz", "bin/sysroot.tar.gz"];
616
- clangd: readonly ["clangd.js", "clangd.wasm.gz"];
664
+ clangd: readonly ["clangd.js", "clangd.wasm.gz", "clangd.headers.json.gz"];
617
665
  };
618
666
  export declare function resolveRuntimeAssetConfig(runtime: RuntimeAssetRuntime, options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string, callCache?: RuntimeAssetCacheOptions): ResolvedRuntimeAssetConfig;
619
667
  export declare function resolveRustCompilerUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
@@ -638,6 +686,7 @@ export declare function resolveErlangBundleUrl(options: string | PlaygroundRunti
638
686
  export declare function resolveTypeScriptModuleUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
639
687
  export declare function resolveWatModuleUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
640
688
  export declare function resolveLuaModuleUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
689
+ export declare function resolveFennelCompilerUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
641
690
  export declare function resolveZigCompilerUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
642
691
  export declare function resolveHaskellModuleUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
643
692
  export declare function resolveHaskellRootfsUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
@@ -649,6 +698,7 @@ export declare function resolveFortranF2cHeaderUrl(options: string | PlaygroundR
649
698
  export declare function resolveFortranAnalyzerUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
650
699
  export declare function resolveFortranRuntimeAssetConfig(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): ResolvedFortranRuntimeAssetConfig;
651
700
  export declare function resolveCobolBaseUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
701
+ export declare function resolveVBaseUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
652
702
  export declare function resolveObjectiveCBaseUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
653
703
  export declare function resolveObjectiveCLibobjcUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
654
704
  export declare function resolveObjectiveCHeadersUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
@@ -774,6 +824,21 @@ export declare function resolveClojureScriptRuntimeAssetConfig(options: string |
774
824
  sha256: string;
775
825
  }>;
776
826
  };
827
+ export declare function resolveReScriptBaseUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
828
+ export declare function resolveReScriptWorkerUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
829
+ export declare function resolveReScriptManifestUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
830
+ export declare function resolveReScriptRuntimeAssetConfig(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): {
831
+ baseUrl: string;
832
+ workerUrl: string;
833
+ manifestUrl: string;
834
+ manifestFingerprint: string;
835
+ preflightKey: string;
836
+ preflightProfile: ReScriptRuntimePreflightProfile;
837
+ workerReceipt: Readonly<{
838
+ bytes: number;
839
+ sha256: string;
840
+ }>;
841
+ };
777
842
  export declare function resolveForthBaseUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
778
843
  export declare function resolveForthWorkerUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
779
844
  export declare function resolveForthManifestUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
@@ -887,7 +952,12 @@ export declare function resolveSqliteWasmUrl(options: string | PlaygroundRuntime
887
952
  export declare function resolveAssemblyScriptRuntimeModuleUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
888
953
  export declare function resolveDuckDbRuntimeModuleUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
889
954
  export declare function resolvePhpRuntimeModuleUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
955
+ export declare function resolvePostgresqlRuntimeModuleUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
890
956
  export declare function resolveRubyRuntimeModuleUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
891
957
  export declare function resolveSqliteRuntimeModuleUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
892
958
  /** C3 uses one code-pinned compiler/worker receipt, served from this base URL. */
893
959
  export declare function resolveC3BaseUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
960
+ /** Grain uses one code-pinned compiler/stdlib/worker receipt, served from this base URL. */
961
+ export declare function resolveGrainBaseUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
962
+ /** Hy wheels are code-pinned receipts served from this base URL and installed into Pyodide. */
963
+ export declare function resolveHyBaseUrl(options: string | PlaygroundRuntimeAssets | undefined, currentUrl?: string): string;
@@ -1,4 +1,4 @@
1
- import { env as dynamicPublicEnv } from '$env/dynamic/public';
1
+ import * as publicEnv from '$app/env/public';
2
2
  import { resolveRuntimeAssetCacheOptions, resolveRuntimeAssetLockEntry } from '@wasm-idle/core';
3
3
  import { BUNDLED_CLANG_ASSET_INTEGRITY } from './clangAssetIntegrity';
4
4
  import { snapshotDOuterAssetConfig } from './dOuterAssets';
@@ -9,8 +9,10 @@ import { WASM_FORTH_ASSET_VERSION, WASM_FORTH_RUNTIME_PROFILE, WASM_FORTH_RUNNER
9
9
  import { WASM_BQN_ASSET_VERSION, WASM_BQN_RUNTIME_PROFILE, WASM_BQN_RUNNER_RECEIPT } from './wasmBqnVersion';
10
10
  import { WASM_BASH_RUNTIME_BUNDLE } from './wasmBashVersion';
11
11
  import { WASM_CLOJURESCRIPT_ASSET_VERSION, WASM_CLOJURESCRIPT_RUNNER_RECEIPT, WASM_CLOJURESCRIPT_RUNTIME_PROFILE } from './wasmClojureScriptVersion';
12
+ import { WASM_RESCRIPT_ASSET_VERSION, WASM_RESCRIPT_RUNNER_RECEIPT, WASM_RESCRIPT_RUNTIME_PROFILE } from './wasmReScriptVersion';
12
13
  import { WASM_J_ASSET_VERSION, WASM_J_RUNNER_RECEIPT, WASM_J_RUNTIME_PROFILE } from './wasmJVersion';
13
14
  import { WASM_JANET_RUNTIME_BUNDLE } from './wasmJanetVersion';
15
+ import { WASM_FENNEL_COMPILER_RECEIPT } from './wasmFennelVersion';
14
16
  import { WASM_JULIA_RUNTIME_BUNDLE } from './wasmJuliaVersion';
15
17
  import { WASM_LISP_ASSET_VERSION } from './wasmLispVersion';
16
18
  import { WASM_NIM_RUNTIME_BUNDLE } from './wasmNimVersion';
@@ -27,10 +29,9 @@ import { WASM_FORTRAN_EXECUTION_ASSET_RECEIPTS } from './wasmFortranExecutionAss
27
29
  import { WASM_D_OUTER_ASSET_RECEIPTS } from './wasmDIntegrity';
28
30
  import { WASM_ZIG_ASSET_RECEIPTS } from './wasmZigVersion';
29
31
  import { snapshotZigExecutionAssetReceipts } from './zigAssets';
30
- const publicEnv = (dynamicPublicEnv || {});
31
32
  export const PYTHON_RUNTIME_LOAD_ASSETS = [
32
33
  'pyodide.mjs',
33
- 'pyodide.asm.js',
34
+ 'pyodide.asm.mjs',
34
35
  'pyodide-lock.json',
35
36
  'pyodide.asm.wasm',
36
37
  'python_stdlib.zip'
@@ -43,7 +44,11 @@ export const CLANG_RUNTIME_LOAD_ASSETS = [
43
44
  'bin/lld.wasm.gz',
44
45
  'bin/sysroot.tar.gz'
45
46
  ];
46
- export const CLANGD_RUNTIME_LOAD_ASSETS = ['clangd.js', 'clangd.wasm.gz'];
47
+ export const CLANGD_RUNTIME_LOAD_ASSETS = [
48
+ 'clangd.js',
49
+ 'clangd.wasm.gz',
50
+ 'clangd.headers.json.gz'
51
+ ];
47
52
  export const RUNTIME_LOAD_ASSETS = {
48
53
  python: PYTHON_RUNTIME_LOAD_ASSETS,
49
54
  java: JAVA_RUNTIME_LOAD_ASSETS,
@@ -482,6 +487,18 @@ export function resolveLuaModuleUrl(options, currentUrl = '') {
482
487
  }
483
488
  return '';
484
489
  }
490
+ export function resolveFennelCompilerUrl(options, currentUrl = '') {
491
+ const configuredCompilerUrl = (typeof options === 'object' && options?.fennel?.compilerUrl) ||
492
+ (publicEnv.PUBLIC_WASM_FENNEL_COMPILER_URL || '').trim();
493
+ if (configuredCompilerUrl) {
494
+ return resolveConfiguredUrl(configuredCompilerUrl, currentUrl);
495
+ }
496
+ const rootUrl = typeof options === 'string' ? options : options?.rootUrl;
497
+ if (rootUrl) {
498
+ return resolveConfiguredUrl(`${normalizeRootUrl(rootUrl) || ''}/${WASM_FENNEL_COMPILER_RECEIPT.path}`, currentUrl);
499
+ }
500
+ return '';
501
+ }
485
502
  export function resolveZigCompilerUrl(options, currentUrl = '') {
486
503
  const configuredCompilerUrl = (typeof options === 'object' && options?.zig?.compilerUrl) ||
487
504
  (publicEnv.PUBLIC_WASM_ZIG_COMPILER_URL || '').trim();
@@ -600,6 +617,20 @@ export function resolveCobolBaseUrl(options, currentUrl = '') {
600
617
  }
601
618
  return normalizeBaseUrl('/wasm-cobol/', currentUrl);
602
619
  }
620
+ export function resolveVBaseUrl(options, currentUrl = '') {
621
+ const configuredBaseUrl = (typeof options === 'object' && options?.v?.baseUrl) ||
622
+ (publicEnv.PUBLIC_WASM_V_BASE_URL || '').trim();
623
+ if (configuredBaseUrl) {
624
+ return normalizeBaseUrl(configuredBaseUrl, currentUrl);
625
+ }
626
+ if (typeof options === 'string') {
627
+ return normalizeBaseUrl(`${normalizeRootUrl(options) || ''}/wasm-v/`, currentUrl);
628
+ }
629
+ if (options?.rootUrl) {
630
+ return normalizeBaseUrl(`${normalizeRootUrl(options.rootUrl) || ''}/wasm-v/`, currentUrl);
631
+ }
632
+ return normalizeBaseUrl('/wasm-v/', currentUrl);
633
+ }
603
634
  export function resolveObjectiveCBaseUrl(options, currentUrl = '') {
604
635
  const configuredBaseUrl = (typeof options === 'object' && options?.objectivec?.baseUrl) ||
605
636
  (publicEnv.PUBLIC_WASM_OBJECTIVEC_BASE_URL || '').trim();
@@ -1589,6 +1620,77 @@ export function resolveClojureScriptRuntimeAssetConfig(options, currentUrl = '')
1589
1620
  workerReceipt: configured?.workerReceipt || WASM_CLOJURESCRIPT_RUNNER_RECEIPT
1590
1621
  };
1591
1622
  }
1623
+ export function resolveReScriptBaseUrl(options, currentUrl = '') {
1624
+ const configuredBaseUrl = (typeof options === 'object' && options?.rescript?.baseUrl) ||
1625
+ (publicEnv.PUBLIC_WASM_RESCRIPT_BASE_URL || '').trim();
1626
+ if (configuredBaseUrl)
1627
+ return normalizeBaseUrl(configuredBaseUrl, currentUrl);
1628
+ if (typeof options === 'string') {
1629
+ return normalizeBaseUrl(`${normalizeRootUrl(options) || ''}/wasm-rescript/`, currentUrl);
1630
+ }
1631
+ if (options?.rootUrl) {
1632
+ return normalizeBaseUrl(`${normalizeRootUrl(options.rootUrl) || ''}/wasm-rescript/`, currentUrl);
1633
+ }
1634
+ return normalizeBaseUrl('/wasm-rescript/', currentUrl);
1635
+ }
1636
+ export function resolveReScriptWorkerUrl(options, currentUrl = '') {
1637
+ const configuredWorkerUrl = (typeof options === 'object' && options?.rescript?.workerUrl) ||
1638
+ (publicEnv.PUBLIC_WASM_RESCRIPT_WORKER_URL || '').trim();
1639
+ if (configuredWorkerUrl)
1640
+ return resolveConfiguredUrl(configuredWorkerUrl, currentUrl);
1641
+ if (typeof options === 'string') {
1642
+ return resolveConfiguredUrl(`${normalizeRootUrl(options) || ''}/wasm-rescript/runner-worker.js`, currentUrl);
1643
+ }
1644
+ if (options?.rootUrl) {
1645
+ return resolveConfiguredUrl(`${normalizeRootUrl(options.rootUrl) || ''}/wasm-rescript/runner-worker.js`, currentUrl);
1646
+ }
1647
+ return resolveConfiguredUrl('/wasm-rescript/runner-worker.js', currentUrl);
1648
+ }
1649
+ export function resolveReScriptManifestUrl(options, currentUrl = '') {
1650
+ const configuredManifestUrl = typeof options === 'object' ? options?.rescript?.manifestUrl : undefined;
1651
+ if (configuredManifestUrl) {
1652
+ return resolveConfiguredUrl(configuredManifestUrl, currentUrl);
1653
+ }
1654
+ return `${resolveReScriptBaseUrl(options, currentUrl)}runtime-manifest.v1.json`;
1655
+ }
1656
+ export function resolveReScriptRuntimeAssetConfig(options, currentUrl = '') {
1657
+ const configured = typeof options === 'object' ? options?.rescript : undefined;
1658
+ const manifestFingerprint = configured?.manifestFingerprint?.trim() || WASM_RESCRIPT_ASSET_VERSION;
1659
+ const usesBundledProfile = manifestFingerprint === WASM_RESCRIPT_ASSET_VERSION;
1660
+ const receipt = (configuredReceipt, bundledReceipt) => {
1661
+ const selected = configuredReceipt || (usesBundledProfile ? bundledReceipt : undefined);
1662
+ return selected
1663
+ ? Object.freeze({
1664
+ bytes: selected.bytes,
1665
+ sha256: selected.sha256,
1666
+ ...(selected.uncompressedBytes === undefined
1667
+ ? {}
1668
+ : { uncompressedBytes: selected.uncompressedBytes }),
1669
+ ...(selected.uncompressedSha256 === undefined
1670
+ ? {}
1671
+ : { uncompressedSha256: selected.uncompressedSha256 })
1672
+ })
1673
+ : undefined;
1674
+ };
1675
+ const preflightProfile = Object.freeze({
1676
+ profileId: configured?.profileId?.trim() ||
1677
+ (usesBundledProfile ? WASM_RESCRIPT_RUNTIME_PROFILE.profileId : ''),
1678
+ sourceRevision: configured?.sourceRevision?.trim() ||
1679
+ (usesBundledProfile ? WASM_RESCRIPT_RUNTIME_PROFILE.sourceRevision : ''),
1680
+ manifestFingerprint,
1681
+ manifestReceipt: receipt(configured?.manifestReceipt, WASM_RESCRIPT_RUNTIME_PROFILE.manifestReceipt),
1682
+ compilerReceipt: receipt(configured?.compilerReceipt, WASM_RESCRIPT_RUNTIME_PROFILE.compilerReceipt)
1683
+ });
1684
+ return {
1685
+ baseUrl: resolveReScriptBaseUrl(options, currentUrl),
1686
+ workerUrl: resolveReScriptWorkerUrl(options, currentUrl),
1687
+ manifestUrl: resolveReScriptManifestUrl(options, currentUrl),
1688
+ manifestFingerprint,
1689
+ preflightKey: JSON.stringify(preflightProfile),
1690
+ preflightProfile,
1691
+ workerReceipt: configured?.workerReceipt || WASM_RESCRIPT_RUNNER_RECEIPT
1692
+ };
1693
+ }
1592
1694
  export function resolveForthBaseUrl(options, currentUrl = '') {
1593
1695
  const configuredBaseUrl = (typeof options === 'object' && options?.forth?.baseUrl) ||
1594
1696
  (publicEnv.PUBLIC_WASM_FORTH_BASE_URL || '').trim();
@@ -2268,6 +2370,9 @@ export function resolveDuckDbRuntimeModuleUrl(options, currentUrl = '') {
2268
2370
  export function resolvePhpRuntimeModuleUrl(options, currentUrl = '') {
2269
2371
  return resolveStaticRuntimeModuleUrl(options, typeof options === 'object' ? options?.php?.moduleUrl : undefined, publicEnv.PUBLIC_WASM_PHP_MODULE_URL || '', 'wasm-php', currentUrl);
2270
2372
  }
2373
+ export function resolvePostgresqlRuntimeModuleUrl(options, currentUrl = '') {
2374
+ return resolveStaticRuntimeModuleUrl(options, typeof options === 'object' ? options?.postgresql?.moduleUrl : undefined, publicEnv.PUBLIC_WASM_POSTGRESQL_MODULE_URL || '', 'wasm-postgresql', currentUrl);
2375
+ }
2271
2376
  export function resolveRubyRuntimeModuleUrl(options, currentUrl = '') {
2272
2377
  return resolveRubyRuntimeAssetConfig(options, currentUrl).moduleUrl;
2273
2378
  }
@@ -2283,3 +2388,21 @@ export function resolveC3BaseUrl(options, currentUrl = '') {
2283
2388
  const root = typeof options === 'string' ? options : options?.rootUrl;
2284
2389
  return normalizeBaseUrl(`${normalizeRootUrl(root || '') || ''}/wasm-c3/`, currentUrl);
2285
2390
  }
2391
+ /** Grain uses one code-pinned compiler/stdlib/worker receipt, served from this base URL. */
2392
+ export function resolveGrainBaseUrl(options, currentUrl = '') {
2393
+ const configured = (typeof options === 'object' && options?.grain?.baseUrl) ||
2394
+ (publicEnv.PUBLIC_WASM_GRAIN_BASE_URL || '').trim();
2395
+ if (configured)
2396
+ return normalizeBaseUrl(configured, currentUrl);
2397
+ const root = typeof options === 'string' ? options : options?.rootUrl;
2398
+ return normalizeBaseUrl(`${normalizeRootUrl(root || '') || ''}/wasm-grain/`, currentUrl);
2399
+ }
2400
+ /** Hy wheels are code-pinned receipts served from this base URL and installed into Pyodide. */
2401
+ export function resolveHyBaseUrl(options, currentUrl = '') {
2402
+ const configured = (typeof options === 'object' && options?.hy?.baseUrl) ||
2403
+ (publicEnv.PUBLIC_WASM_HY_BASE_URL || '').trim();
2404
+ if (configured)
2405
+ return normalizeBaseUrl(configured, currentUrl);
2406
+ const root = typeof options === 'string' ? options : options?.rootUrl;
2407
+ return normalizeBaseUrl(`${normalizeRootUrl(root || '') || ''}/wasm-hy/`, currentUrl);
2408
+ }
@@ -32,6 +32,34 @@ export function createCachedClangSandbox(legacy, language, runtimeCache, cache =
32
32
  let pendingEof = false;
33
33
  const pendingInput = [];
34
34
  const encoder = new TextEncoder();
35
+ // Built in the background by the compile worker after a <bits/stdc++.h> source; it outlives
36
+ // runs and cancellations and is discarded only with the sandbox.
37
+ let precompiledHeader;
38
+ let headerWorker;
39
+ function adoptHeaderWorker(worker, bridge) {
40
+ headerWorker?.dispose();
41
+ const dispose = () => {
42
+ if (headerWorker?.worker === worker)
43
+ headerWorker = undefined;
44
+ bridge?.dispose();
45
+ worker.onmessage = null;
46
+ worker.onerror = null;
47
+ worker.onmessageerror = null;
48
+ worker.terminate();
49
+ };
50
+ headerWorker = { worker, dispose };
51
+ worker.onerror = dispose;
52
+ worker.onmessageerror = dispose;
53
+ worker.onmessage = (event) => {
54
+ if (bridge?.handleMessage(event))
55
+ return;
56
+ if (event.data?.type !== 'precompiled-header')
57
+ return;
58
+ if (event.data.header)
59
+ precompiledHeader = event.data.header;
60
+ dispose();
61
+ };
62
+ }
35
63
  function resetInput() {
36
64
  pendingInput.length = 0;
37
65
  pendingEof = false;
@@ -90,17 +118,21 @@ export function createCachedClangSandbox(legacy, language, runtimeCache, cache =
90
118
  const abort = () => finish(signal?.reason instanceof Error
91
119
  ? signal.reason
92
120
  : new Error('Process terminated'));
93
- const finish = (error, value) => {
121
+ const finish = (error, value, keepForHeader = false) => {
94
122
  if (activeWorker !== worker)
95
123
  return;
96
124
  activeWorker = undefined;
97
125
  cancelWorker = undefined;
98
126
  signal?.removeEventListener('abort', abort);
99
- bridge?.dispose();
100
127
  worker.onmessage = null;
101
128
  worker.onerror = null;
102
129
  worker.onmessageerror = null;
103
- worker.terminate();
130
+ if (keepForHeader)
131
+ adoptHeaderWorker(worker, bridge);
132
+ else {
133
+ bridge?.dispose();
134
+ worker.terminate();
135
+ }
104
136
  if (error)
105
137
  reject(error);
106
138
  else
@@ -142,10 +174,11 @@ export function createCachedClangSandbox(legacy, language, runtimeCache, cache =
142
174
  legacy.output?.(data.stdout);
143
175
  if (data.stderr)
144
176
  legacy.output?.(data.stderr);
177
+ const keepForHeader = data.precompiledHeader === 'building';
145
178
  if (data.type === 'error')
146
- finish(new Error(data.error));
179
+ finish(new Error(data.error), undefined, keepForHeader);
147
180
  else
148
- finish(undefined, data.artifact);
181
+ finish(undefined, data.artifact, keepForHeader);
149
182
  }
150
183
  else if (data.type === 'done') {
151
184
  if (data.exitCode !== 0 && data.exitCode !== null)
@@ -247,6 +280,10 @@ export function createCachedClangSandbox(legacy, language, runtimeCache, cache =
247
280
  maxAssetBytes: limit,
248
281
  languageSysroots,
249
282
  log,
283
+ persistentCache: executionAssetConfig.persistentCache,
284
+ ...(language === 'CPP' && precompiledHeader
285
+ ? { precompiledHeader }
286
+ : {}),
250
287
  assets: {
251
288
  baseUrl: runtimeBaseUrl,
252
289
  maxAssetBytes: limit,
@@ -315,6 +352,8 @@ export function createCachedClangSandbox(legacy, language, runtimeCache, cache =
315
352
  return disposal;
316
353
  disposed = true;
317
354
  stop();
355
+ headerWorker?.dispose();
356
+ precompiledHeader = undefined;
318
357
  disposal = Promise.resolve(legacy.dispose ? legacy.dispose() : legacy.terminate());
319
358
  return disposal;
320
359
  }
@@ -36,6 +36,10 @@ declare class Clang implements Sandbox {
36
36
  private debugMode;
37
37
  private readonly lldbBreakpoints;
38
38
  private debugEvaluationQueue;
39
+ private precompiledHeader?;
40
+ private precompiledHeaderSent?;
41
+ private headerBuilder?;
42
+ private loadedRuntime?;
39
43
  private readonly workerSession;
40
44
  private disposeWorkerAssetBridge;
41
45
  constructor(language: 'C' | 'CPP');
@@ -60,6 +64,7 @@ declare class Clang implements Sandbox {
60
64
  debugDataBreakpointInfo(arguments_: DebugDataBreakpointInfoArguments): Promise<import("@wasm-idle/core").DebugDataBreakpointInfo | null>;
61
65
  debugSetDataBreakpoints(breakpoints: DebugDataBreakpoint[]): Promise<import("@wasm-idle/core").DebugResolvedDataBreakpoint[]>;
62
66
  kill(): Promise<void>;
67
+ private buildPrecompiledHeader;
63
68
  terminate(): Promise<void>;
64
69
  clear(): Promise<void>;
65
70
  setRuntimeAssetCache(cache: RuntimeAssetCache): void;
@@ -48,6 +48,12 @@ class Clang {
48
48
  debugMode = 'none';
49
49
  lldbBreakpoints = new Map();
50
50
  debugEvaluationQueue = Promise.resolve();
51
+ // A helper worker builds the precompiled <bits/stdc++.h> so the warm worker stays free for
52
+ // runs. The header is sent once to each warm worker, which keeps it for later compiles.
53
+ precompiledHeader;
54
+ precompiledHeaderSent;
55
+ headerBuilder;
56
+ loadedRuntime;
51
57
  workerSession = new WorkerSession({
52
58
  label: 'Clang',
53
59
  onDispose: (worker) => {
@@ -102,6 +108,12 @@ class Clang {
102
108
  const languageSysrootProfiles = bundledAssets &&
103
109
  typeof runtimeAssets !== 'string' &&
104
110
  runtimeAssets.clang?.bundledLanguageSysroots === true;
111
+ this.loadedRuntime = {
112
+ assetConfig,
113
+ maxAssetBytes: limits.maxAssetBytes,
114
+ languageSysrootProfiles,
115
+ verifiedStreaming: bundledAssets
116
+ };
105
117
  const needsWorkerReset = !this.worker ||
106
118
  !this.assetBridge ||
107
119
  !this.assetBridge.matches(assetConfig, limits.maxAssetBytes, languageSysrootProfiles);
@@ -130,6 +142,7 @@ class Clang {
130
142
  };
131
143
  this.worker.postMessage({
132
144
  load: true,
145
+ persistentCache: assetConfig.persistentCache,
133
146
  verifiedStreaming: bundledAssets,
134
147
  languageSysrootProfiles,
135
148
  log,
@@ -285,6 +298,17 @@ class Clang {
285
298
  });
286
299
  return;
287
300
  }
301
+ if (event.data.precompiledHeaderKey)
302
+ void this.buildPrecompiledHeader(event.data.precompiledHeaderKey, {
303
+ code,
304
+ language: this.language,
305
+ compileArgs,
306
+ activePath: options.activePath,
307
+ cppVersion: options.cppVersion,
308
+ cVersion: options.cVersion,
309
+ debugMode,
310
+ persistentCache: persistentCache ?? this.persistentCache
311
+ });
288
312
  if (results) {
289
313
  this.elapse = Date.now() - this.begin;
290
314
  this.exit = true;
@@ -310,7 +334,16 @@ class Clang {
310
334
  interrupt[0] = 0;
311
335
  this.worker.onmessage = handler;
312
336
  this.begin = Date.now();
337
+ const precompiledHeader = this.language === 'CPP' &&
338
+ (this.precompiledHeaderSent?.worker !== this.worker ||
339
+ this.precompiledHeaderSent.header !== this.precompiledHeader)
340
+ ? this.precompiledHeader
341
+ : undefined;
342
+ if (precompiledHeader)
343
+ this.precompiledHeaderSent = { worker: this.worker, header: precompiledHeader };
313
344
  this.worker?.postMessage({
345
+ persistentCache: persistentCache ?? this.persistentCache,
346
+ ...(precompiledHeader ? { precompiledHeader } : {}),
314
347
  code,
315
348
  prepare,
316
349
  buffer: this.buffer,
@@ -412,6 +445,71 @@ class Clang {
412
445
  kill() {
413
446
  return this.terminate();
414
447
  }
448
+ async buildPrecompiledHeader(key, request) {
449
+ const runtime = this.loadedRuntime;
450
+ if (!runtime ||
451
+ this.disposed ||
452
+ this.precompiledHeader?.key === key ||
453
+ this.headerBuilder?.key === key)
454
+ return;
455
+ this.headerBuilder?.dispose();
456
+ let cancelled = false;
457
+ const pending = {
458
+ key,
459
+ dispose: () => {
460
+ cancelled = true;
461
+ if (this.headerBuilder === pending)
462
+ this.headerBuilder = undefined;
463
+ }
464
+ };
465
+ this.headerBuilder = pending;
466
+ const { default: ClangWorker } = await import('./worker/clang?worker');
467
+ if (cancelled)
468
+ return;
469
+ const worker = new ClangWorker();
470
+ const bridge = new WorkerAssetBridge(worker, 'clang', runtime.assetConfig, undefined, runtime.maxAssetBytes, runtime.languageSysrootProfiles, this.runtimeAssetCache);
471
+ const builder = {
472
+ key,
473
+ dispose: () => {
474
+ if (this.headerBuilder === builder)
475
+ this.headerBuilder = undefined;
476
+ bridge.dispose();
477
+ worker.onmessage = null;
478
+ worker.onerror = null;
479
+ worker.terminate();
480
+ }
481
+ };
482
+ this.headerBuilder = builder;
483
+ worker.onerror = builder.dispose;
484
+ worker.onmessage = (event) => {
485
+ if (bridge.handleMessage(event))
486
+ return;
487
+ const { data } = event;
488
+ if (data?.load)
489
+ worker.postMessage({ precompileHeader: true, ...request });
490
+ else if (data?.error)
491
+ builder.dispose();
492
+ else if (data && 'precompiledHeader' in data) {
493
+ if (data.precompiledHeader)
494
+ this.precompiledHeader = data.precompiledHeader;
495
+ builder.dispose();
496
+ }
497
+ };
498
+ worker.postMessage({
499
+ load: true,
500
+ persistentCache: runtime.assetConfig.persistentCache,
501
+ verifiedStreaming: runtime.verifiedStreaming,
502
+ languageSysrootProfiles: runtime.languageSysrootProfiles,
503
+ log: false,
504
+ assets: {
505
+ baseUrl: runtime.assetConfig.baseUrl,
506
+ maxAssetBytes: runtime.maxAssetBytes,
507
+ useAssetBridge: runtime.assetConfig.useAssetBridge,
508
+ useModuleBridge: true
509
+ },
510
+ maxAssetBytes: runtime.maxAssetBytes
511
+ });
512
+ }
415
513
  async terminate() {
416
514
  const lldbSession = this.lldbSession;
417
515
  this.lldbSession = undefined;
@@ -460,6 +558,8 @@ class Clang {
460
558
  this.disposal = Promise.resolve()
461
559
  .then(() => this.clear())
462
560
  .finally(() => {
561
+ this.headerBuilder?.dispose();
562
+ this.precompiledHeader = undefined;
463
563
  if (this.ownsRuntimeAssetCache)
464
564
  this.runtimeAssetCache.dispose();
465
565
  this.output = null;
@@ -1,4 +1,4 @@
1
- import type { BrowserClangArtifact, BrowserClangCompileProgress, BrowserClangCompileRequest, BrowserClangWorkspaceFile } from '@wasm-idle/llvm-core/clang';
1
+ import type { BrowserClangArtifact, BrowserClangCompileProgress, BrowserClangCompileRequest, BrowserClangPrecompiledHeader, BrowserClangWorkspaceFile } from '@wasm-idle/llvm-core/clang';
2
2
  import type { WorkerRuntimeAssetConfig } from './worker/assets';
3
3
  export type ClangCompileWorkerRequest = {
4
4
  request: Omit<BrowserClangCompileRequest, 'onProgress'>;
@@ -7,7 +7,14 @@ export type ClangCompileWorkerRequest = {
7
7
  languageSysroots?: boolean;
8
8
  log?: boolean;
9
9
  assets: WorkerRuntimeAssetConfig;
10
+ /** The last precompiled <bits/stdc++.h>; the worker ignores it when its key differs. */
11
+ precompiledHeader?: BrowserClangPrecompiledHeader;
12
+ persistentCache?: import('@wasm-idle/core').RuntimeAssetCacheOptions;
10
13
  };
14
+ /**
15
+ * `precompiledHeader: 'building'` means the worker stays alive after the result and later posts
16
+ * one `precompiled-header` message, with no header when Clang could not build it.
17
+ */
11
18
  export type ClangCompileWorkerResponse = {
12
19
  type: 'progress';
13
20
  progress: BrowserClangCompileProgress;
@@ -16,11 +23,16 @@ export type ClangCompileWorkerResponse = {
16
23
  artifact: BrowserClangArtifact;
17
24
  stdout: string;
18
25
  stderr: string;
26
+ precompiledHeader?: 'building';
19
27
  } | {
20
28
  type: 'error';
21
29
  error: string;
22
30
  stdout: string;
23
31
  stderr: string;
32
+ precompiledHeader?: 'building';
33
+ } | {
34
+ type: 'precompiled-header';
35
+ header?: BrowserClangPrecompiledHeader;
24
36
  };
25
37
  export type ClangExecuteWorkerRequest = {
26
38
  artifact: BrowserClangArtifact;
@@ -0,0 +1,9 @@
1
+ import Lua from './lua';
2
+ /**
3
+ * Fennel runs the pinned official `fennel.lua` compiler on the shared wasm-lua (wasmoon)
4
+ * worker. The worker fetches and verifies the compiler against its receipt before use.
5
+ */
6
+ declare class Fennel extends Lua {
7
+ constructor();
8
+ }
9
+ export default Fennel;