Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 31ea29b

Browse files
authoredApr 28, 2024··
Unrolled build for rust-lang#123942
Rollup merge of rust-lang#123942 - onur-ozkan:x-vendor, r=Mark-Simulacrum `x vendor` This PR implements `x vendor` on bootstrap; enabling dependency vendoring without the need for developers to have `cargo` installed on their system (previously, we suggested running `cargo vendor ...` but now we can accomplish the same task with `x vendor`). In addition, fixes rust-lang#112391 problem.
2 parents aed2187 + 6dd011d commit 31ea29b

File tree

10 files changed

+348
-12
lines changed

10 files changed

+348
-12
lines changed
 

‎src/bootstrap/bootstrap.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -1035,14 +1035,8 @@ def check_vendored_status(self):
10351035
if self.use_vendored_sources:
10361036
vendor_dir = os.path.join(self.rust_root, 'vendor')
10371037
if not os.path.exists(vendor_dir):
1038-
sync_dirs = "--sync ./src/tools/cargo/Cargo.toml " \
1039-
"--sync ./src/tools/rust-analyzer/Cargo.toml " \
1040-
"--sync ./compiler/rustc_codegen_cranelift/Cargo.toml " \
1041-
"--sync ./compiler/rustc_codegen_gcc/Cargo.toml " \
1042-
"--sync ./src/bootstrap/Cargo.toml "
10431038
eprint('ERROR: vendoring required, but vendor directory does not exist.')
1044-
eprint(' Run `cargo vendor {}` to initialize the '
1045-
'vendor directory.'.format(sync_dirs))
1039+
eprint(' Run `x.py vendor` to initialize the vendor directory.')
10461040
eprint(' Alternatively, use the pre-vendored `rustc-src` dist component.')
10471041
eprint(' To get a stable/beta/nightly version, download it from: ')
10481042
eprint(' '

‎src/bootstrap/src/core/build_steps/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ pub(crate) mod synthetic_targets;
1414
pub(crate) mod test;
1515
pub(crate) mod tool;
1616
pub(crate) mod toolstate;
17+
pub(crate) mod vendor;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
2+
use std::path::PathBuf;
3+
use std::process::Command;
4+
5+
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
6+
pub(crate) struct Vendor {
7+
sync_args: Vec<PathBuf>,
8+
versioned_dirs: bool,
9+
root_dir: PathBuf,
10+
}
11+
12+
impl Step for Vendor {
13+
type Output = ();
14+
const DEFAULT: bool = true;
15+
const ONLY_HOSTS: bool = true;
16+
17+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
18+
run.alias("placeholder").default_condition(true)
19+
}
20+
21+
fn make_run(run: RunConfig<'_>) {
22+
run.builder.ensure(Vendor {
23+
sync_args: run.builder.config.cmd.vendor_sync_args(),
24+
versioned_dirs: run.builder.config.cmd.vendor_versioned_dirs(),
25+
root_dir: run.builder.src.clone(),
26+
});
27+
}
28+
29+
fn run(self, builder: &Builder<'_>) -> Self::Output {
30+
let mut cmd = Command::new(&builder.initial_cargo);
31+
cmd.arg("vendor");
32+
33+
if self.versioned_dirs {
34+
cmd.arg("--versioned-dirs");
35+
}
36+
37+
// Sync these paths by default.
38+
for p in [
39+
"src/tools/cargo/Cargo.toml",
40+
"src/tools/rust-analyzer/Cargo.toml",
41+
"compiler/rustc_codegen_cranelift/Cargo.toml",
42+
"compiler/rustc_codegen_gcc/Cargo.toml",
43+
"src/bootstrap/Cargo.toml",
44+
] {
45+
cmd.arg("--sync").arg(builder.src.join(p));
46+
}
47+
48+
// Also sync explicitly requested paths.
49+
for sync_arg in self.sync_args {
50+
cmd.arg("--sync").arg(sync_arg);
51+
}
52+
53+
// Will read the libstd Cargo.toml
54+
// which uses the unstable `public-dependency` feature.
55+
cmd.env("RUSTC_BOOTSTRAP", "1");
56+
57+
cmd.current_dir(self.root_dir);
58+
59+
builder.run(&mut cmd);
60+
}
61+
}

