Skip to content

Commit 0820e31

Browse files
authored
Rollup merge of #110541 - jyn514:fix-configure, r=ozkanonur
Fix various configure bugs Fixes #107050. Fixes #108928. Closes #108641. I recommend reading this commit-by-commit to see the commit descriptions, but the code changes are small. This also changes the README to suggest `configure` instead of `printf`, as well as a few other cleanups described in the commit message.
2 parents b59658c + 8a9668d commit 0820e31

File tree

3 files changed

+32
-31
lines changed

3 files changed

+32
-31
lines changed

README.md

+25-26
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Read ["Installation"] from [The Book].
2222

2323
The Rust build system uses a Python script called `x.py` to build the compiler,
2424
which manages the bootstrapping process. It lives at the root of the project.
25+
It also uses a file named `config.toml` to determine various configuration settings for the build.
26+
You can see a full list of options in `config.example.toml`.
2527

2628
The `x.py` command can be run directly on most Unix systems in the following
2729
format:
@@ -85,6 +87,8 @@ See [the rustc-dev-guide for more info][sysllvm].
8587

8688
### Building on a Unix-like system
8789

90+
#### Build steps
91+
8892
1. Clone the [source] with `git`:
8993

9094
```sh
@@ -96,18 +100,13 @@ See [the rustc-dev-guide for more info][sysllvm].
96100

97101
2. Configure the build settings:
98102

99-
The Rust build system uses a file named `config.toml` in the root of the
100-
source tree to determine various configuration settings for the build.
101-
Set up the defaults intended for distros to get started. You can see a full
102-
list of options in `config.example.toml`.
103-
104103
```sh
105-
printf 'profile = "user" \nchangelog-seen = 2 \n' > config.toml
104+
./configure
106105
```
107106

108107
If you plan to use `x.py install` to create an installation, it is
109108
recommended that you set the `prefix` value in the `[install]` section to a
110-
directory.
109+
directory: `./configure --set install.prefix=<path>`
111110

112111
3. Build and install:
113112

@@ -117,12 +116,25 @@ See [the rustc-dev-guide for more info][sysllvm].
117116

118117
When complete, `./x.py install` will place several programs into
119118
`$PREFIX/bin`: `rustc`, the Rust compiler, and `rustdoc`, the
120-
API-documentation tool. If you've set `profile = "user"` or
121-
`build.extended = true`, it will also include [Cargo], Rust's package
122-
manager.
119+
API-documentation tool. By default, it will also include [Cargo], Rust's package manager.
120+
You can disable this behavior by passing `--set build.extended=false` to `./configure`.
123121

124122
[Cargo]: https://github.com/rust-lang/cargo
125123

124+
#### Configure and Make
125+
126+
This project provides a configure script and makefile (the latter of which just invokes `x.py`).
127+
`./configure` is the recommended way to programatically generate a `config.toml`. `make` is not
128+
recommended (we suggest using `x.py` directly), but it is supported and we try not to break it
129+
unnecessarily.
130+
131+
```sh
132+
./configure
133+
make && sudo make install
134+
```
135+
136+
`configure` generates a `config.toml` which can also be used with normal `x.py` invocations.
137+
126138
### Building on Windows
127139

128140
On Windows, we suggest using [winget] to install dependencies by running the
@@ -186,7 +198,7 @@ toolchain.
186198
4. Navigate to Rust's source code (or clone it), then build it:
187199

188200
```sh
189-
./x.py build && ./x.py install
201+
python x.py setup user && python x.py build && python x.py install
190202
```
191203

192204
#### MSVC
@@ -204,6 +216,7 @@ With these dependencies installed, you can build the compiler in a `cmd.exe`
204216
shell with:
205217

206218
```sh
219+
python x.py setup user
207220
python x.py build
208221
```
209222

@@ -232,21 +245,7 @@ Windows build triples are:
232245

233246
The build triple can be specified by either specifying `--build=<triple>` when
234247
invoking `x.py` commands, or by creating a `config.toml` file (as described in
235-
[Installing from Source](#installing-from-source)), and modifying the `build`
236-
option under the `[build]` section.
237-
238-
### Configure and Make
239-
240-
While it's not the recommended build system, this project also provides a
241-
configure script and makefile (the latter of which just invokes `x.py`).
242-
243-
```sh
244-
./configure
245-
make && sudo make install
246-
```
247-
248-
`configure` generates a `config.toml` which can also be used with normal `x.py`
249-
invocations.
248+
[Building on a Unix-like system](#building-on-a-unix-like-system)), and passing `--set build.build=<triple>` to `./configure`.
250249

251250
## Building Documentation
252251

src/bootstrap/bootstrap_test.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def serialize_and_parse(self, args):
9797
def test_no_args(self):
9898
build = self.serialize_and_parse([])
9999
self.assertEqual(build.get_toml("changelog-seen"), '2')
100+
self.assertEqual(build.get_toml("profile"), 'user')
100101
self.assertIsNone(build.get_toml("llvm.download-ci-llvm"))
101102

102103
def test_set_section(self):
@@ -107,10 +108,9 @@ def test_set_target(self):
107108
build = self.serialize_and_parse(["--set", "target.x86_64-unknown-linux-gnu.cc=gcc"])
108109
self.assertEqual(build.get_toml("cc", section="target.x86_64-unknown-linux-gnu"), 'gcc')
109110

110-
# Uncomment when #108928 is fixed.
111-
# def test_set_top_level(self):
112-
# build = self.serialize_and_parse(["--set", "profile=compiler"])
113-
# self.assertEqual(build.get_toml("profile"), 'compiler')
111+
def test_set_top_level(self):
112+
build = self.serialize_and_parse(["--set", "profile=compiler"])
113+
self.assertEqual(build.get_toml("profile"), 'compiler')
114114

115115
if __name__ == '__main__':
116116
SUITE = unittest.TestSuite()

src/bootstrap/configure.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,8 @@ def parse_example_config(known_args, config):
417417
# Avoid using quotes unless it's necessary.
418418
targets[target][0] = targets[target][0].replace("x86_64-unknown-linux-gnu", "'{}'".format(target) if "." in target else target)
419419

420+
if 'profile' not in config:
421+
set('profile', 'user', config)
420422
configure_file(sections, top_level_keys, targets, config)
421423
return section_order, sections, targets
422424

@@ -475,7 +477,7 @@ def configure_section(lines, config):
475477
def configure_top_level_key(lines, top_level_key, value):
476478
for i, line in enumerate(lines):
477479
if line.startswith('#' + top_level_key + ' = ') or line.startswith(top_level_key + ' = '):
478-
lines[i] = "{} = {}".format(top_level_key, value)
480+
lines[i] = "{} = {}".format(top_level_key, to_toml(value))
479481
return
480482

481483
raise RuntimeError("failed to find config line for {}".format(top_level_key))

0 commit comments

Comments
 (0)