Allow artifact target set for build-std #15772
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds unstable flag
build-std-targets
.The intended use is for projects that mix a Tier 1/2 target as a host with a Tier 3 target in an artifact dependency, which is then deployed at runtime. For instance, x86-64-*-linux and bpfeb-unknown-none, or a supported host with a custom hardware profile given by json.
In these cases it is unlikely that all std libraries should be built from scratch. Additionally, the list of std builds are not only those given as direct targets on the command line but rather discovered by target specifications on artifact dependencies that are embedded to a host loader etc.
The previous state discovered the set of std-builds through the target list of the CLI but never dynamically within the crate graph. The unit graph would then try to access the std build for kinds that were not generated, resulting in panics in unit dependency planning.
What does this PR try to resolve?
Consider a Linux eBPF project in full Rust. We're building two binaries here, firstly a Linux host binary that interacts with the kernel from within x86_64 user space, secondly a binary in the kernel's eBPF language that compiles to a small module uploaded into the kernel at runtime. A nice setup would declare the latter as an artifact dependency of the former to either bundle it into the binary via includes or reference it an asset mechanism otherwise. Since
bpfeb-unknown-none
does not ship with std we must built it.Here's the cargo configuration we can use after this PR:
Note the bpf target applies only the artifact, everything else depends still on the users intended host profile and should not get a fixed target (just using a default).
To address such a project setup cargo should do at least two things:
core
/alloc
is supposed be built, that is independent from the list of targets it is invoked with on the CLI.CompileKinds
that match a need for having their std built and add the std units.In the implementation, step (2.) finds its information of targets based on the
target
attribute of an artifact dependency. It does not interact withforced-target
. This may be a debatable choice depending on how these two features are seen in relation to each other. Should a forced target also propagate as a default to thetarget
attribute, overriding the 'host' meaning that its omission otherwise implies?How to test and review this PR?
Test with cargo infrastructure to be added, see the above crate setup.
In the released cargo this gets an error in all operations:
What remains to be tested is all interactions with different settings of
[build.target]
and command line overrides. Guidance on testing the absence of a std build would be appreciated, i.e. would all information appear appropriately in the generated unit graph as a metadata output?