blob: 0eb7c4b266a9f3a529e1b3c555ac2bf1dee974c1 [file] [log] [blame] [view]
Corey Farwelld2cc79e2020-12-23 19:17:341# The Rust Programming Language
2
Peter Atashianbe43c652016-06-27 17:51:273This is the main source code repository for [Rust]. It contains the compiler,
Andreas Jonson30659cd2020-07-19 14:53:374standard library, and documentation.
Nick Hamann74f18182015-05-15 05:43:405
Alex Touchet8915ba72022-12-29 05:47:096[Rust]: https://www.rust-lang.org/
Tshepang Lekhonkhobea8680de2015-06-18 21:48:517
Gimbles93ebf462022-12-24 15:48:358**Note: this README is for _users_ rather than _contributors_.**
Alex Touchet8915ba72022-12-29 05:47:099If you wish to _contribute_ to the compiler, you should read
10[CONTRIBUTING.md](CONTRIBUTING.md) instead.
mark3f6928f2020-06-17 19:25:0011
Jack Moffitt8d64fa32013-07-18 23:27:4312## Quick Start
Brian Andersonc92d2ed2012-07-10 05:13:4813
Fuqiao Xue09ac4782017-06-09 05:37:2214Read ["Installation"] from [The Book].
Austin Seipp62c4d2c2012-01-23 21:53:1215
misagh3d23e552018-12-10 22:28:5516["Installation"]: https://doc.rust-lang.org/book/ch01-01-installation.html
Eli Friedmanbbbfed22015-08-09 21:15:0517[The Book]: https://doc.rust-lang.org/book/index.html
Jack Moffitt8d64fa32013-07-18 23:27:4318
Who? Me?!0c4602a2019-01-18 21:28:2319## Installing from Source
Jack Moffitt8d64fa32013-07-18 23:27:4320
Anirban22fc18f2020-06-25 10:59:3721The Rust build system uses a Python script called `x.py` to build the compiler,
zahash5b758f02022-09-11 11:09:1922which manages the bootstrapping process. It lives at the root of the project.
Lee Bradley4c12a5d2021-05-18 05:33:1723
Alex Touchet8915ba72022-12-29 05:47:0924The `x.py` command can be run directly on most Unix systems in the following
25format:
Lee Bradley4c12a5d2021-05-18 05:33:1726
27```sh
28./x.py <subcommand> [flags]
29```
30
Alex Touchet8915ba72022-12-29 05:47:0931This is how the documentation and examples assume you are running `x.py`.
32Some alternative ways are:
Lee Bradley4c12a5d2021-05-18 05:33:1733
34```sh
KaDiWa9bf40362022-12-25 23:33:3235# On a Unix shell if you don't have the necessary `python3` command
36./x <subcommand> [flags]
Lee Bradley4c12a5d2021-05-18 05:33:1737
KaDiWa9bf40362022-12-25 23:33:3238# On the Windows Command Prompt (if .py files are configured to run Python)
39x.py <subcommand> [flags]
40
41# You can also run Python yourself, e.g.:
42python x.py <subcommand> [flags]
Lee Bradley4c12a5d2021-05-18 05:33:1743```
44
Alex Touchet8915ba72022-12-29 05:47:0945More information about `x.py` can be found by running it with the `--help` flag
46or reading the [rustc dev guide][rustcguidebuild].
Eric Huss06c32562019-07-09 23:12:4147
Valentindf43dcd2020-07-03 09:42:1248[gettingstarted]: https://rustc-dev-guide.rust-lang.org/getting-started.html
Santiago Pastorinob3b32b72020-03-09 21:33:0449[rustcguidebuild]: https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html
Who? Me?!0c4602a2019-01-18 21:28:2350
Joshua Nelson7dae1b02022-12-24 01:03:5051### Dependencies
Kevin Yap24fa6be2015-02-21 22:46:0652
Joshua Nelson7dae1b02022-12-24 01:03:5053Make sure you have installed the dependencies:
54
Alex Touchet8915ba72022-12-29 05:47:0955* `python` 3 or 2.7
56* `git`
57* A C compiler (when building for the host, `cc` is enough; cross-compiling may
58 need additional compilers)
59* `curl` (not needed on Windows)
60* `pkg-config` if you are compiling on Linux and targeting Linux
61* `libiconv` (already included with glibc on Debian-based distros)
Steve Klabnikf645cad2015-02-13 17:26:4462
Alex Touchet8915ba72022-12-29 05:47:0963To build Cargo, you'll also need OpenSSL (`libssl-dev` or `openssl-devel` on
64most Unix distros).
Joshua Nelson7dae1b02022-12-24 01:03:5065
66If building LLVM from source, you'll need additional tools:
67
68* `g++`, `clang++`, or MSVC with versions listed on
69 [LLVM's documentation](https://llvm.org/docs/GettingStarted.html#host-c-toolchain-both-compiler-and-standard-library)
Alex Touchet8915ba72022-12-29 05:47:0970* `ninja`, or GNU `make` 3.81 or later (Ninja is recommended, especially on
71 Windows)
Joshua Nelson7dae1b02022-12-24 01:03:5072* `cmake` 3.13.4 or later
Alex Touchet8915ba72022-12-29 05:47:0973* `libstdc++-static` may be required on some Linux distributions such as Fedora
74 and Ubuntu
Joshua Nelson7dae1b02022-12-24 01:03:5075
Alex Touchet8915ba72022-12-29 05:47:0976On tier 1 or tier 2 with host tools platforms, you can also choose to download
77LLVM by setting `llvm.download-ci-llvm = true`.
Joshua Nelson7dae1b02022-12-24 01:03:5078Otherwise, you'll need LLVM installed and `llvm-config` in your path.
79See [the rustc-dev-guide for more info][sysllvm].
80
81[sysllvm]: https://rustc-dev-guide.rust-lang.org/building/new-target.html#using-pre-built-llvm
82
83
84### Building on a Unix-like system
85
861. Clone the [source] with `git`:
Jack Moffitt8d64fa32013-07-18 23:27:4387
Kevin Yap24fa6be2015-02-21 22:46:0688 ```sh
qlcom18ce4c12020-09-18 15:08:4889 git clone https://github.com/rust-lang/rust.git
90 cd rust
Kevin Yap24fa6be2015-02-21 22:46:0691 ```
Jack Moffitt8d64fa32013-07-18 23:27:4392
Brian Anderson4acc4832015-02-16 04:20:2593[source]: https://github.com/rust-lang/rust
94
Joshua Nelson7dae1b02022-12-24 01:03:50952. Configure the build settings:
Eric Huss06c32562019-07-09 23:12:4196
Alex Touchet8915ba72022-12-29 05:47:0997 The Rust build system uses a file named `config.toml` in the root of the
98 source tree to determine various configuration settings for the build.
99 Set up the defaults intended for distros to get started. You can see a full
100 list of options in `config.toml.example`.
Adrien Tétara30d61b2014-01-11 14:19:38101
Alex Touchet8915ba72022-12-29 05:47:09102 ```sh
103 printf 'profile = "user" \nchangelog-seen = 2 \n' > config.toml
104 ```
Adrien Tétara30d61b2014-01-11 14:19:38105
Alex Touchet8915ba72022-12-29 05:47:09106 If you plan to use `x.py install` to create an installation, it is
107 recommended that you set the `prefix` value in the `[install]` section to a
108 directory.
Eddie Kovsky71dfb012019-03-21 04:21:53109
Joshua Nelson7dae1b02022-12-24 01:03:501103. Build and install:
Eric Huss06c32562019-07-09 23:12:41111
Alex Touchet8915ba72022-12-29 05:47:09112 ```sh
113 ./x.py build && ./x.py install
114 ```
Eddie Kovsky71dfb012019-03-21 04:21:53115
Alex Touchet8915ba72022-12-29 05:47:09116 When complete, `./x.py install` will place several programs into
117 `$PREFIX/bin`: `rustc`, the Rust compiler, and `rustdoc`, the
118 API-documentation tool. If you've set `profile = "user"` or
119 `build.extended = true`, it will also include [Cargo], Rust's package
120 manager.
Brian Anderson21ed20b2015-02-16 04:41:16121
122[Cargo]: https://github.com/rust-lang/cargo
Jack Moffitt8d64fa32013-07-18 23:27:43123
Luqman Aden8b833552014-06-27 00:07:44124### Building on Windows
Luqman Aden8b833552014-06-27 00:07:44125
Alex Touchet8915ba72022-12-29 05:47:09126On Windows, we suggest using [winget] to install dependencies by running the
127following in a terminal:
Joshua Nelson7dae1b02022-12-24 01:03:50128
129```powershell
130winget install -e Python.Python.3
131winget install -e Kitware.CMake
132winget install -e Git.Git
133```
134
Alex Touchet8915ba72022-12-29 05:47:09135Then edit your system's `PATH` variable and add: `C:\Program Files\CMake\bin`.
136See
137[this guide on editing the system `PATH`](https://www.java.com/en/download/help/path.html)
138from the Java documentation.
Joshua Nelson7dae1b02022-12-24 01:03:50139
140[winget]: https://github.com/microsoft/winget-cli
141
Steve Klabnik011a23e2016-01-04 17:33:43142There are two prominent ABIs in use on Windows: the native (MSVC) ABI used by
zahash5b758f02022-09-11 11:09:19143Visual Studio and the GNU ABI used by the GCC toolchain. Which version of Rust
144you need depends largely on what C/C++ libraries you want to interoperate with.
Alex Touchet8915ba72022-12-29 05:47:09145Use the MSVC build of Rust to interop with software produced by Visual Studio
146and the GNU build to interop with GNU software built using the MinGW/MSYS2
147toolchain.
Steve Klabnik011a23e2016-01-04 17:33:43148
Steve Klabnik011a23e2016-01-04 17:33:43149#### MinGW
Steve Klabnik011a23e2016-01-04 17:33:43150
Alex Crichtoncb74a582016-06-27 23:02:06151[MSYS2][msys2] can be used to easily build Rust on Windows:
Luqman Aden8b833552014-06-27 00:07:44152
Trevor Spiteri3a3e7eb2021-03-10 07:41:53153[msys2]: https://www.msys2.org/
Luqman Aden8b833552014-06-27 00:07:44154
zahash5b758f02022-09-11 11:09:191551. Download the latest [MSYS2 installer][msys2] and go through the installer.
Alex Crichtoncb74a582016-06-27 23:02:06156
zahash5b758f02022-09-11 11:09:191572. Run `mingw32_shell.bat` or `mingw64_shell.bat` from the MSYS2 installation
zahasha91e6182022-09-11 15:45:55158 directory (e.g. `C:\msys64`), depending on whether you want 32-bit or 64-bit
Alex Crichtoncb74a582016-06-27 23:02:06159 Rust. (As of the latest version of MSYS2 you have to run `msys2_shell.cmd
Alex Touchet8915ba72022-12-29 05:47:09160 -mingw32` or `msys2_shell.cmd -mingw64` from the command line instead.)
Alex Crichtoncb74a582016-06-27 23:02:06161
1623. From this terminal, install the required tools:
Luqman Aden8b833552014-06-27 00:07:44163
Kevin Yap24fa6be2015-02-21 22:46:06164 ```sh
Jake Shadle371c0ea2015-08-28 07:46:23165 # Update package mirrors (may be needed if you have a fresh install of MSYS2)
qlcom18ce4c12020-09-18 15:08:48166 pacman -Sy pacman-mirrors
Alex Crichtoncb74a582016-06-27 23:02:06167
168 # Install build tools needed for Rust. If you're building a 32-bit compiler,
Alex Touchet8915ba72022-12-29 05:47:09169 # then replace "x86_64" below with "i686". If you've already got Git, Python,
170 # or CMake installed and in PATH you can remove them from this list.
171 # Note that it is important that you do **not** use the 'python2', 'cmake',
172 # and 'ninja' packages from the 'msys2' subsystem.
173 # The build has historically been known to fail with these packages.
qlcom18ce4c12020-09-18 15:08:48174 pacman -S git \
Alex Crichtoncb74a582016-06-27 23:02:06175 make \
176 diffutils \
Danny Hua2ebef832016-10-14 02:38:49177 tar \
Guillaume Gomez38eb3692019-11-21 12:57:40178 mingw-w64-x86_64-python \
Alex Crichtoncb74a582016-06-27 23:02:06179 mingw-w64-x86_64-cmake \
CDirkx00d459a2020-08-30 23:22:25180 mingw-w64-x86_64-gcc \
181 mingw-w64-x86_64-ninja
Steve Klabnik011a23e2016-01-04 17:33:43182 ```
Carlos Liam3967e1c2015-10-06 15:14:11183
Josh Driverfb2d7632017-02-23 10:45:301844. Navigate to Rust's source code (or clone it), then build it:
Kevin Yap24fa6be2015-02-21 22:46:06185
186 ```sh
qlcom18ce4c12020-09-18 15:08:48187 ./x.py build && ./x.py install
Kevin Yap24fa6be2015-02-21 22:46:06188 ```
Bryce Van Dykee24add2015-10-22 08:52:17189
Steve Klabnik011a23e2016-01-04 17:33:43190#### MSVC
Steve Klabnik011a23e2016-01-04 17:33:43191
Scott McMurray7171bd12019-05-14 04:54:47192MSVC builds of Rust additionally require an installation of Visual Studio 2017
Tushar Dahiya9397b6c2022-08-23 17:57:23193(or later) so `rustc` can use its linker. The simplest way is to get
Alex Touchet8915ba72022-12-29 05:47:09194[Visual Studio], check the "C++ build tools" and "Windows 10 SDK" workload.
Scott McMurray7171bd12019-05-14 04:54:47195
Sunreal3d6070d2019-06-07 16:14:52196[Visual Studio]: https://visualstudio.microsoft.com/downloads/
Scott McMurray7171bd12019-05-14 04:54:47197
Alex Touchet8915ba72022-12-29 05:47:09198(If you're installing CMake yourself, be careful that "C++ CMake tools for
199Windows" doesn't get included under "Individual components".)
Steve Klabnik011a23e2016-01-04 17:33:43200
Alex Crichton0e272de2016-11-16 20:31:19201With these dependencies installed, you can build the compiler in a `cmd.exe`
202shell with:
Steve Klabnik011a23e2016-01-04 17:33:43203
204```sh
qlcom18ce4c12020-09-18 15:08:48205python x.py build
Alex Crichton0e272de2016-11-16 20:31:19206```
207
Alex Touchet8915ba72022-12-29 05:47:09208Right now, building Rust only works with some known versions of Visual Studio.
209If you have a more recent version installed and the build system doesn't
210understand, you may need to force rustbuild to use an older version.
211This can be done by manually calling the appropriate vcvars file before running
212the bootstrap.
Alex Crichtonb67f23c2016-07-06 18:35:33213
Behnam Esfahbod88fe8ac2018-09-09 03:02:50214```batch
qlcom18ce4c12020-09-18 15:08:48215CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
216python x.py build
Peter Atashianbe43c652016-06-27 17:51:27217```
218
Josh Driverfb2d7632017-02-23 10:45:30219#### Specifying an ABI
Josh Driverfb2d7632017-02-23 10:45:30220
221Each specific ABI can also be used from either environment (for example, using
Dhirendra Kumar Kashyap3eaa4a32018-06-13 17:23:50222the GNU ABI in PowerShell) by using an explicit build triple. The available
Josh Driverfb2d7632017-02-23 10:45:30223Windows build triples are:
224- GNU ABI (using GCC)
225 - `i686-pc-windows-gnu`
226 - `x86_64-pc-windows-gnu`
227- The MSVC ABI
228 - `i686-pc-windows-msvc`
229 - `x86_64-pc-windows-msvc`
230
Matt Ickstadt081f32a2017-08-22 18:28:39231The build triple can be specified by either specifying `--build=<triple>` when
Alex Touchet8915ba72022-12-29 05:47:09232invoking `x.py` commands, or by creating a `config.toml` file (as described in
233[Installing from Source](#installing-from-source)), and modifying the `build`
234option under the `[build]` section.
Josh Driverfb2d7632017-02-23 10:45:30235
236### Configure and Make
Josh Driverfb2d7632017-02-23 10:45:30237
238While it's not the recommended build system, this project also provides a
239configure script and makefile (the latter of which just invokes `x.py`).
240
241```sh
qlcom18ce4c12020-09-18 15:08:48242./configure
243make && sudo make install
Josh Driverfb2d7632017-02-23 10:45:30244```
245
Alex Touchet8915ba72022-12-29 05:47:09246`configure` generates a `config.toml` which can also be used with normal `x.py`
247invocations.
Josh Driverfb2d7632017-02-23 10:45:30248
Steve Klabnikfd53ea22015-08-18 17:49:20249## Building Documentation
Steve Klabnikfd53ea22015-08-18 17:49:20250
Alex Touchet8915ba72022-12-29 05:47:09251If you'd like to build the documentation, it's almost the same:
Steve Klabnikfd53ea22015-08-18 17:49:20252
253```sh
qlcom18ce4c12020-09-18 15:08:48254./x.py doc
Steve Klabnikfd53ea22015-08-18 17:49:20255```
256
projektir6b7b2622017-03-13 05:01:32257The generated documentation will appear under `doc` in the `build` directory for
Alex Touchet8915ba72022-12-29 05:47:09258the ABI used. That is, if the ABI was `x86_64-pc-windows-msvc`, the directory
259will be `build\x86_64-pc-windows-msvc\doc`.
Steve Klabnikfd53ea22015-08-18 17:49:20260
Jack Moffitt8d64fa32013-07-18 23:27:43261## Notes
Jack Moffitt8d64fa32013-07-18 23:27:43262
Alex Touchet8915ba72022-12-29 05:47:09263Since the Rust compiler is written in Rust, it must be built by a precompiled
264"snapshot" version of itself (made in an earlier stage of development).
265As such, source builds require an Internet connection to fetch snapshots, and an
266OS that can execute the available snapshot binaries.
Austin Seipp62c4d2c2012-01-23 21:53:12267
Alex Touchet8915ba72022-12-29 05:47:09268See https://doc.rust-lang.org/nightly/rustc/platform-support.html for a list of
269supported platforms.
270Only "host tools" platforms have a pre-compiled snapshot binary available; to
271compile for a platform without host tools you must cross-compile.
Austin Seipp62c4d2c2012-01-23 21:53:12272
Alex Touchet8915ba72022-12-29 05:47:09273You may find that other platforms work, but these are our officially supported
274build environments that are most likely to work.
Austin Seipp62c4d2c2012-01-23 21:53:12275
Kevin Yap24fa6be2015-02-21 22:46:06276## Getting Help
Brian Andersoncd1fabe2014-08-22 18:04:35277
Joshua Nelsona06e5de2022-12-24 01:03:50278See https://www.rust-lang.org/community for a list of chat platforms and forums.
Steve Klabnikf645cad2015-02-13 17:26:44279
280## Contributing
Steve Klabnikf645cad2015-02-13 17:26:44281
Joshua Nelsona06e5de2022-12-24 01:03:50282See [CONTRIBUTING.md](CONTRIBUTING.md).
Camelid8783c622020-09-02 00:48:15283
Brian Andersonc92d2ed2012-07-10 05:13:48284## License
Austin Seipp62c4d2c2012-01-23 21:53:12285
Alex Touchet8915ba72022-12-29 05:47:09286Rust is primarily distributed under the terms of both the MIT license and the
287Apache License (Version 2.0), with portions covered by various BSD-like
288licenses.
Austin Seipp62c4d2c2012-01-23 21:53:12289
Peter Atashianbe43c652016-06-27 17:51:27290See [LICENSE-APACHE](LICENSE-APACHE), [LICENSE-MIT](LICENSE-MIT), and
291[COPYRIGHT](COPYRIGHT) for details.
Andrew Xu8ffb6fd2019-04-06 10:04:06292
293## Trademark
Andrew Xu8ffb6fd2019-04-06 10:04:06294
Liigo Zhuang9c65f9f2021-05-26 02:51:13295[The Rust Foundation][rust-foundation] owns and protects the Rust and Cargo
Alex Touchet8915ba72022-12-29 05:47:09296trademarks and logos (the "Rust Trademarks").
Andrew Xu8ffb6fd2019-04-06 10:04:06297
Alex Touchet8915ba72022-12-29 05:47:09298If you want to use these names or brands, please read the
299[media guide][media-guide].
Andrew Xu8ffb6fd2019-04-06 10:04:06300
Andrew Xu98beb122019-04-12 14:14:21301Third-party logos may be subject to third-party copyrights and trademarks. See
302[Licenses][policies-licenses] for details.
303
Liigo Zhuang2caaa072021-05-20 10:11:01304[rust-foundation]: https://foundation.rust-lang.org/
Alex Touchet8915ba72022-12-29 05:47:09305[media-guide]: https://foundation.rust-lang.org/policies/logo-policy-and-media-guide/
Andrew Xu98beb122019-04-12 14:14:21306[policies-licenses]: https://www.rust-lang.org/policies/licenses