@nimbus-sh/core 0.3.0 → 0.4.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 (36) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +112 -0
  3. package/dist/_shared/tarball-stream.d.ts +93 -0
  4. package/dist/_shared/tarball-stream.d.ts.map +1 -0
  5. package/dist/_shared/tarball-stream.js +235 -0
  6. package/dist/_shared/tarball.d.ts +17 -0
  7. package/dist/_shared/tarball.d.ts.map +1 -0
  8. package/dist/_shared/tarball.js +39 -0
  9. package/dist/runtime/clang-runner.d.ts +38 -0
  10. package/dist/runtime/clang-runner.d.ts.map +1 -0
  11. package/dist/runtime/clang-runner.js +866 -0
  12. package/dist/runtime/facet-host.d.ts +12 -0
  13. package/dist/runtime/facet-host.d.ts.map +1 -1
  14. package/dist/runtime/local-facet-host.d.ts.map +1 -1
  15. package/dist/runtime/local-facet-host.js +29 -9
  16. package/dist/runtime/ruby-gems.d.ts +30 -0
  17. package/dist/runtime/ruby-gems.d.ts.map +1 -0
  18. package/dist/runtime/ruby-gems.js +636 -0
  19. package/dist/runtime/ruby-runner.d.ts +127 -0
  20. package/dist/runtime/ruby-runner.d.ts.map +1 -0
  21. package/dist/runtime/ruby-runner.js +1357 -0
  22. package/dist/runtime/session-process-supervisor.d.ts +15 -0
  23. package/dist/runtime/session-process-supervisor.d.ts.map +1 -1
  24. package/dist/runtime/session-process-supervisor.js +30 -0
  25. package/dist/workspace/nimbus-workspace.d.ts.map +1 -1
  26. package/dist/workspace/nimbus-workspace.js +9 -2
  27. package/package.json +4 -2
  28. package/src/_shared/tarball-stream.ts +263 -0
  29. package/src/_shared/tarball.ts +46 -0
  30. package/src/runtime/clang-runner.ts +924 -0
  31. package/src/runtime/facet-host.ts +12 -0
  32. package/src/runtime/local-facet-host.ts +28 -8
  33. package/src/runtime/ruby-gems.ts +682 -0
  34. package/src/runtime/ruby-runner.ts +1484 -0
  35. package/src/runtime/session-process-supervisor.ts +27 -0
  36. package/src/workspace/nimbus-workspace.ts +10 -1
@@ -75,6 +75,18 @@ export interface FacetSpec {
75
75
  syscalls?: FacetSyscalls;
76
76
  /** Facets the host may keep warm for this spec. Default 1. */
77
77
  concurrency?: number;
78
+ /**
79
+ * Who a warm facet may be reused FOR. Default `session`.
80
+ *
81
+ * A scope keeps whatever the last call left in it, so by default it may only
82
+ * ever answer for the session that opened it. `global` is a claim the
83
+ * RUNTIME makes about itself and one only a pure function can make: no
84
+ * syscalls binding, nothing retained between calls, output decided entirely
85
+ * by the arguments. The clang toolchain is that — a compile is the same
86
+ * compile for every tenant — and one warm isolate holding its 31 MiB of
87
+ * compiled compiler serves all of them.
88
+ */
89
+ reuse?: 'session' | 'global';
78
90
  }
79
91
  /** The session a facet's syscalls reach, and who they reach it as. */
