Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DanielKeep/e94b4ab35fa85737f6f9 to your computer and use it in GitHub Desktop.
Save DanielKeep/e94b4ab35fa85737f6f9 to your computer and use it in GitHub Desktop.
Changes for Rust's Windows instructions
diff --git a/Doc-how-to-install-an-unofficial-nightly-for-Windows.md b/Doc-how-to-install-an-unofficial-nightly-for-Windows.md
index 6d53736..a54b87b 100644
--- a/Doc-how-to-install-an-unofficial-nightly-for-Windows.md
+++ b/Doc-how-to-install-an-unofficial-nightly-for-Windows.md
@@ -1,81 +1 @@
-WARNING: Every nightly snapshot mentioned in this document is **unofficial** and not maintained by the Rust core team.
-**You are fully responsible for any problems due to the use of nightly snapshots.**
-
-## Using with MinGW
-
-Download and run the [MinGW installer](http://sourceforge.net/projects/mingw/files/latest/download?source=files) and follow the instructions.
-There is a checkbox for whether to install the graphical user interface,
-which we will not use but nevertheless may be useful.
-
-> TIP: You can install the GUI later using `mingw-get install mingw-get-gui`.
-
-MinGW, by default, does not append itself to the `PATH` environment variable.
-Since running `rustc` anywhere requires this environment variable,
-you should append a path to the MinGW executables to `PATH` in the control panel.
-(In the default settings, the path would be `C:\MinGW\bin`.)
-
-Turn the Command Prompt on and type the following.
-
- > mingw-get install mingw32-base
-
-> TIP: This would install the C compiler. If you don't want it, use `mingw-get install gcc` instead.
-
-Install [Chocolatey](http://chocolatey.org/)
-by copying the command line in the website and pasting it into the Command Prompt.
-
- > @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin
-
-> TIP: When you get an error (mostly due to older versions of PowerShell), use an [alternative method](https://github.com/chocolatey/chocolatey/wiki/Installation#wiki-powershell-through-batch-method) to install.
-
-Then install Rust using Chocolatey.
-We will use the [NuGet Rust package](https://www.nuget.org/packages/Rust/) maintained by Heather.
-Since NuGet is not a default package feed as of 2014-02, we will manually add it to the available sources.
-Installing Rust would take some time as it weighs about 120 MB.
-
- > choco sources add -name nuget -source https://www.nuget.org/api/v2/
- > choco install Rust
-
-> TIP: If you get the "Unable to read package from path" error shortly after `choco install`,
-> you have the incomplete NuGet package cache.
-> Delete everything starting with `Rust` in `%AppData%\Local\NuGet\Cache` and try again.
-
-`choco install` would install `C:\Chocolatey\lib\Rust.VERSION\bin\rustc.exe` and so on.
-Try `rustc -v` out in the Command Prompt and check if it installs the correct version.
-
-> TIP: If you get an error about not being able to find `libstdc++-6.dll` or other dlls when running `rustc`, install the `mingw32-gcc-g++` package from mingw as well.
-
-You can update the Rust installation using Chocolatey later.
-
- > choco update Rust
-
-## Using with MSYS
-
-MinGW has a subsystem named MSYS which emulates a conventional Unix shell.
-This subsystem is required for projects depending on Unix build systems like `make`,
-and it's a must for building the Rust compiler.
-
-Follow all the instructions for MinGW, then type the following in order to install MSYS.
-
- > mingw-get install msys-base
-
-Then run `msys\1.0\msys.bat` in the MinGW directory.
-
-> TIP: Installing MSYS does not automatically generate a shortcut to it. You are recommended to make a shortcut for `msys.bat`.
-
-> TIP: If you've installed MSYS in your own way, and especially if you don't have a path to MinGW in `PATH`,
-> then you need to run `/postinstall/pi.sh` in the MSYS shell and follow the instructions. (You normally don't need that, however.)
-
-`rustc` installed via Chocolatey works well with MSYS,
-but you can't directly run it since the MSYS shell (currently) can't run batch files generated by Chocolatey.
-You need to make the following files in the MinGW directory by hand...
-
-* `msys\1.0\bin\rustc`
-* `msys\1.0\bin\rustdoc`
-* `msys\1.0\bin\rustpkg`
-
-...with the following contents.
-
- #!/bin/sh
- cmd //c $(basename "$0") "$@"
-
-You can now use `rustc` directly in the MSYS shell.
+See [[Using-Rust-on-Windows]].
diff --git a/Note-Building-Rust-Before-0.8-on-Windows-Systems.md b/Note-Building-Rust-Before-0.8-on-Windows-Systems.md
index 15ca828..0556f2c 100644
--- a/Note-Building-Rust-Before-0.8-on-Windows-Systems.md
+++ b/Note-Building-Rust-Before-0.8-on-Windows-Systems.md
@@ -1,3 +1,5 @@
+For current instructions on building Rust on Windows, see the guide to [[getting started developing Rust|Note-getting-started-developing-Rust]].
+
**Please note that this is an in-progress and temporary guide only intended for versions of Rust before 0.8 on Windows systems.**
This temporary guide will cover building Rust < 0.8 on a Windows system through MSYS & MinGW using gcc 4.8 .
diff --git a/Note-getting-started-developing-Rust.md b/Note-getting-started-developing-Rust.md
index a716810..17afcfd 100644
--- a/Note-getting-started-developing-Rust.md
+++ b/Note-getting-started-developing-Rust.md
@@ -47,21 +47,17 @@ Also, make sure you have the `lmodern` font package (see [#3989](https://github.
### Windows
-Whether building from source or running the rustc binaries, see [[Using Rust on Windows]] for instructions on setting up MinGW.
-
-#### MSYS
-
-The MinGW linked to from the above "using Rust" instructions should also be sufficient for building Rust. Note though that to build Rust, we additionally require MSYS, a collection of Unix utilities ported to Windows. We currently recommend the inclusive version of MSYS provided by the [mingw-builds project](http://sourceforge.net/apps/trac/mingw-w64/wiki/MSYS). Extract these to a directory somewhere and make sure they are on your path when building Rust. Using the MSYS shell can also be slightly more pleasant than building directly from the windows terminal.
+Whether building from source or running the rustc binaries, see [[Using Rust on Windows]] for instructions on setting up GCC and a POSIX environment. Note that, as of August, 2014, you will need to install an MinGW-w64 build of GCC; the MinGW build will not suffice for building Rust. You will also need to install MSYS2.
#### More info for Windows users.
-It is known that msys make freezes randomly i[f `-jN` option is given](http://sourceforge.net/mailarchive/message.php?msg_id=29801372).
+It is known that msys make freezes randomly [if `-jN` option is given](http://sourceforge.net/mailarchive/message.php?msg_id=29801372).
Once installed, we tend to work inside the MSYS shell.
If you are a consistent user of MinGW or plan to be, you might also want to subscribe to their mailing list: [Mingw-users](https://lists.sourceforge.net/lists/listinfo/mingw-users)
(OPTIONAL)
-* Using `mingw-get` alone will open a GUI interface for package management. You can update MinGW components once you start it's console by using the command `mingw-get update`, this updates the package repository for MinGW. After which you can upgrade packages with `mingw-get upgrade`. **mingw-get upgrade will overwrite to latest versions of GCC as well, so you might have to upgrade to a lower version afterwards.**
+* For MinGW, using `mingw-get` alone will open a GUI interface for package management. You can update MinGW components once you start it's console by using the command `mingw-get update`, this updates the package repository for MinGW. After which you can upgrade packages with `mingw-get upgrade`. **mingw-get upgrade will overwrite to latest versions of GCC as well, so you might have to upgrade to a lower version afterwards.**
(OPTIONAL - if using another Git installer or method other than the Quick Steps):
diff --git a/Using-Rust-on-Windows.md b/Using-Rust-on-Windows.md
index d608c9e..ab7e3af 100644
--- a/Using-Rust-on-Windows.md
+++ b/Using-Rust-on-Windows.md
@@ -1,15 +1,149 @@
-As of release 0.10, Rust still depends on GCC for platform linker and C runtime libraries, so you will need to install one before installing Rust itself. Follow these instructions to set up the environment, then run the [Rust installer].
+The Rust compiler depends on the GNU Compiler Collection for linking and its C runtime library. As such, you will need to install some variety of GCC on Windows in order to compile Rust code. Many Rust projects also require a POSIX build environment. Once you have GCC (and, optionally, MSYS or equivalent) installed, read the "Installing and Verifying Rust" section.
-## MinGW
+## Acquiring GCC and a POSIX Environment
-The current recommended way of obtaining Rust's prerequisites is by using the [mingw-w64 installers](http://sourceforge.net/projects/mingwbuilds/files/mingw-builds-install/mingw-builds-install.exe/download) from the [mingw-builds project](https://sourceforge.net/projects/mingwbuilds/files/host-windows/releases/). The official Rust build bots are using such an installer from late March, 2014.
+The short version of this section: **see "Use MSYS2 and MinGW-w64"**, or, if you wish to use `rustc` from *outside* an MSYS shell, see "Use MinGW-w64 outside of MSYS2". **If you are intending to build Rust from source**, you should read this section as well as the guide to [[getting started developing Rust|Note-getting-started-developing-Rust]].
-1. Download and run mingw-builds-install.exe.
-2. Choose installation options: architecture=x32, **threads=win32**, exceptions=dwarf.
-3. Now just download and run the [Rust installer].
-3. Use Rust compiler from mingw-builds terminal (there will be a shortcut in the Start menu), or add `<mingw-builds>\mingw32\bin` directory to your PATH.
-4. Verify Rust installation at mingw-builds terminal by typing `rustc --help`
+There are three primary ways of obtaining GCC on Windows: MinGW, MinGW-w64 and Cygwin.
-[Rust installer]: http://static.rust-lang.org/dist/rust-nightly-install.exe
+* **MinGW** is a Windows-native port of GCC and other utilities. The important property of MinGW is that its compilers (usually) produce standalone executables and libraries that can be used without end-users needing to install MinGW themselves. It only supports building 32-bit binaries.
-*Note: these instructions are sufficient to run Rust from a binary installation. To build Rust see [[further instructions|Note-getting-started-developing-Rust]].*
\ No newline at end of file
+* **MinGW-w64** is a clean-room re-implementation of MinGW originally created to provide support for building 64-bit Windows executables. Despite the name, it *does* support creating 32-bit binaries. Like MinGW, it also produces standalone binaries.
+
+* **Cygwin** is a POSIX layer written on top of the Windows API that (by and large) allows software written for POSIX to be compiled unmodified. In addition to compilers, it also includes standard POSIX environment programs such as shell commands and the shell itself. In essence, whereas MinGW is a port of some POSIX software, Cygwin is a port of a *complete POSIX environment*. Unlike MinGW, however, all binaries compiled using Cygwin's tools will (usually) *require Cygwin components in order to run*.
+
+It is worth noting that there are exceptions to the above. There are versions of MinGW which do not build entirely "native" executables, and it is possible to "cross-compile" using MinGW from inside Cygwin.
+
+At present, **Rust is designed to be used with a MinGW version of GCC** (that is, one that produces standalone executables). Using Rust with Cygwin will not be covered by these instructions.
+
+In addition to Rust's dependence of GCC, a number of Rust projects require a POSIX shell environment to build, due to their use of shell scripts and/or Makefiles. This requirement can be filled by Cygwin (keeping in mind the above about standalone binaries), MSYS or MSYS2.
+
+* **MSYS** is a part of the MinGW project which provides Windows-native ports of various POSIX tools including various common shell commands, the shell itself and `make`. It is a fork of Cygwin, but does *not* have the same "tainting" effect on produced binaries that Cygwin does.
+
+* **MSYS2** is an updated version of MSYS, which exists independent of the MinGW and MinGW-w64 projects. That said, MSYS2 has a package manager which supports installation of **MinGW-w64** within its own environment.
+
+It is recommended that, when compiling Rust projects that require a POSIX environment for the build system, you **use MSYS or MSYS2** rather than Cygwin.
+
+In practice, you should choose one of the following configurations:
+
+* **MSYS2** with **MinGW-w64** installed via the MSYS2 package manager. This requires you to use `rustc` from within MSYS2. The majority of developers working in Windows on the Rust compiler itself use this configuration, and it combines the most compatible GCC with the simplest setup.
+
+* **MinGW** with **MSYS** installed via the MinGW package manager. `rustc` can be used both inside and outside the MSYS shell. Note that, as of August, 2014, **Rust does not build with this configuration** due to incompatibilities with GCC. This configuration is servicable for building *with* a pre-compiled `rustc`, however.
+
+* **MinGW-w64** installed to the system path, with **MSYS2** installed separately. `rustc` can be used both inside and outside the MSYS shell.
+
+### Use MSYS2 and MinGW-w64
+
+These instructions are also summarised in `README.md` in the Rust source repository.
+
+Download and run the MSYS2 installer `msys2-(host platform)-(date).exe` from the [MSYS2 project page](http://sourceforge.net/projects/msys2/files/Base/) and follow the instructions.
+
+Once installed, you will need to launch the MSYS2 shell (this can be done from the Start Menu shortcut, or by running `msys2_shell.bat` from the install directory. First, you will need to install the appropriate MinGW-w64 toolchain, depending on whether you wish to compile 32-bit and/or 64-bit binaries. Note that you can install both if you so desire without them conflicting.
+
+ $ pacman -S mingw-w64-i686-toolchain # for 32-bit builds
+ $ pacman -S mingw-w64-x86_64-toolchain # for 64-bit builds
+
+You will also need to install the rest of the POSIX tools for building software:
+
+ $ pacman -S base-devel
+
+In order to compile with Rust, you will need to start the MSYS2 shell from either the "MinGW-w64 Win32 Shell" or "MinGW-w64 Win64 Shell" Start Menu shortcuts, or the `mingw32_shell.bat` or `mingw64_shell.bat` batch files in the MSYS2 install directory, depending on which toolchain you wish to use.
+
+> **NOTE**: The MinGW-w64 shells change how MSYS2 identifies itself through the `uname` program. Build systems which expect MinGW may fail if used from within a standard MSYS2 shell.
+
+See "Installing and Verifying Rust".
+
+### Use MinGW and MSYS
+
+**TODO**: verify these are all still correct.
+
+Download and run the MinGW installer [mingw-get-setup.exe](http://sourceforge.net/projects/mingw/files/latest/download?source=files) and follow the instructions.
+There is a checkbox for whether to install the graphical user interface,
+which we will not use but nevertheless may be useful.
+
+> **TIP**: You can install the GUI later using `mingw-get install mingw-get-gui`.
+
+MinGW, by default, does not append itself to the `PATH` environment variable.
+Since running `rustc` requires GCC to be accessible on the path,
+you should append a path to the MinGW executables to `PATH` in the control panel.
+(In the default settings, the path would be `C:\MinGW\bin`.)
+
+Alternately, you can write a batch file that adds the MinGW `bin` directory to your `PATH` temporarily, and run this batch file before using `rustc`. For example, it might contain the following:
+
+ @ECHO OFF
+ ECHO Adding MinGW to PATH...
+ SET PATH=C:\MinGW\bin;%PATH%
+
+To actually install GCC, open a command prompt which has MinGW's programs accessible on the path and type the following:
+
+ > mingw-get install mingw32-base
+
+> **TIP**: This will install the C compiler. If you don't want it, use `mingw-get install gcc` instead.
+
+> **TIP**: If you get an error about not being able to find `libstdc++-6.dll` or other dlls when running `rustc`, install the `mingw32-gcc-g++` package from mingw as well.
+
+If you need it, you can now install MSYS, using the following from a command prompt:
+
+ > mingw-get install msys-base
+
+You can now open an MSYS shell either by using the "MinGW Shell" Start Menu shortcut or by directly running `msys\1.0\msys.bat` in the MinGW directory.
+
+> **TIP**: If you've installed MSYS in your own way, and especially if you don't have a path to MinGW in `PATH`,
+> then you need to run `/postinstall/pi.sh` in the MSYS shell and follow the instructions. (You normally don't need that, however.)
+
+See "Installing and Verifying Rust".
+
+### Use MinGW-w64 outside of MSYS2
+
+Download and run the MinGW-w64 installer from the [MinGW-w64 download page](http://mingw-w64.sourceforge.net/download.php#mingw-builds), under the "Mingw-builds project" heading. During installation, you will be asked to choose from various alternatives. The following settings are known to work as of August, 2014 for building Rust itself, although you may be able to use others:
+
+* (GCC) Version: 4.8.1
+* (Target) Architecture: x32
+* Threads: win32 - **Important**
+* Exception: dwarf
+* Build revision: 5
+
+MinGW-w64 does not append itself to the `PATH` environment variable.
+Since running `rustc` requires GCC to be accessible on the path, you should append a path to the MinGW-w64 executables to `PATH` in the control panel.
+Specifically, you should add the `mingw32\bin` or `mingw64\bin` directory in the install directory to `PATH`.
+
+Alternately, you can run the `mingwbuilds.bat` batch file in the install directory to open a configured command prompt.
+
+If you need it, you can now install MSYS2. To do so, follow the instructions in the section on installing MSYS2 with MinGW-w64, but skip the step where you install the MinGW-w64 toolchain package.
+
+Once complete, you should be able to use `rustc` (and the installed MinGW-w64 tools) from both inside and outside an MSYS2 shell.
+
+> **IMPORTANT**: Even if you do not install MinGW-w64 from within MSYS2, `rustc` should *still* be used from within the special MinGW-w64 shells, *not* the standard MSYS2 shell. This ensures the environment identifies itself as MinGW and *not* as MSYS.
+
+
+
+> **NOTE**: Using the MSYS2 MinGW-w64 shells can alter which specific install of MinGW-w64 is used. The behaviour is as follows:
+>
+> * "MSYS2 Shell" / `msys2_shell.bat`: externally-installed MinGW-w64.
+> * "MinGW-w64 Win32 Shell" / `mingw32_shell.bat`: MinGW-w64 targetting i686 as installed by the MSYS2 package manager (`mingw-w64-i686-toolchain`). If that is not installed, will fall back to the externally-installed MinGW-w64.
+> * "MinGW-w64 Win64 Shell" / `mingw64_shell.bat`: MinGW-w64 targetting x86-64 as installed by the MSYS2 package manager (`mingw-w64-x86_64-toolchain`). If that is not installed, will fall back to the externally-installed MinGW-w64.
+
+See "Installing and Verifying Rust".
+
+## Installing and Verifying Rust
+
+The simplest way to get a precompiled version of `rustc` is to download the [nightly Rust installer] from the [Rust website]. This should be used unless you have code that requires an older release version of the language.
+
+[nightly Rust installer]: http://static.rust-lang.org/dist/rust-nightly-install.exe
+[Rust website]: http://www.rust-lang.org/
+
+Once installed, ensure that `rustc` works by running the following from a command prompt:
+
+ > rustc --version
+
+You may also wish to compile and run a minimal test program to ensure that `rustc` can properly locate and use GCC. Place the following into a file called `hello.rs`:
+
+ fn main() {
+ println!("Hello, World!");
+ }
+
+Compile it as follows:
+
+ rustc hello.rs
+
+And then run the resulting `hello.exe` executable. Remember that, if you are using MSYS or MSYS2, you will likely need to run the result using `./hello` rather than just `hello`.
\ No newline at end of file
Included both single diff and individual files.

For current instructions on building Rust on Windows, see the guide to [[getting started developing Rust|Note-getting-started-developing-Rust]].

Please note that this is an in-progress and temporary guide only intended for versions of Rust before 0.8 on Windows systems.

This temporary guide will cover building Rust < 0.8 on a Windows system through MSYS & MinGW using gcc 4.8 .

NOTE

  • Rust requires gcc < 4.6 to build, but recently mingw has upgraded whole system and it is currently not easy to match package versions. This guide directly uses gcc 4.8.
  • Latest mingw w32api package (4.0.0-1) contains some bugs. See "Patches" section below for instruction.
  • There are some abi change between gcc 4.6 and 4.8, and some tests are known to fail due to this. (rust-lang/rust#9205)

MSYS & MinGW Installation

  1. Download the MinGW installer:
  1. Run the mingw-get-setup installer.
  • For simplicity use the default path of C:\MinGW , pretty please.
  • I like to install for all users.
  • Run with Administrator privileges if possible.
  1. Make sure MinGW is on your system path.
  1. It is pretty handy to create a shortcut on your desktop to C:\MinGW\msys\1.0\msys.bat

MSYS & MinGW Packages

We have a few packages to add.

  1. Run the mingw-get GUI from your desktop by double clicking the "MinGW Installer" shortcut.
  2. Right click the following list of packages (bin) within the right pane and select "Mark for Installation". Use the left navigation tree to filter categories.
    • Basic Setup
      • mingw-developer-toolkit
      • mingw32-base
      • mingw32-gcc-g++
    • All Packages
      • msys-wget
      • MinGW Libraries
        • MinGW Standard Libraries
          • mingw32-libpthread-old
          • mingw32-libpthreadgc
  3. From the GUI menu navigate to Installation > Apply Changes
    • This will take some time to complete.
    • Currently some packages should be downgraded (rust-lang/rust#5878)

Git Installation

If you already have Git installed and available on the path you may skip this section. You should be able to use the git command from your msys shell.

  1. Install git for windows from http://git-scm.com/download/win
  2. Uncheck Associate .sh files to be run with Bash from within the components screen.
  3. Select the option to Run Git from the Windows Command Prompt.
  4. It is recommended to choose the option to Checkout as-is, commit Unix-style line endings.
  5. Open a new msys console and type git --version to verify installation.
  • Note: if your shell (explorer) does not return after installation, start the task manager and navigate to File > Run New Task... then enter explorer.

Python27 Installation

If you already have python installed and on the path, you may skip this section.

  1. Get the Python27 installer from http://www.python.org/getit/
  • I am using "Python 2.7.5 Windows X86-64 Installer"
  1. Accept the defaults, please.
  2. Add python to your system path: http://stackoverflow.com/a/6318188/458550

Clone Rust

  1. Navigate to a place on your file system where you feel comfortable downloading the Rust repository.
    • C:\projects is a nice cozy spot!
  2. execute git clone git://github.com/mozilla/rust.git to clone the Rust repository into a new rust directory.

Configure & Build

  1. Navigate to the directory where you cloned rust from within the msys shell. For me that is cd /C/Projects/rust.

  2. Run the command ./configure

    • This will take a while!
  3. When that completes run the command make

    • This will take much longer!
  4. Get your sad face ready because this build will fail. Eventually you should get an error such as this:

     ---------------------------
     rustc.exe - Application Error
     ---------------------------
     The application was unable to start correctly (0xc0000142). Click OK to close the application.
     ---------------------------
     OK  
     ---------------------------
    
  5. Download libstdc++-4.6.2-1-mingw32-dll-6.tar.lzma from http://sourceforge.net/projects/mingw/files/MinGW/Base/gcc/Version4/gcc-4.6.2-1/libstdc%2B%2B-4.6.2-1-mingw32-dll-6.tar.lzma/download and extract the contained libstdc++-6.dll into the \rust\i686-pc-mingw32\stage0\bin folder.

    • Try running rustc.exe to confirm the fix.
  6. Run the make command again.

    • This will take a really long time!

Rust is Ready

User@Machine /c/projects/rust/i686-pc-mingw32/stage2/bin
$ rustc.exe hello.rs

User@Machine /c/projects/rust/i686-pc-mingw32/stage2/bin
$ hello
Hello, world.

Moving Rust

If you want to move rust to a more permanent location on your system (for example C:\Program Files) you must preserve a little bit of structure. If you fail to do this correctly you may receive errors such as can't find crate for `std` . The contents of the stage2/bin folder must be contained within a folder named bin. The simplest way to do this is the following:

  • Copy the contents of stage2/bin to C:\Program Files\rust\bin
    • Be sure to include the rustc folder too
  • Add ;C:\Program Files\rust\bin to your system path

This page describes how to download and build the Rust compiler and associated tools and libraries from the current git sources. If you're more interested in using Rust than in hacking on the Rust compiler, you might prefer to install a released version, following the instructions in the tutorial.

Prerequisites

Version numbers listed here are "what we're using"; the code may well work with earlier versions of these tools, but we don't know minimum version requirements.

  • A recent Linux, OS X 10.6 or later, Win32 or FreeBSD system
  • 1.5 GiB RAM available for the build process (see note below about memory usage)
  • python 2.x (version 2.7 is known to work)
  • GNU make 3.81
  • git 1.7
  • g++ 4.7 at least on Linux, 4.5 on Windows, and the 4.x gcc in Apple's SDK for OS X.
  • curl
  • recommended: valgrind 3.8.0 or later (not required for Linux)
  • optional: if you wish to build LaTeX PDF docs, pandoc 1.9.1 at least, with one or more of pdflatex/xelatex/lualatex
  • optional: ccache to shorten your rebuild times

Memory usage

The Rust build peaks at around 1.3 GiB, so at least that much memory should be available for the build to avoid excessive swapping or out-of-memory. If you only have 2 GiB of RAM total, you may have a difficult time building Rust while doing anything else, such as using a browser.

Note that if you are compiling Rust from within a virtual OS (e.g. via Vagrant) you may need to change how much RAM your VM has access to.

Debian-based Linux distributions

You can install all the prerequisites you need to build Rust by running:

sudo apt-get install python make git g++ curl valgrind

For Ubuntu users willing to build LaTeX doc, you will need some more packages:

sudo apt-get install pandoc texlive-latex-recommended lmodern

Incidentally, the pandoc that's packaged for certain Linux distributions (Ubuntu, for instance) is sometimes quite old, so make sure that pandoc -V gives version 1.9.1 at least, otherwise follow the building instructions.
Also, make sure you have the lmodern font package (see #3989).

Windows

Whether building from source or running the rustc binaries, see [[Using Rust on Windows]] for instructions on setting up GCC and a POSIX environment. Note that, as of August, 2014, you will need to install an MinGW-w64 build of GCC; the MinGW build will not suffice for building Rust. You will also need to install MSYS2.

More info for Windows users.

It is known that msys make freezes randomly if -jN option is given.

Once installed, we tend to work inside the MSYS shell. If you are a consistent user of MinGW or plan to be, you might also want to subscribe to their mailing list: Mingw-users

(OPTIONAL)

  • For MinGW, using mingw-get alone will open a GUI interface for package management. You can update MinGW components once you start it's console by using the command mingw-get update, this updates the package repository for MinGW. After which you can upgrade packages with mingw-get upgrade. mingw-get upgrade will overwrite to latest versions of GCC as well, so you might have to upgrade to a lower version afterwards.

(OPTIONAL - if using another Git installer or method other than the Quick Steps):

  • Put the git binary path after the MinGW path. So add a line like the following to your /etc/profile or .bashrc:
export PATH=$PATH:/c/Program\ Files/Git/bin

(OPTIONAL - working with multiple toolchains & modifying your PATH):

  • In Windows, to try out or work with different toolchains for building Rust with MinGW, the easiest way is to modify and add at the end of your Msys profile file, C:\MinGW\msys\1.0\etc\profile something like the following, and uncomment whichever toolchain path you want to work with and Remember to exit the Msys console and reopen it:
# Enable MinGW64 path by uncommenting one of the following lines:
# export PATH="/c/mingw-builds/x64-4.8.1-release-win32-seh-rev5/mingw64/bin:/usr/local:$PATH"
# export PATH="/c/drangon_mingw64/mingw64/bin:/usr/local:$PATH"
export PATH="/c/mingw-builds/x32-4.8.1-release-win32-dwarf-rev5/mingw32/bin:/usr/local:$PATH"

# Enable LLVM path by uncommenting the following line:
# export PATH="$HOME/build/Release+Asserts/bin:$PATH"

Troubleshooting Windows environment setups:

  • If Python cannot be found during ./configure, then you need to add its path to the end of /c/mingw/msys/1.0/etc/profile, like this:

  • export PATH="/c/PYTHON27:$PATH"

  • If while building you receive an error that libpthread-2.dll is not found, you forgot to install the mingw32-libpthread-old package into MinGW from Step 5, so do this:

  • mingw-get install mingw32-libpthread-old

  • If while building you receive an error that libpthreadGC.dll is not found, you forgot to install libpthreadgc runtime library into MinGW from Step 5, so do this:

  • mingw-get install mingw32-libpthreadgc

  • If while building you receive an error that libpthreadGC2.dll is not found (e.g. when llvm-config tries to run), here is one workaround. (There may be a mingw-get solution too... anyone? I've done windows dev but I'm new to mingw):

  • download pthreads for win32, e.g. here ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.zip

  • unzip the zip file, and copy the pthreads-w32-2-9-1-release/Pre-built.d/dll/*.dll to c:/mingw/bin/

OSX

Get the command line tools for xcode from Apple Developer Downloads or Xcode.app -> Preferences -> Downloads -> Components.

Then, optionally get Valgrind and pandoc. Vallgrind is available in machomebrew: brew install valgrind. pandoc must be installed manually according to the installation instructions. ccache can also be installed from machomebrew: brew install ccache.

Sometimes, on OS X, compiling Rust might fail with a "too many open files" error, especially when running make check.

  • One solution is to limit the number of concurrent threads during the run, via the environment variable RUST_THREADS, e.g. % RUST_THREADS=2 make check.
  • Another solution for this is to raise the open file limit on OS X. One method to achieve the latter that has been tested on 10.7.5 is the following:
  1. Raise the number of maximum files allowed on the system: sudo sysctl -w kern.maxfiles=1048600 and sudo sysctl -w kern.maxfilesperproc=1048576. This can be made persistent by adding the following lines to /etc/sysctl.conf:
kern.maxfiles=1048600
kern.maxfilesperproc=1048576
  1. Raise the launchd limits: sudo launchctl limit maxfiles 1048576. Can be made persistent by adding limit maxfiles 1048576 to /etc/launchd.conf.

  2. Verify the changes. If all goes well, sudo launchctl limit should show something like this:

  [...]
  maxproc     709            1064
  maxfiles    1048575        1048575
  1. Run the compiler. Note that if the changes aren't made persistent, you need to run as root, since the per-user launchd won't inherit the settings. If you do change the config files, you need to reboot to apply the appropriate settings.

FreeBSD

Rust builds on FreeBSD but is not officially supported. It is only known to work on 9.0-RELEASE. You'll need some prerequisites:

pkg_add -r git gmake libexecinfo libunwind

The gcc included with FreeBSD is old, so your best bet is to run the configure script with --enable-clang. Installing gcc 4.6 can also work. Build with gmake instead of make.

Android

See [[building for Android|Doc-building-for-android]]

Downloading and building Rust

Before you get started, you should quickly review the build system notes which describes the Make targets among other things.

git clone git://github.com/mozilla/rust.git
cd rust
./configure   # this may take a while if this is your first time, as it downloads LLVM

If you already have one of the prereqs installed, like Python or Perl, make sure the PATH environment variable is set so the configure script can find it, otherwise you will get errors during configure.

make    # this will definitely take a while if this is your first time, as it builds LLVM

Optional steps:

make check   # run the test suite; on windows, `make check` may not pass well. in any case, make check-fast` should work. (See also #4193)
make install   # install the compiler and associated tools

This will build and test the compiler, standard libraries, and supporting tools.

Note: You can use make -j8 (if you have an 8-core machine) to speed up the build (at least the LLVM part and the tests). On Linux or OS X, if you have Valgrind installed, the tests will run slowly because they are running under Valgrind. If you define CFG_DISABLE_VALGRIND=1 in your build environment or run configure with the --disable-valgrind flag, you can see the tests running at full speed.

Note: If you need to pass in extra flags to make, you can add RUSTFLAGS=... to the argument list for make. For example, make check RUSTFLAGS="-Z debug-info" builds the compiler and runs tests with debug info enabled.

Note: Some make targets are only exercised by make check-full. If you want to see what commands a make invocation is running, you can add VERBOSE=1 to the argument list for make. (Also, if you use make options like --print-data-base to see other targets, note that some rules in the database are only generated dynamically.) See also: Build system notes

Navigating

There's a quick guide to the source of the compiler in src/librustc/README.txt. You should look through it if you're going to be contributing.

Editor support

Syntax highlighting for vim is included in the Rust repository, under src/etc/vim and for emacs under src/etc/emacs. Other editors may [[also be supported|Doc packages, editors, and other tools]].

The issue tracker

We use the GitHub issue tracker to track bugs and feature requests in Rust. If you prefer not to use the standard GitHub issue tracker, there's a secondary front-end that is quite a bit more responsive.

Communicating

Join irc.mozilla.org #rust for real-time discussion of Rust development. We try to remain on that channel during working hours in UTC-7 (US Pacific).

Join the mailing list for longer conversations.

In both cases, please follow the conduct guidelines on the [[development policy|Note development policy]].

The Rust compiler depends on the GNU Compiler Collection for linking and its C runtime library. As such, you will need to install some variety of GCC on Windows in order to compile Rust code. Many Rust projects also require a POSIX build environment. Once you have GCC (and, optionally, MSYS or equivalent) installed, read the "Installing and Verifying Rust" section.

Acquiring GCC and a POSIX Environment

The short version of this section: see "Use MSYS2 and MinGW-w64", or, if you wish to use rustc from outside an MSYS shell, see "Use MinGW-w64 outside of MSYS2". If you are intending to build Rust from source, you should read this section as well as the guide to [[getting started developing Rust|Note-getting-started-developing-Rust]].

There are three primary ways of obtaining GCC on Windows: MinGW, MinGW-w64 and Cygwin.

  • MinGW is a Windows-native port of GCC and other utilities. The important property of MinGW is that its compilers (usually) produce standalone executables and libraries that can be used without end-users needing to install MinGW themselves. It only supports building 32-bit binaries.

  • MinGW-w64 is a clean-room re-implementation of MinGW originally created to provide support for building 64-bit Windows executables. Despite the name, it does support creating 32-bit binaries. Like MinGW, it also produces standalone binaries.

  • Cygwin is a POSIX layer written on top of the Windows API that (by and large) allows software written for POSIX to be compiled unmodified. In addition to compilers, it also includes standard POSIX environment programs such as shell commands and the shell itself. In essence, whereas MinGW is a port of some POSIX software, Cygwin is a port of a complete POSIX environment. Unlike MinGW, however, all binaries compiled using Cygwin's tools will (usually) require Cygwin components in order to run.

It is worth noting that there are exceptions to the above. There are versions of MinGW which do not build entirely "native" executables, and it is possible to "cross-compile" using MinGW from inside Cygwin.

At present, Rust is designed to be used with a MinGW version of GCC (that is, one that produces standalone executables). Using Rust with Cygwin will not be covered by these instructions.

In addition to Rust's dependence of GCC, a number of Rust projects require a POSIX shell environment to build, due to their use of shell scripts and/or Makefiles. This requirement can be filled by Cygwin (keeping in mind the above about standalone binaries), MSYS or MSYS2.

  • MSYS is a part of the MinGW project which provides Windows-native ports of various POSIX tools including various common shell commands, the shell itself and make. It is a fork of Cygwin, but does not have the same "tainting" effect on produced binaries that Cygwin does.

  • MSYS2 is an updated version of MSYS, which exists independent of the MinGW and MinGW-w64 projects. That said, MSYS2 has a package manager which supports installation of MinGW-w64 within its own environment.

It is recommended that, when compiling Rust projects that require a POSIX environment for the build system, you use MSYS or MSYS2 rather than Cygwin.

In practice, you should choose one of the following configurations:

  • MSYS2 with MinGW-w64 installed via the MSYS2 package manager. This requires you to use rustc from within MSYS2. The majority of developers working in Windows on the Rust compiler itself use this configuration, and it combines the most compatible GCC with the simplest setup.

  • MinGW with MSYS installed via the MinGW package manager. rustc can be used both inside and outside the MSYS shell. Note that, as of August, 2014, Rust does not build with this configuration due to incompatibilities with GCC. This configuration is servicable for building with a pre-compiled rustc, however.

  • MinGW-w64 installed to the system path, with MSYS2 installed separately. rustc can be used both inside and outside the MSYS shell.

Use MSYS2 and MinGW-w64

These instructions are also summarised in README.md in the Rust source repository.

Download and run the MSYS2 installer msys2-(host platform)-(date).exe from the MSYS2 project page and follow the instructions.

Once installed, you will need to launch the MSYS2 shell (this can be done from the Start Menu shortcut, or by running msys2_shell.bat from the install directory. First, you will need to install the appropriate MinGW-w64 toolchain, depending on whether you wish to compile 32-bit and/or 64-bit binaries. Note that you can install both if you so desire without them conflicting.

$ pacman -S mingw-w64-i686-toolchain    # for 32-bit builds
$ pacman -S mingw-w64-x86_64-toolchain  # for 64-bit builds

You will also need to install the rest of the POSIX tools for building software:

$ pacman -S base-devel

In order to compile with Rust, you will need to start the MSYS2 shell from either the "MinGW-w64 Win32 Shell" or "MinGW-w64 Win64 Shell" Start Menu shortcuts, or the mingw32_shell.bat or mingw64_shell.bat batch files in the MSYS2 install directory, depending on which toolchain you wish to use.

NOTE: The MinGW-w64 shells change how MSYS2 identifies itself through the uname program. Build systems which expect MinGW may fail if used from within a standard MSYS2 shell.

See "Installing and Verifying Rust".

Use MinGW and MSYS

TODO: verify these are all still correct.

Download and run the MinGW installer mingw-get-setup.exe and follow the instructions. There is a checkbox for whether to install the graphical user interface, which we will not use but nevertheless may be useful.

TIP: You can install the GUI later using mingw-get install mingw-get-gui.

MinGW, by default, does not append itself to the PATH environment variable. Since running rustc requires GCC to be accessible on the path, you should append a path to the MinGW executables to PATH in the control panel. (In the default settings, the path would be C:\MinGW\bin.)

Alternately, you can write a batch file that adds the MinGW bin directory to your PATH temporarily, and run this batch file before using rustc. For example, it might contain the following:

@ECHO OFF
ECHO Adding MinGW to PATH...
SET PATH=C:\MinGW\bin;%PATH%

To actually install GCC, open a command prompt which has MinGW's programs accessible on the path and type the following:

> mingw-get install mingw32-base

TIP: This will install the C compiler. If you don't want it, use mingw-get install gcc instead.

TIP: If you get an error about not being able to find libstdc++-6.dll or other dlls when running rustc, install the mingw32-gcc-g++ package from mingw as well.

If you need it, you can now install MSYS, using the following from a command prompt:

> mingw-get install msys-base

You can now open an MSYS shell either by using the "MinGW Shell" Start Menu shortcut or by directly running msys\1.0\msys.bat in the MinGW directory.

TIP: If you've installed MSYS in your own way, and especially if you don't have a path to MinGW in PATH, then you need to run /postinstall/pi.sh in the MSYS shell and follow the instructions. (You normally don't need that, however.)

See "Installing and Verifying Rust".

Use MinGW-w64 outside of MSYS2

Download and run the MinGW-w64 installer from the MinGW-w64 download page, under the "Mingw-builds project" heading. During installation, you will be asked to choose from various alternatives. The following settings are known to work as of August, 2014 for building Rust itself, although you may be able to use others:

  • (GCC) Version: 4.8.1
  • (Target) Architecture: x32
  • Threads: win32 - Important
  • Exception: dwarf
  • Build revision: 5

MinGW-w64 does not append itself to the PATH environment variable. Since running rustc requires GCC to be accessible on the path, you should append a path to the MinGW-w64 executables to PATH in the control panel. Specifically, you should add the mingw32\bin or mingw64\bin directory in the install directory to PATH.

Alternately, you can run the mingwbuilds.bat batch file in the install directory to open a configured command prompt.

If you need it, you can now install MSYS2. To do so, follow the instructions in the section on installing MSYS2 with MinGW-w64, but skip the step where you install the MinGW-w64 toolchain package.

Once complete, you should be able to use rustc (and the installed MinGW-w64 tools) from both inside and outside an MSYS2 shell.

IMPORTANT: Even if you do not install MinGW-w64 from within MSYS2, rustc should still be used from within the special MinGW-w64 shells, not the standard MSYS2 shell. This ensures the environment identifies itself as MinGW and not as MSYS.

NOTE: Using the MSYS2 MinGW-w64 shells can alter which specific install of MinGW-w64 is used. The behaviour is as follows:

  • "MSYS2 Shell" / msys2_shell.bat: externally-installed MinGW-w64.
  • "MinGW-w64 Win32 Shell" / mingw32_shell.bat: MinGW-w64 targetting i686 as installed by the MSYS2 package manager (mingw-w64-i686-toolchain). If that is not installed, will fall back to the externally-installed MinGW-w64.
  • "MinGW-w64 Win64 Shell" / mingw64_shell.bat: MinGW-w64 targetting x86-64 as installed by the MSYS2 package manager (mingw-w64-x86_64-toolchain). If that is not installed, will fall back to the externally-installed MinGW-w64.

See "Installing and Verifying Rust".

Installing and Verifying Rust

The simplest way to get a precompiled version of rustc is to download the nightly Rust installer from the Rust website. This should be used unless you have code that requires an older release version of the language.

Once installed, ensure that rustc works by running the following from a command prompt:

> rustc --version

You may also wish to compile and run a minimal test program to ensure that rustc can properly locate and use GCC. Place the following into a file called hello.rs:

fn main() {
    println!("Hello, World!");
}

Compile it as follows:

rustc hello.rs

And then run the resulting hello.exe executable. Remember that, if you are using MSYS or MSYS2, you will likely need to run the result using ./hello rather than just hello.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment