isorun 0.1.0.pre-x86_64-darwin

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.
@@ -0,0 +1,327 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 3
4
+
5
+ [[package]]
6
+ name = "aho-corasick"
7
+ version = "0.7.19"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e"
10
+ dependencies = [
11
+ "memchr",
12
+ ]
13
+
14
+ [[package]]
15
+ name = "bindgen"
16
+ version = "0.60.1"
17
+ source = "registry+https://github.com/rust-lang/crates.io-index"
18
+ checksum = "062dddbc1ba4aca46de6338e2bf87771414c335f7b2f2036e8f3e9befebf88e6"
19
+ dependencies = [
20
+ "bitflags",
21
+ "cexpr",
22
+ "clang-sys",
23
+ "lazy_static",
24
+ "lazycell",
25
+ "peeking_take_while",
26
+ "proc-macro2",
27
+ "quote",
28
+ "regex",
29
+ "rustc-hash",
30
+ "shlex",
31
+ ]
32
+
33
+ [[package]]
34
+ name = "bitflags"
35
+ version = "1.3.2"
36
+ source = "registry+https://github.com/rust-lang/crates.io-index"
37
+ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
38
+
39
+ [[package]]
40
+ name = "cexpr"
41
+ version = "0.6.0"
42
+ source = "registry+https://github.com/rust-lang/crates.io-index"
43
+ checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
44
+ dependencies = [
45
+ "nom",
46
+ ]
47
+
48
+ [[package]]
49
+ name = "cfg-if"
50
+ version = "1.0.0"
51
+ source = "registry+https://github.com/rust-lang/crates.io-index"
52
+ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
53
+
54
+ [[package]]
55
+ name = "clang-sys"
56
+ version = "1.4.0"
57
+ source = "registry+https://github.com/rust-lang/crates.io-index"
58
+ checksum = "fa2e27ae6ab525c3d369ded447057bca5438d86dc3a68f6faafb8269ba82ebf3"
59
+ dependencies = [
60
+ "glob",
61
+ "libc",
62
+ "libloading",
63
+ ]
64
+
65
+ [[package]]
66
+ name = "darling"
67
+ version = "0.13.4"
68
+ source = "registry+https://github.com/rust-lang/crates.io-index"
69
+ checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c"
70
+ dependencies = [
71
+ "darling_core",
72
+ "darling_macro",
73
+ ]
74
+
75
+ [[package]]
76
+ name = "darling_core"
77
+ version = "0.13.4"
78
+ source = "registry+https://github.com/rust-lang/crates.io-index"
79
+ checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610"
80
+ dependencies = [
81
+ "fnv",
82
+ "ident_case",
83
+ "proc-macro2",
84
+ "quote",
85
+ "strsim",
86
+ "syn",
87
+ ]
88
+
89
+ [[package]]
90
+ name = "darling_macro"
91
+ version = "0.13.4"
92
+ source = "registry+https://github.com/rust-lang/crates.io-index"
93
+ checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835"
94
+ dependencies = [
95
+ "darling_core",
96
+ "quote",
97
+ "syn",
98
+ ]
99
+
100
+ [[package]]
101
+ name = "fnv"
102
+ version = "1.0.7"
103
+ source = "registry+https://github.com/rust-lang/crates.io-index"
104
+ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
105
+
106
+ [[package]]
107
+ name = "glob"
108
+ version = "0.3.0"
109
+ source = "registry+https://github.com/rust-lang/crates.io-index"
110
+ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
111
+
112
+ [[package]]
113
+ name = "ident_case"
114
+ version = "1.0.1"
115
+ source = "registry+https://github.com/rust-lang/crates.io-index"
116
+ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
117
+
118
+ [[package]]
119
+ name = "isorun"
120
+ version = "0.1.0"
121
+ dependencies = [
122
+ "magnus",
123
+ ]
124
+
125
+ [[package]]
126
+ name = "lazy_static"
127
+ version = "1.4.0"
128
+ source = "registry+https://github.com/rust-lang/crates.io-index"
129
+ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
130
+
131
+ [[package]]
132
+ name = "lazycell"
133
+ version = "1.3.0"
134
+ source = "registry+https://github.com/rust-lang/crates.io-index"
135
+ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
136
+
137
+ [[package]]
138
+ name = "libc"
139
+ version = "0.2.135"
140
+ source = "registry+https://github.com/rust-lang/crates.io-index"
141
+ checksum = "68783febc7782c6c5cb401fbda4de5a9898be1762314da0bb2c10ced61f18b0c"
142
+
143
+ [[package]]
144
+ name = "libloading"
145
+ version = "0.7.3"
146
+ source = "registry+https://github.com/rust-lang/crates.io-index"
147
+ checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd"
148
+ dependencies = [
149
+ "cfg-if",
150
+ "winapi",
151
+ ]
152
+
153
+ [[package]]
154
+ name = "linkify"
155
+ version = "0.9.0"
156
+ source = "registry+https://github.com/rust-lang/crates.io-index"
157
+ checksum = "96dd5884008358112bc66093362197c7248ece00d46624e2cf71e50029f8cff5"
158
+ dependencies = [
159
+ "memchr",
160
+ ]
161
+
162
+ [[package]]
163
+ name = "magnus"
164
+ version = "0.3.2"
165
+ source = "git+https://github.com/matsadler/magnus?rev=cc852bfa31992d882d42509b1165eb5f67f9dc2c#cc852bfa31992d882d42509b1165eb5f67f9dc2c"
166
+ dependencies = [
167
+ "magnus-macros",
168
+ "rb-sys",
169
+ ]
170
+
171
+ [[package]]
172
+ name = "magnus-macros"
173
+ version = "0.1.0"
174
+ source = "git+https://github.com/matsadler/magnus?rev=cc852bfa31992d882d42509b1165eb5f67f9dc2c#cc852bfa31992d882d42509b1165eb5f67f9dc2c"
175
+ dependencies = [
176
+ "darling",
177
+ "proc-macro2",
178
+ "quote",
179
+ "syn",
180
+ ]
181
+
182
+ [[package]]
183
+ name = "memchr"
184
+ version = "2.5.0"
185
+ source = "registry+https://github.com/rust-lang/crates.io-index"
186
+ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
187
+
188
+ [[package]]
189
+ name = "minimal-lexical"
190
+ version = "0.2.1"
191
+ source = "registry+https://github.com/rust-lang/crates.io-index"
192
+ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
193
+
194
+ [[package]]
195
+ name = "nom"
196
+ version = "7.1.1"
197
+ source = "registry+https://github.com/rust-lang/crates.io-index"
198
+ checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36"
199
+ dependencies = [
200
+ "memchr",
201
+ "minimal-lexical",
202
+ ]
203
+
204
+ [[package]]
205
+ name = "peeking_take_while"
206
+ version = "0.1.2"
207
+ source = "registry+https://github.com/rust-lang/crates.io-index"
208
+ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
209
+
210
+ [[package]]
211
+ name = "proc-macro2"
212
+ version = "1.0.47"
213
+ source = "registry+https://github.com/rust-lang/crates.io-index"
214
+ checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
215
+ dependencies = [
216
+ "unicode-ident",
217
+ ]
218
+
219
+ [[package]]
220
+ name = "quote"
221
+ version = "1.0.21"
222
+ source = "registry+https://github.com/rust-lang/crates.io-index"
223
+ checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
224
+ dependencies = [
225
+ "proc-macro2",
226
+ ]
227
+
228
+ [[package]]
229
+ name = "rb-sys"
230
+ version = "0.9.31"
231
+ source = "registry+https://github.com/rust-lang/crates.io-index"
232
+ checksum = "bfc41b26ea88da6100f538d31467941e41ab0c002999d687315e67d3b371b796"
233
+ dependencies = [
234
+ "bindgen",
235
+ "linkify",
236
+ "rb-sys-build",
237
+ ]
238
+
239
+ [[package]]
240
+ name = "rb-sys-build"
241
+ version = "0.9.31"
242
+ source = "registry+https://github.com/rust-lang/crates.io-index"
243
+ checksum = "79be4233eabd2bf9e19eb8116391aeaf4b89b87a7ab38e0ded44de9158006e46"
244
+ dependencies = [
245
+ "regex",
246
+ "shell-words",
247
+ ]
248
+
249
+ [[package]]
250
+ name = "regex"
251
+ version = "1.6.0"
252
+ source = "registry+https://github.com/rust-lang/crates.io-index"
253
+ checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b"
254
+ dependencies = [
255
+ "aho-corasick",
256
+ "memchr",
257
+ "regex-syntax",
258
+ ]
259
+
260
+ [[package]]
261
+ name = "regex-syntax"
262
+ version = "0.6.27"
263
+ source = "registry+https://github.com/rust-lang/crates.io-index"
264
+ checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
265
+
266
+ [[package]]
267
+ name = "rustc-hash"
268
+ version = "1.1.0"
269
+ source = "registry+https://github.com/rust-lang/crates.io-index"
270
+ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
271
+
272
+ [[package]]
273
+ name = "shell-words"
274
+ version = "1.1.0"
275
+ source = "registry+https://github.com/rust-lang/crates.io-index"
276
+ checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
277
+
278
+ [[package]]
279
+ name = "shlex"
280
+ version = "1.1.0"
281
+ source = "registry+https://github.com/rust-lang/crates.io-index"
282
+ checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3"
283
+
284
+ [[package]]
285
+ name = "strsim"
286
+ version = "0.10.0"
287
+ source = "registry+https://github.com/rust-lang/crates.io-index"
288
+ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
289
+
290
+ [[package]]
291
+ name = "syn"
292
+ version = "1.0.102"
293
+ source = "registry+https://github.com/rust-lang/crates.io-index"
294
+ checksum = "3fcd952facd492f9be3ef0d0b7032a6e442ee9b361d4acc2b1d0c4aaa5f613a1"
295
+ dependencies = [
296
+ "proc-macro2",
297
+ "quote",
298
+ "unicode-ident",
299
+ ]
300
+
301
+ [[package]]
302
+ name = "unicode-ident"
303
+ version = "1.0.5"
304
+ source = "registry+https://github.com/rust-lang/crates.io-index"
305
+ checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
306
+
307
+ [[package]]
308
+ name = "winapi"
309
+ version = "0.3.9"
310
+ source = "registry+https://github.com/rust-lang/crates.io-index"
311
+ checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
312
+ dependencies = [
313
+ "winapi-i686-pc-windows-gnu",
314
+ "winapi-x86_64-pc-windows-gnu",
315
+ ]
316
+
317
+ [[package]]
318
+ name = "winapi-i686-pc-windows-gnu"
319
+ version = "0.4.0"
320
+ source = "registry+https://github.com/rust-lang/crates.io-index"
321
+ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
322
+
323
+ [[package]]
324
+ name = "winapi-x86_64-pc-windows-gnu"
325
+ version = "0.4.0"
326
+ source = "registry+https://github.com/rust-lang/crates.io-index"
327
+ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
@@ -0,0 +1,27 @@
1
+ [package]
2
+ name = "isorun"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ authors = ["Hannes Moser <box@hannesmoser.at>"]
6
+ homepage = "https://github.com/eliias/isorun"
7
+ repository = "https://github.com/eliias/isorun"
8
+
9
+ [dependencies]
10
+ deno_console = "0.80.0"
11
+ deno_core = "0.162.0"
12
+ deno_fetch = "0.103.0"
13
+ deno_runtime = "0.88.0"
14
+ deno_url = "0.80.0"
15
+ deno_web = "0.111.0"
16
+ deno_webidl = "0.80.0"
17
+ lazy_static = "1.4.0"
18
+ magnus = { git = "https://github.com/eliias/magnus", rev = "1833ad96919b8891c1b5d62a22f0fc2b94f5961a" } # waiting for release with full rb-sys backend
19
+ tokio = { version = "1.21.1", features = ["full"] }
20
+ v8 = "0.58.0"
21
+
22
+ [dev-dependencies]
23
+ magnus = { git = "https://github.com/eliias/magnus", rev = "1833ad96919b8891c1b5d62a22f0fc2b94f5961a", features = ["embed"] } # waiting for release with full rb-sys backend
24
+
25
+ [lib]
26
+ name = "isorun"
27
+ crate-type = ["cdylib"]
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+ require "rb_sys/mkmf"
5
+
6
+ create_rust_makefile("isorun/isorun")
@@ -0,0 +1,27 @@
1
+ export async function call(options, args, kwargs) {
2
+ const {bundle_path: bundlePath, entrypoint, force_reload: forceReload} = options;
3
+
4
+ // Filter options that should not be passed to JavaScript
5
+ ["bundle_path", "entrypoint", "force_reload", "receiver"].forEach(i => delete options[i]);
6
+
7
+ try {
8
+ let fullBundleUrl = bundlePath
9
+ if (forceReload) {
10
+ fullBundleUrl += `?t=${Date.now()}`
11
+ console.info("[ISORUN] Forced loading bundle");
12
+ }
13
+
14
+ const module = await import(fullBundleUrl);
15
+ const callee = module[entrypoint];
16
+
17
+ // check if callee is actually a function, otherwise just return the member
18
+ // as is
19
+ if (typeof callee === "function") {
20
+ return await callee.call(undefined, ...args, kwargs);
21
+ } else {
22
+ return callee;
23
+ }
24
+ } catch (err) {
25
+ throw new Error(`failed to call "${entrypoint}" in "${bundlePath}" with options: ${JSON.stringify(options, null, " ")}`);
26
+ }
27
+ }
@@ -0,0 +1,9 @@
1
+ use crate::js::worker::WORKER;
2
+ use magnus::block::Proc;
3
+
4
+ pub(crate) fn set_receiver(receiver: Option<Proc>) {
5
+ WORKER.with(|worker| match receiver {
6
+ None => worker.ruby_receiver.replace(None),
7
+ Some(r) => worker.ruby_receiver.replace(Some(r)),
8
+ });
9
+ }
@@ -0,0 +1,46 @@
1
+ use crate::isorun;
2
+ use crate::js::module::Module;
3
+ use crate::js::worker::WORKER;
4
+ use deno_core::JsRealm;
5
+ use magnus::Error;
6
+ use std::cell::RefCell;
7
+ use std::rc::Rc;
8
+
9
+ #[magnus::wrap(class = "Isorun::Context")]
10
+ pub(crate) struct Context(pub(crate) Rc<RefCell<JsRealm>>);
11
+
12
+ /// SAFETY: This is safe because we only access this data when the GVL is held.
13
+ unsafe impl Send for Context {}
14
+
15
+ impl Context {
16
+ pub(crate) fn new() -> Result<Self, Error> {
17
+ WORKER
18
+ .with(|worker| worker.create_realm())
19
+ .map(|realm| Context(Rc::new(RefCell::from(realm))))
20
+ .map_err(|_error| {
21
+ Error::runtime_error("cannot create JavaScript context")
22
+ })
23
+ }
24
+
25
+ pub(crate) fn load(
26
+ &self,
27
+ path: String,
28
+ ) -> Result<isorun::module::Module, Error> {
29
+ let realm = self.0.clone();
30
+
31
+ WORKER
32
+ .with(|worker| {
33
+ worker
34
+ .load_module(path.as_str())
35
+ .map(|id| Module { id, realm })
36
+ })
37
+ .map(|module| isorun::Module(RefCell::from(module)))
38
+ .map_err(|error| {
39
+ Error::runtime_error(format!(
40
+ "cannot load module: `{}`: {}",
41
+ path.as_str(),
42
+ error
43
+ ))
44
+ })
45
+ }
46
+ }
@@ -0,0 +1,60 @@
1
+ use crate::js;
2
+ use crate::js::worker::WORKER;
3
+ use magnus::Error;
4
+ use std::cell::RefCell;
5
+ use std::ops::Deref;
6
+
7
+ #[magnus::wrap(class = "Isorun::Function")]
8
+ pub(crate) struct Function(pub(crate) RefCell<js::module_item::Function>);
9
+
10
+ /// SAFETY: This is safe because we only access this data when the GVL is held.
11
+ unsafe impl Send for Function {}
12
+
13
+ impl Function {
14
+ pub(crate) fn call(
15
+ &self,
16
+ args: &[magnus::Value],
17
+ ) -> Result<magnus::Value, Error> {
18
+ let args = WORKER.with(|worker| {
19
+ let func = self.0.borrow();
20
+ let realm = func.realm.borrow();
21
+ let realm = realm.deref();
22
+
23
+ let mut v8_args = vec![];
24
+ for arg in args {
25
+ let v8_arg = worker.to_v8(realm, *arg).unwrap();
26
+ v8_args.push(v8_arg);
27
+ }
28
+ v8_args
29
+ });
30
+
31
+ self.0.borrow().call(args.as_slice()).map_err(|error| {
32
+ Error::runtime_error(format!("cannot call function: {}", error))
33
+ })
34
+ }
35
+
36
+ pub(crate) fn call_without_gvl(
37
+ &self,
38
+ args: &[magnus::Value],
39
+ ) -> Result<magnus::Value, Error> {
40
+ let args = WORKER.with(|worker| {
41
+ let func = self.0.borrow();
42
+ let realm = func.realm.borrow();
43
+ let realm = realm.deref();
44
+
45
+ let mut v8_args = vec![];
46
+ for arg in args {
47
+ let v8_arg = worker.to_v8(realm, *arg).unwrap();
48
+ v8_args.push(v8_arg);
49
+ }
50
+ v8_args
51
+ });
52
+
53
+ self.0
54
+ .borrow()
55
+ .call_without_gvl(args.as_slice())
56
+ .map_err(|error| {
57
+ Error::runtime_error(format!("cannot call function: {}", error))
58
+ })
59
+ }
60
+ }
@@ -0,0 +1,7 @@
1
+ pub(crate) mod configure;
2
+ pub(crate) mod context;
3
+ pub(crate) mod function;
4
+ pub(crate) mod module;
5
+ pub(crate) mod utils;
6
+
7
+ pub use crate::*;
@@ -0,0 +1,33 @@
1
+ use crate::isorun::function::Function;
2
+ use crate::js;
3
+ use magnus::Error;
4
+ use std::cell::RefCell;
5
+
6
+ #[magnus::wrap(class = "Isorun::Module")]
7
+ pub(crate) struct Module(pub(crate) RefCell<js::module::Module>);
8
+
9
+ /// SAFETY: This is safe because we only access this data when the GVL is held.
10
+ unsafe impl Send for Module {}
11
+
12
+ impl Module {
13
+ pub(crate) fn id(&self) -> String {
14
+ self.0.borrow().id.to_string()
15
+ }
16
+
17
+ pub(crate) fn import(
18
+ &self,
19
+ export_name: String,
20
+ ) -> Result<magnus::Value, Error> {
21
+ let module = self.0.borrow();
22
+ let module_item = module
23
+ .import(export_name.as_str())
24
+ .map_err(|error| Error::runtime_error(format!("{}", error)))?;
25
+
26
+ match module_item {
27
+ js::module_item::ModuleItem::Value(v) => Ok(v.to_ruby().unwrap()),
28
+ js::module_item::ModuleItem::Function(f) => {
29
+ Ok(magnus::Value::from(Function(RefCell::from(f))))
30
+ }
31
+ }
32
+ }
33
+ }