Skip to content

Commit 0148daa

Browse files
committed
Reorganize structure of build directory
Each stage is organized more according to Unix standards and to accommodate multiple target architectures. stageN/ bin - rustc lives here lib - libraries that rustc needs lib/rustc/$(target_triple/ - target libraries
1 parent 79e4961 commit 0148daa

File tree

9 files changed

+126
-114
lines changed

9 files changed

+126
-114
lines changed

Makefile.in

+23-19
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ CFG_LIBRUSTC :=$(call CFG_LIB_NAME,rustc)
5656
ifdef CFG_DISABLE_SHAREDSTD
5757
CFG_STDLIB_DEFAULT = $(1)/lib/libstd.rlib
5858
else
59-
CFG_STDLIB_DEFAULT = $(2)/$(CFG_STDLIB)
59+
CFG_STDLIB_DEFAULT = $(2)/lib/$(CFG_STDLIB)
6060
endif
6161

6262
# version-string calculation
@@ -168,21 +168,24 @@ LLC := $(CFG_LLVM_BINDIR)/llc$(X)
168168

169169
define SREQ
170170
ifdef CFG_DISABLE_SHAREDSTD
171-
SREQ$(1) = stage$(1)/rustc$(X) \
172-
stage$(1)/$$(CFG_RUNTIME) \
171+
SREQ$(1)$(2) = stage$(1)/bin/rustc$(X) \
172+
stage$(1)/lib/$$(CFG_RUNTIME) \
173173
$$(call CFG_STDLIB_DEFAULT,stage$(1),stage$(1)) \
174-
stage$(1)/$$(CFG_RUSTLLVM) \
175-
stage$(1)/lib/main.o \
176-
stage$(1)/lib/$$(CFG_RUNTIME) \
174+
stage$(1)/lib/$$(CFG_RUSTLLVM) \
175+
stage$(1)/lib/rustc/$(2)/$$(CFG_RUNTIME) \
176+
stage$(1)/lib/rustc/$(2)/$$(CFG_STDLIB) \
177+
stage$(1)/lib/rustc/$(2)/intrinsics.bc \
178+
stage$(1)/lib/rustc/$(2)/main.o \
177179
$$(MKFILES)
178180
else
179-
SREQ$(1) = stage$(1)/rustc$(X) \
180-
stage$(1)/$$(CFG_RUNTIME) \
181+
SREQ$(1)$(2) = stage$(1)/bin/rustc$(X) \
182+
stage$(1)/lib/$$(CFG_RUNTIME) \
181183
$$(call CFG_STDLIB_DEFAULT,stage$(1),stage$(1)) \
182-
stage$(1)/$$(CFG_RUSTLLVM) \
183-
stage$(1)/lib/main.o \
184-
stage$(1)/lib/$$(CFG_RUNTIME) \
185-
stage$(1)/lib/$$(CFG_STDLIB) \
184+
stage$(1)/lib/$$(CFG_RUSTLLVM) \
185+
stage$(1)/lib/rustc/$(2)/$$(CFG_RUNTIME) \
186+
stage$(1)/lib/rustc/$(2)/$$(CFG_STDLIB) \
187+
stage$(1)/lib/rustc/$(2)/intrinsics.bc \
188+
stage$(1)/lib/rustc/$(2)/main.o \
186189
$$(MKFILES)
187190
endif
188191

@@ -194,16 +197,17 @@ CFG_VALGRIND_COMPILE$(1) = $$(CFG_VALGRIND_COMPILE)
194197
endif
195198

196199
STAGE$(1) := $$(Q)$$(call CFG_RUN_TARG,stage$(1), \
197-
$$(CFG_VALGRIND_COMPILE$(1)) stage$(1)/rustc$$(X) \
198-
$$(CFG_RUSTC_FLAGS))
200+
$$(CFG_VALGRIND_COMPILE$(1)) stage$(1)/bin/rustc$$(X) \
201+
$$(CFG_RUSTC_FLAGS) --target=$(2))
199202
endef
200203

