Skip to content

Add option to include submodules from vendoring #137583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -981,3 +981,6 @@

# Whether to vendor dependencies for the dist tarball.
#vendor = if "is a tarball source" || "is a git repository" { true } else { false }

# Exclude these submodules from vendoring.
# exclude-submodules-from-vendoring = []
6 changes: 5 additions & 1 deletion src/bootstrap/src/core/build_steps/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ impl Step for GenerateCopyright {
let dest = builder.out.join("COPYRIGHT.html");
let dest_libstd = builder.out.join("COPYRIGHT-library.html");

let paths_to_vendor = default_paths_to_vendor(builder);
let paths_to_vendor = default_paths_to_vendor(
builder,
&builder.config.dist_exclude_submodules_from_vendoring,
);

for (_, submodules) in &paths_to_vendor {
for submodule in submodules {
builder.build.require_submodule(submodule, None);
Expand Down
42 changes: 29 additions & 13 deletions src/bootstrap/src/core/build_steps/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//!
//! This module ensures that all required Cargo dependencies are gathered
//! and stored in the `<src>/<VENDOR_DIR>` directory.
use std::collections::BTreeSet;
use std::path::PathBuf;

use crate::core::build_steps::tool::SUBMODULES_FOR_RUSTBOOK;
Expand All @@ -16,21 +17,32 @@ pub const VENDOR_DIR: &str = "vendor";
/// Returns a `Vec` of `(path_to_manifest, submodules_required)` where
/// `path_to_manifest` is the cargo workspace, and `submodules_required` is
/// the set of submodules that must be available.
pub fn default_paths_to_vendor(builder: &Builder<'_>) -> Vec<(PathBuf, Vec<&'static str>)> {
pub fn default_paths_to_vendor(
builder: &Builder<'_>,
excluded_submodules: &BTreeSet<String>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that all callers of exclude_submodules pass the same argument to it. Can we remove the argument and access builder.config.dist_exclude_submodules_from_vendoring directly inside of the function?

) -> Vec<(PathBuf, Vec<&'static str>)> {
[
("src/tools/cargo/Cargo.toml", vec!["src/tools/cargo"]),
("src/tools/rust-analyzer/Cargo.toml", vec![]),
("compiler/rustc_codegen_cranelift/Cargo.toml", vec![]),
("compiler/rustc_codegen_gcc/Cargo.toml", vec![]),
("library/Cargo.toml", vec![]),
("src/bootstrap/Cargo.toml", vec![]),
("src/tools/rustbook/Cargo.toml", SUBMODULES_FOR_RUSTBOOK.into()),
("src/tools/rustc-perf/Cargo.toml", vec!["src/tools/rustc-perf"]),
("src/tools/opt-dist/Cargo.toml", vec![]),
("src/doc/book/packages/trpl/Cargo.toml", vec![]),
("src/tools/cargo/Cargo.toml", &["src/tools/cargo"][..]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
("src/tools/cargo/Cargo.toml", &["src/tools/cargo"][..]),
("src/tools/cargo/Cargo.toml", &["src/tools/cargo"]),

Just a small nit.

("src/tools/rust-analyzer/Cargo.toml", &[]),
("compiler/rustc_codegen_cranelift/Cargo.toml", &[]),
("compiler/rustc_codegen_gcc/Cargo.toml", &[]),
("library/Cargo.toml", &[]),
("src/bootstrap/Cargo.toml", &[]),
("src/tools/rustbook/Cargo.toml", SUBMODULES_FOR_RUSTBOOK),
("src/tools/rustc-perf/Cargo.toml", &["src/tools/rustc-perf"]),
("src/tools/opt-dist/Cargo.toml", &[]),
("src/doc/book/packages/trpl/Cargo.toml", &[]),
]
.into_iter()
.map(|(path, submodules)| (builder.src.join(path), submodules))
.filter_map(|(path, submodules)| {
for submodule in submodules {
if excluded_submodules.contains(&**submodule) {
return None;
}
}

Some((builder.src.join(path), submodules.into()))
})
.collect()
}

Expand Down Expand Up @@ -82,7 +94,11 @@ impl Step for Vendor {
cmd.arg("--versioned-dirs");
}

let to_vendor = default_paths_to_vendor(builder);
let to_vendor = default_paths_to_vendor(
builder,
&builder.config.dist_exclude_submodules_from_vendoring,
);

// These submodules must be present for `x vendor` to work.
for (_, submodules) in &to_vendor {
for submodule in submodules {
Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ pub struct Config {
pub dist_compression_profile: String,
pub dist_include_mingw_linker: bool,
pub dist_vendor: bool,
pub dist_exclude_submodules_from_vendoring: BTreeSet<String>,

// libstd features
pub backtrace: bool, // support for RUST_BACKTRACE
Expand Down Expand Up @@ -1001,6 +1002,7 @@ define_config! {
compression_profile: Option<String> = "compression-profile",
include_mingw_linker: Option<bool> = "include-mingw-linker",
vendor: Option<bool> = "vendor",
exclude_submodules_from_vendoring: Option<BTreeSet<String>> = "exclude-submodules-from-vendoring",
}
}

Expand Down Expand Up @@ -2227,10 +2229,13 @@ impl Config {
compression_profile,
include_mingw_linker,
vendor,
exclude_submodules_from_vendoring,
} = dist;
config.dist_sign_folder = sign_folder.map(PathBuf::from);
config.dist_upload_addr = upload_addr;
config.dist_compression_formats = compression_formats;
config.dist_exclude_submodules_from_vendoring =
exclude_submodules_from_vendoring.unwrap_or_else(BTreeSet::new);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
exclude_submodules_from_vendoring.unwrap_or_else(BTreeSet::new);
exclude_submodules_from_vendoring.unwrap_or_default();

set(&mut config.dist_compression_profile, compression_profile);
set(&mut config.rust_dist_src, src_tarball);
set(&mut config.dist_include_mingw_linker, include_mingw_linker);
Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/src/utils/change_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
severity: ChangeSeverity::Info,
summary: "Added `build.test-stage = 2` to 'tools' profile defaults",
},
ChangeInfo {
change_id: 137583,
severity: ChangeSeverity::Info,
summary: "It is now possible to filter out submodules from vendoring with `dist.exclude-submodules-from-vendoring`",
},
];
Loading