80
92
  export interface FacetSyscalls {
@@ -1 +1 @@
1
- {"version":3,"file":"facet-host.d.ts","sourceRoot":"","sources":["../../src/runtime/facet-host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,aAAa,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEjF,0EAA0E;AAC1E,MAAM,WAAW,aAAa;IAC5B,kFAAkF;IAClF,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,MAAM,WAAW,SAAS;IACxB,sEAAsE;IACtE,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM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":["../../src/runtime/local-facet-host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAMV,SAAS,EAGV,MAAM,iBAAiB,CAAC;AAuDzB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,IAAI,SAAS,CAwB1C"}
1
+ {"version":3,"file":"local-facet-host.d.ts","sourceRoot":"","sources":["../../src/runtime/local-facet-host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAMV,SAAS,EAGV,MAAM,iBAAiB,CAAC;AAuDzB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,IAAI,SAAS,CAiC1C"}
@@ -85,12 +85,22 @@ export function localFacetHost() {
85
85
  * thousands of startup probes for absent paths from each trying to suspend.
86
86
  */
87
87
  seedFilesystem(vfs, root, options) {
88
- return snapshotVfs(vfs, root, {
88
+ const seeded = snapshotVfs(vfs, root, {
89
89
  extraRoots: options?.extraRoots,
90
90
  skipSubdirs: [],
91
91
  maxBytes: LOCAL_SEED_MAX_BYTES,
92
92
  maxFiles: LOCAL_SEED_MAX_FILES,
93
93
  });
94
+ if ('error' in seeded)
95
+ return seeded;
96
+ // The seed is also the WHOLE of what this guest has, which is a stronger
97
+ // claim than the walk's: `snapshotVfs` reports the roots it listed
98
+ // exhaustively, and this says every path outside them is absent too. It
99
+ // is — a miss out there could only be answered by suspending the guest
100
+ // mid-syscall, which this host cannot do, so the alternative to "absent"
101
+ // is not "fetched" but a read the guest can never receive. Ruby's VM
102
+ // startup stats dozens of prefixes it was never given.
103
+ return { ...seeded, snapshot: { ...seeded.snapshot, enumeratedRoots: [''] } };
94
104
  },
95
105
  open: (spec) => new LocalFacet(spec),
96
106
  };
@@ -122,8 +132,7 @@ class LocalFacet {
122
132
  async call(fn, args, options) {
123
133
  if (this.disposed)
124
134
  throw new Error(`Nimbus: facet '${this.spec.tag}' is disposed`);
125
- const scope = await this.scope();
126
- await this.addModules(options?.wasmModules);
135
+ const scope = await this.scope(options?.wasmModules);
127
136
  let scoped = this.scoped.get(fn);
128
137
  if (!scoped) {
129
138
  const value = scope(`(${fn.toString()})`);
@@ -141,15 +150,26 @@ class LocalFacet {
141
150
  * The returned closure's `eval` is a DIRECT eval inside the body the preamble
142
151
  * was evaluated in, which is what puts the preamble's top-level declarations
143
152
  * in scope for every function submitted afterwards.
153
+ *
154
+ * Both wasm tables are filled BEFORE that body runs, per-call images merged
155
+ * over the spec's. A preamble may boot its runtime as it is evaluated — Ruby
156
+ * instantiates the interpreter right there — so it reads the table at that
157
+ * moment and an image added afterwards would arrive to a facet that had
158
+ * already given up on it. workerd has the same ordering for the same reason:
159
+ * per-call images ride in the module map the inner worker is built from.
144
160
  */
145
- async scope() {
146
- if (this.evaluate)
147
- return this.evaluate;
148
- await this.addModules(this.spec.wasmModules);
161
+ async scope(callModules) {
162
+ const built = this.evaluate;
163
+ if (!built)
164
+ await this.addModules(this.spec.wasmModules);
165
+ await this.addModules(callModules);
166
+ if (built)
167
+ return built;
149
168
  const globals = { __NIMBUS_WASM: this.wasmTable };
150
169
  const build = new AsyncFunction('globalThis', `${this.spec.preamble ?? ''}\nreturn (source) => eval(source);`);
151
- this.evaluate = await build.call(globals, globals);
152
- return this.evaluate;
170
+ const evaluate = await build.call(globals, globals);
171
+ this.evaluate = evaluate;
172
+ return evaluate;
153
173
  }
154
174
  async addModules(modules) {
155
175
  for (const [name, bytes] of Object.entries(modules ?? {})) {
@@ -0,0 +1,30 @@
1
+ import type { CredentialedVfs } from '../vfs/sqlite-vfs.js';
2
+ export interface RubyGemRequest {
3
+ name: string;
4
+ requirements: string[];
5
+ }
6
+ export interface RubyGemInstallReport {
7
+ installed: string[];
8
+ alreadyInstalled: string[];
9
+ }
10
+ export interface InstalledRubyGemBin {
11
+ name: string;
12
+ path: string;
13
+ }
14
+ export declare function defaultGemHome(): string;
15
+ export declare function installedGemLibRoots(vfs: CredentialedVfs, gemHome?: string): string[];
16
+ export declare function installedGemBins(vfs: CredentialedVfs, gemHome?: string): InstalledRubyGemBin[];
17
+ export declare function installRubyGems(vfs: CredentialedVfs, requests: RubyGemRequest[], opts?: {
18
+ gemHome?: string;
19
+ includeDependencies?: boolean;
20
+ }): Promise<RubyGemInstallReport>;
21
+ export declare function installRubyBundle(vfs: CredentialedVfs, cwd: string, opts?: {
22
+ gemHome?: string;
23
+ }): Promise<{
24
+ requests: RubyGemRequest[];
25
+ report: RubyGemInstallReport;
26
+ lockfilePath: string;
27
+ }>;
28
+ export declare function parseGemfile(text: string): RubyGemRequest[];
29
+ export declare function parseRubyGemRequirements(input: string | undefined): string[];
30
+ //# sourceMappingURL=ruby-gems.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ruby-gems.d.ts","sourceRoot":"","sources":["../../src/runtime/ruby-gems.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAO5D,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B;AA4BD,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,eAAe,EAAE,OAAO,SAAmB,GAAG,MAAM,EAAE,CAU/F;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,eAAe,EAAE,OAAO,SAAmB,GAAG,mBAAmB,EAAE,CAOxG;AAED,wBAAsB,eAAe,CACnC,GAAG,EAAE,eAAe,EACpB,QAAQ,EAAE,cAAc,EAAE,EAC1B,IAAI,GAAE;IAAE,OAAO,CAAC,EAAE,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