Skip to content

Commit 345eb14

Browse files
committed
Remove vendoring support when building from git sources
This is difficult to support without submodule handling in bootstrap.py, because cargo will refuse to vendor sources unless it knows the Cargo.toml files of all tools in tree. Moving vendor support to rustbuild means that rustbuild will be built without vendoring. Rather than trying to solve this, just remove support altogether and require people to use `rustc-src` if they want vendoring (or run `cargo vendor` manually).
1 parent 85c87f6 commit 345eb14

File tree

3 files changed

+31
-43
lines changed

3 files changed

+31
-43
lines changed

src/bootstrap/CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
77

88
## [Changes since the last major version]
99

10+
- Vendoring is no longer done automatically when building from git sources. To use vendoring, run `cargo vendor` manually, or use the pre-vendored `rustc-src` tarball.
1011
- `llvm-libunwind` now accepts `in-tree` (formerly true), `system` or `no` (formerly false) [#77703](https://github.com/rust-lang/rust/pull/77703)
1112
- The options `infodir`, `localstatedir`, and `gpg-password-file` are no longer allowed in config.toml. Previously, they were ignored without warning. Note that `infodir` and `localstatedir` are still accepted by `./configure`, with a warning. [#82451](https://github.com/rust-lang/rust/pull/82451)
12-
- Add options for enabling overflow checks, one for std (`overflow-checks-std`) and one for everything else (`overflow-checks`). Both default to false.
1313
- Change the names for `dist` commands to match the component they generate. [#90684](https://github.com/rust-lang/rust/pull/90684)
1414
- The `build.fast-submodules` option has been removed. Fast submodule checkouts are enabled unconditionally. Automatic submodule handling can still be disabled with `build.submodules = false`.
1515

@@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1919
- The default bootstrap profiles are now located at `bootstrap/defaults/config.$PROFILE.toml` (previously they were located at `bootstrap/defaults/config.toml.$PROFILE`) [#77558](https://github.com/rust-lang/rust/pull/77558)
2020
- If you have Rust already installed, `x.py` will now infer the host target
2121
from the default rust toolchain. [#78513](https://github.com/rust-lang/rust/pull/78513)
22+
- Add options for enabling overflow checks, one for std (`overflow-checks-std`) and one for everything else (`overflow-checks`). Both default to false.
2223

2324

2425
## [Version 2] - 2020-09-25

src/bootstrap/bootstrap.py

+17-41
Original file line numberDiff line numberDiff line change
@@ -822,55 +822,32 @@ def set_dist_environment(self, url):
822822

823823
def check_vendored_status(self):
824824
"""Check that vendoring is configured properly"""
825-
vendor_dir = os.path.join(self.rust_root, 'vendor')
826825
if 'SUDO_USER' in os.environ and not self.use_vendored_sources:
827826
if os.getuid() == 0:
828827
self.use_vendored_sources = True
829828
print('info: looks like you\'re trying to run this command as root')
830829
print(' and so in order to preserve your $HOME this will now')
831830
print(' use vendored sources by default.')
832-
if not os.path.exists(vendor_dir):
833-
print('error: vendoring required, but vendor directory does not exist.')
834-
print(' Run `cargo vendor` without sudo to initialize the '
835-
'vendor directory.')
836-
raise Exception("{} not found".format(vendor_dir))
837831

832+
cargo_dir = os.path.join(self.rust_root, '.cargo')
838833
if self.use_vendored_sources:
839-
config = ("[source.crates-io]\n"
840-
"replace-with = 'vendored-sources'\n"
841-
"registry = 'https://example.com'\n"
842-
"\n"
843-
"[source.vendored-sources]\n"
844-
"directory = '{}/vendor'\n"
845-
.format(self.rust_root))
846-
if not os.path.exists('.cargo'):
847-
os.makedirs('.cargo')
848-
with output('.cargo/config') as cargo_config:
849-
cargo_config.write(config)
850-
else:
851-
print('info: using vendored source, but .cargo/config is already present.')
852-
print(' Reusing the current configuration file. But you may want to '
853-
'configure vendoring like this:')
854-
print(config)
834+
vendor_dir = os.path.join(self.rust_root, 'vendor')
835+
if not os.path.exists(vendor_dir):
836+
sync_dirs = "--sync ./src/tools/rust-analyzer/Cargo.toml " \
837+
"--sync ./compiler/rustc_codegen_cranelift/Cargo.toml " \
838+
"--sync ./src/bootstrap/Cargo.toml "
839+
print('error: vendoring required, but vendor directory does not exist.')
840+
print(' Run `cargo vendor {}` to initialize the '
841+
'vendor directory.'.format(sync_dirs))
842+
print('Alternatively, use the pre-vendored `rustc-src` dist component.')
843+
raise Exception("{} not found".format(vendor_dir))
844+
845+
if not os.path.exists(cargo_dir):
846+
print('error: vendoring required, but .cargo/config does not exist.')
847+
raise Exception("{} not found".format(cargo_dir))
855848
else:
856-
if os.path.exists('.cargo'):
857-
shutil.rmtree('.cargo')
858-
859-
def ensure_vendored(self):
860-
"""Ensure that the vendored sources are available if needed"""
861-
vendor_dir = os.path.join(self.rust_root, 'vendor')
862-
# Note that this does not handle updating the vendored dependencies if
863-
# the rust git repository is updated. Normal development usually does
864-
# not use vendoring, so hopefully this isn't too much of a problem.
865-
if self.use_vendored_sources and not os.path.exists(vendor_dir):
866-
run([
867-
self.cargo(),
868-
"vendor",
869-
"--sync=./src/bootstrap/Cargo.toml",
870-
"--sync=./src/tools/rust-analyzer/Cargo.toml",
871-
"--sync=./compiler/rustc_codegen_cranelift/Cargo.toml",
872-
], verbose=self.verbose, cwd=self.rust_root)
873-
849+
if os.path.exists(cargo_dir):
850+
shutil.rmtree(cargo_dir)
874851

875852
def bootstrap(help_triggered):
876853
"""Configure, fetch, build and run the initial bootstrap"""
@@ -953,7 +930,6 @@ def bootstrap(help_triggered):
953930
# Fetch/build the bootstrap
954931
build.download_toolchain()
955932
sys.stdout.flush()
956-
build.ensure_vendored()
957933
build.build_bootstrap()
958934
sys.stdout.flush()
959935

src/bootstrap/dist.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -894,8 +894,19 @@ impl Step for PlainSourceTarball {
894894
.arg(builder.src.join("./src/tools/rust-analyzer/Cargo.toml"))
895895
.arg("--sync")
896896
.arg(builder.src.join("./compiler/rustc_codegen_cranelift/Cargo.toml"))
897+
.arg("--sync")
898+
.arg(builder.src.join("./src/bootstrap/Cargo.toml"))
897899
.current_dir(&plain_dst_src);
898-
builder.run(&mut cmd);
900+
901+
let config = if !builder.config.dry_run {
902+
t!(String::from_utf8(t!(cmd.output()).stdout))
903+
} else {
904+
String::new()
905+
};
906+
907+
let cargo_config_dir = plain_dst_src.join(".cargo");
908+
builder.create_dir(&cargo_config_dir);
909+
builder.create(&cargo_config_dir.join("config.toml"), &config);
899910
}
900911

901912
tarball.bare()

0 commit comments

Comments
 (0)