Skip to content

Commit b1363a7

Browse files
authored
Auto merge of #35021 - japaric:rustc-builtins, r=alexcrichton
crate-ify compiler-rt into compiler-builtins libcompiler-rt.a is dead, long live libcompiler-builtins.rlib This commit moves the logic that used to build libcompiler-rt.a into a compiler-builtins crate on top of the core crate and below the std crate. This new crate still compiles the compiler-rt instrinsics using gcc-rs but produces an .rlib instead of a static library. Also, with this commit rustc no longer passes -lcompiler-rt to the linker. This effectively makes the "no-compiler-rt" field of target specifications a no-op. Users of `no_std` will have to explicitly add the compiler-builtins crate to their crate dependency graph *if* they need the compiler-rt intrinsics - this is a [breaking-change]. Users of the `std` have to do nothing extra as the std crate depends on compiler-builtins. Finally, this a step towards lazy compilation of std with Cargo as the compiler-rt intrinsics can now be built by Cargo instead of having to be supplied by the user by some other method. closes #34400 --- r? @alexcrichton
2 parents 2fd0608 + 848cfe2 commit b1363a7

File tree

28 files changed

+739
-616
lines changed

28 files changed

+739
-616
lines changed

mk/clean.mk

-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ define CLEAN_TARGET_STAGE_N
102102
clean$(1)_T_$(2)_H_$(3): \
103103
$$(foreach crate,$$(CRATES),clean$(1)_T_$(2)_H_$(3)-lib-$$(crate)) \
104104
$$(foreach tool,$$(TOOLS) $$(DEBUGGER_BIN_SCRIPTS_ALL),clean$(1)_T_$(2)_H_$(3)-tool-$$(tool))
105-
$$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/libcompiler-rt.a
106105
$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/librun_pass_stage* # For unix
107106
$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/run_pass_stage* # For windows
108107

mk/crates.mk

+6-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
TARGET_CRATES := libc std term \
5353
getopts collections test rand \
54-
core alloc \
54+
compiler_builtins core alloc \
5555
rustc_unicode rustc_bitflags \
5656
alloc_system alloc_jemalloc \
5757
panic_abort panic_unwind unwind
@@ -65,6 +65,7 @@ HOST_CRATES := syntax syntax_ext proc_macro syntax_pos $(RUSTC_CRATES) rustdoc f
6565
TOOLS := compiletest rustdoc rustc rustbook error_index_generator
6666

6767
DEPS_core :=
68+
DEPS_compiler_builtins := core
6869
DEPS_alloc := core libc alloc_system
6970
DEPS_alloc_system := core libc
7071
DEPS_alloc_jemalloc := core libc native:jemalloc
@@ -77,12 +78,14 @@ DEPS_panic_abort := libc alloc
7778
DEPS_panic_unwind := libc alloc unwind
7879
DEPS_unwind := libc
7980

81+
RUSTFLAGS_compiler_builtins := -lstatic=compiler-rt
82+
8083
# FIXME(stage0): change this to just `RUSTFLAGS_panic_abort := ...`
8184
RUSTFLAGS1_panic_abort := -C panic=abort
8285
RUSTFLAGS2_panic_abort := -C panic=abort
8386
RUSTFLAGS3_panic_abort := -C panic=abort
8487

85-
DEPS_std := core libc rand alloc collections rustc_unicode \
88+
DEPS_std := core libc rand alloc collections compiler_builtins rustc_unicode \
8689
native:backtrace \
8790
alloc_system panic_abort panic_unwind unwind
8891
DEPS_arena := std
@@ -153,6 +156,7 @@ TOOL_SOURCE_rustc := $(S)src/driver/driver.rs
153156
TOOL_SOURCE_rustbook := $(S)src/tools/rustbook/main.rs
154157
TOOL_SOURCE_error_index_generator := $(S)src/tools/error_index_generator/main.rs
155158

159+
ONLY_RLIB_compiler_builtins := 1
156160
ONLY_RLIB_core := 1
157161
ONLY_RLIB_libc := 1
158162
ONLY_RLIB_alloc := 1

mk/main.mk

+4-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,10 @@ endif
455455
TSREQ$(1)_T_$(2)_H_$(3) = \
456456
$$(HSREQ$(1)_H_$(3)) \
457457
$$(foreach obj,$$(REQUIRED_OBJECTS_$(2)),\
458-
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(obj))
458+
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(obj)) \
459+
$$(TLIB0_T_$(2)_H_$(3))/$$(call CFG_STATIC_LIB_NAME_$(2),compiler-rt)
460+
# ^ This copies `libcompiler-rt.a` to the stage0 sysroot
461+
# ^ TODO(stage0) update this to not copy `libcompiler-rt.a` to stage0
459462

460463
# Prerequisites for a working stageN compiler and libraries, for a specific
461464
# target

mk/platform.mk

-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ include $(wildcard $(CFG_SRC_DIR)mk/cfg/*.mk)
102102
define ADD_INSTALLED_OBJECTS
103103
INSTALLED_OBJECTS_$(1) += $$(CFG_INSTALLED_OBJECTS_$(1))
104104
REQUIRED_OBJECTS_$(1) += $$(CFG_THIRD_PARTY_OBJECTS_$(1))
105-
INSTALLED_OBJECTS_$(1) += $$(call CFG_STATIC_LIB_NAME_$(1),compiler-rt)
106-
REQUIRED_OBJECTS_$(1) += $$(call CFG_STATIC_LIB_NAME_$(1),compiler-rt)
107105
endef
108106

109107
$(foreach target,$(CFG_TARGET), \

0 commit comments

Comments
 (0)