Skip to content

Reliably determine standard lib dir #7637

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

cknitt
Copy link
Member

@cknitt cknitt commented Jul 12, 2025

To determine the standard library path in a reliable way that works with all package managers / package directory layouts, we need to do it on the JS side, see cli/common/stdlib.js.

We pass the directory to the compiler exe via the environment variable RESCRIPT_STDLIB.

This should fix pnpm issues for good.

@cknitt cknitt changed the title Stdlib dir Reliably determine standard lib dir Jul 12, 2025
Copy link

pkg-pr-new bot commented Jul 12, 2025

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7637

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7637

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7637

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7637

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7637

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7637

commit: 56bb638

@cknitt
Copy link
Member Author

cknitt commented Jul 12, 2025

BTW this approach should also make it easier to move the runtime to @rescript/runtime.

@cknitt
Copy link
Member Author

cknitt commented Jul 12, 2025

@zth This probably needs to be taken into account in the editor extension, too?

BTW this approach should also make it easier to move the runtime to @rescript/runtime.

So maybe the variable should actually be RESCRIPT_RUNTIME or RESCRIPT_RUNTIME_PATH or something like that.

@cknitt cknitt force-pushed the stdlib-dir branch 2 times, most recently from a18e180 to 2daa984 Compare July 12, 2025 13:27
@zth
Copy link
Collaborator

zth commented Jul 12, 2025

@cknitt this means that you have to supply that env variable always to be able to run bsc standalone...?

@cknitt
Copy link
Member Author

cknitt commented Jul 12, 2025

Yes. I mean we could fall back to the previous algorithm if the variable is not set, but we need to be aware that there are cases where this algorithm will not work.

We could also use a command line argument instead of an env var if that's your concern - just more work to implement to get it passed through for both rewatch and bsb.

@nojaf
Copy link
Collaborator

nojaf commented Jul 12, 2025

Would like to have a fallback for this. I frequently run bsc.

@cknitt
Copy link
Member Author

cknitt commented Jul 13, 2025

Note that that would only be an issue when directly running the platform-specific bsc.exe though.

When running bsc via yarn bsc or ./node_modules/bin/bsc, you would be running the node wrapper script that correctly supplies the env var.

@nojaf
Copy link
Collaborator

nojaf commented Jul 13, 2025

Note that that would only be an issue when directly running the platform-specific bsc.exe though.

That includes running dune exec bsc right? If so, could you please add a note which relative path to set from this repository.

@zth
Copy link
Collaborator

zth commented Jul 13, 2025

Would it be possible to make it an optional bsc arg (that uses the old algorithm if not supplied) and bake resolving that into the "compiler args" command? Rewatch could call a node script to get the path. Maybe in the future we could check if this resolution is needed at all by checking what package manager is used.

Bsc is already used standalone in a few places, and I envision it being used even more standalone in the future (Svelte integration, one off scripts, code blocks in docs etc). The overhead of calling a node process for each invocation is non-negligible, and the orchestration for figuring out how to call it shouldn't be too difficult (that's why compiler args is so nice).

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.

3 participants