-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a flake.nix that is capable of building ocaml components of bindings.
- Loading branch information
Showing
12 changed files
with
713 additions
and
51 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
{ | ||
inputs = { | ||
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11-small"; | ||
mina.url = | ||
"git+https://github.com/minaprotocol/mina?submodules=1&ref=georgeee/granular-nix&shallow=1"; | ||
mina.inputs.nixpkgs.follows = "nixpkgs"; | ||
describe-dune.url = "github:o1-labs/describe-dune"; | ||
describe-dune.inputs.nixpkgs.follows = "nixpkgs"; | ||
describe-dune.inputs.flake-utils.follows = "flake-utils"; | ||
dune-nix.url = "github:o1-labs/dune-nix"; | ||
dune-nix.inputs.nixpkgs.follows = "nixpkgs"; | ||
dune-nix.inputs.flake-utils.follows = "flake-utils"; | ||
mina.inputs.dune-nix.follows = "dune-nix"; | ||
mina.inputs.describe-dune.follows = "describe-dune"; | ||
flake-utils.url = "github:numtide/flake-utils"; | ||
}; | ||
outputs = { self, nixpkgs, flake-utils, ... }@inputs: | ||
flake-utils.lib.eachDefaultSystem (system: | ||
let | ||
pkgs = nixpkgs.legacyPackages.${system}; | ||
dune-nix = inputs.dune-nix.lib.${system}; | ||
describe-dune = inputs.describe-dune.defaultPackage.${system}; | ||
dune-description = pkgs.stdenv.mkDerivation { | ||
pname = "dune-description"; | ||
version = "dev"; | ||
src = with pkgs.lib.fileset; | ||
(toSource { | ||
root = ./.; | ||
fileset = unions [ | ||
./ocaml/dune | ||
./ocaml/lib/dune | ||
./ocaml/dune-project | ||
./ocaml/js/dune | ||
]; | ||
}); | ||
phases = [ "unpackPhase" "buildPhase" ]; | ||
buildPhase = '' | ||
${describe-dune}/bin/describe-dune > $out | ||
''; | ||
}; | ||
desc = builtins.fromJSON (builtins.readFile dune-description); | ||
allOcamlDeps_ = pkgs.lib.concatMap (duneSpec: | ||
pkgs.lib.concatMap (unitSpec: unitSpec.deps or [ ]) | ||
(duneSpec.units or [ ])) desc; | ||
allOcamlDeps = | ||
builtins.map (d: builtins.head (pkgs.lib.splitString "." d)) | ||
allOcamlDeps_; | ||
mina = inputs.mina.packages."${system}"; | ||
minaDepsDrv = mina.info.deps; | ||
minaDeps_ = | ||
builtins.intersectAttrs (pkgs.lib.genAttrs allOcamlDeps (_: { })) | ||
mina.info.raw.deps.units; | ||
minaDeps = builtins.attrNames (builtins.foldl' | ||
(acc: pkg: acc // dune-nix.deps.packageDeps minaDeps_ "pkgs" pkg) | ||
minaDeps_ (builtins.attrNames minaDeps_)); | ||
commonOverrides = { | ||
DUNE_PROFILE = "dev"; | ||
buildInputs = [ mina.base-libs ] ++ mina.external-libs | ||
++ pkgs.lib.attrVals minaDeps mina.pkgs; | ||
}; | ||
info = dune-nix.info desc; | ||
allDeps = dune-nix.allDeps info; | ||
noTestSkipping = _: false; | ||
prj_ = dune-nix.outputs' commonOverrides (pkgs.lib.fileset.toSource { | ||
root = ./.; | ||
fileset = ./ocaml; | ||
}) allDeps info noTestSkipping prj; | ||
prj = prj_ // { | ||
pkgs = prj_.pkgs // { | ||
__ocaml-js__ = prj_.pkgs.__ocaml-js__.overrideAttrs { | ||
PREBUILT_KIMCHI_BINDINGS_JS_WEB = | ||
"${mina.files.src-lib-crypto-kimchi_bindings-js-web}/src/lib/crypto/kimchi_bindings/js/web"; | ||
PREBUILT_KIMCHI_BINDINGS_JS_NODE_JS = | ||
"${mina.files.src-lib-crypto-kimchi_bindings-js-node_js}/src/lib/crypto/kimchi_bindings/js/node_js"; | ||
}; | ||
}; | ||
}; | ||
in { | ||
formatter = pkgs.nixfmt; | ||
# TODO build from ./ocaml root, not ./. (after fixing a bug in dune-nix) | ||
packages = { | ||
inherit dune-description; | ||
default = prj.pkgs.o1js_bindings; | ||
js = prj.pkgs.__ocaml-js__; | ||
}; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(lang dune 3.3) | ||
|
||
(package (name o1js_bindings)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
(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 ../../../mina/src/lib/crypto/kimchi_bindings/js/node_js/plonk_wasm.js) (:d2 ../../../mina/src/lib/crypto/kimchi_bindings/js/node_js/plonk_wasm_bg.wasm) ) | ||
(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 ../../../mina/src/lib/crypto/kimchi_bindings/js/web/plonk_wasm.js) (:d2 ../../../mina/src/lib/crypto/kimchi_bindings/js/web/plonk_wasm_bg.wasm) ) | ||
(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) | ||
(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) | ||
(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) | ||
(flags (-g)) | ||
(link_flags | ||
(-noautolink -g)) | ||
(js_of_ocaml | ||
(flags +toplevel.js +dynlink.js --pretty --source-map) | ||
(link_flags --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) | ||
(link_flags (-noautolink)) | ||
(js_of_ocaml | ||
(flags +toplevel.js +dynlink.js --pretty) | ||
(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))) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
(library | ||
(public_name o1js_bindings.lib) | ||
(name o1js_bindings_lib) | ||
(libraries | ||
;; opam libraries ;; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters