Skip to content

Commit 18c6cc6

Browse files
committed
More steps to arch-specific target libs (#474)
1 parent 5310cf4 commit 18c6cc6

File tree

5 files changed

+139
-49
lines changed

5 files changed

+139
-49
lines changed

Makefile.in

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ endif
1313

1414
CFG_INFO := $(info cfg: shell host triple $(CFG_HOST_TRIPLE))
1515
CFG_INFO := $(info cfg: llvm host triple $(CFG_LLVM_TRIPLE))
16+
CFG_INFO := $(info cfg: llvm target triples $(CFG_LLVM_TRIPLES))
1617

1718
ifdef CFG_DISABLE_OPTIMIZE
1819
$(info cfg: disabling rustc optimization (CFG_DISABLE_OPTIMIZE))

configure

+43-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ step_msg() {
1010
msg
1111
}
1212

13+
warn() {
14+
echo "configure: WARNING: $1"
15+
}
16+
1317
err() {
1418
echo "configure: error: $1"
1519
exit 1
@@ -228,7 +232,6 @@ putvar CFG_SRC_DIR
228232
putvar CFG_BUILD_DIR
229233
putvar CFG_OSTYPE
230234
putvar CFG_CPUTYPE
231-
putvar CFG_HOST_TRIPLE
232235
putvar CFG_CONFIGURE_ARGS
233236

234237
step_msg "looking for build programs"
@@ -335,6 +338,26 @@ then
335338
else
336339
CFG_C_COMPILER="gcc"
337340
fi
341+
342+
if [ ! -z "$CFG_LLVM_TRIPLE" ]
343+
then
344+
if [ $CFG_HOST_TRIPLE != $CFG_LLVM_TRIPLE ]
345+
then
346+
warn "LLVM host-triple $CFG_LLVM_TRIPLE differs from"
347+
warn "detected host triple $CFG_HOST_TRIPLE"
348+
warn "choosing LLVM host-triple instead"
349+
msg ""
350+
CFG_HOST_TRIPLE=$CFG_LLVM_TRIPLE
351+
fi
352+
fi
353+
354+
# FIXME: add support for extending the target-triples list
355+
CFG_TARGET_TRIPLES="${CFG_HOST_TRIPLE}"
356+
357+
putvar CFG_HOST_TRIPLE
358+
putvar CFG_TARGET_TRIPLES
359+
360+
338361
putvar CFG_C_COMPILER
339362

340363
putvar CFG_LLVM_ROOT
@@ -356,14 +379,31 @@ for i in \
356379
doc \
357380
rt rt/isaac rt/bigint rt/sync rt/test rt/arch/i386 \
358381
rt/libuv rt/libuv/src/ares rt/libuv/src/eio rt/libuv/src/ev \
359-
rustllvm \
360-
dl stage{0,1,2,3}{,/lib,/lib/$CFG_LLVM_TRIPLE} \
382+
rustllvm dl \
361383
test/run-pass test/run-fail test/compile-fail \
362384
test/bench test/perf test/pretty
363385
do
364386
make_dir $i
365387
done
366388

389+
for t in $CFG_TARGET_TRIPLES
390+
do
391+
for i in 0 1 2 3
392+
do
393+
# old-style "bin" dir
394+
make_dir stage$i
395+
396+
# new-style bin dir, not yet used
397+
make_dir stage$i/bin
398+
399+
# old-style non-arch libs
400+
make_dir stage$i/lib
401+
402+
# new-style arch-prefixed libs, not yet used
403+
make_dir stage$i/lib/rustc/$t
404+
done
405+
done
406+
367407
copy ${CFG_SRC_DIR}Makefile.in ./Makefile
368408

369409
copy ${CFG_SRC_DIR}src/rt/libuv/Makefile rt/libuv/Makefile

mk/stage0.mk

+3-10
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,9 @@ stage0/$(CFG_STDLIB): stage0/rustc$(X)
1717
stage0/$(CFG_RUSTLLVM): stage0/rustc$(X)
1818
$(Q)touch $@
1919

20-
# Target libs will be made in the process of making rustc above.
21-
22-
stage0/lib/glue.o: stage0/rustc$(X)
23-
$(Q)touch $@
24-
25-
stage0/lib/main.o: stage0/rustc$(X)
26-
$(Q)touch $@
27-
2820
# Instantiate template (in stageN.mk) for building
29-
# stage0/lib/$(CFG_STDLIB) and stage0/lib/libstd.rlib.
21+
# target libraries.
22+
3023
SREQpre = stage0/lib/main.o $(MKFILES)
31-
$(eval $(call LIBGEN,pre,0))
24+
$(eval $(call TARGET_LIBS,pre,0,$(CFG_HOST_TRIPLE)))
3225

mk/stageN.mk

+91-35
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,15 @@
1-
# StageN template: arg 1 is the N we're building *from*, arg 2 is N+1.
1+
# STAGE_N template: arg 1 is the N we're building *from*, arg 2 is N+1, arg 3
2+
# is the target triple we're building for. You have to invoke this for each
3+
# target triple.
24
#
35
# The easiest way to read this template is to assume we're building stage2
46
# using stage1, and mentally gloss $(1) as 1, $(2) as 2.
57
#
6-
# LIBGEN is pulled out seperately because we need to specially invoke
8+
# TARGET_LIBS is pulled out seperately because we need to specially invoke
79
# it to build stage0/lib/libstd using stage0/rustc and to use the
810
# new rustrt in stage0/lib/.
911

10-
define LIBGEN
11-
stage$(2)/lib/$$(CFG_STDLIB): $$(STDLIB_CRATE) $$(STDLIB_INPUTS) \
12-
stage$(2)/rustc$$(X) \
13-
stage$(2)/$$(CFG_RUNTIME) \
14-
stage$(2)/$$(CFG_RUSTLLVM) \
15-
stage$(2)/lib/glue.o \
16-
$$(SREQ$(1))
17-
@$$(call E, compile_and_link: $$@)
18-
$$(STAGE$(2)) --lib -o $$@ $$<
19-
20-
stage$(2)/lib/libstd.rlib: $$(STDLIB_CRATE) $$(STDLIB_INPUTS) \
21-
stage$(2)/rustc$$(X) \
22-
stage$(2)/$$(CFG_RUNTIME) \
23-
stage$(2)/$$(CFG_RUSTLLVM) \
24-
stage$(2)/lib/glue.o \
25-
$$(SREQ$(1))
26-
@$$(call E, compile_and_link: $$@)
27-
$$(STAGE$(2)) --lib --static -o $$@ $$<
28-
29-
stage$(2)/lib/$$(CFG_RUNTIME): rt/$$(CFG_RUNTIME)
30-
@$$(call E, cp: $$@)
31-
$$(Q)cp $$< $$@
32-
33-
endef
34-
35-
define STAGEN
12+
define STAGE_N
3613

3714
# Host libraries and executables (stage$(2)/rustc and its runtime needs)
3815
#
@@ -74,9 +51,14 @@ stage$(2)/$$(CFG_RUSTLLVM): rustllvm/$$(CFG_RUSTLLVM)
7451
@$$(call E, cp: $$@)
7552
$$(Q)cp $$< $$@
7653

54+
# Expand out target libraries
7755

78-
# Target libraries (for binaries generated by stage$(2)/rustc)
56+
$(eval $(call TARGET_LIBS,$(1),$(2),$(3)))
7957

58+
endef
59+
60+
61+
define TARGET_LIBS
8062
stage$(2)/lib/intrinsics.bc: $$(INTRINSICS_BC)
8163
@$$(call E, cp: $$@)
8264
$$(Q)cp $$< $$@
@@ -89,8 +71,6 @@ stage$(2)/lib/glue.o: stage$(2)/rustc$$(X) \
8971
@$$(call E, generate: $$@)
9072
$$(STAGE$(2)) -c -o $$@ --glue
9173

92-
$(eval $(call LIBGEN,$(1),$(2)))
93-
9474
stage$(2)/lib/main.o: rt/main.o
9575
@$$(call E, cp: $$@)
9676
$$(Q)cp $$< $$@
@@ -100,10 +80,86 @@ stage$(2)/lib/$$(CFG_LIBRUSTC): $$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
10080
@$$(call E, compile_and_link: $$@)
10181
$$(STAGE$(2)) --lib -o $$@ $$<
10282

83+
stage$(2)/lib/$$(CFG_STDLIB): $$(STDLIB_CRATE) $$(STDLIB_INPUTS) \
84+
stage$(2)/rustc$$(X) \
85+
stage$(2)/$$(CFG_RUNTIME) \
86+
stage$(2)/$$(CFG_RUSTLLVM) \
87+
stage$(2)/lib/glue.o \
88+
$$(SREQ$(1))
89+
@$$(call E, compile_and_link: $$@)
90+
$$(STAGE$(2)) --lib -o $$@ $$<
91+
92+
stage$(2)/lib/libstd.rlib: $$(STDLIB_CRATE) $$(STDLIB_INPUTS) \
93+
stage$(2)/rustc$$(X) \
94+
stage$(2)/$$(CFG_RUNTIME) \
95+
stage$(2)/$$(CFG_RUSTLLVM) \
96+
stage$(2)/lib/glue.o \
97+
$$(SREQ$(1))
98+
@$$(call E, compile_and_link: $$@)
99+
$$(STAGE$(2)) --lib --static -o $$@ $$<
100+
101+
stage$(2)/lib/$$(CFG_RUNTIME): rt/$$(CFG_RUNTIME)
102+
@$$(call E, cp: $$@)
103+
$$(Q)cp $$< $$@
104+
105+
106+
# New per-target-arch target libraries; when we've transitioned to
107+
# using these exclusively, you should delete the non-arch-prefixed
108+
# rules above. They're duplicates, redundant.
109+
110+
stage$(2)/lib/rustc/$(3)/intrinsics.bc: $$(INTRINSICS_BC)
111+
@$$(call E, cp: $$@)
112+
$$(Q)cp $$< $$@
113+
114+
stage$(2)/lib/rustc/$(3)/glue.o: \
115+
stage$(2)/rustc$$(X) \
116+
stage$(2)/$$(CFG_RUNTIME) \
117+
stage$(2)/$$(CFG_RUSTLLVM) \
118+
stage$(2)/lib/intrinsics.bc \
119+
$$(SREQ$(1))
120+
@$$(call E, generate: $$@)
121+
$$(STAGE$(2)) -c -o $$@ --glue
122+
123+
stage$(2)/lib/rustc/$(3)/main.o: rt/main.o
124+
@$$(call E, cp: $$@)
125+
$$(Q)cp $$< $$@
126+
127+
stage$(2)/lib/rustc/$(3)/$$(CFG_LIBRUSTC): \
128+
$$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
129+
$$(SREQ$(2))
130+
@$$(call E, compile_and_link: $$@)
131+
$$(STAGE$(2)) --lib -o $$@ $$<
132+
133+
stage$(2)/lib/rustc/$(3)/$$(CFG_STDLIB): \
134+
$$(STDLIB_CRATE) $$(STDLIB_INPUTS) \
135+
stage$(2)/rustc$$(X) \
136+
stage$(2)/$$(CFG_RUNTIME) \
137+
stage$(2)/$$(CFG_RUSTLLVM) \
138+
stage$(2)/lib/rustc/$(3)/glue.o \
139+
$$(SREQ$(1))
140+
@$$(call E, compile_and_link: $$@)
141+
$$(STAGE$(2)) --lib -o $$@ $$<
142+
143+
stage$(2)/lib/rustc/$(3)/libstd.rlib: \
144+
$$(STDLIB_CRATE) $$(STDLIB_INPUTS) \
145+
stage$(2)/rustc$$(X) \
146+
stage$(2)/$$(CFG_RUNTIME) \
147+
stage$(2)/$$(CFG_RUSTLLVM) \
148+
stage$(2)/lib/rustc/$(3)/glue.o \
149+
$$(SREQ$(1))
150+
@$$(call E, compile_and_link: $$@)
151+
$$(STAGE$(2)) --lib --static -o $$@ $$<
152+
153+
stage$(2)/lib/rustc/$(3)/$$(CFG_RUNTIME): rt/$$(CFG_RUNTIME)
154+
@$$(call E, cp: $$@)
155+
$$(Q)cp $$< $$@
156+
103157
endef
104158

105-
# Instantiate template for 0->1, 1->2, 2->3 build dirs
106159

107-
$(eval $(call STAGEN,0,1))
108-
$(eval $(call STAGEN,1,2))
109-
$(eval $(call STAGEN,2,3))
160+
161+
# Instantiate template for 0->1, 1->2, 2->3 build dirs
162+
$(foreach target,$(CFG_TARGET_TRIPLES), \
163+
$(eval $(call STAGE_N,0,1,$(target))) \
164+
$(eval $(call STAGE_N,1,2,$(target))) \
165+
$(eval $(call STAGE_N,2,3,$(target))))

src/comp/driver/rustc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ fn build_session_options(binary: str, match: getopts::match, binary_dir: str)
372372
};
373373

374374
let library_search_paths = [binary_dir + "/lib", // FIXME: legacy
375-
binary_dir + "/lib/" + target ];
375+
binary_dir + "/lib/rustc/" + target ];
376376
let lsp_vec = getopts::opt_strs(match, "L");
377377
for lsp: str in lsp_vec { library_search_paths += [lsp]; }
378378

0 commit comments

Comments
 (0)