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

Embed config-relative paths as a substring #12193

Open
rhgndf opened this issue May 27, 2023 · 8 comments
Open

Embed config-relative paths as a substring #12193

rhgndf opened this issue May 27, 2023 · 8 comments
Labels
A-environment-variables Area: environment variables C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.

Comments

@rhgndf
Copy link

rhgndf commented May 27, 2023

Problem

Config env vars as far as I can tell cannot embed relative paths as a substring.

Proposed Solution

It would be useful to be able to set env vars like this for dependencies that need to compile C libraries.

[env]
CFLAGS = ["-I", { value = "include", relative = true }]

Notes

Useful if needed to modify how a library compiles for wasm32-unknown-unknown

@rhgndf rhgndf 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 May 27, 2023
@rhgndf rhgndf changed the title Config-relative paths as a substring? Embed config-relative paths as a substring May 28, 2023
@weihanglo
Copy link
Member

Thanks for the report. It's a bit unclear what you want to achieve. Can you share a more complete example for your use case? Will environment variable expansion #10789 helps?

Besides, an unstable flag -C can change the current directory. Please have a look whether it is useful in this situation.

@weihanglo weihanglo added S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. A-environment-variables Area: environment variables and removed S-triage Status: This issue is waiting on initial triage. labels May 30, 2023
@rhgndf
Copy link
Author

rhgndf commented Jun 10, 2023

I think #10789 might work if it can expand env vars set within the cargo.toml.

For this feature request, it is to emulate setting the env var on the command line like CFLAGS="-I$(pwd)/include"

@weihanglo
Copy link
Member

weihanglo commented Jun 21, 2023

Pretty much understood. Just to me feel a bit awkward to have a nested { relative = "…" } inside an array. Personally I am looking forward to #10789 more.

@rustbot label -S-needs-design +S-needs-team-input +I-nominated-to-discuss -S-needs-info

@rustbot rustbot added I-nominated-to-discuss To be discussed during issue triage on the next Cargo team meeting S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. S-needs-team-input Status: Needs input from team on whether/how to proceed. and removed S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. labels Jun 21, 2023
@joshtriplett
Copy link
Member

Slight bikeshed: this seems like it could be written more simply as { relative-path = "include" }.

@joshtriplett
Copy link
Member

@rhgndf Could you please expand on your use case here? When we discussed this in a Cargo meeting, we weren't clear on exactly what the use case was. In particular, could you explain why this is relative to the config rather than the package root, and why -I include does not work? Are you looking to have a user-global environment variable with a relative path on it?

@weihanglo weihanglo removed the I-nominated-to-discuss To be discussed during issue triage on the next Cargo team meeting label Jun 27, 2023
@rhgndf
Copy link
Author

rhgndf commented Jul 5, 2023

It seems like when compiling a dependency's C file the relative path does not start from the cargo.toml path. Maybe it starts from the dependency package root instead? I would like to use this feature to include some header files not present in wasm32-unknown-unknown in order to make the C source files from the dependency compile successfully.

@weihanglo weihanglo added S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. and removed S-needs-team-input Status: Needs input from team on whether/how to proceed. labels Jul 5, 2023
@weihanglo
Copy link
Member

Where is the .cargo/config.toml you expect Cargo to read, and where did you execute cargo build from?

Note that Cargo configurations .cargo/config.toml are probed starting from the current working directory. Any path not at the probe path will be ignored.

It would be helpful if you could provide a concrete layout of the project or a reproducible example.

@rhgndf
Copy link
Author

rhgndf commented Jul 5, 2023

Here's an example: https://github.com/rhgndf/configrelative

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-environment-variables Area: environment variables C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.
Projects
None yet
Development

No branches or pull requests

4 participants