neon-bindings / neon

Rust bindings for writing safe and fast native Node.js modules.
https://www.neon-bindings.com/
Apache License 2.0
7.98k stars 282 forks source link

Neon fails when having a main.rs file #1040

Closed paviro closed 3 months ago

paviro commented 3 months ago

Hi, My project also builds a CLI tool from main.rs it seems like as soon as a main.rs is present neon fails with

> neon dist < cargo.log

error: No artifacts were generated for crate

Moving it to main_.rs and then back to main.rs when building with neon works.

Best, Paul

kjvalencik commented 3 months ago

I believe when a crate is both a lib and a bin cargo defaults to building the bin. Can you try adding adding --lib to the build command?

cargo build --lib
paviro commented 3 months ago

Sadly this does not help. But also without it cargo does build both the bin and the lib.

kjvalencik commented 3 months ago

@dherman This might be a bug in the new CLI.

@paviro As a workaround you can make a wrapper crate for the Neon lib that re-exports everything. It will require making the project a workspace.

paviro commented 3 months ago

My workaround right now is:

cd src && mv main.rs main_.rs && cd ..
npm run build
cd src && mv main_.rs main.rs && cd ..

Looks ridiculous but works for my case. Thank you for the additional hints though!

kjvalencik commented 3 months ago

I'm glad you have a workaround! If you have a second to test cargo-cp-artifact to see if it works, that will help narrow down if the issue was introduced in the new CLI. Thanks!

paviro commented 3 months ago

I am quite new to rust and neon so I am not sure what exactly to test. Could you give me a hint?

dherman commented 3 months ago

I can reproduce too! I'll get this fixed asap.

dherman commented 3 months ago

Found the culprit. I'll publish a fix soon!

dherman commented 3 months ago

@paviro What version of @neon-rs/cli do you have in your package.json? I've published a new version that fixes the issue, and it should work to just update to 0.1.69. But let me know if you have trouble upgrading and I'll be happy to help.

dherman commented 3 months ago

(Reopening for now just to make sure it actually works for @paviro.)

paviro commented 3 months ago

It works, thank you for the quick fix! And for being so lovely to reopen the issue until I confirmed, made me smile!

tsingwong commented 3 months ago

thanks. update the newest version help me fix the problem.