blob: 9e87ce1d9e69a198cfc87d5f200cb82be5bba46c [file] [log] [blame]
Graydon Hoared1affff2012-12-11 01:32:481# Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2# file at the top-level directory of this distribution and at
3# http://rust-lang.org/COPYRIGHT.
4#
5# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8# option. This file may not be copied, modified, or distributed
9# except according to those terms.
10
Brian Anderson334af012014-02-14 11:34:1811# <help> \(^o^)/
Brian Andersonb11e73d2014-02-14 05:22:0812#
Brian Anderson334af012014-02-14 11:34:1813# Greetings, adventurer! The Rust Build System is at your service.
Brian Andersonb11e73d2014-02-14 05:22:0814#
Brian Anderson334af012014-02-14 11:34:1815# Whether you want a genuine copy of `rustc`, access to the latest and
16# most authoritative Rust documentation, or even to investigate the
17# most intimate workings of the compiler itself, you've come to the
18# right place. Let's see what's on the menu.
Brian Andersonb11e73d2014-02-14 05:22:0819#
Brian Anderson334af012014-02-14 11:34:1820# First, start with one of these build targets:
21#
Virgile Andreani54f710f2014-02-18 10:55:3422# * all - The default. Build a complete, bootstrapped compiler.
Brian Anderson334af012014-02-14 11:34:1823# `rustc` will be in `${target-triple}/stage2/bin/`. Run it
24# directly from the build directory if you like. This also
25# comes with docs in `doc/`.
26#
27# * check - Run the complete test suite
28#
Alex Gaynora2fbf9d2015-09-19 12:10:5429# * clean - Clean the build repository. It is advised to run this
Virgile Andreani54f710f2014-02-18 10:55:3430# command if you want to build Rust again, after an update
31# of the git repository.
32#
Brian Anderson334af012014-02-14 11:34:1833# * install - Install Rust. Note that installation is not necessary
34# to use the compiler.
35#
36# * uninstall - Uninstall the binaries
37#
Brian Anderson8d4b6752014-02-15 03:17:5038# For tips on working with The Rust Build System, just:
Brian Anderson334af012014-02-14 11:34:1839#
Brian Anderson8d4b6752014-02-15 03:17:5040# run `make tips`
Brian Anderson334af012014-02-14 11:34:1841#
42# Otherwise
43#
Brian Anderson8d4b6752014-02-15 03:17:5044# run `make`
Brian Anderson334af012014-02-14 11:34:1845#
46# </help>
47#
Brian Anderson8d4b6752014-02-15 03:17:5048# <tips>
Brian Anderson334af012014-02-14 11:34:1849#
50# # The Rust Build System Tip Line
51#
52# There are a bazillion different targets you might want to build. Here
53# are a few ideas.
54#
55# * docs - Build gobs of HTML documentation and put it into `doc/`
56# * check-$(crate) - Test a crate, e.g. `check-std`
57# * check-ref - Run the language reference tests
58# * check-docs - Test the documentation examples
Brian Anderson8d4b6752014-02-15 03:17:5059# * check-stage$(stage)-$(crate) - Test a crate in a specific stage
60# * check-stage$(stage)-{rpass,rfail,cfail,rmake,...} - Run tests in src/test/
61# * check-stage1-T-$(target)-H-$(host) - Run cross-compiled-tests
Georg Brandle24999e2016-05-03 05:13:1062# * tidy - Basic style check, show highest rustc error code and
63# the status of language and lib features
Peter Elmers9b6fe6c2015-06-29 01:49:2264# * rustc-stage$(stage) - Only build up to a specific stage
flo-l4e879862016-06-02 20:19:2065# * $host/stage1/bin/rustc - Only build stage1 rustc, not libstd. For further
66# information see "Rust recipes for build system success" below.
Brian Andersonb11e73d2014-02-14 05:22:0867#
68# Then mix in some of these environment variables to harness the
Brian Anderson334af012014-02-14 11:34:1869# ultimate power of The Rust Build System.
Brian Andersonb11e73d2014-02-14 05:22:0870#
Brian Anderson334af012014-02-14 11:34:1871# * `VERBOSE=1` - Print all commands. Use this to see what's going on.
72# * `RUSTFLAGS=...` - Add compiler flags to all `rustc` invocations
Daniel Micay1ee099d2014-09-07 18:05:3273# * `JEMALLOC_FLAGS=...` - Pass flags to jemalloc's configure script
Brian Anderson334af012014-02-14 11:34:1874#
75# * `TESTNAME=...` - Specify the name of tests to run
76# * `CHECK_IGNORED=1` - Run normally-ignored tests
Alex Crichtonbfbd7322014-05-15 18:15:3577# * `PLEASE_BENCH=1` - Run crate benchmarks (enable `--bench` flag)
Brian Anderson334af012014-02-14 11:34:1878#
79# * `CFG_ENABLE_VALGRIND=1` - Run tests under valgrind
80# * `VALGRIND_COMPILE=1` - Run the compiler itself under valgrind
Tamir Dubersteincc267ce2015-04-17 14:35:3581# (requires `CFG_ENABLE_VALGRIND`)
Brian Anderson334af012014-02-14 11:34:1882#
83# * `NO_REBUILD=1` - Don't rebootstrap when testing std
84# (and possibly other crates)
Brian Anderson8d4b6752014-02-15 03:17:5085# * `NO_MKFILE_DEPS=1` - Don't rebuild for modified .mk files
Brian Anderson334af012014-02-14 11:34:1886#
87# * `SAVE_TEMPS=1` - Use `--save-temps` flag on all `rustc` invocations
88# * `ASM_COMMENTS=1` - Use `-Z asm-comments`
89# * `TIME_PASSES=1` - Use `-Z time-passes`
90# * `TIME_LLVM_PASSES=1` - Use `-Z time-llvm-passes`
91# * `TRACE=1` - Use `-Z trace`
Brian Andersonb11e73d2014-02-14 05:22:0892#
Brian Anderson8d4b6752014-02-15 03:17:5093# # Rust recipes for build system success
94#
Richo Healeyf07b11d2015-06-29 02:05:0995# // Modifying libstd? Use this command to run unit tests just on your change
Brian Anderson8d4b6752014-02-15 03:17:5096# make check-stage1-std NO_REBUILD=1 NO_BENCH=1
97#
flo-l4e879862016-06-02 20:19:2098# // Modifying just rustc?
99# // Compile rustc+libstd once
100# make rustc-stage1
101# // From now on use this command to rebuild just rustc and reuse the previously built libstd
102# // $host is a target triple, eg. x86_64-unknown-linux-gnu
103# // The resulting binary is located at $host/stage1/bin/rustc.
104# // If there are any issues with libstd recompile it with the command above.
105# make $host/stage1/bin/rustc
106#
Brian Anderson8d4b6752014-02-15 03:17:50107# // Added a run-pass test? Use this to test running your test
108# make check-stage1-rpass TESTNAME=my-shiny-new-test
109#
110# // Having trouble figuring out which test is failing? Turn off parallel tests
Steve Klabnik7cbc4282015-03-19 19:42:53111# make check-stage1-std RUST_TEST_THREADS=1
Brian Anderson8d4b6752014-02-15 03:17:50112#
Manish Goregaokarbdecd9d2016-02-25 04:51:32113# // To make debug!() and other logging calls visible, reconfigure:
114# ./configure --enable-debug-assertions
115# make ....
116#
Brian Anderson8d4b6752014-02-15 03:17:50117# If you really feel like getting your hands dirty, then:
Brian Anderson334af012014-02-14 11:34:18118#
Brian Anderson8d4b6752014-02-15 03:17:50119# run `make nitty-gritty`
Brian Anderson334af012014-02-14 11:34:18120#
Guillaume Gomez0619eeb2016-05-07 21:51:13121# # Make command examples
122#
123# ## Docs linked commands
124#
125# * make check-stage1-rustdocck: Builds rustdoc. It has the advantage to compile
126# quite quickly since we're only using stage1
127# executables.
128# * make doc/error-index.md: Gets all doc blocks from doc comments and error
129# explanations to put them in a markdown file. You
130# can then test them by running
131# "rustdoc --test error-index.md".
132#
133# And of course, the wonderfully useful 'make tidy'! Always run it before opening a pull request to rust!
134#
Brian Anderson8d4b6752014-02-15 03:17:50135# </tips>
Brian Anderson334af012014-02-14 11:34:18136#
Virgile Andreaniece12d82014-02-18 10:53:23137# <nitty-gritty>
Brian Anderson334af012014-02-14 11:34:18138#
139# # The Rust Build System
140#
141# Gosh I wish there was something useful here (TODO).
Brian Andersonb11e73d2014-02-14 05:22:08142#
143# # An (old) explanation of how the build is structured:
144#
145# *Note: Hey, like, this is probably inaccurate, and is definitely
146# an outdated and insufficient explanation of the remarkable
Brian Anderson334af012014-02-14 11:34:18147# Rust Build System.*
Brian Anderson6e654562011-10-02 03:12:08148#
149# There are multiple build stages (0-3) needed to verify that the
150# compiler is properly self-hosting. Each stage is divided between
151# 'host' artifacts and 'target' artifacts, where the stageN host
152# compiler builds artifacts for 1 or more stageN target architectures.
153# Once the stageN target compiler has been built for the host
154# architecture it is promoted (copied) to a stageN+1 host artifact.
155#
156# The stage3 host compiler is a compiler that successfully builds
157# itself and should (in theory) be bitwise identical to the stage2
158# host compiler. The process is bootstrapped using a stage0 host
159# compiler downloaded from a previous snapshot.
160#
161# At no time should stageN artifacts be interacting with artifacts
162# from other stages. For consistency, we use the 'promotion' logic
163# for all artifacts, even those that don't make sense on non-host
164# architectures.
165#
166# The directory layout for a stage is intended to match the layout
167# of the installed compiler, and looks like the following:
168#
169# stageN - this is the system root, corresponding to, e.g. /usr
170# bin - binaries compiled for the host
171# lib - libraries used by the host compiler
Jan Niklas Hasse6abe0ef2014-01-05 01:55:20172# rustlib - rustc's own place to organize libraries
Brian Anderson6e654562011-10-02 03:12:08173# $(target) - target-specific artifacts
174# bin - binaries for target architectures
175# lib - libraries for target architectures
176#
177# A note about host libraries:
178#
179# The only libraries that get promoted to stageN/lib are those needed
Brian Anderson19797df2011-11-03 17:53:49180# by rustc. In general, rust programs, even those compiled for the
Brian Anderson6e654562011-10-02 03:12:08181# host architecture will use libraries from the target
182# directories. This gives rust some freedom to experiment with how
183# libraries are managed and versioned without polluting the common
184# areas of the filesystem.
185#
Virgile Andreani54f710f2014-02-18 10:55:34186# General rust binaries may still live in the host bin directory; they
Brian Anderson6e654562011-10-02 03:12:08187# will just link against the libraries in the target lib directory.
188#
189# Admittedly this is a little convoluted.
Brian Anderson334af012014-02-14 11:34:18190#
Richo Healey7a1d7262015-04-11 00:01:09191# If you find yourself working on the make infrastructure itself, and trying to
192# find the value of a given variable after expansion, you can use:
193#
194# make print-VARIABLE_NAME
195#
196# To extract it
197#
Virgile Andreaniece12d82014-02-18 10:53:23198# </nitty-gritty>
Brian Anderson334af012014-02-14 11:34:18199#
Brian Anderson6e654562011-10-02 03:12:08200
Graydon Hoare9c6e7e62011-03-16 16:17:32201######################################################################
Brian Anderson2852fea2014-02-14 07:55:49202# Primary rules
Graydon Hoaree961f532011-03-21 18:23:19203######################################################################
204
Felix S. Klock II2835df22013-09-26 21:56:53205# Issue #9531: If you change the order of any of the following (or add
206# new definitions), make sure definitions always precede their uses,
207# especially for the dependency lists of recipes.
208
Brian Anderson2852fea2014-02-14 07:55:49209# First, load the variables exported by the configure script
210include config.mk
211
212# Just a few macros used everywhere
213include $(CFG_SRC_DIR)mk/util.mk
Brian Anderson2852fea2014-02-14 07:55:49214# Reconfiguring when the makefiles or submodules change
215include $(CFG_SRC_DIR)mk/reconfig.mk
Alex Crichton47093642014-03-25 22:40:52216# All crates and their dependencies
217include $(CFG_SRC_DIR)mk/crates.mk
Brian Anderson2852fea2014-02-14 07:55:49218# Various bits of setup, common macros, and top-level rules
219include $(CFG_SRC_DIR)mk/main.mk
220# C and assembly components that are not LLVM
Alex Crichton0ce1b2f2013-10-31 06:57:27221include $(CFG_SRC_DIR)mk/rt.mk
Brian Anderson2852fea2014-02-14 07:55:49222# Rules for crates in the target directories
Graydon Hoare89dec282012-03-26 23:05:33223include $(CFG_SRC_DIR)mk/target.mk
Brian Anderson2852fea2014-02-14 07:55:49224# Rules for crates in the host directories
Graydon Hoare89dec282012-03-26 23:05:33225include $(CFG_SRC_DIR)mk/host.mk
Brian Anderson2852fea2014-02-14 07:55:49226# Special rules for bootstrapping stage0
Graydon Hoare89dec282012-03-26 23:05:33227include $(CFG_SRC_DIR)mk/stage0.mk
Brian Anderson2852fea2014-02-14 07:55:49228# Rust-specific LLVM extensions
Graydon Hoare89dec282012-03-26 23:05:33229include $(CFG_SRC_DIR)mk/rustllvm.mk
Brian Anderson2852fea2014-02-14 07:55:49230# Documentation
Graydon Hoare89dec282012-03-26 23:05:33231include $(CFG_SRC_DIR)mk/docs.mk
Brian Anderson2852fea2014-02-14 07:55:49232# LLVM
Graydon Hoare89dec282012-03-26 23:05:33233include $(CFG_SRC_DIR)mk/llvm.mk
Michael Woerister7608d062014-11-13 16:25:15234# Rules for installing debugger scripts
235include $(CFG_SRC_DIR)mk/debuggers.mk
Graydon Hoare79ba3152011-06-25 19:23:27236
Graydon Hoare79ba3152011-06-25 19:23:27237######################################################################
238# Secondary makefiles, conditionalized for speed
239######################################################################
240
Brian Anderson2852fea2014-02-14 07:55:49241# The test suite
Graydon Hoaredf8161d2011-06-30 20:41:20242ifneq ($(strip $(findstring check,$(MAKECMDGOALS)) \
243 $(findstring test,$(MAKECMDGOALS)) \
Graydon Hoaredf8161d2011-06-30 20:41:20244 $(findstring tidy,$(MAKECMDGOALS))),)
245 CFG_INFO := $(info cfg: including test rules)
Graydon Hoare89dec282012-03-26 23:05:33246 include $(CFG_SRC_DIR)mk/tests.mk
Corey Richardsonc41a7df2014-07-21 20:04:35247 include $(CFG_SRC_DIR)mk/grammar.mk
Graydon Hoare79ba3152011-06-25 19:23:27248endif
249
Brian Anderson4cd8bdc2014-02-13 01:26:10250# Copy all the distributables to another directory for binary install
251ifneq ($(strip $(findstring prepare,$(MAKECMDGOALS)) \
Brian Anderson508cb292014-02-13 08:22:18252 $(findstring dist,$(MAKECMDGOALS)) \
Brian Anderson4cd8bdc2014-02-13 01:26:10253 $(findstring install,$(MAKECMDGOALS))),)
254 CFG_INFO := $(info cfg: including prepare rules)
255 include $(CFG_SRC_DIR)mk/prepare.mk
256endif
257
Brian Andersone509cd62014-03-26 00:54:26258# Source and binary distribution artifacts
259ifneq ($(strip $(findstring dist,$(MAKECMDGOALS)) \
260 $(findstring install,$(MAKECMDGOALS)) \
261 $(findstring clean,$(MAKECMDGOALS))),)
262 CFG_INFO := $(info cfg: including dist rules)
263 include $(CFG_SRC_DIR)mk/dist.mk
264endif
265
Brian Anderson4cd8bdc2014-02-13 01:26:10266# (Unix) Installation from the build directory
267ifneq ($(findstring install,$(MAKECMDGOALS)),)
268 CFG_INFO := $(info cfg: including install rules)
269 include $(CFG_SRC_DIR)mk/install.mk
270endif
271
Brian Anderson2852fea2014-02-14 07:55:49272# Cleaning
Graydon Hoare79ba3152011-06-25 19:23:27273ifneq ($(findstring clean,$(MAKECMDGOALS)),)
Graydon Hoaredf8161d2011-06-30 20:41:20274 CFG_INFO := $(info cfg: including clean rules)
Graydon Hoare89dec282012-03-26 23:05:33275 include $(CFG_SRC_DIR)mk/clean.mk
Michael Sullivanb01ecb12011-07-21 18:58:01276endif
Brian Anderson9563c172011-10-01 02:00:19277
Brian Anderson2852fea2014-02-14 07:55:49278# CTAGS building
Niko Matsakise1c470c2011-10-12 19:10:21279ifneq ($(strip $(findstring TAGS.emacs,$(MAKECMDGOALS)) \
Felix S. Klock II272ce382016-06-17 10:07:48280 $(findstring TAGS.vi,$(MAKECMDGOALS)) \
281 $(findstring TAGS.rustc.emacs,$(MAKECMDGOALS)) \
282 $(findstring TAGS.rustc.vi,$(MAKECMDGOALS))),)
Niko Matsakise1c470c2011-10-12 19:10:21283 CFG_INFO := $(info cfg: including ctags rules)
Graydon Hoare89dec282012-03-26 23:05:33284 include $(CFG_SRC_DIR)mk/ctags.mk
Niko Matsakise1c470c2011-10-12 19:10:21285endif
Guillaume Gomez0619eeb2016-05-07 21:51:13286
287.DEFAULT:
Georg Brandld5c7ddc2016-05-22 06:28:42288 @echo
289 @echo "======================================================"
Guillaume Gomez0619eeb2016-05-07 21:51:13290 @echo "== If you need help, run 'make help' or 'make tips' =="
Georg Brandld5c7ddc2016-05-22 06:28:42291 @echo "======================================================"
292 @echo
Guillaume Gomez0619eeb2016-05-07 21:51:13293 exit 1