Skip to content

Commit 21f240e

Browse files
committed
Add option to include submodules from vendoring
This adds a config option `exclude-submodules-from-vendoring` that explicitly filters out listed submodules from vendoring. This allows us to exclude submodules like `rustc-perf`, which vendors a number of libraries for benchmarking, and has a complicated licensing story. Closes rust-lang#137272
1 parent 617aad8 commit 21f240e

File tree

5 files changed

+47
-14
lines changed

5 files changed

+47
-14
lines changed

config.example.toml

+3
Original file line numberDiff line numberDiff line change
@@ -981,3 +981,6 @@
981981

982982
# Whether to vendor dependencies for the dist tarball.
983983
#vendor = if "is a tarball source" || "is a git repository" { true } else { false }
984+
985+
# Exclude these submodules from vendoring.
986+
# exclude-submodules-from-vendoring = []

src/bootstrap/src/core/build_steps/run.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,11 @@ impl Step for GenerateCopyright {
209209
let dest = builder.out.join("COPYRIGHT.html");
210210
let dest_libstd = builder.out.join("COPYRIGHT-library.html");
211211

212-
let paths_to_vendor = default_paths_to_vendor(builder);
212+
let paths_to_vendor = default_paths_to_vendor(
213+
builder,
214+
&builder.config.dist_exclude_submodules_from_vendoring,
215+
);
216+
213217
for (_, submodules) in &paths_to_vendor {
214218
for submodule in submodules {
215219
builder.build.require_submodule(submodule, None);

src/bootstrap/src/core/build_steps/vendor.rs

+29-13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//!
33
//! This module ensures that all required Cargo dependencies are gathered
44
//! and stored in the `<src>/<VENDOR_DIR>` directory.
5+
use std::collections::BTreeSet;
56
use std::path::PathBuf;
67

78
use crate::core::build_steps::tool::SUBMODULES_FOR_RUSTBOOK;
@@ -16,21 +17,32 @@ pub const VENDOR_DIR: &str = "vendor";
1617
/// Returns a `Vec` of `(path_to_manifest, submodules_required)` where
1718
/// `path_to_manifest` is the cargo workspace, and `submodules_required` is
1819
/// the set of submodules that must be available.
19-
pub fn default_paths_to_vendor(builder: &Builder<'_>) -> Vec<(PathBuf, Vec<&'static str>)> {
20+
pub fn default_paths_to_vendor(
21+
builder: &Builder<'_>,
22+
excluded_submodules: &BTreeSet<String>,
23+
) -> Vec<(PathBuf, Vec<&'static str>)> {
2024
[
21-
("src/tools/cargo/Cargo.toml", vec!["src/tools/cargo"]),
22-
("src/tools/rust-analyzer/Cargo.toml", vec![]),
23-
("compiler/rustc_codegen_cranelift/Cargo.toml", vec![]),
24-
("compiler/rustc_codegen_gcc/Cargo.toml", vec![]),
25-
("library/Cargo.toml", vec![]),
26-
("src/bootstrap/Cargo.toml", vec![]),
27-
("src/tools/rustbook/Cargo.toml", SUBMODULES_FOR_RUSTBOOK.into()),
28-
("src/tools/rustc-perf/Cargo.toml", vec!["src/tools/rustc-perf"]),
29-
("src/tools/opt-dist/Cargo.toml", vec![]),
30-
("src/doc/book/packages/trpl/Cargo.toml", vec![]),
25+
("src/tools/cargo/Cargo.toml", &["src/tools/cargo"][..]),
26+
("src/tools/rust-analyzer/Cargo.toml", &[]),
27+
("compiler/rustc_codegen_cranelift/Cargo.toml", &[]),
28+
("compiler/rustc_codegen_gcc/Cargo.toml", &[]),
29+
("library/Cargo.toml", &[]),
30+
("src/bootstrap/Cargo.toml", &[]),
31+
("src/tools/rustbook/Cargo.toml", SUBMODULES_FOR_RUSTBOOK),
32+
("src/tools/rustc-perf/Cargo.toml", &["src/tools/rustc-perf"]),
33+
("src/tools/opt-dist/Cargo.toml", &[]),
34+
("src/doc/book/packages/trpl/Cargo.toml", &[]),
3135
]
3236
.into_iter()
33-
.map(|(path, submodules)| (builder.src.join(path), submodules))
37+
.filter_map(|(path, submodules)| {
38+
for submodule in submodules {
39+
if excluded_submodules.contains(&**submodule) {
40+
return None;
41+
}
42+
}
43+
44+
Some((builder.src.join(path), submodules.into()))
45+
})
3446
.collect()
3547
}
3648

@@ -82,7 +94,11 @@ impl Step for Vendor {
8294
cmd.arg("--versioned-dirs");
8395
}
8496

85-
let to_vendor = default_paths_to_vendor(builder);
97+
let to_vendor = default_paths_to_vendor(
98+
builder,
99+
&builder.config.dist_exclude_submodules_from_vendoring,
100+
);
101+
86102
// These submodules must be present for `x vendor` to work.
87103
for (_, submodules) in &to_vendor {
88104
for submodule in submodules {

src/bootstrap/src/core/config/config.rs

+5
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ pub struct Config {
339339
pub dist_compression_profile: String,
340340
pub dist_include_mingw_linker: bool,
341341
pub dist_vendor: bool,
342+
pub dist_exclude_submodules_from_vendoring: BTreeSet<String>,
342343

343344
// libstd features
344345
pub backtrace: bool, // support for RUST_BACKTRACE
@@ -1001,6 +1002,7 @@ define_config! {
10011002
compression_profile: Option<String> = "compression-profile",
10021003
include_mingw_linker: Option<bool> = "include-mingw-linker",
10031004
vendor: Option<bool> = "vendor",
1005+
exclude_submodules_from_vendoring: Option<BTreeSet<String>> = "exclude-submodules-from-vendoring",
10041006
}
10051007
}
10061008

@@ -2227,10 +2229,13 @@ impl Config {
22272229
compression_profile,
22282230
include_mingw_linker,
22292231
vendor,
2232+
exclude_submodules_from_vendoring,
22302233
} = dist;
22312234
config.dist_sign_folder = sign_folder.map(PathBuf::from);
22322235
config.dist_upload_addr = upload_addr;
22332236
config.dist_compression_formats = compression_formats;
2237+
config.dist_exclude_submodules_from_vendoring =
2238+
exclude_submodules_from_vendoring.unwrap_or_else(BTreeSet::new);
22342239
set(&mut config.dist_compression_profile, compression_profile);
22352240
set(&mut config.rust_dist_src, src_tarball);
22362241
set(&mut config.dist_include_mingw_linker, include_mingw_linker);

src/bootstrap/src/utils/change_tracker.rs

+5
Original file line numberDiff line numberDiff line change
@@ -360,4 +360,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
360360
severity: ChangeSeverity::Info,
361361
summary: "Added `build.test-stage = 2` to 'tools' profile defaults",
362362
},
363+
ChangeInfo {
364+
change_id: 137583,
365+
severity: ChangeSeverity::Info,
366+
summary: "It is now possible to filter out submodules from vendoring with `dist.exclude-submodules-from-vendoring`",
367+
},
363368
];

0 commit comments

Comments
 (0)