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

Unknown module prelude when installing via cargo-install #165

Closed
irevoire opened this issue Sep 20, 2023 · 3 comments · Fixed by #168
Closed

Unknown module prelude when installing via cargo-install #165

irevoire opened this issue Sep 20, 2023 · 3 comments · Fixed by #168

Comments

@irevoire
Copy link
Contributor

Hey!

When installing numbat with cargo install we then can't run anything because it’s missing its prelude:

% numbat 1
error: while resolving imports in
  ┌─ <input>:1:5
  │
1 │ use prelude
  │     ^^^^^^^ Unknown module

Make sure that you have properly set up Numbat's module path.
Interpreter error in Prelude code

Do you think it would be doable to shove all the prelude directly in the binary? 🤔

@sharkdp
Copy link
Owner

sharkdp commented Sep 20, 2023

Thank you for the feedback.

Unfortunately, it's not (yet) possible to install artifacts using cargo install (see e.g. rust-lang/cargo#2729). It is actually possible to ship files with a crate, and I have just updated the code to load the Numbat modules from CARGO_MANIFEST_DIR when using cargo test. We could do the same for cargo run, but that doesn't really solve cargo install problem that you mention here.

Including everything in the binary is definitely possible. This is what we do for the WASM version, albeit in a very hacky way for the moment. But this mechanism could certainly be improved with a custom build.rs file. The question is: is this what we want? My original idea was to have the "Numbat standard library" available as files on the users machine, for easy inspection, extension, and potentially even modification.

We could think about using a builtin version of the prelude as a fallback, if nothing else is available. But I'm not sure if that is a good idea. The prelude is structured into multiple files. If only some of them would be available (e.g. leftover from a previous install of Numbat), we would fall through to the builtin files for some of the modules, possible creating a lot of confusion. But I guess that's maybe more of a general problem.

I'm happy for any suggestions!

For now, I clarified the instructions here: https://numbat.dev/doc/cli-installation.html#from-source

@irevoire
Copy link
Contributor Author

irevoire commented Sep 21, 2023

Including everything in the binary is definitely possible. This is what we do for the WASM version, albeit in a very hacky way for the moment.

Yeah tbh I was expecting something similar to what you did for the wasm, or using a crate to hide the « hacky stuff » (is there really any other way to do it?)

The question is: is this what we want? My

Well, I’m not a maintainor or anything, just someone who used a lot insect.sh and was happy to discover that you wrote a new version running on rust.
So, obviously, you get to choose how you want to see the project evolve in the end 😅
But, as a dumb user, what I can say is that I was happy to share with my colleagues and friends that we finally got a cli version that’s easy to install (we're all doing rust). And I find the installation a bit « complex » with the prelude to import somewhere else (basically, you need to read the doc vs a simple install) and I still don't get how to make it work on macOS because it just ignore the ~/.config/numbat 🥺

My original idea was to have the "Numbat standard library" available as files on the user's machine, for easy inspection, extension, and potentially even modification.

Also, about that, I’m wondering what is the best approach. If everyone copy-paste the lib in their local dir, then there is a good chance that they never update it and thus get an outdated stdlib.
In helix, they have a similar problem, and instead of recommending you to copy/paste their runtime directory, IIRC they tell you to symlink it to their repo and git pull it when you want to update the editor.

Thanks for the awesome project, now that a rust version exists I might contribute to it 🔥

sharkdp added a commit that referenced this issue Sep 21, 2023
This changeset adds a fixed version of the Numbat standard library
(`prelude`) to the binary itself. This way, the installation procedure
for the typical user is greatly simplified. They just need one
executable.

Customization is still possible, as described here:
https://numbat.dev/doc/cli-customization.html

closes #165
sharkdp added a commit that referenced this issue Sep 21, 2023
This changeset adds a fixed version of the Numbat standard library
(`prelude`) to the binary itself. This way, the installation procedure
for the typical user is greatly simplified. They just need one
executable.

Customization is still possible, as described here:
https://numbat.dev/doc/cli-customization.html

closes #165
@sharkdp
Copy link
Owner

sharkdp commented Sep 21, 2023

Thanks for being insistent. This should now be fixed, and I agree that the situation for users is much better. And the situation for developers is not worse (it's slightly more complicated to understand what's going on though).

You should now be able to do cargo install numbat-cli.

or using a crate to hide the « hacky stuff »

Oh, thank you for mentioning that! This worked out nicely. Also for the wasm version.

and I still don't get how to make it work on macOS because it just ignore the ~/.config/numbat 🥺

I documented it here: https://numbat.dev/doc/cli-customization.html#config-path — it's not that relevant anymore, since modules are now inside the binary. But it would actually be good to hear if that folder works for init.nbt-customization. And if Numbat works on macOS at all 😄.

Also, about that, I’m wondering what is the best approach. If everyone copy-paste the lib in their local dir, then there is a good chance that they never update it and thus get an outdated stdlib.

👍 I have now added instructions for developers in the README. And clarified the documentation here for users, so that there shouldn't be any problems, unless someone starts to actively modify the prelude.

Thanks for the awesome project, now that a rust version exists I might contribute to it 🔥

Thank you very much for the feedback. Seeing what you work on (professionally and in your personal projects) you would definitely be more than qualified to work on the Numbat compiler/interpreter! In fact, having the possibility to attract contributors was one of the main factors to rewrite Numbat in Rust. The PureScript community was just too small for that.

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 a pull request may close this issue.

2 participants