rust-lang / wg-cargo-std-aware

Repo for working on "std aware cargo"
133 stars 8 forks source link

restricted_std applicability to custom JSON targets #90

Open Mark-Simulacrum opened 4 months ago

Mark-Simulacrum commented 4 months ago

In https://github.com/rust-lang/rust/pull/120232, std's build script was moved to using the TARGET_OS and other fine-grained environment variables set by Cargo. This means that some JSON targets (regardless of filename, which is the previous filter?) do not enable the restricted_std mode.

Before stabilizing -Zbuild-std, we will want to figure out what guarantees we want to make here.

cc https://github.com/rust-lang/rust/issues/71009, https://github.com/rust-lang/rust/issues/38338

ehuss commented 4 months ago

Thanks for filing the issue! I'm a little unclear about exactly what this means, can you clarify? Is this possibly suggesting that the "std supported" flag should be in the target spec and not in std's build.rs?

I think my original intent was:

There is a much larger question of "I want to build for a new target, and I need to modify std to do it.", which is tracked in #3. I'm skeptical that moving just the "std supported" flag to the target spec will be sufficient for most custom targets.

If/when build-std is stabilized, I would want to ensure that https://github.com/rust-lang/rust/issues/71009 is resolved first.

6 also contains some considerations for why target-spec JSON needs a lot of work.

Mark-Simulacrum commented 4 months ago

I think if target specs are not stable (i.e. https://github.com/rust-lang/rust/issues/71009) then this is not really a problem for build-std (any instability in std builds is under the target spec instability umbrella at that point).

The current way we decide whether std is stable or not is by matching on a small subset of the target cfg values. For example, if I am target something like wasm32-linux, that might be considered stable by the current rules in std's build script, but perhaps should not be.

I filed this mostly since we closed https://github.com/rust-lang/wg-cargo-std-aware/issues/60 -- there should be, IMO, some explicit decision in the RFC/FCP stabilizing build-std as to how we do the filter in std's build.rs. Right now that filter is pretty loose, we may want to tighten it (e.g., must precisely match a tier-3+ target that's in tree across all cfgs). Maybe this should be closed as a duplicate of https://github.com/rust-lang/wg-cargo-std-aware/issues/6.