@remix_labs/machine-starter 2.2196.0 → 2.2198.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 { mixcoreFFIs } from "./mixcore-common.js";
2
3
  import { nanoid } from "nanoid";
3
4
 
4
5
  let workers = {};
@@ -56,52 +57,72 @@ function StartWASM(hub, baseURL, org, workspace, vmID, user, token, noOutputViaM
56
57
  })
57
58
  }
58
59
 
59
- function StartWASM2(hub, config) {
60
+ function makeLocalFFIs(mixcore, names) {
61
+ console.log("Mixcore FFIs (local)", names);
62
+ return Object.fromEntries(
63
+ names.map(name => [name, {
64
+ isRaw: true,
65
+ run: (conn, argsBuf) => mixcore.ffiDispatch(conn.call_id, name, argsBuf),
66
+ }]));
67
+ }
68
+
69
+ // See `mix-rs/mixcore/bindings/javascript/mixcore.js` for a description of the
70
+ // values of config.mixcore.
71
+ async function StartWASM2(hub, config) {
60
72
  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;
82
- }
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
- })
73
+ let channel = await hub.newChannel();
74
+ // injected by either index.js or node.js
75
+ let worker = globalThis.GetMachineWASMWorker();
76
+ workers[config.vmID] = worker;
77
+ let localFFIs = config.localFFIs || {};
78
+ if (config.mixcore && config.mixcore.kind == 'mixcore') {
79
+ let {mixcore, enableFFIs, disableFFIs} = config.mixcore;
80
+ let ffiNames = await mixcoreFFIs(mixcore, enableFFIs, disableFFIs);
81
+ let ffis = makeLocalFFIs(mixcore, ffiNames);
82
+ localFFIs = {...localFFIs, ...ffis};
83
+ config.mixcore = null;
84
+ }
85
+ let localFFIkind = {};
86
+ let localFFIfuns = {};
87
+ if (localFFIs) {
88
+ for (const [k, v] of Object.entries(localFFIs)) {
89
+ console.log("local FFI", k, v);
90
+ localFFIfuns[k] = {...v};
91
+ if (v.isRaw && (v.canFail || v.useJsonDecoder)) {
92
+ console.error("A raw, local FFI must neither be failing nor use the JSON decoder: " + k);
93
+ } else {
94
+ localFFIkind[k] = {...v};
95
+ delete localFFIkind[k].run;
96
+ }
97
+ };
98
+ let vm_kind = { isRaw:false, canFail:false, useJsonDecoder:false};
99
+ localFFIkind["$vm_start"] = vm_kind;
100
+ localFFIfuns["$vm_start"] = ffi_vm_start;
101
+ localFFIkind["$vm_stop"] = vm_kind;
102
+ localFFIfuns["$vm_stop"] = ffi_vm_stop;
103
+ }
104
+ let config_msg =
105
+ { "_rmx_type": "msg_vm_configure",
106
+ "baseURL": config.baseURL,
107
+ "org": config.org,
108
+ "workspace": config.workspace,
109
+ "vmID": config.vmID,
110
+ "user": config.user,
111
+ "token": config.token,
112
+ "hub": channel.port,
113
+ "outputViaMQTT": !(config.noOutputViaMQTT),
114
+ "machType": config.machType,
115
+ "debugMask": initialMask,
116
+ "localFFIs": localFFIkind,
117
+ "allowInsecureHttp": globalThis.GROOVEBOX_ALLOW_INSECURE_HTTP,
118
+ "interceptFFI": config.interceptFFI,
119
+ "interceptDynloadFFI": config.interceptDynloadFFI,
120
+ "mixcore": config.mixcore,
121
+ };
122
+ worker.postMessage(config_msg, [ channel.port ]);
123
+ if (localFFIs)
124
+ setupLocalFFIs(hub, config, localFFIfuns); // don't await!
125
+ return worker;
105
126
  }
106
127
 
107
128
  async function ffi_vm_start(conn, args) {
@@ -1,2 +1,2 @@
1
- var GROOVEBOX_BUILD = "2368";
1
+ var GROOVEBOX_BUILD = "2371";
2
2
  export { GROOVEBOX_BUILD }