‎src/bootstrap/src/core/builder.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ use std::sync::OnceLock;
1414
use std::time::{Duration, Instant};
1515

1616
use crate::core::build_steps::tool::{self, SourceType};
17-
use crate::core::build_steps::{check, clean, compile, dist, doc, install, run, setup, test};
18-
use crate::core::build_steps::{clippy, llvm};
17+
use crate::core::build_steps::{
18+
check, clean, clippy, compile, dist, doc, install, llvm, run, setup, test, vendor,
19+
};
1920
use crate::core::config::flags::{Color, Subcommand};
2021
use crate::core::config::{DryRun, SplitDebuginfo, TargetSelection};
2122
use crate::prepare_behaviour_dump_dir;
@@ -638,6 +639,7 @@ pub enum Kind {
638639
Run,
639640
Setup,
640641
Suggest,
642+
Vendor,
641643
}
642644

643645
impl Kind {
@@ -658,6 +660,7 @@ impl Kind {
658660
Kind::Run => "run",
659661
Kind::Setup => "setup",
660662
Kind::Suggest => "suggest",
663+
Kind::Vendor => "vendor",
661664
}
662665
}
663666

@@ -921,6 +924,7 @@ impl<'a> Builder<'a> {
921924
),
922925
Kind::Setup => describe!(setup::Profile, setup::Hook, setup::Link, setup::Vscode),
923926
Kind::Clean => describe!(clean::CleanAll, clean::Rustc, clean::Std),
927+
Kind::Vendor => describe!(vendor::Vendor),
924928
// special-cased in Build::build()
925929
Kind::Format | Kind::Suggest => vec![],
926930
}
@@ -993,6 +997,7 @@ impl<'a> Builder<'a> {
993997
Kind::Setup,
994998
path.as_ref().map_or([].as_slice(), |path| std::slice::from_ref(path)),
995999
),
1000+
Subcommand::Vendor { .. } => (Kind::Vendor, &paths[..]),
9961001
};
9971002

9981003
Self::new_internal(build, kind, paths.to_owned())

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -2027,7 +2027,8 @@ impl Config {
20272027
| Subcommand::Run { .. }
20282028
| Subcommand::Setup { .. }
20292029
| Subcommand::Format { .. }
2030-
| Subcommand::Suggest { .. } => flags.stage.unwrap_or(0),
2030+
| Subcommand::Suggest { .. }
2031+
| Subcommand::Vendor { .. } => flags.stage.unwrap_or(0),
20312032
};
20322033

20332034
// CI should always run stage 2 builds, unless it specifically states otherwise
@@ -2054,7 +2055,8 @@ impl Config {
20542055
| Subcommand::Run { .. }
20552056
| Subcommand::Setup { .. }
20562057
| Subcommand::Format { .. }
2057-
| Subcommand::Suggest { .. } => {}
2058+
| Subcommand::Suggest { .. }
2059+
| Subcommand::Vendor { .. } => {}
20582060
}
20592061
}
20602062

‎src/bootstrap/src/core/config/flags.rs

+24
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,15 @@ Arguments:
456456
#[arg(long)]
457457
run: bool,
458458
},
459+
/// Vendor dependencies
460+
Vendor {
461+
/// Additional `Cargo.toml` to sync and vendor
462+
#[arg(long)]
463+
sync: Vec<PathBuf>,
464+
/// Always include version in subdir name
465+
#[arg(long)]
466+
versioned_dirs: bool,
467+
},
459468
}
460469

461470
impl Subcommand {
@@ -476,6 +485,7 @@ impl Subcommand {
476485
Subcommand::Run { .. } => Kind::Run,
477486
Subcommand::Setup { .. } => Kind::Setup,
478487
Subcommand::Suggest { .. } => Kind::Suggest,
488+
Subcommand::Vendor { .. } => Kind::Vendor,
479489
}
480490
}
481491

@@ -581,6 +591,20 @@ impl Subcommand {
581591
_ => false,
582592
}
583593
}
594+
595+
pub fn vendor_versioned_dirs(&self) -> bool {
596+
match *self {
597+
Subcommand::Vendor { versioned_dirs, .. } => versioned_dirs,
598+
_ => false,
599+
}
600+
}
601+
602+
pub fn vendor_sync_args(&self) -> Vec<PathBuf> {
603+
match self {
604+
Subcommand::Vendor { sync, .. } => sync.clone(),
605+
_ => vec![],
606+
}
607+
}
584608
}
585609

