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

Support specifying additional config files/values in environment variable. #14508

Open
BGR360 opened this issue Sep 6, 2024 · 0 comments
Open
Labels
A-config-cli Area: --config CLI option A-configuration Area: cargo config files and env vars C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage.

Comments

@BGR360
Copy link

BGR360 commented Sep 6, 2024

Problem

TL;DR I have a separate Cargo config web.toml that I use with a particular target, and I want to be able to use Cargo-wrapping tools like Trunk to build that target and specify my custom config file via an environment variable.

More details...

I'm trying to make a cross-platform project for desktop and web. My project uses threads, so for the web build only, I need to enable the following Cargo options:

[unstable]
build-std = ["panic_abort", "std"]

[build]
rustflags = "-C target-feature=+atomics,+bulk-memory,+mutable-globals"

I know that it's possible to gate the rustflags on the web target:

[target.wasm32-unknown-unknown]
rustflags = "-C target-feature=+atomics,+bulk-memory,+mutable-globals"

But it's not currently possible to do the same for build-std. So I have two options:

  • Force myself/users to rebuild std when compiling for native (not great).
  • Make an extra config file .config/web.toml and require passing --config .config/web.toml to Cargo when compiling for web (acceptable).

This works fine until it comes time to use Trunk to package my web app. Trunk doesn't provide an option to pass arbitrary flags to Cargo (though there is an open issue requesting this functionality).

Proposed Solution

In addition to accepting --config BLAH on the command line, Cargo should also accept an environment variable like CARGO_CONFIG=BLAH.

This would allow me to run:

$ CARGO_CONFIG=.config/web.toml trunk build

Notes

IMO I think Trunk really should add the ability to pass more flags to Cargo. But I also think that supporting a CARGO_CONFIG environment variable is very much in line with the way Cargo already works for many other things.

An open question that I'm not experienced enough to decide on: how should this fit in with the current config precedence rules?

@BGR360 BGR360 added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage. labels Sep 6, 2024
@epage epage added A-configuration Area: cargo config files and env vars A-config-cli Area: --config CLI option labels Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-config-cli Area: --config CLI option A-configuration Area: cargo config files and env vars C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

2 participants