@remix_labs/machine-starter 2.2226.0-dev → 2.2228.0-dev

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/common.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { GROOVEBOX_BUILD } from "./groovebox_build.js";
2
+ import { filterFFINames } from "./mixcore-common.js";
2
3
  import { nanoid } from "nanoid";
3
4
 
4
5
  let workers = {};
@@ -56,52 +57,73 @@ function StartWASM(hub, baseURL, org, workspace, vmID, user, token, noOutputViaM
56
57
  })
57
58
  }
58
59
 
59
- function StartWASM2(hub, config) {
60
+ function mixcoreLocalFFIs(mixcore, names) {
61
+ return Object.fromEntries(
62
+ names.map(name => [name, {
63
+ isRaw: true,
64
+ run: (conn, argsBuf) => mixcore.ffiDispatch(conn.call_id, name, argsBuf),
65
+ }]));
66
+ }
67
+
68
+ // See `mix-rs/mixcore/README.md` for a description of the values of
69
+ // config.mixcore.
70
+ async function StartWASM2(hub, config) {
60
71
  console.log("GROOVEBOX_BUILD (machine-starter)", GROOVEBOX_BUILD);
61
- return hub.newChannel().then(channel => {
62
- // injected by either index.js or node.js
63
- let worker = globalThis.GetMachineWASMWorker();
64
- workers[config.vmID] = worker;
65
- let localFFIkind = {};
66
- let localFFIfuns = {};
67
- if (config.localFFIs) {
68
- for (const [k, v] of Object.entries(config.localFFIs)) {
69
- localFFIfuns[k] = {...v};
70
- if (v.isRaw && (v.canFail || v.useJsonDecoder)) {
71
- console.error("A raw, local FFI must neither be failing nor use the JSON decoder: " + k);
72
- } else {
73
- localFFIkind[k] = {...v};
74
- delete localFFIkind[k].run;
75
- }
76
- };
77
- let vm_kind = { isRaw:false, canFail:false, useJsonDecoder:false};
78
- localFFIkind["$vm_start"] = vm_kind;
79
- localFFIfuns["$vm_start"] = ffi_vm_start;
80
- localFFIkind["$vm_stop"] = vm_kind;
81
- localFFIfuns["$vm_stop"] = ffi_vm_stop;
72
+ let channel = await hub.newChannel();
73
+ // injected by either index.js or node.js
74
+ let worker = globalThis.GetMachineWASMWorker();
75
+ workers[config.vmID] = worker;
76
+ let mixcore = null;
77
+ let localFFIs = config.localFFIs || {};
78
+ if (config.mixcore && config.mixcore.kind == 'mixcore') {
79
+ let enableFFIs, disableFFIs;
80
+ ({mixcore, enableFFIs, disableFFIs} = config.mixcore);
81
+ let ffiNames = filterFFINames(await mixcore.ffiNames(), enableFFIs, disableFFIs);
82
+ console.log("Mixcore (starter)", mixcore, ffiNames, mixcore.registerDebugObject);
83
+ localFFIs = {...localFFIs, ...mixcoreLocalFFIs(mixcore, ffiNames)};
84
+ config.mixcore = {};
85
+ if (mixcore.registerDebugObject) {
86
+ config.mixcore.publishDebugObjects = true;
87
+ subscribeDebugObjects(mixcore, hub, config);
82
88
  }
83
- let config_msg =
84
- { "_rmx_type": "msg_vm_configure",
85
- "baseURL": config.baseURL,
86
- "org": config.org,
87
- "workspace": config.workspace,
88
- "vmID": config.vmID,
89
- "user": config.user,
90
- "token": config.token,
91
- "hub": channel.port,
92
- "outputViaMQTT": !(config.noOutputViaMQTT),
93
- "machType": config.machType,
94
- "debugMask": initialMask,
95
- "localFFIs": localFFIkind,
96
- "allowInsecureHttp": globalThis.GROOVEBOX_ALLOW_INSECURE_HTTP,
97
- "interceptFFI": config.interceptFFI,
98
- "interceptDynloadFFI": config.interceptDynloadFFI,
99
- };
100
- worker.postMessage(config_msg, [ channel.port ]);
101
- if (config.localFFIs)
102
- setupLocalFFIs(hub, config, localFFIfuns); // don't await!
103
- return worker;
104
- })
89
+ }
90
+ let localFFIkind = {};
91
+ let localFFIfuns = {};
92
+ for (const [k, v] of Object.entries(localFFIs)) {
93
+ localFFIfuns[k] = {...v};
94
+ if (v.isRaw && (v.canFail || v.useJsonDecoder)) {
95
+ console.error("A raw, local FFI must neither be failing nor use the JSON decoder: " + k);
96
+ } else {
97
+ localFFIkind[k] = {...v};
98
+ delete localFFIkind[k].run;
99
+ }
100
+ };
101
+ let vm_kind = { isRaw:false, canFail:false, useJsonDecoder:false};
102
+ localFFIkind["$vm_start"] = vm_kind;
103
+ localFFIfuns["$vm_start"] = ffi_vm_start;
104
+ localFFIkind["$vm_stop"] = vm_kind;
105
+ localFFIfuns["$vm_stop"] = ffi_vm_stop;
106
+ let config_msg =
107
+ { "_rmx_type": "msg_vm_configure",
108
+ "baseURL": config.baseURL,
109
+ "org": config.org,
110
+ "workspace": config.workspace,
111
+ "vmID": config.vmID,
112
+ "user": config.user,
113
+ "token": config.token,
114
+ "hub": channel.port,
115
+ "outputViaMQTT": !(config.noOutputViaMQTT),
116
+ "machType": config.machType,
117
+ "debugMask": initialMask,
118
+ "localFFIs": localFFIkind,
119
+ "allowInsecureHttp": globalThis.GROOVEBOX_ALLOW_INSECURE_HTTP,
120
+ "interceptFFI": config.interceptFFI,
121
+ "interceptDynloadFFI": config.interceptDynloadFFI,
122
+ "mixcore": config.mixcore,
123
+ };
124
+ worker.postMessage(config_msg, [ channel.port ]);
125
+ setupLocalFFIs(hub, config, localFFIfuns); // don't await!
126
+ return worker;
105
127
  }
106
128
 
107
129
  async function ffi_vm_start(conn, args) {
@@ -260,8 +282,7 @@ async function setupLocalFFIs(hub, config, localFFIs) {
260
282
  let args = decode(msg.payload.args);
261
283
  let fun = localFFIs[name];
262
284
  try {
263
- if (!fun)
264
- throw new Error("no such local FFI: " + name);
285
+ if (!fun) throw new Error("no such local FFI: " + name);
265
286
  let connector =
266
287
  { call_id: call_id,
267
288
  hub: hub,
@@ -284,6 +305,19 @@ async function setupLocalFFIs(hub, config, localFFIs) {
284
305
  }
285
306
  }
286
307
 
308
+ async function subscribeDebugObjects(mixcore, hub, config) {
309
+ let channel = await hub.newChannel();
310
+ let vmID = config.vmID;
311
+ await channel.setLocalSubTopic(`/debug-objects/${vmID}`);
312
+ let sub = await channel.subscribe(`/debug-objects/${vmID}`);
313
+ while (true) {
314
+ let msg = await sub.next();
315
+ let id = msg.payload.id;
316
+ let code = msg.payload.code;
317
+ mixcore.registerDebugObject(id, code);
318
+ }
319
+ }
320
+
287
321
  class FFIComm {
288
322
  constructor(vmID, hub, channel) {
289
323
  this.vmID = vmID;
@@ -1,2 +1,2 @@
1
- var GROOVEBOX_BUILD = "2403";
1
+ var GROOVEBOX_BUILD = "2405";
2
2
  export { GROOVEBOX_BUILD }