201-
FUZZ := stage1/fuzzer$(X)
204+
FUZZ := stage1/bin/fuzzer$(X)
202205

203-
$(eval $(call SREQ,0))
204-
$(eval $(call SREQ,1))
205-
$(eval $(call SREQ,2))
206-
$(eval $(call SREQ,3))
206+
$(foreach target,$(CFG_TARGET_TRIPLES), \
207+
$(eval $(call SREQ,0,$(target))) \
208+
$(eval $(call SREQ,1,$(target))) \
209+
$(eval $(call SREQ,2,$(target))) \
210+
$(eval $(call SREQ,3,$(target))))
207211

208212
######################################################################
209213
# Entrypoint rule

mk/fuzzer.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
FUZZER_CRATE := $(S)src/fuzzer/fuzzer.rc
44
FUZZER_INPUTS := $(wildcard $(addprefix $(S)src/fuzzer/, *.rs))
55

6-
stage1/fuzzer$(X): $(FUZZER_CRATE) $(FUZZER_INPUTS) $(SREQ1) \
7-
stage1/lib/$(CFG_LIBRUSTC)
6+
stage1/bin/fuzzer$(X): $(FUZZER_CRATE) $(FUZZER_INPUTS) $(SREQ1) \
7+
stage1/lib/rustc/$(CFG_HOST_TRIPLE)/$(CFG_LIBRUSTC)
88
@$(call E, compile_and_link: $@)
99
$(STAGE1) -o $@ $<

mk/platform.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ ifdef CFG_UNIXY
9898
CFG_EXE_SUFFIX :=
9999
CFG_LDPATH :=
100100
CFG_RUN=$(CFG_LDENV)=$(1) $(2)
101-
CFG_RUN_TARG=$(call CFG_RUN,$(CFG_BUILD_DIR)/$(1),$(2))
101+
CFG_RUN_TARG=$(call CFG_RUN,$(CFG_BUILD_DIR)/$(1)/lib,$(2))
102102
CFG_RUN_TEST=$(call CFG_RUN,$(call CFG_TESTLIB,$(1)),\
103103
$(CFG_VALGRIND) $(1))
104104
CFG_LIBUV_LINK_FLAGS=-lpthread

mk/stage0.mk

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
# FIXME: temporary hack: stdlib and rustrt come in the lib/ directory,
22
# but we want them in the base directory, so we move them out.
3-
stage0/rustc$(X): $(S)src/snapshots.txt $(S)src/etc/get-snapshot.py $(MKFILES)
3+
stage0/bin/rustc$(X): $(S)src/snapshots.txt $(S)src/etc/get-snapshot.py $(MKFILES)
44
@$(call E, fetch: $@)
55
$(Q)$(S)src/etc/get-snapshot.py
6-
$(Q)mv stage0/lib/$(CFG_STDLIB) stage0/$(CFG_STDLIB)
6+
$(Q)cp stage0/rustc$(X) stage0/bin/rustc$(X)
7+
$(Q)cp stage0/$(CFG_RUNTIME) stage0/lib/$(CFG_RUNTIME)
8+
$(Q)cp stage0/$(CFG_RUSTLLVM) stage0/lib/$(CFG_RUSTLLVM)
9+
$(Q)mkdir -p stage0/bin/lib
10+
$(Q)cp stage0/lib/intrinsics.bc stage0/bin/lib/intrinsics.bc
11+
$(Q)cp stage0/lib/glue.o stage0/bin/lib/glue.o
12+
$(Q)cp stage0/lib/main.o stage0/bin/lib/main.o
713
$(Q)touch $@
814

915
# Host libs will be made in the process of making rustc above.
1016

11-
stage0/$(CFG_RUNTIME): stage0/rustc$(X)
17+
stage0/lib/$(CFG_RUNTIME): stage0/bin/rustc$(X)
1218
$(Q)touch $@
1319

14-
stage0/$(CFG_STDLIB): stage0/rustc$(X)
20+
stage0/lib/$(CFG_STDLIB): stage0/bin/rustc$(X)
1521
$(Q)touch $@
1622

