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

[feat] crates-io mirror environment config #12724

Closed
loynoir opened this issue Sep 22, 2023 · 4 comments
Closed

[feat] crates-io mirror environment config #12724

loynoir opened this issue Sep 22, 2023 · 4 comments
Labels
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-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@loynoir
Copy link

loynoir commented Sep 22, 2023

Problem

Let package manager env-configure-able is very convenient for scenario like

  • docker

  • devcontainer

.devcontainer/devcontainer.json

  "remoteEnv": {
    "NPM_CONFIG_REGISTRY": "http://self-hosted-verdaccio",

within container

$ npm config ls -l | grep verdaccio
registry = "http://self-hosted-verdaccio" 

But currently, cargo seems not env-configure-able, only accept .cargo/config.

Proposed Solution

Let cargo config env-configure-able.

Notes

No response

@loynoir loynoir 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 22, 2023
@weihanglo
Copy link
Member

Configuring Cargo via environment variables is documented here: https://doc.rust-lang.org/cargo/reference/environment-variables.html#configuration-environment-variables. You can also set configuration via --config cli argument.

Is there something missing you're looking for specifically?

@weihanglo weihanglo added S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. and removed S-triage Status: This issue is waiting on initial triage. labels Sep 22, 2023
@loynoir loynoir closed this as completed Sep 22, 2023
@loynoir
Copy link
Author

loynoir commented Sep 22, 2023

Seems not working.

Expected

[source.crates-io]
replace-with = 'mirror'

[source.mirror]
registry = "sparse+https://mirror/crates.io-index/"
$ cargo build
...
    Updating `mirror` index
...

Actual

$ env \
    CARGO_REGISTRIES_MIRROR_INDEX="sparse+https://mirror/crates.io-index/" \
    CARGO_REGISTRY_DEFAULT="mirror" \
    cargo build
...
    Updating crates.io index
...

@loynoir loynoir reopened this Sep 22, 2023
@loynoir loynoir changed the title [feat] environment config [feat] crates-io mirror environment config Sep 22, 2023
@Eh2406
Copy link
Contributor

Eh2406 commented Sep 22, 2023

In your second example you set https://doc.rust-lang.org/cargo/reference/config.html#registrydefault but in the ferst you set https://doc.rust-lang.org/cargo/reference/config.html#sourcenamereplace-with witch do very difrent things. (despite the confusing naming, sorry.)

@weihanglo
Copy link
Member

Also, as you may have read, a Cargo config value usually but not always has a counterpart of environment variable

Currently only integer, boolean, string and some array values are supported to be defined by environment variables. Descriptions below indicate which keys support environment variables and otherwise they are not supported due to technical issues.

Besides, there is a pretty unstable feature -Zadvanced-env tracked in #7406, which tries to fill the gap between config files and environment variables. I believe that also fixes your issue of setting source replacement via env, so closing in favor of #5416 and #7406.

Thank you for the report :)

@weihanglo weihanglo closed this as not planned Won't fix, can't repro, duplicate, stale Sep 22, 2023
@weihanglo weihanglo added A-environment-variables Area: environment variables A-configuration Area: cargo config files and env vars and removed A-environment-variables Area: environment variables labels Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
None yet
Development

No branches or pull requests

3 participants