586610
/// Returns the shell completion for a given shell, if the result differs from the current

‎src/etc/completions/x.py.fish

+37
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ complete -c x.py -n "__fish_use_subcommand" -f -a "install" -d 'Install distribu
4747
complete -c x.py -n "__fish_use_subcommand" -f -a "run" -d 'Run tools contained in this repository'
4848
complete -c x.py -n "__fish_use_subcommand" -f -a "setup" -d 'Set up the environment for development'
4949
complete -c x.py -n "__fish_use_subcommand" -f -a "suggest" -d 'Suggest a subset of tests to run, based on modified files'
50+
complete -c x.py -n "__fish_use_subcommand" -f -a "vendor" -d 'Vendor dependencies'
5051
complete -c x.py -n "__fish_seen_subcommand_from build" -l config -d 'TOML configuration file for build' -r -F
5152
complete -c x.py -n "__fish_seen_subcommand_from build" -l build-dir -d 'Build directory, overrides `build.build-dir` in `config.toml`' -r -f -a "(__fish_complete_directories)"
5253
complete -c x.py -n "__fish_seen_subcommand_from build" -l build -d 'build target of the stage0 compiler' -r -f
@@ -590,3 +591,39 @@ complete -c x.py -n "__fish_seen_subcommand_from suggest" -l llvm-profile-genera
590591
complete -c x.py -n "__fish_seen_subcommand_from suggest" -l enable-bolt-settings -d 'Enable BOLT link flags'
591592
complete -c x.py -n "__fish_seen_subcommand_from suggest" -l skip-stage0-validation -d 'Skip stage0 compiler validation'
592593
complete -c x.py -n "__fish_seen_subcommand_from suggest" -s h -l help -d 'Print help (see more with \'--help\')'
594+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l sync -d 'Additional `Cargo.toml` to sync and vendor' -r -F
595+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l config -d 'TOML configuration file for build' -r -F
596+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l build-dir -d 'Build directory, overrides `build.build-dir` in `config.toml`' -r -f -a "(__fish_complete_directories)"
597+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l build -d 'build target of the stage0 compiler' -r -f
598+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l host -d 'host targets to build' -r -f
599+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l target -d 'target targets to build' -r -f
600+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l exclude -d 'build paths to exclude' -r -F
601+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l skip -d 'build paths to skip' -r -F
602+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l rustc-error-format -r -f
603+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l on-fail -d 'command to run on failure' -r -f -a "(__fish_complete_command)"
604+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l stage -d 'stage to build (indicates compiler to use/test, e.g., stage 0 uses the bootstrap compiler, stage 1 the stage 0 rustc artifacts, etc.)' -r -f
605+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l keep-stage -d 'stage(s) to keep without recompiling (pass multiple times to keep e.g., both stages 0 and 1)' -r -f
606+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l keep-stage-std -d 'stage(s) of the standard library to keep without recompiling (pass multiple times to keep e.g., both stages 0 and 1)' -r -f
607+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l src -d 'path to the root of the rust checkout' -r -f -a "(__fish_complete_directories)"
608+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -s j -l jobs -d 'number of jobs to run in parallel' -r -f
609+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l warnings -d 'if value is deny, will deny warnings if value is warn, will emit warnings otherwise, use the default configured behaviour' -r -f -a "{deny '',warn '',default ''}"
610+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l error-format -d 'rustc error format' -r -f
611+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l color -d 'whether to use color in cargo and rustc output' -r -f -a "{always '',never '',auto ''}"
612+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l llvm-skip-rebuild -d 'whether rebuilding llvm should be skipped, overriding `skip-rebuld` in config.toml' -r -f -a "{true '',false ''}"
613+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l rust-profile-generate -d 'generate PGO profile with rustc build' -r -F
614+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l rust-profile-use -d 'use PGO profile for rustc build' -r -F
615+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l llvm-profile-use -d 'use PGO profile for LLVM build' -r -F
616+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l reproducible-artifact -d 'Additional reproducible artifacts that should be added to the reproducible artifacts archive' -r
617+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l set -d 'override options in config.toml' -r -f
618+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l versioned-dirs -d 'Always include version in subdir name'
619+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -s v -l verbose -d 'use verbose output (-vv for very verbose)'
620+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -s i -l incremental -d 'use incremental compilation'
621+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l include-default-paths -d 'include default paths in addition to the provided ones'
622+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l dry-run -d 'dry run; don\'t build anything'
623+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l dump-bootstrap-shims -d 'Indicates whether to dump the work done from bootstrap shims'
624+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l json-output -d 'use message-format=json'
625+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l bypass-bootstrap-lock -d 'Bootstrap uses this value to decide whether it should bypass locking the build process. This is rarely needed (e.g., compiling the std library for different targets in parallel)'
626+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l llvm-profile-generate -d 'generate PGO profile with llvm built for rustc'
627+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l enable-bolt-settings -d 'Enable BOLT link flags'
628+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -l skip-stage0-validation -d 'Skip stage0 compiler validation'
629+
complete -c x.py -n "__fish_seen_subcommand_from vendor" -s h -l help -d 'Print help (see more with \'--help\')'

