blob: fca7d1cc5bd3c9d4c1afb75535ae219441752ef7 [file] [log] [blame] [view]
Brian Andersona08c5aa2012-07-10 05:18:371# The Rust Programming Language
Austin Seipp62c4d2c2012-01-23 21:53:122
Peter Atashianbe43c652016-06-27 17:51:273This is the main source code repository for [Rust]. It contains the compiler,
4standard library, and documentation.
Nick Hamann74f18182015-05-15 05:43:405
Brian Anderson77938292015-11-09 21:22:166[Rust]: https://www.rust-lang.org
Tshepang Lekhonkhobea8680de2015-06-18 21:48:517
Jack Moffitt8d64fa32013-07-18 23:27:438## Quick Start
Brian Andersonc92d2ed2012-07-10 05:13:489
Brian Anderson73cc4ed2015-02-16 05:20:2710Read ["Installing Rust"] from [The Book].
Austin Seipp62c4d2c2012-01-23 21:53:1211
Andrew Barchuk1339ca92016-01-29 09:45:3712["Installing Rust"]: https://doc.rust-lang.org/book/getting-started.html#installing-rust
Eli Friedmanbbbfed22015-08-09 21:15:0513[The Book]: https://doc.rust-lang.org/book/index.html
Jack Moffitt8d64fa32013-07-18 23:27:4314
Alex Crichton46867cc2014-04-02 23:59:3915## Building from Source
Jack Moffitt8d64fa32013-07-18 23:27:4316
Adrien Tétara30d61b2014-01-11 14:19:38171. Make sure you have installed the dependencies:
Kevin Yap24fa6be2015-02-21 22:46:0618
omtcyfz71020e32017-03-21 16:26:1919 * `g++` 4.7 or later or `clang++` 3.x or later
Robin Kruppe999051d2016-02-13 20:19:4420 * `python` 2.7 (but not 3.x)
Kevin Yap24fa6be2015-02-21 22:46:0621 * GNU `make` 3.81 or later
Neil Williams4254b312016-08-17 04:30:1722 * `cmake` 3.4.3 or later
Kevin Yap24fa6be2015-02-21 22:46:0623 * `curl`
24 * `git`
Steve Klabnikf645cad2015-02-13 17:26:4425
Brian Anderson7430e582015-02-18 21:46:20262. Clone the [source] with `git`:
Jack Moffitt8d64fa32013-07-18 23:27:4327
Kevin Yap24fa6be2015-02-21 22:46:0628 ```sh
29 $ git clone https://github.com/rust-lang/rust.git
30 $ cd rust
31 ```
Jack Moffitt8d64fa32013-07-18 23:27:4332
Brian Anderson4acc4832015-02-16 04:20:2533[source]: https://github.com/rust-lang/rust
34
353. Build and install:
Adrien Tétara30d61b2014-01-11 14:19:3836
Kevin Yap24fa6be2015-02-21 22:46:0637 ```sh
Josh Driverfb2d7632017-02-23 10:45:3038 $ ./x.py build && sudo ./x.py dist --install
Kevin Yap24fa6be2015-02-21 22:46:0639 ```
Adrien Tétara30d61b2014-01-11 14:19:3840
Josh Driverfb2d7632017-02-23 10:45:3041 > ***Note:*** Install locations can be adjusted by copying the config file
42 > from `./src/bootstrap/config.toml.example` to `./config.toml`, and
43 > adjusting the `prefix` option under `[install]`. Various other options are
44 > also supported, and are documented in the config file.
Jack Moffitt8d64fa32013-07-18 23:27:4345
Josh Driverfb2d7632017-02-23 10:45:3046 When complete, `sudo ./x.py dist --install` will place several programs into
Corey Richardson25fe2ca2014-02-02 07:56:5547 `/usr/local/bin`: `rustc`, the Rust compiler, and `rustdoc`, the
Brian Anderson21ed20b2015-02-16 04:41:1648 API-documentation tool. This install does not include [Cargo],
49 Rust's package manager, which you may also want to build.
50
51[Cargo]: https://github.com/rust-lang/cargo
Jack Moffitt8d64fa32013-07-18 23:27:4352
Luqman Aden8b833552014-06-27 00:07:4453### Building on Windows
54
Steve Klabnik011a23e2016-01-04 17:33:4355There are two prominent ABIs in use on Windows: the native (MSVC) ABI used by
56Visual Studio, and the GNU ABI used by the GCC toolchain. Which version of Rust
57you need depends largely on what C/C++ libraries you want to interoperate with:
58for interop with software produced by Visual Studio use the MSVC build of Rust;
59for interop with GNU software built using the MinGW/MSYS2 toolchain use the GNU
60build.
61
Steve Klabnik011a23e2016-01-04 17:33:4362#### MinGW
63
Alex Crichtoncb74a582016-06-27 23:02:0664[MSYS2][msys2] can be used to easily build Rust on Windows:
Luqman Aden8b833552014-06-27 00:07:4465
Alex Crichtonb67f23c2016-07-06 18:35:3366[msys2]: https://msys2.github.io/
Luqman Aden8b833552014-06-27 00:07:4467
Alex Crichtoncb74a582016-06-27 23:02:06681. Grab the latest [MSYS2 installer][msys2] and go through the installer.
69
702. Run `mingw32_shell.bat` or `mingw64_shell.bat` from wherever you installed
71 MSYS2 (i.e. `C:\msys64`), depending on whether you want 32-bit or 64-bit
72 Rust. (As of the latest version of MSYS2 you have to run `msys2_shell.cmd
73 -mingw32` or `msys2_shell.cmd -mingw64` from the command line instead)
74
753. From this terminal, install the required tools:
Luqman Aden8b833552014-06-27 00:07:4476
Kevin Yap24fa6be2015-02-21 22:46:0677 ```sh
Jake Shadle371c0ea2015-08-28 07:46:2378 # Update package mirrors (may be needed if you have a fresh install of MSYS2)
Jake Shadle7ab8ed82015-08-28 18:24:1379 $ pacman -Sy pacman-mirrors
Alex Crichtoncb74a582016-06-27 23:02:0680
81 # Install build tools needed for Rust. If you're building a 32-bit compiler,
82 # then replace "x86_64" below with "i686". If you've already got git, python,
83 # or CMake installed and in PATH you can remove them from this list. Note
Corey Farwell273cc302016-12-21 18:58:4684 # that it is important that you do **not** use the 'python2' and 'cmake'
85 # packages from the 'msys2' subsystem. The build has historically been known
86 # to fail with these packages.
Alex Crichtoncb74a582016-06-27 23:02:0687 $ pacman -S git \
88 make \
89 diffutils \
Danny Hua2ebef832016-10-14 02:38:4990 tar \
Alex Crichtoncb74a582016-06-27 23:02:0691 mingw-w64-x86_64-python2 \
92 mingw-w64-x86_64-cmake \
93 mingw-w64-x86_64-gcc
Steve Klabnik011a23e2016-01-04 17:33:4394 ```
Carlos Liam3967e1c2015-10-06 15:14:1195
Josh Driverfb2d7632017-02-23 10:45:30964. Navigate to Rust's source code (or clone it), then build it:
Kevin Yap24fa6be2015-02-21 22:46:0697
98 ```sh
Josh Driverfb2d7632017-02-23 10:45:3099 $ ./x.py build && ./x.py dist --install
Kevin Yap24fa6be2015-02-21 22:46:06100 ```
Bryce Van Dykee24add2015-10-22 08:52:17101
Steve Klabnik011a23e2016-01-04 17:33:43102#### MSVC
103
104MSVC builds of Rust additionally require an installation of Visual Studio 2013
105(or later) so `rustc` can use its linker. Make sure to check the “C++ tools”
Alex Crichtonb67f23c2016-07-06 18:35:33106option.
Steve Klabnik011a23e2016-01-04 17:33:43107
Alex Crichton0e272de2016-11-16 20:31:19108With these dependencies installed, you can build the compiler in a `cmd.exe`
109shell with:
Steve Klabnik011a23e2016-01-04 17:33:43110
111```sh
Alex Crichton0e272de2016-11-16 20:31:19112> python x.py build
113```
114
Alex Crichton0e272de2016-11-16 20:31:19115Currently building Rust only works with some known versions of Visual Studio. If
116you have a more recent version installed the build system doesn't understand
Alex Crichtonb67f23c2016-07-06 18:35:33117then you may need to force rustbuild to use an older version. This can be done
118by manually calling the appropriate vcvars file before running the bootstrap.
119
120```
Peter Atashianbe43c652016-06-27 17:51:27121CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat"
Alex Crichtona270b802016-10-21 20:18:09122python x.py build
Peter Atashianbe43c652016-06-27 17:51:27123```
124
Josh Driverfb2d7632017-02-23 10:45:30125#### Specifying an ABI
126
127Each specific ABI can also be used from either environment (for example, using
128the GNU ABI in powershell) by using an explicit build triple. The available
129Windows build triples are:
130- GNU ABI (using GCC)
131 - `i686-pc-windows-gnu`
132 - `x86_64-pc-windows-gnu`
133- The MSVC ABI
134 - `i686-pc-windows-msvc`
135 - `x86_64-pc-windows-msvc`
136
137The build triple can be specified by either specifying `--build=ABI` when
138invoking `x.py` commands, or by copying the `config.toml` file (as described
139in Building From Source), and modifying the `build` option under the `[build]`
140section.
141
142### Configure and Make
143
144While it's not the recommended build system, this project also provides a
145configure script and makefile (the latter of which just invokes `x.py`).
146
147```sh
148$ ./configure
149$ make && sudo make install
150```
151
Mátyás Mustohaf121e612017-03-06 11:29:52152When using the configure script, the generated `config.mk` file may override the
Josh Driverfb2d7632017-02-23 10:45:30153`config.toml` file. To go back to the `config.toml` file, delete the generated
154`config.mk` file.
155
Steve Klabnikfd53ea22015-08-18 17:49:20156## Building Documentation
157
158If you’d like to build the documentation, it’s almost the same:
159
160```sh
Josh Driverfb2d7632017-02-23 10:45:30161$ ./x.py doc
Steve Klabnikfd53ea22015-08-18 17:49:20162```
163
projektir6b7b2622017-03-13 05:01:32164The generated documentation will appear under `doc` in the `build` directory for
165the ABI used. I.e., if the ABI was `x86_64-pc-windows-msvc`, the directory will be
166`build\x86_64-pc-windows-msvc\doc`.
Steve Klabnikfd53ea22015-08-18 17:49:20167
Jack Moffitt8d64fa32013-07-18 23:27:43168## Notes
169
170Since the Rust compiler is written in Rust, it must be built by a
171precompiled "snapshot" version of itself (made in an earlier state of
172development). As such, source builds require a connection to the Internet, to
173fetch snapshots, and an OS that can execute the available snapshot binaries.
Austin Seipp62c4d2c2012-01-23 21:53:12174
Brian Anderson4c833af2012-10-11 00:56:38175Snapshot binaries are currently built and tested on several platforms:
Brian Anderson3403e412012-07-10 05:20:32176
c4rlo66ae4812016-09-01 21:42:51177| Platform / Architecture | x86 | x86_64 |
Richo Healey6f3701d2015-05-12 06:43:58178|--------------------------------|-----|--------|
179| Windows (7, 8, Server 2008 R2) | ✓ | ✓ |
180| Linux (2.6.18 or later) | ✓ | ✓ |
181| OSX (10.7 Lion or later) | ✓ | ✓ |
Austin Seipp62c4d2c2012-01-23 21:53:12182
Adrien Tétara30d61b2014-01-11 14:19:38183You may find that other platforms work, but these are our officially
Brian Anderson4c833af2012-10-11 00:56:38184supported build environments that are most likely to work.
Austin Seipp62c4d2c2012-01-23 21:53:12185
Peter Atashianbe43c652016-06-27 17:51:27186Rust currently needs between 600MiB and 1.5GiB to build, depending on platform.
187If it hits swap, it will take a very long time to build.
Brian Anderson4c833af2012-10-11 00:56:38188
Brian Andersonc2735712015-02-18 21:48:46189There is more advice about hacking on Rust in [CONTRIBUTING.md].
Austin Seipp62c4d2c2012-01-23 21:53:12190
Brian Andersonc2735712015-02-18 21:48:46191[CONTRIBUTING.md]: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md
Austin Seipp62c4d2c2012-01-23 21:53:12192
Kevin Yap24fa6be2015-02-21 22:46:06193## Getting Help
Brian Andersoncd1fabe2014-08-22 18:04:35194
195The Rust community congregates in a few places:
196
Kevin Yap24fa6be2015-02-21 22:46:06197* [Stack Overflow] - Direct questions about using the language.
198* [users.rust-lang.org] - General discussion and broader questions.
Brian Anderson5716ede2015-01-29 23:49:00199* [/r/rust] - News and general discussion.
Brian Andersoncd1fabe2014-08-22 18:04:35200
Kevin Yap24fa6be2015-02-21 22:46:06201[Stack Overflow]: http://stackoverflow.com/questions/tagged/rust
Brian Andersoncd1fabe2014-08-22 18:04:35202[/r/rust]: http://reddit.com/r/rust
Eli Friedmanbbbfed22015-08-09 21:15:05203[users.rust-lang.org]: https://users.rust-lang.org/
Steve Klabnikf645cad2015-02-13 17:26:44204
205## Contributing
206
Daniel Lobato García13d5e572015-03-08 21:37:23207To contribute to Rust, please see [CONTRIBUTING](CONTRIBUTING.md).
Brian Andersoncd1fabe2014-08-22 18:04:35208
Brian Anderson46189552015-02-16 04:58:06209Rust has an [IRC] culture and most real-time collaboration happens in a
210variety of channels on Mozilla's IRC network, irc.mozilla.org. The
211most popular channel is [#rust], a venue for general discussion about
David AO Lozanoc233f2e2016-03-31 02:07:53212Rust. And a good place to ask for help would be [#rust-beginners].
Brian Anderson46189552015-02-16 04:58:06213
214[IRC]: https://en.wikipedia.org/wiki/Internet_Relay_Chat
Brian Anderson7430e582015-02-18 21:46:20215[#rust]: irc://irc.mozilla.org/rust
David AO Lozanoc233f2e2016-03-31 02:07:53216[#rust-beginners]: irc://irc.mozilla.org/rust-beginners
Brian Anderson46189552015-02-16 04:58:06217
Brian Andersonc92d2ed2012-07-10 05:13:48218## License
Austin Seipp62c4d2c2012-01-23 21:53:12219
Brian Anderson11a99182012-12-28 21:40:33220Rust is primarily distributed under the terms of both the MIT license
221and the Apache License (Version 2.0), with portions covered by various
222BSD-like licenses.
Austin Seipp62c4d2c2012-01-23 21:53:12223
Peter Atashianbe43c652016-06-27 17:51:27224See [LICENSE-APACHE](LICENSE-APACHE), [LICENSE-MIT](LICENSE-MIT), and
225[COPYRIGHT](COPYRIGHT) for details.