Skip to content

Commit b72a0d8

Browse files
David Tolnayfacebook-github-bot
authored andcommitted
Add separate extra_deps and omit_deps fixups for build scripts
Summary: It is goofy that when you use `extra_deps` in a fixup, those deps get applied to **both** the library/binary and to its build script. There is almost never a case you would want to add an identical dependency to both a library/binary and its build script. And in the worse case, this makes `extra_deps` completely unusable, such as when you want to add a platform-specific dependency (e.g. Android) which is incompatible with your execution platform. Since {D73977930} there is a dedicated section for controlling the build-script build. This diff adds support for `extra_deps` and `omit_deps` in that section, and changes top-level `extra_deps` and `omit_deps` to no longer apply to build scripts. ```lang=toml omit_deps = ["example"] extra_deps = [":better-example"] [buildscript.build] omit_deps = ["example"] extra_deps = [":better-example"] ``` Reviewed By: JakobDegen Differential Revision: D74158951 fbshipit-source-id: cc1e8865cbcccecf6b6e2791942e61bfdd88b8e7
1 parent 39d3a39 commit b72a0d8

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/fixups.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,9 +727,14 @@ impl<'meta> Fixups<'meta> {
727727
// Pre-compute the list of all filtered dependencies. If a platform filters a dependency
728728
// added by the base, we need to filter it from the base and add it to all other platforms.
729729
for (platform, fixup) in self.fixup_config.configs(&self.package.version) {
730+
let fixup_omit_deps = if self.target.crate_bin() && self.target.kind_custom_build() {
731+
&fixup.buildscript.build.omit_deps
732+
} else {
733+
&fixup.omit_deps
734+
};
730735
let platform_omits = omits.entry(platform).or_insert_with(HashSet::new);
731-
platform_omits.extend(fixup.omit_deps.iter().map(String::as_str));
732-
all_omits.extend(fixup.omit_deps.iter().map(String::as_str));
736+
platform_omits.extend(fixup_omit_deps.iter().map(String::as_str));
737+
all_omits.extend(fixup_omit_deps.iter().map(String::as_str));
733738
}
734739

735740
for ResolvedDep {
@@ -819,7 +824,12 @@ impl<'meta> Fixups<'meta> {
819824
}
820825

821826
for (platform, config) in self.fixup_config.configs(&self.package.version) {
822-
ret.extend(config.extra_deps.iter().map(|dep| {
827+
let fixup_extra_deps = if self.target.crate_bin() && self.target.kind_custom_build() {
828+
&config.buildscript.build.extra_deps
829+
} else {
830+
&config.extra_deps
831+
};
832+
ret.extend(fixup_extra_deps.iter().map(|dep| {
823833
(
824834
None,
825835
RuleRef::new(dep.to_string()).with_platform(platform),

src/fixups/buildscript.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
use std::collections::BTreeMap;
9+
use std::collections::BTreeSet;
910
use std::fmt;
1011
use std::path::PathBuf;
1112

@@ -47,6 +48,10 @@ pub struct BuildscriptBuild {
4748
#[serde(default)]
4849
pub env: BTreeMap<String, String>,
4950
pub link_style: Option<String>,
51+
#[serde(default)]
52+
pub extra_deps: BTreeSet<String>,
53+
#[serde(default)]
54+
pub omit_deps: BTreeSet<String>,
5055
#[serde(skip_deserializing)]
5156
pub defaulted_to_empty: bool,
5257
}
@@ -56,6 +61,8 @@ impl Default for BuildscriptBuild {
5661
BuildscriptBuild {
5762
env: BTreeMap::new(),
5863
link_style: None,
64+
extra_deps: BTreeSet::new(),
65+
omit_deps: BTreeSet::new(),
5966
defaulted_to_empty: true,
6067
}
6168
}

0 commit comments

Comments
 (0)