blob: 6cf9577d3330eb06a47f194afc2ccac9342d4244 [file] [log] [blame] [view]
Andreas Jonson30659cd2020-07-19 14:53:371<a href = "https://www.rust-lang.org/">
Anirban4c33b7c2020-06-25 14:03:192<img width = "90%" height = "auto" src = "https://img.shields.io/badge/Rust-Programming%20Language-black?style=flat&logo=rust" alt = "The Rust Programming Language">
Anirban3a1ac282020-06-25 11:13:273</a>
Austin Seipp62c4d2c2012-01-23 21:53:124
Peter Atashianbe43c652016-06-27 17:51:275This is the main source code repository for [Rust]. It contains the compiler,
Andreas Jonson30659cd2020-07-19 14:53:376standard library, and documentation.
Nick Hamann74f18182015-05-15 05:43:407
Brian Anderson77938292015-11-09 21:22:168[Rust]: https://www.rust-lang.org
Tshepang Lekhonkhobea8680de2015-06-18 21:48:519
mark3f6928f2020-06-17 19:25:0010**Note: this README is for _users_ rather than _contributors_.**
11
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
mark3f6928f2020-06-17 19:25:0021**Note: If you wish to _contribute_ to the compiler, you should read the
22[Getting Started][gettingstarted] of the rustc-dev-guide instead of this
23section.**
Eric Huss06c32562019-07-09 23:12:4124
Anirban22fc18f2020-06-25 10:59:3725The Rust build system uses a Python script called `x.py` to build the compiler,
Andreas Jonson30659cd2020-07-19 14:53:3726which manages the bootstrapping process. More information about it can be found
Anirband6cf8fc2020-06-24 15:39:0827by running `./x.py --help` or reading the [rustc dev guide][rustcguidebuild].
Eric Huss06c32562019-07-09 23:12:4128
Valentindf43dcd2020-07-03 09:42:1229[gettingstarted]: https://rustc-dev-guide.rust-lang.org/getting-started.html
Santiago Pastorinob3b32b72020-03-09 21:33:0430[rustcguidebuild]: https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html
Who? Me?!0c4602a2019-01-18 21:28:2331
DutchGhost503048c2020-06-02 14:12:3632### Building on a Unix-like system
Adrien Tétara30d61b2014-01-11 14:19:38331. Make sure you have installed the dependencies:
Kevin Yap24fa6be2015-02-21 22:46:0634
Andreas Jonson166719a2019-08-31 06:50:0235 * `g++` 5.1 or later or `clang++` 3.5 or later
Guillaume Gomez38eb3692019-11-21 12:57:4036 * `python` 3 or 2.7
Kevin Yap24fa6be2015-02-21 22:46:0637 * GNU `make` 3.81 or later
Neil Williams4254b312016-08-17 04:30:1738 * `cmake` 3.4.3 or later
Josh Triplett30b7dac2020-07-29 18:37:3339 * `ninja`
Kevin Yap24fa6be2015-02-21 22:46:0640 * `curl`
41 * `git`
Aditya Atluri7dd5c662019-09-06 19:54:4242 * `ssl` which comes in `libssl-dev` or `openssl-devel`
=d695e242019-09-29 15:58:2943 * `pkg-config` if you are compiling on Linux and targeting Linux
Steve Klabnikf645cad2015-02-13 17:26:4444
Brian Anderson7430e582015-02-18 21:46:20452. Clone the [source] with `git`:
Jack Moffitt8d64fa32013-07-18 23:27:4346
Kevin Yap24fa6be2015-02-21 22:46:0647 ```sh
48 $ git clone https://github.com/rust-lang/rust.git
49 $ cd rust
50 ```
Jack Moffitt8d64fa32013-07-18 23:27:4351
Brian Anderson4acc4832015-02-16 04:20:2552[source]: https://github.com/rust-lang/rust
53
Eric Huss06c32562019-07-09 23:12:41543. Configure the build settings:
55
56 The Rust build system uses a file named `config.toml` in the root of the
57 source tree to determine various configuration settings for the build.
58 Copy the default `config.toml.example` to `config.toml` to get started.
Adrien Tétara30d61b2014-01-11 14:19:3859
Kevin Yap24fa6be2015-02-21 22:46:0660 ```sh
Eric Huss06c32562019-07-09 23:12:4161 $ cp config.toml.example config.toml
Kevin Yap24fa6be2015-02-21 22:46:0662 ```
Adrien Tétara30d61b2014-01-11 14:19:3863
Anirban3b5d7f82020-06-24 04:59:3564 If you plan to use `x.py install` to create an installation, it is recommended
65 that you set the `prefix` value in the `[install]` section to a directory.
Eddie Kovsky71dfb012019-03-21 04:21:5366
Aditya Atluri7dd5c662019-09-06 19:54:4267 Create install directory if you are not installing in default directory
68
Eric Huss06c32562019-07-09 23:12:41694. Build and install:
70
71 ```sh
72 $ ./x.py build && ./x.py install
Eddie Kovsky71dfb012019-03-21 04:21:5373 ```
74
Eric Huss06c32562019-07-09 23:12:4175 When complete, `./x.py install` will place several programs into
76 `$PREFIX/bin`: `rustc`, the Rust compiler, and `rustdoc`, the
Brian Anderson21ed20b2015-02-16 04:41:1677 API-documentation tool. This install does not include [Cargo],
Eric Huss06c32562019-07-09 23:12:4178 Rust's package manager. To build and install Cargo, you may
79 run `./x.py install cargo` or set the `build.extended` key in
80 `config.toml` to `true` to build and install all tools.
Brian Anderson21ed20b2015-02-16 04:41:1681
82[Cargo]: https://github.com/rust-lang/cargo
Jack Moffitt8d64fa32013-07-18 23:27:4383
Luqman Aden8b833552014-06-27 00:07:4484### Building on Windows
Luqman Aden8b833552014-06-27 00:07:4485
Steve Klabnik011a23e2016-01-04 17:33:4386There are two prominent ABIs in use on Windows: the native (MSVC) ABI used by
87Visual Studio, and the GNU ABI used by the GCC toolchain. Which version of Rust
88you need depends largely on what C/C++ libraries you want to interoperate with:
89for interop with software produced by Visual Studio use the MSVC build of Rust;
90for interop with GNU software built using the MinGW/MSYS2 toolchain use the GNU
91build.
92
Steve Klabnik011a23e2016-01-04 17:33:4393#### MinGW
Steve Klabnik011a23e2016-01-04 17:33:4394
Alex Crichtoncb74a582016-06-27 23:02:0695[MSYS2][msys2] can be used to easily build Rust on Windows:
Luqman Aden8b833552014-06-27 00:07:4496
Alex Crichtonb67f23c2016-07-06 18:35:3397[msys2]: https://msys2.github.io/
Luqman Aden8b833552014-06-27 00:07:4498
Alex Crichtoncb74a582016-06-27 23:02:06991. Grab the latest [MSYS2 installer][msys2] and go through the installer.
100
1012. Run `mingw32_shell.bat` or `mingw64_shell.bat` from wherever you installed
102 MSYS2 (i.e. `C:\msys64`), depending on whether you want 32-bit or 64-bit
103 Rust. (As of the latest version of MSYS2 you have to run `msys2_shell.cmd
104 -mingw32` or `msys2_shell.cmd -mingw64` from the command line instead)
105
1063. From this terminal, install the required tools:
Luqman Aden8b833552014-06-27 00:07:44107
Kevin Yap24fa6be2015-02-21 22:46:06108 ```sh
Jake Shadle371c0ea2015-08-28 07:46:23109 # Update package mirrors (may be needed if you have a fresh install of MSYS2)
Jake Shadle7ab8ed82015-08-28 18:24:13110 $ pacman -Sy pacman-mirrors
Alex Crichtoncb74a582016-06-27 23:02:06111
112 # Install build tools needed for Rust. If you're building a 32-bit compiler,
113 # then replace "x86_64" below with "i686". If you've already got git, python,
114 # or CMake installed and in PATH you can remove them from this list. Note
CDirkx00d459a2020-08-30 23:22:25115 # that it is important that you do **not** use the 'python2', 'cmake' and 'ninja'
Corey Farwell273cc302016-12-21 18:58:46116 # packages from the 'msys2' subsystem. The build has historically been known
117 # to fail with these packages.
Alex Crichtoncb74a582016-06-27 23:02:06118 $ pacman -S git \
119 make \
120 diffutils \
Danny Hua2ebef832016-10-14 02:38:49121 tar \
Guillaume Gomez38eb3692019-11-21 12:57:40122 mingw-w64-x86_64-python \
Alex Crichtoncb74a582016-06-27 23:02:06123 mingw-w64-x86_64-cmake \
CDirkx00d459a2020-08-30 23:22:25124 mingw-w64-x86_64-gcc \
125 mingw-w64-x86_64-ninja
Steve Klabnik011a23e2016-01-04 17:33:43126 ```
Carlos Liam3967e1c2015-10-06 15:14:11127
Josh Driverfb2d7632017-02-23 10:45:301284. Navigate to Rust's source code (or clone it), then build it:
Kevin Yap24fa6be2015-02-21 22:46:06129
130 ```sh
Marc-Antoine Perennou150d6442017-05-18 20:48:14131 $ ./x.py build && ./x.py install
Kevin Yap24fa6be2015-02-21 22:46:06132 ```
Bryce Van Dykee24add2015-10-22 08:52:17133
Steve Klabnik011a23e2016-01-04 17:33:43134#### MSVC
Steve Klabnik011a23e2016-01-04 17:33:43135
Scott McMurray7171bd12019-05-14 04:54:47136MSVC builds of Rust additionally require an installation of Visual Studio 2017
137(or later) so `rustc` can use its linker. The simplest way is to get the
Sunreal1cf662e2019-06-07 14:08:22138[Visual Studio], check the “C++ build tools” and “Windows 10 SDK” workload.
Scott McMurray7171bd12019-05-14 04:54:47139
Sunreal3d6070d2019-06-07 16:14:52140[Visual Studio]: https://visualstudio.microsoft.com/downloads/
Scott McMurray7171bd12019-05-14 04:54:47141
Scott McMurray67ee2862019-05-24 06:40:07142(If you're installing cmake yourself, be careful that “C++ CMake tools for
143Windows” doesn't get included under “Individual components”.)
Steve Klabnik011a23e2016-01-04 17:33:43144
Alex Crichton0e272de2016-11-16 20:31:19145With these dependencies installed, you can build the compiler in a `cmd.exe`
146shell with:
Steve Klabnik011a23e2016-01-04 17:33:43147
148```sh
Alex Crichton0e272de2016-11-16 20:31:19149> python x.py build
150```
151
Dhirendra Kumar Kashyap3eaa4a32018-06-13 17:23:50152Currently, building Rust only works with some known versions of Visual Studio. If
Anirban886f81e2020-06-23 10:41:13153you have a more recent version installed and the build system doesn't understand,
154you may need to force rustbuild to use an older version. This can be done
Alex Crichtonb67f23c2016-07-06 18:35:33155by manually calling the appropriate vcvars file before running the bootstrap.
156
Behnam Esfahbod88fe8ac2018-09-09 03:02:50157```batch
Martin Finkel54e268c2019-07-31 03:58:17158> CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
Behnam Esfahbod88fe8ac2018-09-09 03:02:50159> python x.py build
Peter Atashianbe43c652016-06-27 17:51:27160```
161
Josh Driverfb2d7632017-02-23 10:45:30162#### Specifying an ABI
Josh Driverfb2d7632017-02-23 10:45:30163
164Each specific ABI can also be used from either environment (for example, using
Dhirendra Kumar Kashyap3eaa4a32018-06-13 17:23:50165the GNU ABI in PowerShell) by using an explicit build triple. The available
Josh Driverfb2d7632017-02-23 10:45:30166Windows build triples are:
167- GNU ABI (using GCC)
168 - `i686-pc-windows-gnu`
169 - `x86_64-pc-windows-gnu`
170- The MSVC ABI
171 - `i686-pc-windows-msvc`
172 - `x86_64-pc-windows-msvc`
173
Matt Ickstadt081f32a2017-08-22 18:28:39174The build triple can be specified by either specifying `--build=<triple>` when
Josh Driverfb2d7632017-02-23 10:45:30175invoking `x.py` commands, or by copying the `config.toml` file (as described
Eric Huss06c32562019-07-09 23:12:41176in [Installing From Source](#installing-from-source)), and modifying the
177`build` option under the `[build]` section.
Josh Driverfb2d7632017-02-23 10:45:30178
179### Configure and Make
Josh Driverfb2d7632017-02-23 10:45:30180
181While it's not the recommended build system, this project also provides a
182configure script and makefile (the latter of which just invokes `x.py`).
183
184```sh
185$ ./configure
186$ make && sudo make install
187```
188
Dhirendra Kumar Kashyapb0a55552018-06-13 17:50:50189When using the configure script, the generated `config.mk` file may override the
Josh Driverfb2d7632017-02-23 10:45:30190`config.toml` file. To go back to the `config.toml` file, delete the generated
191`config.mk` file.
192
Steve Klabnikfd53ea22015-08-18 17:49:20193## Building Documentation
Steve Klabnikfd53ea22015-08-18 17:49:20194
195If you’d like to build the documentation, it’s almost the same:
196
197```sh
Josh Driverfb2d7632017-02-23 10:45:30198$ ./x.py doc
Steve Klabnikfd53ea22015-08-18 17:49:20199```
200
projektir6b7b2622017-03-13 05:01:32201The generated documentation will appear under `doc` in the `build` directory for
202the ABI used. I.e., if the ABI was `x86_64-pc-windows-msvc`, the directory will be
203`build\x86_64-pc-windows-msvc\doc`.
Steve Klabnikfd53ea22015-08-18 17:49:20204
Jack Moffitt8d64fa32013-07-18 23:27:43205## Notes
Jack Moffitt8d64fa32013-07-18 23:27:43206
207Since the Rust compiler is written in Rust, it must be built by a
Dhirendra Kumar Kashyap3eaa4a32018-06-13 17:23:50208precompiled "snapshot" version of itself (made in an earlier stage of
Jack Moffitt8d64fa32013-07-18 23:27:43209development). As such, source builds require a connection to the Internet, to
Dhirendra Kumar Kashyapb0a55552018-06-13 17:50:50210fetch snapshots, and an OS that can execute the available snapshot binaries.
Austin Seipp62c4d2c2012-01-23 21:53:12211
Brian Anderson4c833af2012-10-11 00:56:38212Snapshot binaries are currently built and tested on several platforms:
Brian Anderson3403e412012-07-10 05:20:32213
Lzu Tao029ff372020-08-31 14:43:54214| Platform / Architecture | x86 | x86_64 |
215|---------------------------------------------|-----|--------|
216| Windows (7, 8, 10, ...) | ✓ | ✓ |
217| Linux (kernel 2.6.32, glibc 2.11 or later) | ✓ | ✓ |
Lzu Tao116ad982020-09-01 01:11:05218| macOS (10.7 Lion or later) | (\*) | ✓ |
219
220(\*): Apple dropped support for running 32-bit binaries starting from macOS 10.15 and iOS 11.
221Due to this decision from Apple, the targets are no longer useful to our users.
222Please read [our blog post][macx32] for more info.
223
224[macx32]: https://blog.rust-lang.org/2020/01/03/reducing-support-for-32-bit-apple-targets.html
Austin Seipp62c4d2c2012-01-23 21:53:12225
Adrien Tétara30d61b2014-01-11 14:19:38226You may find that other platforms work, but these are our officially
Brian Anderson4c833af2012-10-11 00:56:38227supported build environments that are most likely to work.
Austin Seipp62c4d2c2012-01-23 21:53:12228
Kevin Yap24fa6be2015-02-21 22:46:06229## Getting Help
Brian Andersoncd1fabe2014-08-22 18:04:35230
231The Rust community congregates in a few places:
232
Kevin Yap24fa6be2015-02-21 22:46:06233* [Stack Overflow] - Direct questions about using the language.
234* [users.rust-lang.org] - General discussion and broader questions.
Brian Anderson5716ede2015-01-29 23:49:00235* [/r/rust] - News and general discussion.
Brian Andersoncd1fabe2014-08-22 18:04:35236
Maxwell Paul Bricknerf7e90412017-04-19 21:45:48237[Stack Overflow]: https://stackoverflow.com/questions/tagged/rust
238[/r/rust]: https://reddit.com/r/rust
Eli Friedmanbbbfed22015-08-09 21:15:05239[users.rust-lang.org]: https://users.rust-lang.org/
Steve Klabnikf645cad2015-02-13 17:26:44240
241## Contributing
Steve Klabnikf645cad2015-02-13 17:26:44242
mark3f6928f2020-06-17 19:25:00243If you are interested in contributing to the Rust project, please take a look
244at the [Getting Started][gettingstarted] guide in the [rustc-dev-guide].
Brian Anderson46189552015-02-16 04:58:06245
Camelid8783c622020-09-02 00:48:15246[rustc-dev-guide]: https://rustc-dev-guide.rust-lang.org
247
Brian Andersonc92d2ed2012-07-10 05:13:48248## License
Austin Seipp62c4d2c2012-01-23 21:53:12249
Brian Anderson11a99182012-12-28 21:40:33250Rust is primarily distributed under the terms of both the MIT license
251and the Apache License (Version 2.0), with portions covered by various
252BSD-like licenses.
Austin Seipp62c4d2c2012-01-23 21:53:12253
Peter Atashianbe43c652016-06-27 17:51:27254See [LICENSE-APACHE](LICENSE-APACHE), [LICENSE-MIT](LICENSE-MIT), and
255[COPYRIGHT](COPYRIGHT) for details.
Andrew Xu8ffb6fd2019-04-06 10:04:06256
257## Trademark
Andrew Xu8ffb6fd2019-04-06 10:04:06258
259The Rust programming language is an open source, community project governed
260by a core team. It is also sponsored by the Mozilla Foundation (“Mozilla”),
261which owns and protects the Rust and Cargo trademarks and logos
262(the “Rust Trademarks”).
263
264If you want to use these names or brands, please read the [media guide][media-guide].
265
Andrew Xu98beb122019-04-12 14:14:21266Third-party logos may be subject to third-party copyrights and trademarks. See
267[Licenses][policies-licenses] for details.
268
Andrew Xu8ffb6fd2019-04-06 10:04:06269[media-guide]: https://www.rust-lang.org/policies/media-guide
Andrew Xu98beb122019-04-12 14:14:21270[policies-licenses]: https://www.rust-lang.org/policies/licenses