blob: 78a9f509bbcb4c79b37608963b241f748b8aa64b [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
Fuqiao Xue09ac4782017-06-09 05:37:2210Read ["Installation"] from [The Book].
Austin Seipp62c4d2c2012-01-23 21:53:1211
Fuqiao Xue09ac4782017-06-09 05:37:2212["Installation"]: https://doc.rust-lang.org/book/second-edition/ch01-01-installation.html
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
Marc-Antoine Perennou150d6442017-05-18 20:48:1438 $ ./x.py build && sudo ./x.py 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
Steven Fackler1126a852017-08-12 05:24:2542 > from `./config.toml.example` to `./config.toml`, and
Lee Bousfield857d9db2017-07-04 02:04:5743 > adjusting the `prefix` option under `[install]`. Various other options, such
44 > as enabling debug information, are also supported, and are documented in
45 > the config file.
Jack Moffitt8d64fa32013-07-18 23:27:4346
Marc-Antoine Perennou150d6442017-05-18 20:48:1447 When complete, `sudo ./x.py install` will place several programs into
Corey Richardson25fe2ca2014-02-02 07:56:5548 `/usr/local/bin`: `rustc`, the Rust compiler, and `rustdoc`, the
Brian Anderson21ed20b2015-02-16 04:41:1649 API-documentation tool. This install does not include [Cargo],
50 Rust's package manager, which you may also want to build.
51
52[Cargo]: https://github.com/rust-lang/cargo
Jack Moffitt8d64fa32013-07-18 23:27:4353
Luqman Aden8b833552014-06-27 00:07:4454### Building on Windows
55
Steve Klabnik011a23e2016-01-04 17:33:4356There are two prominent ABIs in use on Windows: the native (MSVC) ABI used by
57Visual Studio, and the GNU ABI used by the GCC toolchain. Which version of Rust
58you need depends largely on what C/C++ libraries you want to interoperate with:
59for interop with software produced by Visual Studio use the MSVC build of Rust;
60for interop with GNU software built using the MinGW/MSYS2 toolchain use the GNU
61build.
62
Steve Klabnik011a23e2016-01-04 17:33:4363#### MinGW
64
Alex Crichtoncb74a582016-06-27 23:02:0665[MSYS2][msys2] can be used to easily build Rust on Windows:
Luqman Aden8b833552014-06-27 00:07:4466
Alex Crichtonb67f23c2016-07-06 18:35:3367[msys2]: https://msys2.github.io/
Luqman Aden8b833552014-06-27 00:07:4468
Alex Crichtoncb74a582016-06-27 23:02:06691. Grab the latest [MSYS2 installer][msys2] and go through the installer.
70
712. Run `mingw32_shell.bat` or `mingw64_shell.bat` from wherever you installed
72 MSYS2 (i.e. `C:\msys64`), depending on whether you want 32-bit or 64-bit
73 Rust. (As of the latest version of MSYS2 you have to run `msys2_shell.cmd
74 -mingw32` or `msys2_shell.cmd -mingw64` from the command line instead)
75
763. From this terminal, install the required tools:
Luqman Aden8b833552014-06-27 00:07:4477
Kevin Yap24fa6be2015-02-21 22:46:0678 ```sh
Jake Shadle371c0ea2015-08-28 07:46:2379 # Update package mirrors (may be needed if you have a fresh install of MSYS2)
Jake Shadle7ab8ed82015-08-28 18:24:1380 $ pacman -Sy pacman-mirrors
Alex Crichtoncb74a582016-06-27 23:02:0681
82 # Install build tools needed for Rust. If you're building a 32-bit compiler,
83 # then replace "x86_64" below with "i686". If you've already got git, python,
84 # or CMake installed and in PATH you can remove them from this list. Note
Corey Farwell273cc302016-12-21 18:58:4685 # that it is important that you do **not** use the 'python2' and 'cmake'
86 # packages from the 'msys2' subsystem. The build has historically been known
87 # to fail with these packages.
Alex Crichtoncb74a582016-06-27 23:02:0688 $ pacman -S git \
89 make \
90 diffutils \
Danny Hua2ebef832016-10-14 02:38:4991 tar \
Alex Crichtoncb74a582016-06-27 23:02:0692 mingw-w64-x86_64-python2 \
93 mingw-w64-x86_64-cmake \
94 mingw-w64-x86_64-gcc
Steve Klabnik011a23e2016-01-04 17:33:4395 ```
Carlos Liam3967e1c2015-10-06 15:14:1196
Josh Driverfb2d7632017-02-23 10:45:30974. Navigate to Rust's source code (or clone it), then build it:
Kevin Yap24fa6be2015-02-21 22:46:0698
99 ```sh
Marc-Antoine Perennou150d6442017-05-18 20:48:14100 $ ./x.py build && ./x.py install
Kevin Yap24fa6be2015-02-21 22:46:06101 ```
Bryce Van Dykee24add2015-10-22 08:52:17102
Steve Klabnik011a23e2016-01-04 17:33:43103#### MSVC
104
105MSVC builds of Rust additionally require an installation of Visual Studio 2013
106(or later) so `rustc` can use its linker. Make sure to check the “C++ tools”
Alex Crichtonb67f23c2016-07-06 18:35:33107option.
Steve Klabnik011a23e2016-01-04 17:33:43108
Alex Crichton0e272de2016-11-16 20:31:19109With these dependencies installed, you can build the compiler in a `cmd.exe`
110shell with:
Steve Klabnik011a23e2016-01-04 17:33:43111
112```sh
Alex Crichton0e272de2016-11-16 20:31:19113> python x.py build
114```
115
Alex Crichton0e272de2016-11-16 20:31:19116Currently building Rust only works with some known versions of Visual Studio. If
117you have a more recent version installed the build system doesn't understand
Alex Crichtonb67f23c2016-07-06 18:35:33118then you may need to force rustbuild to use an older version. This can be done
119by manually calling the appropriate vcvars file before running the bootstrap.
120
121```
Peter Atashianbe43c652016-06-27 17:51:27122CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat"
Alex Crichtona270b802016-10-21 20:18:09123python x.py build
Peter Atashianbe43c652016-06-27 17:51:27124```
125
Josh Driverfb2d7632017-02-23 10:45:30126#### Specifying an ABI
127
128Each specific ABI can also be used from either environment (for example, using
129the GNU ABI in powershell) by using an explicit build triple. The available
130Windows build triples are:
131- GNU ABI (using GCC)
132 - `i686-pc-windows-gnu`
133 - `x86_64-pc-windows-gnu`
134- The MSVC ABI
135 - `i686-pc-windows-msvc`
136 - `x86_64-pc-windows-msvc`
137
Matt Ickstadt081f32a2017-08-22 18:28:39138The build triple can be specified by either specifying `--build=<triple>` when
Josh Driverfb2d7632017-02-23 10:45:30139invoking `x.py` commands, or by copying the `config.toml` file (as described
140in Building From Source), and modifying the `build` option under the `[build]`
141section.
142
143### Configure and Make
144
145While it's not the recommended build system, this project also provides a
146configure script and makefile (the latter of which just invokes `x.py`).
147
148```sh
149$ ./configure
150$ make && sudo make install
151```
152
Mátyás Mustohaf121e612017-03-06 11:29:52153When using the configure script, the generated `config.mk` file may override the
Josh Driverfb2d7632017-02-23 10:45:30154`config.toml` file. To go back to the `config.toml` file, delete the generated
155`config.mk` file.
156
Steve Klabnikfd53ea22015-08-18 17:49:20157## Building Documentation
158
159If you’d like to build the documentation, it’s almost the same:
160
161```sh
Josh Driverfb2d7632017-02-23 10:45:30162$ ./x.py doc
Steve Klabnikfd53ea22015-08-18 17:49:20163```
164
projektir6b7b2622017-03-13 05:01:32165The generated documentation will appear under `doc` in the `build` directory for
166the ABI used. I.e., if the ABI was `x86_64-pc-windows-msvc`, the directory will be
167`build\x86_64-pc-windows-msvc\doc`.
Steve Klabnikfd53ea22015-08-18 17:49:20168
Jack Moffitt8d64fa32013-07-18 23:27:43169## Notes
170
171Since the Rust compiler is written in Rust, it must be built by a
172precompiled "snapshot" version of itself (made in an earlier state of
173development). As such, source builds require a connection to the Internet, to
174fetch snapshots, and an OS that can execute the available snapshot binaries.
Austin Seipp62c4d2c2012-01-23 21:53:12175
Brian Anderson4c833af2012-10-11 00:56:38176Snapshot binaries are currently built and tested on several platforms:
Brian Anderson3403e412012-07-10 05:20:32177
c4rlo66ae4812016-09-01 21:42:51178| Platform / Architecture | x86 | x86_64 |
Richo Healey6f3701d2015-05-12 06:43:58179|--------------------------------|-----|--------|
180| Windows (7, 8, Server 2008 R2) | ✓ | ✓ |
181| Linux (2.6.18 or later) | ✓ | ✓ |
182| OSX (10.7 Lion or later) | ✓ | ✓ |
Austin Seipp62c4d2c2012-01-23 21:53:12183
Adrien Tétara30d61b2014-01-11 14:19:38184You may find that other platforms work, but these are our officially
Brian Anderson4c833af2012-10-11 00:56:38185supported build environments that are most likely to work.
Austin Seipp62c4d2c2012-01-23 21:53:12186
Peter Atashianbe43c652016-06-27 17:51:27187Rust currently needs between 600MiB and 1.5GiB to build, depending on platform.
188If it hits swap, it will take a very long time to build.
Brian Anderson4c833af2012-10-11 00:56:38189
Brian Andersonc2735712015-02-18 21:48:46190There is more advice about hacking on Rust in [CONTRIBUTING.md].
Austin Seipp62c4d2c2012-01-23 21:53:12191
Brian Andersonc2735712015-02-18 21:48:46192[CONTRIBUTING.md]: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md
Austin Seipp62c4d2c2012-01-23 21:53:12193
Kevin Yap24fa6be2015-02-21 22:46:06194## Getting Help
Brian Andersoncd1fabe2014-08-22 18:04:35195
196The Rust community congregates in a few places:
197
Kevin Yap24fa6be2015-02-21 22:46:06198* [Stack Overflow] - Direct questions about using the language.
199* [users.rust-lang.org] - General discussion and broader questions.
Brian Anderson5716ede2015-01-29 23:49:00200* [/r/rust] - News and general discussion.
Brian Andersoncd1fabe2014-08-22 18:04:35201
Maxwell Paul Bricknerf7e90412017-04-19 21:45:48202[Stack Overflow]: https://stackoverflow.com/questions/tagged/rust
203[/r/rust]: https://reddit.com/r/rust
Eli Friedmanbbbfed22015-08-09 21:15:05204[users.rust-lang.org]: https://users.rust-lang.org/
Steve Klabnikf645cad2015-02-13 17:26:44205
206## Contributing
207
Daniel Lobato García13d5e572015-03-08 21:37:23208To contribute to Rust, please see [CONTRIBUTING](CONTRIBUTING.md).
Brian Andersoncd1fabe2014-08-22 18:04:35209
Brian Anderson46189552015-02-16 04:58:06210Rust has an [IRC] culture and most real-time collaboration happens in a
211variety of channels on Mozilla's IRC network, irc.mozilla.org. The
212most popular channel is [#rust], a venue for general discussion about
David AO Lozanoc233f2e2016-03-31 02:07:53213Rust. And a good place to ask for help would be [#rust-beginners].
Brian Anderson46189552015-02-16 04:58:06214
215[IRC]: https://en.wikipedia.org/wiki/Internet_Relay_Chat
Brian Anderson7430e582015-02-18 21:46:20216[#rust]: irc://irc.mozilla.org/rust
David AO Lozanoc233f2e2016-03-31 02:07:53217[#rust-beginners]: irc://irc.mozilla.org/rust-beginners
Brian Anderson46189552015-02-16 04:58:06218
Brian Andersonc92d2ed2012-07-10 05:13:48219## License
Austin Seipp62c4d2c2012-01-23 21:53:12220
Brian Anderson11a99182012-12-28 21:40:33221Rust is primarily distributed under the terms of both the MIT license
222and the Apache License (Version 2.0), with portions covered by various
223BSD-like licenses.
Austin Seipp62c4d2c2012-01-23 21:53:12224
Peter Atashianbe43c652016-06-27 17:51:27225See [LICENSE-APACHE](LICENSE-APACHE), [LICENSE-MIT](LICENSE-MIT), and
226[COPYRIGHT](COPYRIGHT) for details.