Skip to content

Conversation

@sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Feb 22, 2023

This setting is enabled by default when NODERAWFS is enabled, but can also be disabled explicitly.

Fixes: #18816, #25791

@kleisauke
Copy link
Collaborator

Instead of this PR, perhaps it would be useful to document at https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html#interacting-with-code-environment-variables that it's quite easy to mirror the entire environment on Node.js with:

Module.preRun = () => {ENV = Object.create(process.env)};

(see #3948 (comment) where this was originally mentioned)

@kleisauke
Copy link
Collaborator

FWIW, the reason I mentioned this is that Rust no longer test the wasm32-unknown-emscripten target triple on CI due to this:
rust-lang/rust#116381
rust-lang/rust#116362 (comment)

@sbc100 sbc100 changed the title Mirror entire environment under node Add NODE_RAW_ENV to mirror host env vars under node Nov 18, 2025
@sbc100
Copy link
Collaborator Author

sbc100 commented Nov 18, 2025

OK, I went with NODE_HOST_ENV which is enabled by default when NODERAWFS is used.

It should fix the libc++ get_temp_directory issue under windows.

@sbc100 sbc100 requested a review from pavelsavara November 18, 2025 02:25
@sbc100 sbc100 changed the title Add NODE_RAW_ENV to mirror host env vars under node Add NODE_HOST_ENV to mirror host env vars under node Nov 18, 2025
@sbc100
Copy link
Collaborator Author

sbc100 commented Nov 18, 2025

Reviving this 2 years old PR!

@sbc100 sbc100 force-pushed the node_env branch 2 times, most recently from 393e0e8 to e67fb52 Compare November 18, 2025 03:50
@sbc100 sbc100 requested review from dschuff and removed request for pavelsavara November 18, 2025 16:10
@sbc100 sbc100 force-pushed the node_env branch 2 times, most recently from dc377ee to 21e4019 Compare November 18, 2025 17:33
@sbc100 sbc100 enabled auto-merge (squash) November 18, 2025 17:39
@sbc100 sbc100 requested a review from kleisauke November 18, 2025 20:40
@sbc100
Copy link
Collaborator Author

sbc100 commented Nov 19, 2025

Ping .. someone want to approve this?

When running under nodejs, expose the underlying OS environment variables.
This is similiar to how ``NODERAWFS`` exporses the underlying FS.
This setting gets enabled by default when ``NODERAWFS`` is enabled, but can
also be controlled separatley.
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps leave it orthogonal to NODERAWFS? That would avoid a breaking change, and seems more reasonable unless I'm missing something.

Copy link
Collaborator Author

@sbc100 sbc100 Nov 20, 2025

Choose a reason for hiding this comment

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

It is orthogonal, but enabled by NODERAWFS default since I think anyone exposing the full host FS would also certainly also want the host environment variables. They are often very much linked.. think TMPDIR, HOME, etc

Its pretty hard to imagine giving full FS access but then not wanting to give access to environment variables. The former is a lot more permissive.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I updated the changelog entry and improved the docs.

Copy link
Member

Choose a reason for hiding this comment

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

Fair points. But I still worry about a breaking change here. In particular this exposes more of the host environment to the compiled program - it already had files, and now it has env vars as well, which can contain sensitive info.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Honestly, you can already access them, at least on linux. i.e. cat /proc/self/environ.

Copy link
Collaborator Author

@sbc100 sbc100 Nov 20, 2025

Choose a reason for hiding this comment

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

Another reason to link them by default is that if you don't you into issues like #25791 because the values in the environment don't correspond to real paths on the filesystem. e.g. our fake environment has TMP=/tmp but that path does not exist on windows with NODERAWFS. So I don't think it makes much sense to fake one without the other (unless you really know what you are doing and want to opt into it).

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough, good points.

@sbc100 sbc100 force-pushed the node_env branch 2 times, most recently from 3df9be7 to 9ecd8a0 Compare November 20, 2025 00:44
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

lgtm % comments

One can still use `-sDETERMINISITIC` to avoid this behaviour.

Fixes: #18816, #25791
@sbc100 sbc100 merged commit 4bd88b2 into main Nov 20, 2025
34 checks passed
@sbc100 sbc100 deleted the node_env branch November 20, 2025 21:53
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.

Do not overwrite LANG on NodeJS

5 participants