‎src/etc/completions/x.py.ps1

+44
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Register-ArgumentCompleter -Native -CommandName 'x.py' -ScriptBlock {
7474
[CompletionResult]::new('run', 'run', [CompletionResultType]::ParameterValue, 'Run tools contained in this repository')
7575
[CompletionResult]::new('setup', 'setup', [CompletionResultType]::ParameterValue, 'Set up the environment for development')
7676
[CompletionResult]::new('suggest', 'suggest', [CompletionResultType]::ParameterValue, 'Suggest a subset of tests to run, based on modified files')
77+
[CompletionResult]::new('vendor', 'vendor', [CompletionResultType]::ParameterValue, 'Vendor dependencies')
7778
break
7879
}
7980
'x.py;build' {
@@ -724,6 +725,49 @@ Register-ArgumentCompleter -Native -CommandName 'x.py' -ScriptBlock {
724725
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')')
725726
break
726727
}
728+
'x.py;vendor' {
729+
[CompletionResult]::new('--sync', 'sync', [CompletionResultType]::ParameterName, 'Additional `Cargo.toml` to sync and vendor')
730+
[CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'TOML configuration file for build')
731+
[CompletionResult]::new('--build-dir', 'build-dir', [CompletionResultType]::ParameterName, 'Build directory, overrides `build.build-dir` in `config.toml`')
732+
[CompletionResult]::new('--build', 'build', [CompletionResultType]::ParameterName, 'build target of the stage0 compiler')
733+
[CompletionResult]::new('--host', 'host', [CompletionResultType]::ParameterName, 'host targets to build')
734+
[CompletionResult]::new('--target', 'target', [CompletionResultType]::ParameterName, 'target targets to build')
735+
[CompletionResult]::new('--exclude', 'exclude', [CompletionResultType]::ParameterName, 'build paths to exclude')
736+
[CompletionResult]::new('--skip', 'skip', [CompletionResultType]::ParameterName, 'build paths to skip')
737+
[CompletionResult]::new('--rustc-error-format', 'rustc-error-format', [CompletionResultType]::ParameterName, 'rustc-error-format')
738+
[CompletionResult]::new('--on-fail', 'on-fail', [CompletionResultType]::ParameterName, 'command to run on failure')
739+
[CompletionResult]::new('--stage', 'stage', [CompletionResultType]::ParameterName, 'stage to build (indicates compiler to use/test, e.g., stage 0 uses the bootstrap compiler, stage 1 the stage 0 rustc artifacts, etc.)')
740+
[CompletionResult]::new('--keep-stage', 'keep-stage', [CompletionResultType]::ParameterName, 'stage(s) to keep without recompiling (pass multiple times to keep e.g., both stages 0 and 1)')
741+
[CompletionResult]::new('--keep-stage-std', 'keep-stage-std', [CompletionResultType]::ParameterName, 'stage(s) of the standard library to keep without recompiling (pass multiple times to keep e.g., both stages 0 and 1)')
742+
[CompletionResult]::new('--src', 'src', [CompletionResultType]::ParameterName, 'path to the root of the rust checkout')
743+
[CompletionResult]::new('-j', 'j', [CompletionResultType]::ParameterName, 'number of jobs to run in parallel')
744+
[CompletionResult]::new('--jobs', 'jobs', [CompletionResultType]::ParameterName, 'number of jobs to run in parallel')
745+
[CompletionResult]::new('--warnings', 'warnings', [CompletionResultType]::ParameterName, 'if value is deny, will deny warnings if value is warn, will emit warnings otherwise, use the default configured behaviour')
746+
[CompletionResult]::new('--error-format', 'error-format', [CompletionResultType]::ParameterName, 'rustc error format')
747+
[CompletionResult]::new('--color', 'color', [CompletionResultType]::ParameterName, 'whether to use color in cargo and rustc output')
748+
[CompletionResult]::new('--llvm-skip-rebuild', 'llvm-skip-rebuild', [CompletionResultType]::ParameterName, 'whether rebuilding llvm should be skipped, overriding `skip-rebuld` in config.toml')
749+
[CompletionResult]::new('--rust-profile-generate', 'rust-profile-generate', [CompletionResultType]::ParameterName, 'generate PGO profile with rustc build')
750+
[CompletionResult]::new('--rust-profile-use', 'rust-profile-use', [CompletionResultType]::ParameterName, 'use PGO profile for rustc build')
751+
[CompletionResult]::new('--llvm-profile-use', 'llvm-profile-use', [CompletionResultType]::ParameterName, 'use PGO profile for LLVM build')
752+
[CompletionResult]::new('--reproducible-artifact', 'reproducible-artifact', [CompletionResultType]::ParameterName, 'Additional reproducible artifacts that should be added to the reproducible artifacts archive')
753+
[CompletionResult]::new('--set', 'set', [CompletionResultType]::ParameterName, 'override options in config.toml')
754+
[CompletionResult]::new('--versioned-dirs', 'versioned-dirs', [CompletionResultType]::ParameterName, 'Always include version in subdir name')
755+
[CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'use verbose output (-vv for very verbose)')
756+
[CompletionResult]::new('--verbose', 'verbose', [CompletionResultType]::ParameterName, 'use verbose output (-vv for very verbose)')
757+
[CompletionResult]::new('-i', 'i', [CompletionResultType]::ParameterName, 'use incremental compilation')
758+
[CompletionResult]::new('--incremental', 'incremental', [CompletionResultType]::ParameterName, 'use incremental compilation')
759+
[CompletionResult]::new('--include-default-paths', 'include-default-paths', [CompletionResultType]::ParameterName, 'include default paths in addition to the provided ones')
760+
[CompletionResult]::new('--dry-run', 'dry-run', [CompletionResultType]::ParameterName, 'dry run; don''t build anything')
761+
[CompletionResult]::new('--dump-bootstrap-shims', 'dump-bootstrap-shims', [CompletionResultType]::ParameterName, 'Indicates whether to dump the work done from bootstrap shims')
762+
[CompletionResult]::new('--json-output', 'json-output', [CompletionResultType]::ParameterName, 'use message-format=json')
763+
[CompletionResult]::new('--bypass-bootstrap-lock', 'bypass-bootstrap-lock', [CompletionResultType]::ParameterName, 'Bootstrap uses this value to decide whether it should bypass locking the build process. This is rarely needed (e.g., compiling the std library for different targets in parallel)')
764+
[CompletionResult]::new('--llvm-profile-generate', 'llvm-profile-generate', [CompletionResultType]::ParameterName, 'generate PGO profile with llvm built for rustc')
765+
[CompletionResult]::new('--enable-bolt-settings', 'enable-bolt-settings', [CompletionResultType]::ParameterName, 'Enable BOLT link flags')
766+
[CompletionResult]::new('--skip-stage0-validation', 'skip-stage0-validation', [CompletionResultType]::ParameterName, 'Skip stage0 compiler validation')
767+
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')')
768+
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')')
769+
break
770+
}
727771
})
728772

729773
$completions.Where{ $_.CompletionText -like "$wordToComplete*" } |

0 commit comments

Comments
 (0)
Please sign in to comment.