17-
stage0/$(CFG_RUSTLLVM): stage0/rustc$(X)
23+
stage0/lib/$(CFG_RUSTLLVM): stage0/bin/rustc$(X)
1824
$(Q)touch $@
1925

2026
# Instantiate template (in stageN.mk) for building
2127
# target libraries.
2228

23-
SREQpre = stage0/lib/main.o $(MKFILES)
29+
SREQpre = stage0/lib/$(CFG_HOST_TRIPLE)/main.o $(MKFILES)
2430
$(eval $(call TARGET_LIBS,pre,0,$(CFG_HOST_TRIPLE)))
2531

mk/stageN.mk

+37-59
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,41 @@ define STAGE_N
2020
# compiler that relies on a .o file.
2121

2222
STAGE$(2) := $$(Q)$$(call CFG_RUN_TARG,stage$(2), \
23-
$$(CFG_VALGRIND_COMPILE) stage$(2)/rustc$$(X) \
24-
$$(CFG_RUSTC_FLAGS))
23+
$$(CFG_VALGRIND_COMPILE) stage$(2)/bin/rustc$$(X) \
24+
$$(CFG_RUSTC_FLAGS) --target=$(3))
2525

2626
PERF_STAGE$(2) := $$(Q)$$(call CFG_RUN_TARG,stage$(2), \
27-
$$(CFG_PERF_TOOL) stage$(2)/rustc$$(X) \
28-
$$(CFG_RUSTC_FLAGS))
27+
$$(CFG_PERF_TOOL) stage$(2)/bin/rustc$$(X) \
28+
$$(CFG_RUSTC_FLAGS) --target=$(3))
2929

30-
stage$(2)/%.o: stage$(2)/%.s
30+
stage$(2)/bin/%.o: stage$(2)/bin/%.s
3131
@$$(call E, assemble [gcc]: $$@)
3232
$$(Q)gcc $$(CFG_GCCISH_CFLAGS) -o $$@ -c $$<
3333

34-
stage$(2)/rustc$$(X): $$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
35-
stage$(2)/$$(CFG_RUNTIME) \
36-
$$(call CFG_STDLIB_DEFAULT,stage$(1),stage$(2)) \
37-
stage$(2)/$$(CFG_RUSTLLVM) \
38-
$$(SREQ$(1))
34+
stage$(2)/lib/%.o: stage$(2)/lib/%.s
35+
@$$(call E, assemble [gcc]: $$@)
36+
$$(Q)gcc $$(CFG_GCCISH_CFLAGS) -o $$@ -c $$<
37+
38+
# FIXME: the bin/lib/libstd.so dep is transitional
39+
40+
stage$(2)/bin/rustc$$(X): $$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
41+
stage$(2)/lib/$$(CFG_RUNTIME) \
42+
$$(call CFG_STDLIB_DEFAULT,stage$(1),stage$(2)) \
43+
stage$(2)/lib/$$(CFG_RUSTLLVM) \
44+
stage$(1)/bin/lib/$$(CFG_STDLIB) \
45+
$$(SREQ$(1)$(3))
3946
@$$(call E, compile_and_link: $$@)
4047
$$(STAGE$(1)) -L stage$(2) -o $$@ $$<
4148

42-
stage$(2)/$$(CFG_RUNTIME): rt/$$(CFG_RUNTIME)
49+
stage$(2)/lib/$$(CFG_RUNTIME): rt/$$(CFG_RUNTIME)
4350
@$$(call E, cp: $$@)
4451
$$(Q)cp $$< $$@
4552

46-
stage$(2)/$$(CFG_STDLIB): stage$(1)/lib/$$(CFG_STDLIB)
53+
stage$(2)/lib/$$(CFG_STDLIB): stage$(1)/lib/rustc/$$(CFG_HOST_TRIPLE)/$$(CFG_STDLIB)
4754
@$$(call E, cp: $$@)
4855
$$(Q)cp $$< $$@
4956

50-
stage$(2)/$$(CFG_RUSTLLVM): rustllvm/$$(CFG_RUSTLLVM)
57+
stage$(2)/lib/$$(CFG_RUSTLLVM): rustllvm/$$(CFG_RUSTLLVM)
5158
@$$(call E, cp: $$@)
5259
$$(Q)cp $$< $$@
5360

