Skip to content

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

Open
@BGR360

Description

@BGR360

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-config-cliArea: --config CLI optionA-configurationArea: cargo config files and env varsC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions