Skip to content

Commit d9286c8

Browse files
msullivanbrson
authored andcommitted
Build stage0/lib/libstd.so using the stage0 compiler.
This essentially starts the bootstrapping one step earlier by building the stdlib from source using the stage0 compiler and then using that stdlib to build the stage1 compiler. (Instead of starting by building the stage1 compiler and then building a stdlib with it). This means we should now be able to add features to the stdlib and use them in the compiler without having to do a snapshot. (On the flip side, this means that we now need to do a snapshot if we want to use a new language feature in the stdlib, but that doesn't really seem too burdensome (we already need to snapshot if we want to use a new language feature in the compiler)).
1 parent ea371a3 commit d9286c8

File tree

3 files changed

+41
-29
lines changed

3 files changed

+41
-29
lines changed

mk/stage0.mk

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1+
# FIXME: temporary hack: stdlib comes in the lib/ directory, but we want it in
2+
# the base directory, so we move it out.
13
stage0/rustc$(X): $(S)src/snapshots.txt $(S)src/etc/get-snapshot.py $(MKFILES)
24
@$(call E, fetch: $@)
35
$(Q)$(S)src/etc/get-snapshot.py
6+
$(Q)mv stage0/lib/$(CFG_STDLIB) stage0/$(CFG_STDLIB)
47
$(Q)touch $@
58

69
# Host libs will be made in the process of making rustc above.
710

8-
# FIXME: temporary hack: the first two are currently carried in
9-
# lib/ directory only, so we copy them out.
11+
# FIXME: temporary hack: the runtime is currently carried in
12+
# lib/ directory only, so we copy it out.
1013

1114
stage0/$(CFG_RUNTIME): stage0/lib/$(CFG_RUNTIME)
1215
$(Q)cp $< $@
1316

14-
stage0/$(CFG_STDLIB): stage0/lib/$(CFG_STDLIB)
15-
$(Q)cp $< $@
17+
stage0/$(CFG_STDLIB): stage0/rustc$(X)
18+
$(Q)touch $@
1619

1720
stage0/$(CFG_RUSTLLVM): stage0/rustc$(X)
1821
$(Q)touch $@
@@ -28,11 +31,10 @@ stage0/lib/glue.o: stage0/rustc$(X)
2831
stage0/lib/main.o: rt/main.o
2932
$(Q)cp $< $@
3033

34+
3135
stage0/lib/$(CFG_RUNTIME): stage0/rustc$(X)
3236
$(Q)touch $@
3337

34-
stage0/lib/$(CFG_STDLIB): stage0/rustc$(X)
35-
$(Q)touch $@
38+
# stage0/lib/$(CFG_STDLIB) and stage0/lib/libstd.rlib rules are generated
39+
# in stageN.mk
3640

37-
stage0/lib/libstd.rlib: stage0/rustc$(X)
38-
$(Q)touch $@

mk/stageN.mk

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,29 @@
22
#
33
# The easiest way to read this template is to assume we're building stage2
44
# using stage1, and mentally gloss $(1) as 1, $(2) as 2.
5+
#
6+
# STDLIBGEN is pulled out seperately because we need to specially invoke
7+
# it to build stage0/lib/libstd using stage0/rustc.
8+
9+
define STDLIBGEN
10+
stage$(2)/lib/$$(CFG_STDLIB): $$(STDLIB_CRATE) $$(STDLIB_INPUTS) \
11+
stage$(2)/rustc$$(X) \
12+
stage$(2)/$$(CFG_RUNTIME) \
13+
stage$(2)/$$(CFG_RUSTLLVM) \
14+
stage$(2)/lib/glue.o \
15+
$$(SREQ$(1))
16+
@$$(call E, compile_and_link: $$@)
17+
$$(STAGE$(2)) --lib -o $$@ $$<
18+
19+
stage$(2)/lib/libstd.rlib: $$(STDLIB_CRATE) $$(STDLIB_INPUTS) \
20+
stage$(2)/rustc$$(X) \
21+
stage$(2)/$$(CFG_RUNTIME) \
22+
stage$(2)/$$(CFG_RUSTLLVM) \
23+
stage$(2)/lib/glue.o \
24+
$$(SREQ$(1))
25+
@$$(call E, compile_and_link: $$@)
26+
$$(STAGE$(2)) --lib --static -o $$@ $$<
27+
endef
528

629
define STAGEN
730

@@ -56,24 +79,7 @@ stage$(2)/lib/glue.o: stage$(2)/rustc$$(X) \
5679
@$$(call E, generate: $$@)
5780
$$(STAGE$(2)) -c -o $$@ --glue
5881

59-
stage$(2)/lib/$$(CFG_STDLIB): $$(STDLIB_CRATE) $$(STDLIB_INPUTS) \
60-
stage$(2)/rustc$$(X) \
61-
stage$(2)/$$(CFG_RUNTIME) \
62-
stage$(2)/$$(CFG_RUSTLLVM) \
63-
stage$(2)/lib/glue.o \
64-
$$(SREQ$(1))
65-
@$$(call E, compile_and_link: $$@)
66-
$$(STAGE$(2)) --lib -o $$@ $$<
67-
68-
stage$(2)/lib/libstd.rlib: $$(STDLIB_CRATE) $$(STDLIB_INPUTS) \
69-
stage$(2)/rustc$$(X) \
70-
stage$(2)/$$(CFG_RUNTIME) \
71-
stage$(2)/$$(CFG_RUSTLLVM) \
72-
stage$(2)/lib/glue.o \
73-
$$(SREQ$(1))
74-
@$$(call E, compile_and_link: $$@)
75-
$$(STAGE$(2)) --lib --static -o $$@ $$<
76-
82+
$(eval $(call STDLIBGEN,$(1),$(2)))
7783

7884
stage$(2)/lib/main.o: rt/main.o
7985
@$$(call E, cp: $$@)
@@ -90,6 +96,10 @@ stage$(2)/lib/$$(CFG_LIBRUSTC): $$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
9096

9197
endef
9298

99+
# Instantiate template for building initial stdlib
100+
SREQpre = stage0/lib/main.o $(MKFILES)
101+
$(eval $(call STDLIBGEN,pre,0))
102+
93103
# Instantiate template for 0->1, 1->2, 2->3 build dirs
94104

95105
$(eval $(call STAGEN,0,1))

src/etc/snapshot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ def scrub(b):
1616
download_unpack_base = os.path.join(download_dir_base, "unpack")
1717

1818
snapshot_files = {
19-
"linux": ["rustc", "lib/glue.o", "lib/libstd.so", "lib/libstd.rlib",
19+
"linux": ["rustc", "lib/glue.o", "lib/libstd.so",
2020
"lib/librustrt.so", "librustllvm.so", "lib/intrinsics.bc"],
21-
"macos": ["rustc", "lib/glue.o", "lib/libstd.dylib", "lib/libstd.rlib",
21+
"macos": ["rustc", "lib/glue.o", "lib/libstd.dylib",
2222
"lib/librustrt.dylib", "librustllvm.dylib", "lib/intrinsics.bc"],
23-
"winnt": ["rustc.exe", "lib/glue.o", "lib/std.dll", "lib/libstd.rlib",
23+
"winnt": ["rustc.exe", "lib/glue.o", "lib/std.dll",
2424
"lib/rustrt.dll", "rustllvm.dll", "lib/intrinsics.bc"]
2525
}
2626

0 commit comments

Comments
 (0)