rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.75k stars 2.42k forks source link

Add `target="host"` meaning the current host #13051

Open kpreid opened 11 months ago

kpreid commented 11 months ago

Problem

Cargo defaults to compiling for the host's target triple, which is appropriate for most cases, particularly because this is the only (default) way to build tests that can be run. However, once the target has been overridden by configuration, there is no way to explicitly request on the command line that it be the host.

Proposed Solution

Wherever a target triple is accepted, accept the special string host as an alias for the host platform's target triple.

Notes

Use cases:

weihanglo commented 11 months ago

This also looks pretty symmetric to host-config feature.

weihanglo commented 11 months ago

In RFC 3028 artfiact dependencies target = "host" was also mentioned:

We could specify a target = "host" value to build for the host even for [dependencies] or [dev-dependencies] which would normally default to building for the target. If any use case arises for such a dependency, we can easily add that.

weihanglo commented 11 months ago

Another alternative solution to this issue: A way to unsetting config value https://github.com/rust-lang/cargo/issues/8112

kpreid commented 11 months ago

Unsetting config is a good thing to have, but I don't think it significantly overlaps with this — 3/4 of the use cases I listed won't work with unsetting.

Oh, another cross-reference: #6777 was a PR that implemented essentially this idea — except that it treated --target=HOST as unsetting, which was noted as undesirable semantics, and the PR was closed basically as “guess it's not this simple”.

bravely-beep commented 2 months ago

I'm also running into this issue; specifically, the second bullet point use-case in the original post would be very helpful for my project.