Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Nix] package snarkyjs, client_sdk, mina-signer #11092

Merged
merged 19 commits into from
Jun 15, 2022
Merged

Conversation

yorickvP
Copy link
Collaborator

@yorickvP yorickvP commented May 25, 2022

The Nix code was still missing builds for client_sdk, snarkyjs and mina-signer. This PR:

  • Enables the Rust wasm builds (also needed a Cargo.lock)
  • Fixes the build for client_sdk_bindings
  • Adds a build for mina-signer (was missing jest as a dependency)
  • Adds a build for snarkyjs

Things left to do:

@yorickvP yorickvP added the Tweag label May 25, 2022
@yorickvP yorickvP requested a review from balsoft May 25, 2022 18:42
Comment on lines +159 to +196
sed -i 's/function failwith(s){throw \[0,Failure,s\]/function failwith(s){throw joo_global_object.Error(s.c)/' "$BINDINGS_PATH"/snarky_js_node.bc.js
sed -i 's/function invalid_arg(s){throw \[0,Invalid_argument,s\]/function invalid_arg(s){throw joo_global_object.Error(s.c)/' "$BINDINGS_PATH"/snarky_js_node.bc.js
sed -i 's/return \[0,Exn,t\]/return joo_global_object.Error(t.c)/' "$BINDINGS_PATH"/snarky_js_node.bc.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eww
But I see why it's needed

@balsoft balsoft force-pushed the nix-packaging-develop branch 2 times, most recently from c282c8f to b082f0e Compare May 27, 2022 09:09
Base automatically changed from nix-packaging-develop to develop May 27, 2022 12:48
@yorickvP yorickvP self-assigned this May 30, 2022
@mitschabaude
Copy link
Contributor

mitschabaude commented May 30, 2022

Move snarkyjs tests into snarkyjs repo? @mitschabaude ?

No, I'd prefer if they stay where they are

  • the ones in /tests depend only on the Mina code and are run as unit tests in Mina CI, so make more sense in that repo
  • the ones in /test_module are for integration / unit tests in Mina CI; also depend on a local version of mina-signer which shouldn't be in snarkyjs (snarkyjs is supposed to work as a self-contained repo)

Make snarky-run work with this package

This is not important, that script is not documented to the outside world, only used for snarkyjs development right now

@yorickvP yorickvP force-pushed the yorickvp/nix-rust-wasm branch 2 times, most recently from a9830f0 to 68014c1 Compare June 1, 2022 15:04
@yorickvP yorickvP force-pushed the yorickvp/nix-rust-wasm branch from b8844d8 to 2132add Compare June 3, 2022 11:48
@yorickvP yorickvP force-pushed the yorickvp/nix-rust-wasm branch 4 times, most recently from 4338c49 to 530eae6 Compare June 9, 2022 13:31
@yorickvP yorickvP marked this pull request as ready for review June 9, 2022 13:34
@yorickvP yorickvP requested review from a team and mitschabaude as code owners June 9, 2022 13:34
@yorickvP yorickvP added the ci-build-me Add this label to trigger a circle+buildkite build for this branch label Jun 9, 2022
@yorickvP yorickvP requested a review from mrmr1993 June 9, 2022 13:35
@yorickvP yorickvP force-pushed the yorickvp/nix-rust-wasm branch 2 times, most recently from 724e652 to 0b0c5fe Compare June 9, 2022 14:45
@yorickvP yorickvP force-pushed the yorickvp/nix-rust-wasm branch from dfbe8cf to 8501943 Compare June 9, 2022 15:01
Copy link
Member

@mrmr1993 mrmr1993 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really a fan of this. Can you make a version that doesn't change what dune is doing?

packages.snarky_js = nix-npm-buildPackage.buildNpmPackage {
src = ./src/lib/snarky_js_bindings/snarkyjs;
preBuild = ''
BINDINGS_PATH=./dist/server/node_bindings
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a script that we can run to do this? Or does it need to be inlined here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's currently inside ./scripts/build-snarkyjs-node.sh, but it should probably be somewhere else, possibly on the ocaml side.

(target dune-build-root)
(deps (sandbox none))
(action
(system "echo -n $(realpath %{workspace_root}/..) > %{target}")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you revert this? The workspace root isn't necessarily at the top of the project if its vendored.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to set the cargo target path explicitly (to _build/cargo_...), instead of letting cargo find one, because, depending on the build order, it sometimes finds _build/default/src/lib/crypto/target, if that workspace Cargo.toml file happens to be copied over. Also because cargo metadata does some checks that depend on the entire workspace.

Maybe %{project_root} could be the way to go?

@yorickvP yorickvP force-pushed the yorickvp/nix-rust-wasm branch from fcb1131 to 0e86061 Compare June 10, 2022 16:05
@yorickvP
Copy link
Collaborator Author

@mrmr1993 I'd like to talk about this some more. I basically need a Cargo.lock file for the src/lib/crypto libs.
The current strategy has.. a problem, in that the cargo target path is sometimes . and sometimes ./_build/default/src/lib/crypto/target, depending on if dune copies over src/lib/crypto/Cargo.toml.
So I'd need about 3 cargo lockfiles with the current codebase, and I'd need to keep them in sync. Another thing we can do with the lockfile is switch to a cargo git dep instead of a git submodule :).

Would you be open to discuss ways to improve this situation?

yorickvP and others added 19 commits June 14, 2022 12:16
Previously, we were letting cargo autodetect a cargo directory,
which was dependent on the workspace. dune would not copy
src/lib/crypto/Cargo.toml, and so cargo would find the
mina root workspace (/Cargo.toml) from the source directory.

However, we shouldn't rely on dune not copying this file,
or use the target directory from this workspace.

Now, we calculate the path _build/cargo_kimchi_{wasm,bindgen,stubs},
and provide it to cargo via $CARGO_TARGET_DIR. This simplifies some
code and allows for more determinism.
Tested using dune build --sandbox=symlinks
@yorickvP yorickvP force-pushed the yorickvp/nix-rust-wasm branch from 0e86061 to e00ff8d Compare June 14, 2022 10:17
@yorickvP yorickvP merged commit 2e2e1d3 into develop Jun 15, 2022
@yorickvP yorickvP deleted the yorickvp/nix-rust-wasm branch June 15, 2022 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-build-me Add this label to trigger a circle+buildkite build for this branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Nix] Frontend packaging
4 participants