Rollup merge of #110541 - jyn514:fix-configure, r=ozkanonur

Fix various configure bugs

Fixes https://github.com/rust-lang/rust/issues/107050. Fixes https://github.com/rust-lang/rust/issues/108928. Closes https://github.com/rust-lang/rust/pull/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.
This commit is contained in:
Matthias Krüger 2023-04-19 17:54:44 +02:00 committed by GitHub
commit 0820e31a00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 31 deletions

View file

@ -22,6 +22,8 @@ Read ["Installation"] from [The Book].
The Rust build system uses a Python script called `x.py` to build the compiler, The Rust build system uses a Python script called `x.py` to build the compiler,
which manages the bootstrapping process. It lives at the root of the project. which manages the bootstrapping process. It lives at the root of the project.
It also uses a file named `config.toml` to determine various configuration settings for the build.
You can see a full list of options in `config.example.toml`.
The `x.py` command can be run directly on most Unix systems in the following The `x.py` command can be run directly on most Unix systems in the following
format: format:
@ -85,6 +87,8 @@ See [the rustc-dev-guide for more info][sysllvm].
### Building on a Unix-like system ### Building on a Unix-like system
#### Build steps
1. Clone the [source] with `git`: 1. Clone the [source] with `git`:
```sh ```sh
@ -96,18 +100,13 @@ See [the rustc-dev-guide for more info][sysllvm].
2. Configure the build settings: 2. Configure the build settings:
The Rust build system uses a file named `config.toml` in the root of the
source tree to determine various configuration settings for the build.
Set up the defaults intended for distros to get started. You can see a full
list of options in `config.example.toml`.
```sh ```sh
printf 'profile = "user" \nchangelog-seen = 2 \n' > config.toml ./configure
``` ```
If you plan to use `x.py install` to create an installation, it is If you plan to use `x.py install` to create an installation, it is
recommended that you set the `prefix` value in the `[install]` section to a recommended that you set the `prefix` value in the `[install]` section to a
directory. directory: `./configure --set install.prefix=<path>`
3. Build and install: 3. Build and install:
@ -117,12 +116,25 @@ See [the rustc-dev-guide for more info][sysllvm].
When complete, `./x.py install` will place several programs into When complete, `./x.py install` will place several programs into
`$PREFIX/bin`: `rustc`, the Rust compiler, and `rustdoc`, the `$PREFIX/bin`: `rustc`, the Rust compiler, and `rustdoc`, the
API-documentation tool. If you've set `profile = "user"` or API-documentation tool. By default, it will also include [Cargo], Rust's package manager.
`build.extended = true`, it will also include [Cargo], Rust's package You can disable this behavior by passing `--set build.extended=false` to `./configure`.
manager.
[Cargo]: https://github.com/rust-lang/cargo [Cargo]: https://github.com/rust-lang/cargo
#### Configure and Make
This project provides a configure script and makefile (the latter of which just invokes `x.py`).
`./configure` is the recommended way to programatically generate a `config.toml`. `make` is not
recommended (we suggest using `x.py` directly), but it is supported and we try not to break it
unnecessarily.
```sh
./configure
make && sudo make install
```
`configure` generates a `config.toml` which can also be used with normal `x.py` invocations.
### Building on Windows ### Building on Windows
On Windows, we suggest using [winget] to install dependencies by running the On Windows, we suggest using [winget] to install dependencies by running the
@ -186,7 +198,7 @@ toolchain.
4. Navigate to Rust's source code (or clone it), then build it: 4. Navigate to Rust's source code (or clone it), then build it:
```sh ```sh
./x.py build && ./x.py install python x.py setup user && python x.py build && python x.py install
``` ```
#### MSVC #### MSVC
@ -204,6 +216,7 @@ With these dependencies installed, you can build the compiler in a `cmd.exe`
shell with: shell with:
```sh ```sh
python x.py setup user
python x.py build python x.py build
``` ```
@ -232,21 +245,7 @@ Windows build triples are:
The build triple can be specified by either specifying `--build=<triple>` when The build triple can be specified by either specifying `--build=<triple>` when
invoking `x.py` commands, or by creating a `config.toml` file (as described in invoking `x.py` commands, or by creating a `config.toml` file (as described in
[Installing from Source](#installing-from-source)), and modifying the `build` [Building on a Unix-like system](#building-on-a-unix-like-system)), and passing `--set build.build=<triple>` to `./configure`.
option under the `[build]` section.
### Configure and Make
While it's not the recommended build system, this project also provides a
configure script and makefile (the latter of which just invokes `x.py`).
```sh
./configure
make && sudo make install
```
`configure` generates a `config.toml` which can also be used with normal `x.py`
invocations.
## Building Documentation ## Building Documentation

View file

@ -97,6 +97,7 @@ class GenerateAndParseConfig(unittest.TestCase):
def test_no_args(self): def test_no_args(self):
build = self.serialize_and_parse([]) build = self.serialize_and_parse([])
self.assertEqual(build.get_toml("changelog-seen"), '2') self.assertEqual(build.get_toml("changelog-seen"), '2')
self.assertEqual(build.get_toml("profile"), 'user')
self.assertIsNone(build.get_toml("llvm.download-ci-llvm")) self.assertIsNone(build.get_toml("llvm.download-ci-llvm"))
def test_set_section(self): def test_set_section(self):
@ -107,10 +108,9 @@ class GenerateAndParseConfig(unittest.TestCase):
build = self.serialize_and_parse(["--set", "target.x86_64-unknown-linux-gnu.cc=gcc"]) build = self.serialize_and_parse(["--set", "target.x86_64-unknown-linux-gnu.cc=gcc"])
self.assertEqual(build.get_toml("cc", section="target.x86_64-unknown-linux-gnu"), 'gcc') self.assertEqual(build.get_toml("cc", section="target.x86_64-unknown-linux-gnu"), 'gcc')
# Uncomment when #108928 is fixed. def test_set_top_level(self):
# def test_set_top_level(self): build = self.serialize_and_parse(["--set", "profile=compiler"])
# build = self.serialize_and_parse(["--set", "profile=compiler"]) self.assertEqual(build.get_toml("profile"), 'compiler')
# self.assertEqual(build.get_toml("profile"), 'compiler')
if __name__ == '__main__': if __name__ == '__main__':
SUITE = unittest.TestSuite() SUITE = unittest.TestSuite()

View file

@ -417,6 +417,8 @@ def parse_example_config(known_args, config):
# Avoid using quotes unless it's necessary. # Avoid using quotes unless it's necessary.
targets[target][0] = targets[target][0].replace("x86_64-unknown-linux-gnu", "'{}'".format(target) if "." in target else target) targets[target][0] = targets[target][0].replace("x86_64-unknown-linux-gnu", "'{}'".format(target) if "." in target else target)
if 'profile' not in config:
set('profile', 'user', config)
configure_file(sections, top_level_keys, targets, config) configure_file(sections, top_level_keys, targets, config)
return section_order, sections, targets return section_order, sections, targets
@ -475,7 +477,7 @@ def configure_section(lines, config):
def configure_top_level_key(lines, top_level_key, value): def configure_top_level_key(lines, top_level_key, value):
for i, line in enumerate(lines): for i, line in enumerate(lines):
if line.startswith('#' + top_level_key + ' = ') or line.startswith(top_level_key + ' = '): if line.startswith('#' + top_level_key + ' = ') or line.startswith(top_level_key + ' = '):
lines[i] = "{} = {}".format(top_level_key, value) lines[i] = "{} = {}".format(top_level_key, to_toml(value))
return return
raise RuntimeError("failed to find config line for {}".format(top_level_key)) raise RuntimeError("failed to find config line for {}".format(top_level_key))