rust-lang / rust-lang/cargo

Feature request: Set cargo --features via environment variables

Open
#4,829 15 comments 33 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-environment-variables A-features C-feature-request S-propose-close
Dominant language
Rust
Stars
15.5k
Forks
3k
Avg merge
23h 30m
Merged PRs (30d)
51

Description

Consider a Cargo.toml including

[features]
default = []
unstable = [] # Enables nightly features

Simply put, you'd now be able to enable unstable by setting CARGO_SET_FEATURE_UNSTABLE to "truthy". Alternatively, you'd be able to set CARGO_SET_FEATURES to a comma separated string of the features you wish to enable. This of course works for any number of features by setting more env vars or adding more to the comma separated string.

Having this capability would make .travis.yml files capable of enabling features very succinctly without relying on travis-cargo or other methods. An example:

language: rust
sudo: false
dist: trusty
rust:
- 1.22.1
- stable
- beta

matrix:
  allow_failures:
    - rust: nightly
  include:
    - rust: nightly
      env: CARGO_SET_FEATURE_UNSTABLE

cache: cargo

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue does not name files, tests, or an implementation entry point. Start by locating Cargo’s feature-selection and environment-variable handling, then clarify the truthy values and how per-feature variables interact with the comma-separated form. Done means the selected features are enabled reliably from both environment-variable styles and covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system, cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.