Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
(package (name node_error_service))
(package (name node_status_service))
(package (name non_zero_curve_point))
(package (name o1js_bindings))
(package (name o1trace))
(package (name o1trace_webkit_event))
(package (name one_or_two))
Expand Down
2 changes: 2 additions & 0 deletions src/lib/o1js_bindings/artifacts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
44 changes: 44 additions & 0 deletions src/lib/o1js_bindings/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
(executable
(instrumentation
(backend bisect_ppx))
(libraries fields_derivers.zkapps mina_base yojson)
(link_flags (-linkall))
(modes native)
(modules o1js_types)
(name o1js_types)
(package o1js_bindings)
(preprocess
(pps ppx_version))
(public_name o1js-types))

(rule
(targets jsLayout.json)
(action
(with-stdout-to
jsLayout.json
(run %{exe:./o1js_types.exe}))))

(executable
(instrumentation
(backend bisect_ppx))
(libraries
base
base58_check
core_kernel
hash_prefixes
mina_base
mina_signature_kind
pickles
protocol_version
random_oracle
random_oracle.permutation.ocaml
sponge
yojson)
(link_flags (-linkall))
(name o1js_constants)
(modes native)
(modules o1js_constants)
(package o1js_bindings)
(preprocess
(pps ppx_version))
(public_name o1js-constants))
107 changes: 107 additions & 0 deletions src/lib/o1js_bindings/jsoo_exports/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
(env
(_
(js_of_ocaml
(compilation_mode whole_program))))

(rule
(enabled_if
(= %{env:PREBUILT_KIMCHI_BINDINGS_JS_NODE_JS=n} n))
(targets node_js_plonk_wasm.js node_js_plonk_wasm_bg.wasm)
(deps
(:d1 ../../crypto/kimchi_bindings/js/node_js/plonk_wasm.js)
(:d2 ../../crypto/kimchi_bindings/js/node_js/plonk_wasm_bg.wasm))
(mode
(promote
(into ../artifacts)))
(action
(progn
(run cp %{d1} node_js_plonk_wasm.js)
(run cp %{d2} node_js_plonk_wasm_bg.wasm))))

(rule
(enabled_if
(= %{env:PREBUILT_KIMCHI_BINDINGS_JS_WEB=n} n))
(targets web_plonk_wasm.js web_plonk_wasm_bg.wasm)
(deps
(:d1 ../../crypto/kimchi_bindings/js/web/plonk_wasm.js)
(:d2 ../../crypto/kimchi_bindings/js/web/plonk_wasm_bg.wasm))
(mode
(promote
(into ../artifacts)))
(action
(progn
(run cp %{d1} web_plonk_wasm.js)
(run cp %{d2} web_plonk_wasm_bg.wasm))))

(rule
(enabled_if
(<> %{env:PREBUILT_KIMCHI_BINDINGS_JS_NODE_JS=n} n))
(targets node_js_plonk_wasm.js node_js_plonk_wasm_bg.wasm)
(mode
(promote
(into ../artifacts)))
(action
(progn
(run
cp
%{env:PREBUILT_KIMCHI_BINDINGS_JS_NODE_JS=n}/plonk_wasm.js
node_js_plonk_wasm.js)
(run
cp
%{env:PREBUILT_KIMCHI_BINDINGS_JS_NODE_JS=n}/plonk_wasm_bg.wasm
node_js_plonk_wasm_bg.wasm))))

(rule
(enabled_if
(<> %{env:PREBUILT_KIMCHI_BINDINGS_JS_WEB=n} n))
(targets web_plonk_wasm.js web_plonk_wasm_bg.wasm)
(mode
(promote
(into ../artifacts)))
(action
(progn
(run
cp
%{env:PREBUILT_KIMCHI_BINDINGS_JS_WEB=n}/plonk_wasm.js
web_plonk_wasm.js)
(run
cp
%{env:PREBUILT_KIMCHI_BINDINGS_JS_WEB=n}/plonk_wasm_bg.wasm
web_plonk_wasm_bg.wasm))))

(executable
(name o1js_node)
(modules o1js_node)
(modes js)
(promote
(into ../artifacts))
(link_flags :standard -noautolink -g)
(js_of_ocaml
(flags :standard +toplevel.js +dynlink.js --source-map)
(link_flags :standard --source-map)
(javascript_files overrides.js))
(libraries o1js_bindings.lib bindings_js.node_backend)
(link_deps node_js_plonk_wasm.js node_js_plonk_wasm_bg.wasm)
(instrumentation
(backend bisect_ppx))
(forbidden_libraries async core re2 ctypes)
(preprocess
(pps ppx_version js_of_ocaml-ppx)))

(executable
(name o1js_web)
(modules o1js_web)
(modes js)
(promote
(into ../artifacts))
(link_flags :standard -noautolink)
(js_of_ocaml
(flags :standard +toplevel.js +dynlink.js)
(javascript_files overrides.js))
(libraries o1js_bindings.lib bindings_js.web_backend)
(link_deps web_plonk_wasm.js web_plonk_wasm_bg.wasm)
(instrumentation
(backend bisect_ppx))
(forbidden_libraries async core re2 ctypes)
(preprocess
(pps ppx_version js_of_ocaml-ppx)))
3 changes: 3 additions & 0 deletions src/lib/o1js_bindings/jsoo_exports/o1js_node.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let () = O1js_bindings_lib.export_global ()

let () = O1js_bindings_lib.export ()
1 change: 1 addition & 0 deletions src/lib/o1js_bindings/jsoo_exports/o1js_web.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = O1js_bindings_lib.export_global ()
75 changes: 75 additions & 0 deletions src/lib/o1js_bindings/jsoo_exports/overrides.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* global caml_named_value, caml_global_data, caml_string_of_jsstring
*/

//Provides: caml_wrap_exception const (const)
//Requires: caml_global_data,caml_string_of_jsstring,caml_named_value
//Requires: caml_return_exn_constant
function caml_wrap_exception(e) {
if (e instanceof Array) return e;
if (e instanceof globalThis.Error && caml_named_value('jsError'))
return [0, caml_named_value('jsError'), e];
//fallback: wrapped in Failure
return [0, caml_global_data.Failure, caml_string_of_jsstring(String(e))];
}

//Provides: caml_raise_with_string (const, const)
function caml_raise_with_string(tag, msg) {
throw globalThis.Error(msg.c);
}

//Provides: custom_reraise_exn
function custom_reraise_exn(exn, fallbackMessage) {
// this handles the common case of a JS Error reraised by OCaml
// in that case, the error will first be wrapped in OCaml with "caml_wrap_exception"
// (defined in js_of_ocaml-compiler / jslib.js)
// which results in [0, caml_named_value("jsError"), err]
var err = exn[2];
if (err instanceof globalThis.Error) {
throw err;
} else {
throw Error(fallbackMessage);
}
}

/**
* This overrides the handler for uncaught exceptions in js_of_ocaml,
* fixing the flaw that by default, no actual `Error`s are thrown,
* but other objects (arrays) which are missing an error trace.
* This override should make it much easier to find the source of an error.
*/
//Provides: caml_fatal_uncaught_exception
function caml_fatal_uncaught_exception(err) {
// first, we search for an actual error inside `err`,
// since this is the best thing to throw
function throw_errors(err) {
if (err instanceof Error) throw err;
else if (Array.isArray(err)) {
err.forEach(throw_errors);
}
}
throw_errors(err);
// if this didn't throw an error, let's log whatever we got
console.dir(err, { depth: 20 });
// now, try to collect all strings in the error and throw that
function collect_strings(err, acc) {
var str = undefined;
if (typeof err === 'string') {
str = err;
} else if (err && err.constructor && err.constructor.name === 'MlBytes') {
str = err.c;
} else if (Array.isArray(err)) {
err.forEach(function (e) {
collect_strings(e, acc);
});
}
if (!str) return acc.string;
if (acc.string === undefined) acc.string = str;
else acc.string = acc.string + '\n' + str;
return acc.string;
}
var str = collect_strings(err, {});
if (str !== undefined) throw globalThis.Error(str);
// otherwise, just throw an unhelpful error
console.dir(err, { depth: 10 });
throw globalThis.Error('Unknown error thrown from OCaml');
}
Loading