@@ -59,41 +66,6 @@ endef
5966

6067

6168
define TARGET_LIBS
62-
stage$(2)/lib/intrinsics.bc: $$(INTRINSICS_BC)
63-
@$$(call E, cp: $$@)
64-
$$(Q)cp $$< $$@
65-
66-
stage$(2)/lib/main.o: rt/main.o
67-
@$$(call E, cp: $$@)
68-
$$(Q)cp $$< $$@
69-
70-
stage$(2)/lib/$$(CFG_LIBRUSTC): $$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
71-
$$(SREQ$(2))
72-
@$$(call E, compile_and_link: $$@)
73-
$$(STAGE$(2)) --lib -o $$@ $$<
74-
75-
stage$(2)/lib/$$(CFG_STDLIB): $$(STDLIB_CRATE) $$(STDLIB_INPUTS) \
76-
stage$(2)/rustc$$(X) \
77-
stage$(2)/$$(CFG_RUNTIME) \
78-
stage$(2)/$$(CFG_RUSTLLVM) \
79-
stage$(2)/lib/intrinsics.bc \
80-
$$(SREQ$(1))
81-
@$$(call E, compile_and_link: $$@)
82-
$$(STAGE$(2)) --lib -o $$@ $$<
83-
84-
stage$(2)/lib/libstd.rlib: $$(STDLIB_CRATE) $$(STDLIB_INPUTS) \
85-
stage$(2)/rustc$$(X) \
86-
stage$(2)/$$(CFG_RUNTIME) \
87-
stage$(2)/$$(CFG_RUSTLLVM) \
88-
stage$(2)/lib/intrinsics.bc \
89-
$$(SREQ$(1))
90-
@$$(call E, compile_and_link: $$@)
91-
$$(STAGE$(2)) --lib --static -o $$@ $$<
92-
93-
stage$(2)/lib/$$(CFG_RUNTIME): rt/$$(CFG_RUNTIME)
94-
@$$(call E, cp: $$@)
95-
$$(Q)cp $$< $$@
96-
9769

9870
# New per-target-arch target libraries; when we've transitioned to
9971
# using these exclusively, you should delete the non-arch-prefixed
@@ -109,30 +81,36 @@ stage$(2)/lib/rustc/$(3)/main.o: rt/main.o
10981

11082
stage$(2)/lib/rustc/$(3)/$$(CFG_LIBRUSTC): \
11183
$$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
112-
$$(SREQ$(2))
84+
$$(SREQ$(2)$(3))
11385
@$$(call E, compile_and_link: $$@)
11486
$$(STAGE$(2)) --lib -o $$@ $$<
11587

11688
stage$(2)/lib/rustc/$(3)/$$(CFG_STDLIB): \
11789
$$(STDLIB_CRATE) $$(STDLIB_INPUTS) \
118-
stage$(2)/rustc$$(X) \
119-
stage$(2)/$$(CFG_RUNTIME) \
120-
stage$(2)/$$(CFG_RUSTLLVM) \
121-
stage$(2)/lib/intrinsics.bc \
122-
$$(SREQ$(1))
90+
stage$(2)/bin/rustc$$(X) \
91+
stage$(2)/lib/$$(CFG_RUNTIME) \
92+
stage$(2)/lib/$$(CFG_RUSTLLVM) \
93+
stage$(2)/lib/rustc/$(3)/intrinsics.bc \
94+
$$(SREQ$(1)$(3))
12395
@$$(call E, compile_and_link: $$@)
12496
$$(STAGE$(2)) --lib -o $$@ $$<
12597

