Skip to content

Commit eca8f11

Browse files
committed
auto merge of #18592 : alexcrichton/rust/dylib-harder, r=pcwalton
If a dylib is being produced, the compiler will now first check to see if it can be created entirely statically before falling back to dynamic dependencies. This behavior can be overridden with `-C prefer-dynamic`. Due to the alteration in behavior, this is a breaking change. Any previous users relying on dylibs implicitly maximizing dynamic dependencies should start passing `-C prefer-dynamic` to compilations. Closes #18499 [breaking-change]
2 parents 4375b32 + 3036b00 commit eca8f11

File tree

20 files changed

+105
-41
lines changed

20 files changed

+105
-41
lines changed

mk/main.mk

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,13 @@ endif
148148
# libraries, so in the interest of space, prefer dynamic linking throughout the
149149
# compilation process.
150150
#
151-
# Note though that these flags are omitted for stage2+. This means that the
152-
# snapshot will be generated with a statically linked rustc so we only have to
153-
# worry about the distribution of one file (with its native dynamic
151+
# Note though that these flags are omitted for the *bins* in stage2+. This means
152+
# that the snapshot will be generated with a statically linked rustc so we only
153+
# have to worry about the distribution of one file (with its native dynamic
154154
# dependencies)
155155
RUSTFLAGS_STAGE0 += -C prefer-dynamic
156156
RUSTFLAGS_STAGE1 += -C prefer-dynamic
157+
RUST_LIB_FLAGS_ST2 += -C prefer-dynamic
157158

158159
# Landing pads require a lot of codegen. We can get through bootstrapping faster
159160
# by not emitting them.

mk/target.mk

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ export CFG_COMPILER_HOST_TRIPLE
1717
# code, make sure that these common warnings are denied by default. These can
1818
# be overridden during development temporarily. For stage0, we allow warnings
1919
# which may be bugs in stage0 (should be fixed in stage1+)
20-
WFLAGS_ST0 = -W warnings
21-
WFLAGS_ST1 = -D warnings
22-
WFLAGS_ST2 = -D warnings
20+
RUST_LIB_FLAGS_ST0 += -W warnings
21+
RUST_LIB_FLAGS_ST1 += -D warnings
22+
RUST_LIB_FLAGS_ST2 += -D warnings
2323

2424
# Macro that generates the full list of dependencies for a crate at a particular
2525
# stage/target/host tuple.
@@ -80,7 +80,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \
8080
$$(call REMOVE_ALL_OLD_GLOB_MATCHES, \
8181
$$(dir $$@)$$(call CFG_RLIB_GLOB,$(4)))
8282
$$(STAGE$(1)_T_$(2)_H_$(3)) \
83-
$$(WFLAGS_ST$(1)) \
83+
$$(RUST_LIB_FLAGS_ST$(1)) \
8484
-L "$$(RT_OUTPUT_DIR_$(2))" \
8585
-L "$$(LLVM_LIBDIR_$(2))" \
8686
-L "$$(dir $$(LLVM_STDCPP_LOCATION_$(2)))" \

src/librustc/middle/dependency_format.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ fn calculate_type(sess: &session::Session,
123123
return Vec::new();
124124
}
125125

126+
// Generating a dylib without `-C prefer-dynamic` means that we're going
127+
// to try to eagerly statically link all dependencies. This is normally
128+
// done for end-product dylibs, not intermediate products.
129+
config::CrateTypeDylib if !sess.opts.cg.prefer_dynamic => {
130+
match attempt_static(sess) {
131+
Some(v) => return v,
132+
None => {}
133+
}
134+
}
135+
126136
// Everything else falls through below
127137
config::CrateTypeExecutable | config::CrateTypeDylib => {},
128138
}

src/test/auxiliary/issue-12133-dylib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// no-prefer-dynamic
12-
1311
#![crate_type = "dylib"]

src/test/auxiliary/syntax-extension-with-dll-deps-1.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// no-prefer-dynamic
1211
// force-host
1312

1413
#![crate_type = "dylib"]

src/test/auxiliary/syntax-extension-with-dll-deps-2.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
// force-host
12-
// no-prefer-dynamic
1312

1413
#![crate_type = "dylib"]
1514
#![feature(plugin_registrar, quote, globs)]

src/test/run-make/c-dynamic-dylib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ all:
66
echo ignored
77
else
88
all: $(call DYLIB,cfoo)
9-
$(RUSTC) foo.rs
9+
$(RUSTC) foo.rs -C prefer-dynamic
1010
$(RUSTC) bar.rs
1111
$(call RUN,bar)
1212
$(call REMOVE_DYLIBS,cfoo)

src/test/run-make/c-static-dylib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-include ../tools.mk
22

33
all: $(call STATICLIB,cfoo)
4-
$(RUSTC) foo.rs
4+
$(RUSTC) foo.rs -C prefer-dynamic
55
$(RUSTC) bar.rs
66
rm $(TMPDIR)/$(call STATICLIB_GLOB,cfoo)
77
$(call RUN,bar)

src/test/run-make/dylib-chain/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
-include ../tools.mk
22

33
all:
4-
$(RUSTC) m1.rs
5-
$(RUSTC) m2.rs
6-
$(RUSTC) m3.rs
4+
$(RUSTC) m1.rs -C prefer-dynamic
5+
$(RUSTC) m2.rs -C prefer-dynamic
6+
$(RUSTC) m3.rs -C prefer-dynamic
77
$(RUSTC) m4.rs
88
$(call RUN,m4)
99
$(call REMOVE_DYLIBS,m1)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-include ../tools.mk
22

33
all: $(TMPDIR)/libfoo.a
4-
$(RUSTC) foo.rs -C extra-filename=-383hf8
4+
$(RUSTC) foo.rs -C extra-filename=-383hf8 -C prefer-dynamic
55
$(RUSTC) bar.rs
66
$(call RUN,bar)

0 commit comments

Comments
 (0)