Skip to content

Bazel: Pass nodejs binary path as an environment variable. - #1518

Merged
walkingeyerobot merged 3 commits into
emscripten-core:mainfrom
cburchert:nodejs_path
Feb 12, 2025
Merged

walkingeyerobot merged 3 commits into
emscripten-core:mainfrom
cburchert:nodejs_path

Conversation

@cburchert

@cburchert cburchert commented Feb 2, 2025 •

Copy link
Copy Markdown
Contributor

The current way to derive the binary path relies on a specific name for the nodejs repository. This blocks migrating to bzlmod, as bzlmod prefixes repository directories with the module name that created them. By asking bazel for the path instead we always get the correct path, so we can work with both bzlmod and WORKSPACE based dependencies at the same time.

The repository @nodejs, used in the build label, refers to nodejs for the host platform and is generated by the following macro (wasn't too obvious to me):
https://github.com/bazel-contrib/rules_nodejs/blob/d19d695275c5fd0d5224ddc7826d9f7f4b8186df/nodejs/repositories.bzl#L452

This is some work towards solving #1509.

The current way to derive the binary path relies on a specific name for
the nodejs repository. This blocks migrating to bzlmod, as it generates
repository names based on which module is creating them, resulting in a
different name.

By letting Bazel tell us the correct name and passing it in, we can keep
this working with both old and new name, independent of using bzlmod.
@cburchert cburchert changed the title Bazel: Pass nodejs binary path as an environment variable. Bazel: Pass nodejs binary path as an environment variable. #1509 Feb 2, 2025
@cburchert cburchert changed the title Bazel: Pass nodejs binary path as an environment variable. #1509 Bazel: Pass nodejs binary path as an environment variable. Feb 2, 2025
),
env_entry(
key = "NODE_JS_PATH",
value = nodejs_path,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If this is is an absolute path (or can be) then you can just pass EM_NODE_JS and completely remove the line from the config file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I looked a bit more into this, but couldn't find a way to do this much better. When this code here is executed, then the absolute path is not known yet, as we aren't yet executing actions, which run in sandboxes. I looked for some variable that will get substituted later, but couldn't find any.

There is env.sh, which is called before we end up in the config and it could do the conversion to an absolute path, but that doesn't really save any work. If we do it in env.sh, it does not work on Windows, which has its own env.bat, so the conversion forks into two places.

Can't test on Windows, so let's see what CI says.
@cburchert

Copy link
Copy Markdown
Contributor Author

Ok this seems to have fixed the Windows issue. I don't fully understand why this broke the closure compiler call and it wasn't broken before, but I guess having the same workaround on all platforms at least is better.

@cburchert
cburchert marked this pull request as ready for review February 5, 2025 22:33
@cburchert

Copy link
Copy Markdown
Contributor Author

Hi! Anything left to do here?

@sbc100

sbc100 commented Feb 11, 2025

Copy link
Copy Markdown
Collaborator

lgtm if @walkingeyerobot is happy. Are you able to hit the merge button @walkingeyerobot ?

@walkingeyerobot
walkingeyerobot merged commit 85390ce into emscripten-core:main Feb 12, 2025
@walkingeyerobot

Copy link
Copy Markdown
Collaborator

Sorry! sbc had started the review so I wanted to approve but didn't want to hit the merge without his approval as well.

Thanks very much for contributing!

mmorel-35 pushed a commit to mmorel-35/emsdk that referenced this pull request Feb 3, 2026
…n-core#1518)

The current way to derive the binary path relies on a specific name for
the nodejs repository. This blocks migrating to bzlmod, as bzlmod
prefixes repository directories with the module name that created them.
By asking bazel for the path instead we always get the correct path, so
we can work with both bzlmod and WORKSPACE based dependencies at the
same time.

The repository @nodejs, used in the build label, refers to nodejs for
the host platform and is generated by the following macro (wasn't too
obvious to me):

https://github.com/bazel-contrib/rules_nodejs/blob/d19d695275c5fd0d5224ddc7826d9f7f4b8186df/nodejs/repositories.bzl#L452

This is some work towards solving emscripten-core#1509.
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