12698
stage$(2)/lib/rustc/$(3)/libstd.rlib: \
12799
$$(STDLIB_CRATE) $$(STDLIB_INPUTS) \
128-
stage$(2)/rustc$$(X) \
129-
stage$(2)/$$(CFG_RUNTIME) \
130-
stage$(2)/$$(CFG_RUSTLLVM) \
131-
stage$(2)/lib/intrinsics.bc \
132-
$$(SREQ$(1))
100+
stage$(2)/bin/rustc$$(X) \
101+
stage$(2)/lib/$$(CFG_RUNTIME) \
102+
stage$(2)/lib/$$(CFG_RUSTLLVM) \
103+
stage$(2)/lib/rustc/$(3)/intrinsics.bc \
104+
$$(SREQ$(1)$(3))
133105
@$$(call E, compile_and_link: $$@)
134106
$$(STAGE$(2)) --lib --static -o $$@ $$<
135107

108+
# FIXME: Transitional so that stage0 can find std when building stage1/rustc
109+
stage$(2)/bin/lib/$$(CFG_STDLIB): stage$(2)/lib/rustc/$(3)/$$(CFG_STDLIB)
110+
@$$(call E, cp: $$@)
111+
$$(Q)mkdir -p stage$(2)/bin/lib
112+
$$(Q)cp $$< $$@
113+
136114
stage$(2)/lib/rustc/$(3)/$$(CFG_RUNTIME): rt/$$(CFG_RUNTIME)
137115
@$$(call E, cp: $$@)
138116
$$(Q)cp $$< $$@

mk/tests.mk

+13-13
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ check-stage$(2): tidy \
131131
check-stage$(2)-std: test/stdtest.stage$(2).out \
132132

133133
test/stdtest.stage$(2)$$(X): $$(STDTEST_CRATE) $$(STDTEST_INPUTS) \
134-
$$(SREQ$(2))
134+
$$(SREQ$(2)$(CFG_HOST_TRIPLE))
135135
@$$(call E, compile_and_link: $$@)
136136
$$(STAGE$(2)) -o $$@ $$< --test
137137

@@ -146,16 +146,16 @@ test/stdtest.stage$(2).out.tmp: test/stdtest.stage$(2)$$(X)
146146
check-stage$(2)-rustc: test/rustctest.stage$(2).out \
147147

148148
test/rustctest.stage$(2)$$(X): $$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
149-
stage$(2)/$$(CFG_RUNTIME) \
149+
stage$(2)/lib/$$(CFG_RUNTIME) \
150150
$$(call CFG_STDLIB_DEFAULT,stage$(1),stage$(2)) \
151-
stage$(2)/$$(CFG_RUSTLLVM) \
152-
$$(SREQ$(1))
151+
stage$(2)/lib/$$(CFG_RUSTLLVM) \
152+
$$(SREQ$(1)$(CFG_HOST_TRIPLE))
153153
@$$(call E, compile_and_link: $$@)
154154
$$(STAGE$(1)) -o $$@ $$< --test
155155

156156
test/rustctest.stage$(2).out.tmp: test/rustctest.stage$(2)$$(X)
157157
@$$(call E, run: $$<)
158-
$$(Q)$$(call CFG_RUN,stage$(2),$$(CFG_VALGRIND) $$<) \
158+
$$(Q)$$(call CFG_RUN,$(CFG_BUILD_DIR)/stage$(2)/lib,$$(CFG_VALGRIND) $$<) \
159159
$$(TESTARGS)
160160
$$(Q)touch $$@
161161

@@ -185,11 +185,11 @@ check-stage$(2)-pretty: check-stage$(2)-pretty-rpass \
185185
check-stage$(2)-pretty-bench \
186186
check-stage$(2)-pretty-pretty \
187187

188-
CTEST_COMMON_ARGS$(2) := --compile-lib-path stage$(2) \
189-
--run-lib-path stage$(2)/lib \
190-
--rustc-path stage$(2)/rustc$$(X) \
188+
CTEST_COMMON_ARGS$(2) := --compile-lib-path stage$(2)/lib \
189+
--run-lib-path stage$(2)/lib/$$(CFG_HOST_TRIPLE) \
190+
--rustc-path stage$(2)/bin/rustc$$(X) \
191191
--stage-id stage$(2) \
192-
--rustcflags "$$(CFG_RUSTC_FLAGS)" \
192+
--rustcflags "--target=$$(CFG_HOST_TRIPLE) $$(CFG_RUSTC_FLAGS)" \
193193
$$(CTEST_TESTARGS) \
194194

195195
CFAIL_ARGS$(2) := $$(CTEST_COMMON_ARGS$(2)) \
@@ -243,7 +243,7 @@ PRETTY_PRETTY_ARGS$(2) := $$(CTEST_COMMON_ARGS$(2)) \
243243

244244
test/compiletest.stage$(2)$$(X): $$(COMPILETEST_CRATE) \
245245
$$(COMPILETEST_INPUTS) \
246-
$$(SREQ$(2))
246+
$$(SREQ$(2)$(CFG_HOST_TRIPLE))
247247
@$$(call E, compile_and_link: $$@)
248248
$$(STAGE$(2)) -o $$@ $$<
249249

@@ -320,13 +320,13 @@ test/$(FT).rc test/$(FT_DRIVER).rs: $(TEST_RPASS_SOURCES_STAGE2) \
320320
@$(call E, check: building combined stage2 test runner)
321321
$(Q)$(S)src/etc/combine-tests.py
322322

323-
stage2/lib/$(FT_LIB): test/$(FT).rc $(SREQ2)
323+
stage2/lib/$(FT_LIB): test/$(FT).rc $(SREQ2$(CFG_HOST_TRIPLE))
324324
@$(call E, compile_and_link: $@)
325325
$(STAGE2) --lib -o $@ $<
326326

327-
test/$(FT_DRIVER)$(X): test/$(FT_DRIVER).rs stage2/lib/$(FT_LIB) $(SREQ2)
327+
test/$(FT_DRIVER)$(X): test/$(FT_DRIVER).rs stage2/lib/$(FT_LIB) $(SREQ2$(CFG_HOST_TRIPLE))
328328
@$(call E, compile_and_link: $@)
329329
$(STAGE2) -o $@ $<
330330

331-
test/$(FT_DRIVER).out: test/$(FT_DRIVER)$(X) $(SREQ2)
331+
test/$(FT_DRIVER).out: test/$(FT_DRIVER)$(X) $(SREQ2$(CFG_HOST_TRIPLE))
332332
$(Q)$(call CFG_RUN_TEST, $<)

src/comp/back/link.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,23 @@ fn llvm_err(sess: session::session, msg: str) {
3939
} else { sess.fatal(msg + ": " + str::str_from_cstr(buf)); }
4040
}
4141

42+
fn get_target_lib_path(sess: session::session) -> fs::path {
43+
let path = [
44+
sess.get_opts().sysroot,
45+
"lib/rustc",
46+
sess.get_opts().target_triple];
47+
check vec::is_not_empty(path);
48+
let path = fs::connect_many(path);
49+
ret path;
50+
}
51+
52+
fn get_target_lib_file_path(sess: session::session,
53+
file: fs::path) -> fs::path {
54+
fs::connect(get_target_lib_path(sess), file)
55+
}
56+
4257
fn link_intrinsics(sess: session::session, llmod: ModuleRef) {
43-
let path = fs::connect(sess.get_opts().sysroot, "lib/intrinsics.bc");
58+
let path = get_target_lib_file_path(sess, "intrinsics.bc");
4459
let membuf = str::as_buf(path, {|buf|
4560
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
4661
});
@@ -495,10 +510,9 @@ fn mangle_internal_name_by_seq(ccx: @crate_ctxt, flav: str) -> str {
495510
// If the user wants an exe generated we need to invoke
496511
// gcc to link the object file with some libs
497512
fn link_binary(sess: session::session,
498-
binary_dir: str,
499513
saved_out_filename: str) {
500-
let main: str = binary_dir + "/lib/main.o";
501-
let stage: str = "-L" + binary_dir + "/lib";
514+
let main: str = get_target_lib_file_path(sess, "main.o");
515+
let stage: str = "-L" + get_target_lib_path(sess);
502516
let prog: str = "gcc";
503517
// The invocations of gcc share some flags across platforms
504518

0 commit comments

Comments
 (0)