Skip to content

Commit 37fe870

Browse files
committed
---
yaml --- r: 5651 b: refs/heads/master c: 6e65456 h: refs/heads/master i: 5649: aa3dcdf 5647: 4396837 v: v3
1 parent 6f5ca53 commit 37fe870

File tree

11 files changed

+236
-168
lines changed

11 files changed

+236
-168
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 9563c17d78570dc5646786c142a0f0b68a86dd3e
2+
refs/heads/master: 6e654564db85819ef401eeb4e950acf02096796c

trunk/Makefile.in

Lines changed: 76 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
# An explanation of how the build is structured:
2+
#
3+
# There are multiple build stages (0-3) needed to verify that the
4+
# compiler is properly self-hosting. Each stage is divided between
5+
# 'host' artifacts and 'target' artifacts, where the stageN host
6+
# compiler builds artifacts for 1 or more stageN target architectures.
7+
# Once the stageN target compiler has been built for the host
8+
# architecture it is promoted (copied) to a stageN+1 host artifact.
9+
#
10+
# The stage3 host compiler is a compiler that successfully builds
11+
# itself and should (in theory) be bitwise identical to the stage2
12+
# host compiler. The process is bootstrapped using a stage0 host
13+
# compiler downloaded from a previous snapshot.
14+
#
15+
# At no time should stageN artifacts be interacting with artifacts
16+
# from other stages. For consistency, we use the 'promotion' logic
17+
# for all artifacts, even those that don't make sense on non-host
18+
# architectures.
19+
#
20+
# The directory layout for a stage is intended to match the layout
21+
# of the installed compiler, and looks like the following:
22+
#
23+
# stageN - this is the system root, corresponding to, e.g. /usr
24+
# bin - binaries compiled for the host
25+
# lib - libraries used by the host compiler
26+
# rustc - rustc's own place to organize libraries
27+
# $(target) - target-specific artifacts
28+
# bin - binaries for target architectures
29+
# lib - libraries for target architectures
30+
#
31+
# A note about host libraries:
32+
#
33+
# The only libraries that get promoted to stageN/lib are those needed
34+
# by rustc. In general, rustc programs, even those compiled for the
35+
# host architecture will use libraries from the target
36+
# directories. This gives rust some freedom to experiment with how
37+
# libraries are managed and versioned without polluting the common
38+
# areas of the filesystem.
39+
#
40+
# General rust binaries may stil live in the host bin directory; they
41+
# will just link against the libraries in the target lib directory.
42+
#
43+
# Admittedly this is a little convoluted.
44+
145
######################################################################
246
# Residual auto-configuration
347
######################################################################
@@ -142,12 +186,16 @@ COMPILER_INPUTS := $(wildcard $(addprefix $(S)src/comp/, \
142186
# Exports for sub-utilities
143187
######################################################################
144188

189+
# Note that any variable that re-configure should pick up needs to be
190+
# exported
191+
145192
export CFG_SRC_DIR
146193
export CFG_BUILD_DIR
147194
export CFG_VERSION
148195
export CFG_HOST_TRIPLE
149196
export CFG_LLVM_ROOT
150197
export CFG_ENABLE_MINGW_CROSS
198+
export CFG_PREFIX
151199

152200
######################################################################
153201
# Subprograms
@@ -179,33 +227,34 @@ TARGET_HOST_ROOT$(1) = $$(TARGET_ROOT$(1)$$(CFG_HOST_TRIPLE))
179227
TARGET_HOST_BIN$(1) = $$(TARGET_BIN$(1)$$(CFG_HOST_TRIPLE))
180228
TARGET_HOST_LIB$(1) = $$(TARGET_LIB$(1)$$(CFG_HOST_TRIPLE))
181229

230+
# The name of the standard library used by rustc
182231
ifdef CFG_DISABLE_SHAREDSTD
183232
HOST_STDLIB_DEFAULT$(1) = $$(HOST_LIB$(1))/libstd.rlib
233+
TARGET_STDLIB_DEFAULT$(1)$(2) = $$(TARGET_LIB$(1)$(2))/libstd.rlib
184234
else
185235
HOST_STDLIB_DEFAULT$(1) = $$(HOST_LIB$(1))/$(CFG_STDLIB)
236+
TARGET_STDLIB_DEFAULT$(1)$(2) = $$(TARGET_LIB$(1)$(2))/$(CFG_STDLIB)
186237
endif
187238

188-
ifdef CFG_DISABLE_SHAREDSTD
189-
SREQ$(1)$(2) = $$(HOST_BIN$(1))/rustc$(X) \
190-
$$(HOST_LIB$(1))/$$(CFG_RUNTIME) \
191-
$$(HOST_STDLIB_DEFAULT$(1)) \
192-
$$(HOST_LIB$(1))/$$(CFG_RUSTLLVM) \
193-
$$(TARGET_LIB$(1)$(2))/$$(CFG_RUNTIME) \
194-
$$(TARGET_LIB$(1)$(2))/$$(CFG_STDLIB) \
195-
$$(TARGET_LIB$(1)$(2))/intrinsics.bc \
196-
$$(TARGET_LIB$(1)$(2))/main.o \
197-
$$(MKFILES)
198-
else
199-
SREQ$(1)$(2) = $$(HOST_BIN$(1))/rustc$(X) \
200-
$$(HOST_LIB$(1))/$$(CFG_RUNTIME) \
201-
$$(HOST_STDLIB_DEFAULT$(1)) \
202-
$$(HOST_LIB$(1))/$$(CFG_RUSTLLVM) \
203-
$$(TARGET_LIB$(1)$(2))/$$(CFG_RUNTIME) \
204-
$$(TARGET_LIB$(1)$(2))/$$(CFG_STDLIB) \
205-
$$(TARGET_LIB$(1)$(2))/intrinsics.bc \
206-
$$(TARGET_LIB$(1)$(2))/main.o \
207-
$$(MKFILES)
208-
endif
239+
# Preqrequisites for using the stageN compiler
240+
HOST_SREQ$(1) = \
241+
$$(HOST_BIN$(1))/rustc$$(X) \
242+
$$(HOST_LIB$(1))/$$(CFG_RUNTIME) \
243+
$$(HOST_LIB$(1))/$$(CFG_RUSTLLVM) \
244+
$$(HOST_STDLIB_DEFAULT$(1)) \
245+
$$(MKFILES)
246+
247+
# Prerequisites for using the stageN compiler to build target artifacts
248+
TARGET_SREQ$(1)$(2) = \
249+
$$(HOST_SREQ$(1)) \
250+
$$(TARGET_LIB$(1)$(2))/$$(CFG_RUNTIME) \
251+
$$(TARGET_LIB$(1)$(2))/intrinsics.bc \
252+
$$(TARGET_LIB$(1)$(2))/main.o
253+
254+
# Prerequisites for complete stageN targets
255+
SREQ$(1)$(2) = \
256+
$$(TARGET_SREQ$(1)$(2)) \
257+
$$(TARGET_LIB$(1)$(2))/$$(CFG_STDLIB)
209258

210259
ifeq ($(1),0)
211260
# Don't run the the stage0 compiler under valgrind - that ship has sailed
@@ -241,16 +290,14 @@ CFG_INFO := $(info cfg: *** compiler is in snapshot transition ***)
241290
CFG_INFO := $(info cfg: *** stage2 and later will not be built ***)
242291
CFG_INFO := $(info cfg:)
243292

244-
FUZZ := $(HOST_BIN1)/fuzzer$(X)
293+
all: $(SREQ1$(CFG_HOST_TRIPLE)) $(GENERATED) $(DOCS)
245294

246-
all: $(SREQ0$(CFG_HOST_TRIPLE)) $(SREQ1$(CFG_HOST_TRIPLE)) \
247-
$(GENERATED) $(DOCS) $(FUZZ)
248295
else
249296

250-
ALL_SREQS = $(foreach target,$(CFG_TARGET_TRIPLES), \
251-
$(SREQ0$(target)) $(SREQ1$(target)) $(SREQ2$(target)) $(SREQ3$(target)))
297+
FUZZ := $(HOST_BIN3)/fuzzer$(X)
298+
299+
all: $(SREQ3$(CFG_HOST_TRIPLE)) $(GENERATED) $(DOCS) $(FUZZ)
252300

253-
all: $(ALL_SREQS) $(GENERATED) $(DOCS) $(FUZZ)
254301
endif
255302

256303

@@ -268,7 +315,8 @@ config.mk: $(S)configure $(S)Makefile.in $(S)src/snapshots.txt
268315
######################################################################
269316

270317
include $(CFG_SRC_DIR)/mk/intrinsics.mk
271-
include $(CFG_SRC_DIR)/mk/stageN.mk
318+
include $(CFG_SRC_DIR)/mk/target.mk
319+
include $(CFG_SRC_DIR)/mk/host.mk
272320
include $(CFG_SRC_DIR)/mk/stage0.mk
273321
include $(CFG_SRC_DIR)/mk/rt.mk
274322
include $(CFG_SRC_DIR)/mk/rustllvm.mk

trunk/configure

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ opt mingw-cross 0 "cross-compile for win32 using mingw"
223223

224224
if [ $HELP -eq 1 ]
225225
then
226+
echo ""
227+
echo "Useful environment variables:"
228+
echo ""
229+
printf " %-32s %s\n" "CFG_LLVM_ROOT" "The host LLVM install"
230+
printf " %-32s %s\n" "CFG_PREFIX" "The installation prefix"
226231
echo ""
227232
exit 0
228233
fi

trunk/mk/clean.mk

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
######################################################################
44

55
CLEAN_STAGE_RULES = $(foreach target,$(CFG_TARGET_TRIPLES), \
6-
clean0$(target) clean1$(target) clean2$(target) clean3$(target))
6+
clean0$(target) clean1$(target) clean2$(target) clean3$(target)) \
7+
clean0 clean1 clean2 clean3
78

89

910
.PHONY: clean
@@ -43,14 +44,20 @@ clean-misc:
4344

4445
define CLEAN_STAGE_N
4546

46-
clean$(1)$(2):
47+
clean$(1):
4748
$(Q)rm -f $$(HOST_BIN$(1))/rustc
4849
$(Q)rm -f $$(HOST_BIN$(1))/fuzzer
4950
$(Q)rm -f $$(HOST_LIB$(1))/$(CFG_RUNTIME)
5051
$(Q)rm -f $$(HOST_LIB$(1))/$(CFG_STDLIB)
5152
$(Q)rm -f $$(HOST_LIB$(1))/$(CFG_RUSTLLVM)
53+
$(Q)rm -f $$(HOST_LIB$(1))/libstd.rlib
54+
55+
clean$(1)$(2):
56+
$(Q)rm -f $$(TARGET_BIN$(1)$(2))/rustc
57+
$(Q)rm -f $$(TARGET_BIN$(1)$(2))/fuzzer
5258
$(Q)rm -f $$(TARGET_LIB$(1)$(2))/$(CFG_RUNTIME)
5359
$(Q)rm -f $$(TARGET_LIB$(1)$(2))/$(CFG_STDLIB)
60+
$(Q)rm -f $$(TARGET_LIB$(1)$(2))/$(CFG_RUSTLLVM)
5461
$(Q)rm -f $$(TARGET_LIB$(1)$(2))/libstd.rlib
5562
$(Q)rm -f $$(TARGET_LIB$(1)$(2))/intrinsics.bc
5663
$(Q)rm -f $$(TARGET_LIB$(1)$(2))/main.o

trunk/mk/fuzzer.mk

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,23 @@ FUZZER_INPUTS := $(wildcard $(addprefix $(S)src/fuzzer/, *.rs))
33

44
define FUZZ_STAGE_N
55

6-
stage$(2)/bin/fuzzer$$(X): $$(FUZZER_CRATE) $$(FUZZER_INPUTS) \
7-
$$(SREQ$(2)$$(CFG_HOST_TRIPLE)) \
8-
$$(HOST_LIB$(2))/$$(CFG_RUNTIME) \
9-
$$(HOST_LIB$(2))/$$(CFG_RUSTLLVM) \
10-
$$(HOST_LIB$(2))/$$(CFG_STDLIB) \
11-
$$(HOST_LIB$(2))/$$(CFG_LIBRUSTC)
6+
# We only really care about fuzzing on the host arch
7+
$$(TARGET_BIN$(1)$(CFG_HOST_TRIPLE))/fuzzer$$(X): \
8+
$$(FUZZER_CRATE) $$(FUZZER_INPUTS) \
9+
$$(TARGET_SREQ$(1)$(CFG_HOST_TRIPLE)) \
10+
$$(TARGET_LIB$(1)$(CFG_HOST_TRIPLE))/$$(CFG_STDLIB) \
11+
$$(TARGET_LIB$(1)$(CFG_HOST_TRIPLE))/$$(CFG_LIBRUSTC)
1212
@$$(call E, compile_and_link: $$@)
13-
$$(STAGE$(1)) -L $$(HOST_LIB$(2)) -o $$@ $$<
13+
$$(STAGE$(1)) -o $$@ $$<
14+
15+
# Promote the stageN target to stageN+1 host
16+
# FIXME: Shouldn't need to depend on host/librustc.so once
17+
# rpath is working
18+
$$(HOST_BIN$(2))/fuzzer$$(X): \
19+
$$(TARGET_BIN$(1)$(CFG_HOST_TRIPLE))/fuzzer$$(X) \
20+
$$(HOST_LIB$(2))/$$(CFG_LIBRUSTC)
21+
@$$(call E, cp: $$@)
22+
$$(Q)cp $$< $$@
1423

1524
endef
1625

trunk/mk/host.mk

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# HOST_STAGE_N template: arg 1 is the N we're promoting *from*, arg 2
2+
# is N+1. Must be invoked to promote target artifacts to host artifacts
3+
# for stage 1-3 (stage0 host artifacts come from the snapshot).
4+
#
5+
# The easiest way to read this template is to assume we're promoting
6+
# stage1 to stage2 and mentally gloss $(1) as 1, $(2) as 2.
7+
8+
define HOST_STAGE_N
9+
10+
# Host libraries and executables (stage$(2)/bin/rustc and its runtime needs)
11+
12+
$$(HOST_BIN$(2))/rustc$$(X): \
13+
$$(TARGET_HOST_BIN$(1))/rustc$$(X) \
14+
$$(HOST_LIB$(2))/$$(CFG_RUNTIME) \
15+
$$(HOST_LIB$(2))/$$(CFG_RUSTLLVM) \
16+
$$(HOST_STDLIB_DEFAULT$(2))
17+
@$$(call E, cp: $$@)
18+
$$(Q)cp $$< $$@
19+
20+
# FIXME: The fuzzer depends on this. Remove once it's rpathed to correctly
21+
# find it in the appropriate target directory
22+
$$(HOST_LIB$(2))/$$(CFG_LIBRUSTC): \
23+
$$(TARGET_HOST_LIB$(1))/$$(CFG_LIBRUSTC) \
24+
$$(HOST_LIB$(2))/$$(CFG_RUNTIME) \
25+
$$(HOST_LIB$(2))/$$(CFG_RUSTLLVM) \
26+
$$(HOST_STDLIB_DEFAULT$(2))
27+
@$$(call E, cp: $$@)
28+
$$(Q)cp $$< $$@
29+
30+
$$(HOST_LIB$(2))/$$(CFG_RUNTIME): \
31+
$$(TARGET_HOST_LIB$(1))/$$(CFG_RUNTIME)
32+
@$$(call E, cp: $$@)
33+
$$(Q)cp $$< $$@
34+
35+
$$(HOST_LIB$(2))/$$(CFG_STDLIB): \
36+
$$(TARGET_HOST_LIB$(1))/$$(CFG_STDLIB) \
37+
$$(HOST_LIB$(2))/$$(CFG_RUNTIME)
38+
@$$(call E, cp: $$@)
39+
$$(Q)cp $$< $$@
40+
41+
$$(HOST_LIB$(2))/libstd.rlib: \
42+
$$(TARGET_HOST_LIB$(1))/libstd.rlib \
43+
$$(HOST_LIB$(2))/$$(CFG_RUNTIME)
44+
@$$(call E, cp: $$@)
45+
$$(Q)cp $$< $$@
46+
47+
$$(HOST_LIB$(2))/$$(CFG_RUSTLLVM): \
48+
$$(TARGET_HOST_LIB$(1))/$$(CFG_RUSTLLVM)
49+
@$$(call E, cp: $$@)
50+
$$(Q)cp $$< $$@
51+
52+
endef
53+
54+
$(eval $(call HOST_STAGE_N,0,1))
55+
$(eval $(call HOST_STAGE_N,1,2))
56+
$(eval $(call HOST_STAGE_N,2,3))

trunk/mk/install.mk

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
ifdef VERBOSE
22
INSTALL = cp $(1)/$(3) $(2)/$(3)
33
else
4-
INSTALL = @$(call E, install $(2)/$(3)) && cp $(1)/$(3) $(2)/$(3)
4+
INSTALL = @$(call E, install: $(2)/$(3)) && cp $(1)/$(3) $(2)/$(3)
55
endif
66

7-
ISTAGE = 1
7+
# The stage we install from
8+
ISTAGE = 3
89

910
PREFIX_ROOT = $(CFG_PREFIX)
1011
PREFIX_BIN = $(PREFIX_ROOT)/bin

trunk/mk/snap.mk

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11

2-
snap-stage1: $(HOST_BIN1)/rustc$(X) $(HOST_LIB1)/$(CFG_RUNTIME) \
3-
$(HOST_LIB1)/$(CFG_RUSTLLVM) $(HOST_LIB1)/$(CFG_STDLIB)
2+
snap-stage1: $(HOST_SREQ1)
43
$(S)src/etc/make-snapshot.py stage1
54

6-
snap-stage2: $(HOST_BIN2)/rustc$(X) $(HOST_LIB2)/$(CFG_RUNTIME) \
7-
$(HOST_LIB2)/$(CFG_RUSTLLVM) $(HOST_LIB2)/$(CFG_STDLIB)
5+
snap-stage2: $(HOST_SREQ2)
86
$(S)src/etc/make-snapshot.py stage2
97

10-
snap-stage3: $(HOST_BIN3)/rustc$(X) $(HOST_LIB3)/$(CFG_RUNTIME) \
11-
$(HOST_LIB3)/$(CFG_RUSTLLVM) $(HOST_LIB3)/$(CFG_STDLIB)
8+
snap-stage3: $(HOST_SREQ3)
129
$(S)src/etc/make-snapshot.py stage3

trunk/mk/stage0.mk

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
$(HOST_BIN0)/rustc$(X): $(S)src/snapshots.txt $(S)src/etc/get-snapshot.py $(MKFILES)
1+
# Extract the snapshot host compiler
2+
3+
$(HOST_BIN0)/rustc$(X): \
4+
$(S)src/snapshots.txt \
5+
$(S)src/etc/get-snapshot.py $(MKFILES)
26
@$(call E, fetch: $@)
37
$(Q)$(S)src/etc/get-snapshot.py
48
$(Q)touch $@
59

6-
# Host libs will be made in the process of making rustc above.
10+
# Host libs will be extracted by the above rule
711

812
$(HOST_LIB0)/$(CFG_RUNTIME): $(HOST_BIN0)/rustc$(X)
913
$(Q)touch $@
@@ -13,10 +17,3 @@ $(HOST_LIB0)/$(CFG_STDLIB): $(HOST_BIN0)/rustc$(X)
1317

1418
$(HOST_LIB0)/$(CFG_RUSTLLVM): $(HOST_BIN0)/rustc$(X)
1519
$(Q)touch $@
16-
17-
# Instantiate template (in stageN.mk) for building
18-
# target libraries.
19-
20-
SREQpre = $(MKFILES)
21-
$(eval $(call TARGET_LIBS,pre,0,$(CFG_HOST_TRIPLE)))
22-

0 commit comments

Comments
 (0)