Skip to content

Conversation

@bleepbloopsify
Copy link
Contributor

No description provided.

@bleepbloopsify bleepbloopsify requested review from a team as code owners October 21, 2025 20:25
@bleepbloopsify bleepbloopsify requested review from 45930 and querolita and removed request for a team October 21, 2025 20:25
@@ -0,0 +1,3 @@
const native = require('./index.node');
Copy link
Member

Choose a reason for hiding this comment

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

right now we load the wasm module here to inject it into jsoo and load it again for usage in o1js itself here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I see, it needs to be loaded and built in mina

@@ -0,0 +1,3 @@
{
"packageName": "plonk-napi"
Copy link
Member

Choose a reason for hiding this comment

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

So this is so you can import the canary in the unit test as import PlonkNapi from 'plonk-napi';?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes correct

this is because the napi-rs package expects us to export this native module as a standalone npm package, rather than bundled together with our JS code.

I believe its so npm can decide which native bundle to download for the end-user, that way they don't grab every compiled binary for every version. (Also so they don't need rust to build and install an npm package).

I'm not sure what our plan for packaged and release was here, but we might need to do something like this, or we're going to implement the OS/ARCH switching ourselves?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe related to this issue #2415, linking here for future reference

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah perfect

# package.json requires an empty `napi` object in order to read the config JSON
# we specify here
DEBUG="napi:*" napi build \
--manifest-path ./src/mina/src/lib/crypto/proof-systems/plonk-napi/Cargo.toml \
Copy link
Member

Choose a reason for hiding this comment

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

So should this replace

cargo build \
    --manifest-path "${PLONK_NAPI_ROOT}/Cargo.toml" \
    --release

in https://github.com/MinaProtocol/mina/blob/d4ff2e968c9b3239e99f9c414afe2a24ac855a1d/src/lib/crypto/kimchi_bindings/js/native/build.sh#L12-L14
?

I suppose the napi cli takes care of the different extensions for the dynamic library (depending on OS) and renames it to .node without needing us to do it manually?

Copy link
Contributor Author

@bleepbloopsify bleepbloopsify Oct 22, 2025

Choose a reason for hiding this comment

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

Yes correct.

We can also have it setup individual npm packages for us by specifying output locations and architectures (since I believe rust supports cross-compilation -- could also use docker/buildkit here)

It won't change the import paths, and as long as we have the js side exposed, everyone should be happy here

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's a good idea, having separate folders for different architectures.

Regarding the replacement, then feel free to update the build.sh script so it won't build the dynamic library twice once we go for this approach.

@bleepbloopsify
Copy link
Contributor Author

Did several more inches of work here:
generating the platform + the header .js file with napi allows us to import the proper symbols now (but no default export, so YMMV, lol)

I'm opting to leave the current loading for wasm + napi AS-IS in the kimchi_stubs, this is meant so we can import the native module and run it locally in o1js (which I think still has value).

The JSOO process to compile the native plonk_wasm.js file requires that its a static JS file locally so that dune can pick it up and bundle everything together.

This process will allow us to load it in later in o1js, and access the methods easier, and also break up the native bundle properly.

I hope I'm not jumping the gun here, but this is probably the right way to continue, since npm is how we will distribute the appropriate native binaries, supposedly.

I'm OK to leave this as draft for now, since we also have a unit-test in gate-vector that seems to work just fine. On the other hand, this tests our type generation, so it might be even more important to get in

@bleepbloopsify
Copy link
Contributor Author

request: decision

  1. close this in favor of only using the rust side of napi-rs (and not napi-rs/cli -- no generating types)
  2. keep this and flesh it out in favor of having both this and the build.sh build our bundle for now, to ensure that both typegen works and the native module separation works

@Trivo25 @querolita

@bleepbloopsify
Copy link
Contributor Author

closing this because #2596 does this but way better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants