Skip to content

Commit 06c3256

Browse files
committed
Update cargo-vendor usage
1 parent 5d8ffb5 commit 06c3256

File tree

4 files changed

+71
-95
lines changed

4 files changed

+71
-95
lines changed

CONTRIBUTING.md

+1-8
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ Speaking of tests, Rust has a comprehensive test suite. More information about
179179
it can be found [here][rctd].
180180

181181
### External Dependencies
182-
[external-dependencies]: #external-dependencies
183182

184183
Currently building Rust will also build the following external projects:
185184

@@ -209,7 +208,6 @@ Breakage is not allowed in the beta and stable channels, and must be addressed
209208
before the PR is merged.
210209

211210
#### Breaking Tools Built With The Compiler
212-
[breaking-tools-built-with-the-compiler]: #breaking-tools-built-with-the-compiler
213211

214212
Rust's build system builds a number of tools that make use of the
215213
internals of the compiler. This includes
@@ -242,7 +240,7 @@ Here are those same steps in detail:
242240
`config.toml.example` in the root directory of the Rust repository.
243241
Set `submodules = false` in the `[build]` section. This will prevent `x.py`
244242
from resetting to the original branch after you make your changes. If you
245-
need to [update any submodules to their latest versions][updating-submodules],
243+
need to [update any submodules to their latest versions](#updating-submodules),
246244
see the section of this file about that for more information.
247245
2. (optional) Run `./x.py test src/tools/rustfmt` (substituting the submodule
248246
that broke for `rustfmt`). Fix any errors in the submodule (and possibly others).
@@ -256,7 +254,6 @@ Here are those same steps in detail:
256254
8. (optional) Send a PR to rust-lang/rust updating the submodule.
257255

258256
#### Updating submodules
259-
[updating-submodules]: #updating-submodules
260257

261258
These instructions are specific to updating `rustfmt`, however they may apply
262259
to the other submodules as well. Please help by improving these instructions
@@ -310,7 +307,6 @@ This should change the version listed in `Cargo.lock` to the new version you upd
310307
the submodule to. Running `./x.py build` should work now.
311308

312309
## Writing Documentation
313-
[writing-documentation]: #writing-documentation
314310

315311
Documentation improvements are very welcome. The source of `doc.rust-lang.org`
316312
is located in `src/doc` in the tree, and standard API documentation is generated
@@ -337,7 +333,6 @@ tracker in that repo is also a great way to find things that need doing. There
337333
are issues for beginners and advanced compiler devs alike!
338334

339335
## Issue Triage
340-
[issue-triage]: #issue-triage
341336

342337
Sometimes, an issue will stay open, even though the bug has been fixed. And
343338
sometimes, the original bug may go stale because something has changed in the
@@ -405,7 +400,6 @@ If you're looking for somewhere to start, check out the [E-easy][eeasy] tag.
405400
[rfcbot]: https://github.com/anp/rfcbot-rs/
406401

407402
## Out-of-tree Contributions
408-
[out-of-tree-contributions]: #out-of-tree-contributions
409403

410404
There are a number of other ways to contribute to Rust that don't deal with
411405
this repository.
@@ -425,7 +419,6 @@ valuable!
425419
[community-library]: https://github.com/rust-lang/rfcs/labels/A-community-library
426420

427421
## Helpful Links and Information
428-
[helpful-info]: #helpful-info
429422

430423
For people new to Rust, and just starting to contribute, or even for
431424
more seasoned developers, some useful places to look for information

README.md

+27-41
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@ standard library, and documentation.
66
[Rust]: https://www.rust-lang.org
77

88
## Quick Start
9-
[quick-start]: #quick-start
109

1110
Read ["Installation"] from [The Book].
1211

1312
["Installation"]: https://doc.rust-lang.org/book/ch01-01-installation.html
1413
[The Book]: https://doc.rust-lang.org/book/index.html
1514

1615
## Installing from Source
17-
[building-from-source]: #building-from-source
1816

19-
_Note: If you wish to contribute to the compiler, you should read
20-
[this chapter](https://rust-lang.github.io/rustc-guide/how-to-build-and-run.html)
21-
of the rustc-guide instead of this section._
17+
_Note: If you wish to contribute to the compiler, you should read [this
18+
chapter][rustcguidebuild] of the rustc-guide instead of this section._
19+
20+
The Rust build system has a Python script called `x.py` to bootstrap building
21+
the compiler. More information about it may be found by running `./x.py --help`
22+
or reading the [rustc guide][rustcguidebuild].
23+
24+
[rustcguidebuild]: https://rust-lang.github.io/rustc-guide/how-to-build-and-run.html
2225

2326
### Building on *nix
2427
1. Make sure you have installed the dependencies:
@@ -39,43 +42,36 @@ of the rustc-guide instead of this section._
3942

4043
[source]: https://github.com/rust-lang/rust
4144

42-
3. Build and install:
43-
44-
```sh
45-
$ ./x.py build && sudo ./x.py install
46-
```
45+
3. Configure the build settings:
4746

48-
If after running `sudo ./x.py install` you see an error message like
47+
The Rust build system uses a file named `config.toml` in the root of the
48+
source tree to determine various configuration settings for the build.
49+
Copy the default `config.toml.example` to `config.toml` to get started.
4950

50-
```
51-
error: failed to load source for a dependency on 'cc'
51+
```sh
52+
$ cp config.toml.example config.toml
5253
```
5354

54-
then run these two commands and then try `sudo ./x.py install` again:
55+
It is recommended that if you plan to use the Rust build system to create
56+
an installation (using `./x.py install`) that you set the `prefix` value
57+
in the `[install]` section to a directory that you have write permissions.
5558

56-
```
57-
$ cargo install cargo-vendor
58-
```
59+
4. Build and install:
5960

61+
```sh
62+
$ ./x.py build && ./x.py install
6063
```
61-
$ cargo vendor
62-
```
63-
64-
> ***Note:*** Install locations can be adjusted by copying the config file
65-
> from `./config.toml.example` to `./config.toml`, and
66-
> adjusting the `prefix` option under `[install]`. Various other options, such
67-
> as enabling debug information, are also supported, and are documented in
68-
> the config file.
6964

70-
When complete, `sudo ./x.py install` will place several programs into
71-
`/usr/local/bin`: `rustc`, the Rust compiler, and `rustdoc`, the
65+
When complete, `./x.py install` will place several programs into
66+
`$PREFIX/bin`: `rustc`, the Rust compiler, and `rustdoc`, the
7267
API-documentation tool. This install does not include [Cargo],
73-
Rust's package manager, which you may also want to build.
68+
Rust's package manager. To build and install Cargo, you may
69+
run `./x.py install cargo` or set the `build.extended` key in
70+
`config.toml` to `true` to build and install all tools.
7471
7572
[Cargo]: https://github.com/rust-lang/cargo
7673
7774
### Building on Windows
78-
[building-on-windows]: #building-on-windows
7975
8076
There are two prominent ABIs in use on Windows: the native (MSVC) ABI used by
8177
Visual Studio, and the GNU ABI used by the GCC toolchain. Which version of Rust
@@ -85,7 +81,6 @@ for interop with GNU software built using the MinGW/MSYS2 toolchain use the GNU
8581
build.
8682
8783
#### MinGW
88-
[windows-mingw]: #windows-mingw
8984
9085
[MSYS2][msys2] can be used to easily build Rust on Windows:
9186
@@ -126,7 +121,6 @@ build.
126121
```
127122
128123
#### MSVC
129-
[windows-msvc]: #windows-msvc
130124
131125
MSVC builds of Rust additionally require an installation of Visual Studio 2017
132126
(or later) so `rustc` can use its linker. The simplest way is to get the
@@ -155,7 +149,6 @@ by manually calling the appropriate vcvars file before running the bootstrap.
155149
```
156150
157151
#### Specifying an ABI
158-
[specifying-an-abi]: #specifying-an-abi
159152
160153
Each specific ABI can also be used from either environment (for example, using
161154
the GNU ABI in PowerShell) by using an explicit build triple. The available
@@ -169,11 +162,10 @@ Windows build triples are:
169162
170163
The build triple can be specified by either specifying `--build=<triple>` when
171164
invoking `x.py` commands, or by copying the `config.toml` file (as described
172-
in Building From Source), and modifying the `build` option under the `[build]`
173-
section.
165+
in [Installing From Source](#installing-from-source)), and modifying the
166+
`build` option under the `[build]` section.
174167
175168
### Configure and Make
176-
[configure-and-make]: #configure-and-make
177169
178170
While it's not the recommended build system, this project also provides a
179171
configure script and makefile (the latter of which just invokes `x.py`).
@@ -188,7 +180,6 @@ When using the configure script, the generated `config.mk` file may override the
188180
`config.mk` file.
189181
190182
## Building Documentation
191-
[building-documentation]: #building-documentation
192183
193184
If you’d like to build the documentation, it’s almost the same:
194185
@@ -201,7 +192,6 @@ the ABI used. I.e., if the ABI was `x86_64-pc-windows-msvc`, the directory will
201192
`build\x86_64-pc-windows-msvc\doc`.
202193
203194
## Notes
204-
[notes]: #notes
205195
206196
Since the Rust compiler is written in Rust, it must be built by a
207197
precompiled "snapshot" version of itself (made in an earlier stage of
@@ -224,7 +214,6 @@ There is more advice about hacking on Rust in [CONTRIBUTING.md].
224214
[CONTRIBUTING.md]: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md
225215
226216
## Getting Help
227-
[getting-help]: #getting-help
228217
229218
The Rust community congregates in a few places:
230219
@@ -237,7 +226,6 @@ The Rust community congregates in a few places:
237226
[users.rust-lang.org]: https://users.rust-lang.org/
238227
239228
## Contributing
240-
[contributing]: #contributing
241229
242230
To contribute to Rust, please see [CONTRIBUTING](CONTRIBUTING.md).
243231
@@ -258,7 +246,6 @@ Also, you may find the [rustdocs for the compiler itself][rustdocs] useful.
258246
[rustdocs]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc/
259247
260248
## License
261-
[license]: #license
262249
263250
Rust is primarily distributed under the terms of both the MIT license
264251
and the Apache License (Version 2.0), with portions covered by various
@@ -268,7 +255,6 @@ See [LICENSE-APACHE](LICENSE-APACHE), [LICENSE-MIT](LICENSE-MIT), and
268255
[COPYRIGHT](COPYRIGHT) for details.
269256
270257
## Trademark
271-
[trademark]: #trademark
272258
273259
The Rust programming language is an open source, community project governed
274260
by a core team. It is also sponsored by the Mozilla Foundation (“Mozilla”),

src/bootstrap/bootstrap.py

+43-24
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,47 @@ def set_dev_environment(self):
735735
"""Set download URL for development environment"""
736736
self._download_url = 'https://dev-static.rust-lang.org'
737737

738+
def check_vendored_status(self):
739+
"""Check that vendoring is configured properly"""
740+
vendor_dir = os.path.join(self.rust_root, 'vendor')
741+
if 'SUDO_USER' in os.environ and not self.use_vendored_sources:
742+
if os.environ.get('USER') != os.environ['SUDO_USER']:
743+
self.use_vendored_sources = True
744+
print('info: looks like you are running this command under `sudo`')
745+
print(' and so in order to preserve your $HOME this will now')
746+
print(' use vendored sources by default.')
747+
if not os.path.exists(vendor_dir):
748+
print('error: vendoring required, but vendor directory does not exist.')
749+
print(' Run `cargo vendor` without sudo to initialize the '
750+
'vendor directory.')
751+
raise Exception("{} not found".format(vendor_dir))
752+
753+
if self.use_vendored_sources:
754+
if not os.path.exists('.cargo'):
755+
os.makedirs('.cargo')
756+
with output('.cargo/config') as cargo_config:
757+
cargo_config.write(
758+
"[source.crates-io]\n"
759+
"replace-with = 'vendored-sources'\n"
760+
"registry = 'https://example.com'\n"
761+
"\n"
762+
"[source.vendored-sources]\n"
763+
"directory = '{}/vendor'\n"
764+
.format(self.rust_root))
765+
else:
766+
if os.path.exists('.cargo'):
767+
shutil.rmtree('.cargo')
768+
769+
def ensure_vendored(self):
770+
"""Ensure that the vendored sources are available if needed"""
771+
vendor_dir = os.path.join(self.rust_root, 'vendor')
772+
# Note that this does not handle updating the vendored dependencies if
773+
# the rust git repository is updated. Normal development usually does
774+
# not use vendoring, so hopefully this isn't too much of a problem.
775+
if self.use_vendored_sources and not os.path.exists(vendor_dir):
776+
run([self.cargo(), "vendor"],
777+
verbose=self.verbose, cwd=self.rust_root)
778+
738779

739780
def bootstrap(help_triggered):
740781
"""Configure, fetch, build and run the initial bootstrap"""
@@ -776,30 +817,7 @@ def bootstrap(help_triggered):
776817

777818
build.use_locked_deps = '\nlocked-deps = true' in build.config_toml
778819

779-
if 'SUDO_USER' in os.environ and not build.use_vendored_sources:
780-
if os.environ.get('USER') != os.environ['SUDO_USER']:
781-
build.use_vendored_sources = True
782-
print('info: looks like you are running this command under `sudo`')
783-
print(' and so in order to preserve your $HOME this will now')
784-
print(' use vendored sources by default. Note that if this')
785-
print(' does not work you should run a normal build first')
786-
print(' before running a command like `sudo ./x.py install`')
787-
788-
if build.use_vendored_sources:
789-
if not os.path.exists('.cargo'):
790-
os.makedirs('.cargo')
791-
with output('.cargo/config') as cargo_config:
792-
cargo_config.write("""
793-
[source.crates-io]
794-
replace-with = 'vendored-sources'
795-
registry = 'https://example.com'
796-
797-
[source.vendored-sources]
798-
directory = '{}/vendor'
799-
""".format(build.rust_root))
800-
else:
801-
if os.path.exists('.cargo'):
802-
shutil.rmtree('.cargo')
820+
build.check_vendored_status()
803821

804822
data = stage0_data(build.rust_root)
805823
build.date = data['date']
@@ -815,6 +833,7 @@ def bootstrap(help_triggered):
815833
build.build = args.build or build.build_triple()
816834
build.download_stage0()
817835
sys.stdout.flush()
836+
build.ensure_vendored()
818837
build.build_bootstrap()
819838
sys.stdout.flush()
820839

src/bootstrap/dist.rs

-22
Original file line numberDiff line numberDiff line change
@@ -935,8 +935,6 @@ impl Step for Src {
935935
}
936936
}
937937

938-
const CARGO_VENDOR_VERSION: &str = "0.1.22";
939-
940938
#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
941939
pub struct PlainSourceTarball;
942940

@@ -998,26 +996,6 @@ impl Step for PlainSourceTarball {
998996

999997
// If we're building from git sources, we need to vendor a complete distribution.
1000998
if builder.rust_info.is_git() {
1001-
// Get cargo-vendor installed, if it isn't already.
1002-
let mut has_cargo_vendor = false;
1003-
let mut cmd = Command::new(&builder.initial_cargo);
1004-
for line in output(cmd.arg("install").arg("--list")).lines() {
1005-
has_cargo_vendor |= line.starts_with("cargo-vendor ");
1006-
}
1007-
if !has_cargo_vendor {
1008-
let mut cmd = builder.cargo(
1009-
builder.compiler(0, builder.config.build),
1010-
Mode::ToolBootstrap,
1011-
builder.config.build,
1012-
"install"
1013-
);
1014-
cmd.arg("--force")
1015-
.arg("--debug")
1016-
.arg("--vers").arg(CARGO_VENDOR_VERSION)
1017-
.arg("cargo-vendor");
1018-
builder.run(&mut cmd);
1019-
}
1020-
1021999
// Vendor all Cargo dependencies
10221000
let mut cmd = Command::new(&builder.initial_cargo);
10231001
cmd.arg("vendor")

0 commit comments

Comments
 (0)