Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#13842 - skogseth:build-only-specified-artifac…
…t-library, r=weihanglo Fix: Build only the specified artifact library when multiple types are available ### What does this PR try to resolve? Fixes rust-lang#12109. #### TL;DR: A crate `bar` exposes it's library as both a `staticlib` and a `cdylib`. A second crate `foo` specifies an artifact dependency of type `staticlib` on `bar`, meaning cargo should build `bar` as a `staticlib` and expose certain environment variables (e.g. `CARGO_STATICLIB_FILE_BAR`). However, due to a bug, cargo ends up building (and exposing the associated environment variables) for both the `staticlib` and `cdylib`. The same happens if `foo` specifies an artifact dependency of type `cdylib`; both artifact types are built. ### How should we test and review this PR? The first commit introduces a test which reproduces the issue, the second commit introduces the fix. This setup was recommended by `@ehuss.` ### Additional information Artifact dependencies: https://rust-lang.github.io/rfcs/3028-cargo-binary-dependencies.html #### TL;DR If a crate `foo` requests an artifact dependency of kind <artifact_kind> from a crate `bar` then the following happens: - `bar` is built with crate-type <artifact_kind> and a directory is created at `target/<profile>/deps/artifact/bar-<build_hash_or_something>/<artifact_kind>`. The binary artifact is placed in this directory. - Cargo exposes certain environment variables, the most important for this PR is `CARGO_<artifact_kind>_FILE_BAR`, which points to the binary artifact that was specified. This environment variable is available at compile time for normal dependencies and at runtime for build-dependencies. If multiple artifact-kinds are requested cargo will create a unit for each, and so they will all be built separately.
- Loading branch information