Skip to content

Conversation

@CPunisher
Copy link
Member

Description:

Currently, WasiEnvBuilder clones a lot to pass environment variables to Wasm. I think it should get environment variables from the host dynamically. Any plan to support it?

Originally posted by @kdy1 in #9668

I think this is possible, we can manually add envs to WasiEnvBuilder by add_env. So I finsh a rough implementation. More suggestions are welcome.

.swcrc

{ "jsc": { "experimental": { "plugins": [["./my_first_plugin.wasm", {}]], "pluginEnvVars": ["BUILD_REPOSITORY_NAME"] } } }

plugin.rs

#[plugin_transform] pub fn process_transform(program: Program, _metadata: TransformPluginProgramMetadata) -> Program { for env in std::env::vars() { println!("{}: {}", env.0, env.1); } program }

Related issue (if exists):

closes #9668

@CPunisher CPunisher requested review from a team as code owners April 6, 2025 05:27
@changeset-bot
Copy link

changeset-bot bot commented Apr 6, 2025

🦋 Changeset detected

Latest commit: 6be63a0

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codspeed-hq
Copy link

codspeed-hq bot commented Apr 6, 2025

CodSpeed Performance Report

Merging #10318 will not alter performance

Comparing CPunisher:04-06-feat/plugin-env-var (6be63a0) with main (ddbf3e1)

Summary

✅ 152 untouched benchmarks

@CPunisher CPunisher changed the title feat(plugin/runner): support pluginEnvVars feat(plugin/runner): Support pluginEnvVars Apr 6, 2025
@kdy1 kdy1 self-assigned this Apr 6, 2025
@kdy1 kdy1 added this to the Planned milestone Apr 6, 2025
Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

I think it would give optimal API (no lifetime) without lesser allocations

@kdy1 kdy1 merged commit 795fedc into swc-project:main Apr 8, 2025
19 checks passed
@kdy1 kdy1 modified the milestones: Planned, v1.11.19 Apr 10, 2025
@swc-project swc-project locked as resolved and limited conversation to collaborators May 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

2 participants