Skip to content

Commit 832fede

Browse files
committed
Add unstable feature flags
1 parent 7e2f6c1 commit 832fede

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

compiler/rustc_metadata/src/dependency_format.rs

+20-6
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,22 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
9191
//
9292
// Treat cdylibs and staticlibs similarly. If `-C prefer-dynamic` is set,
9393
// the caller may be code-size conscious, but without it, it makes sense
94-
// to statically link a cdylib or staticlib.
95-
CrateType::Dylib | CrateType::Cdylib | CrateType::Staticlib => {
96-
if sess.opts.cg.prefer_dynamic { Linkage::Dynamic } else { Linkage::Static }
94+
// to statically link a cdylib or staticlib. For staticlibs we use
95+
// `-Z staticlib-prefer-dynamic` for now. This may be merged into
96+
// `-C prefer-dynamic` in the future.
97+
CrateType::Dylib | CrateType::Cdylib => {
98+
if sess.opts.cg.prefer_dynamic {
99+
Linkage::Dynamic
100+
} else {
101+
Linkage::Static
102+
}
103+
}
104+
CrateType::Staticlib => {
105+
if sess.opts.unstable_opts.staticlib_prefer_dynamic {
106+
Linkage::Dynamic
107+
} else {
108+
Linkage::Static
109+
}
97110
}
98111

99112
// If the global prefer_dynamic switch is turned off, or the final
@@ -123,9 +136,10 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
123136

124137
// Static executables must have all static dependencies.
125138
// If any are not found, generate some nice pretty errors.
126-
if ty == CrateType::Executable
127-
&& sess.crt_static(Some(ty))
128-
&& !sess.target.crt_static_allows_dylibs
139+
if (ty == CrateType::Staticlib && !sess.opts.unstable_opts.staticlib_allow_rdylib_deps)
140+
|| (ty == CrateType::Executable
141+
&& sess.crt_static(Some(ty))
142+
&& !sess.target.crt_static_allows_dylibs)
129143
{
130144
for &cnum in tcx.crates(()).iter() {
131145
if tcx.dep_kind(cnum).macros_only() {

compiler/rustc_session/src/options.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,10 @@ options! {
16731673
#[rustc_lint_opt_deny_field_access("use `Session::stack_protector` instead of this field")]
16741674
stack_protector: StackProtector = (StackProtector::None, parse_stack_protector, [TRACKED],
16751675
"control stack smash protection strategy (`rustc --print stack-protector-strategies` for details)"),
1676+
staticlib_allow_rdylib_deps: bool = (false, parse_bool, [TRACKED],
1677+
"allow staticlibs to have rust dylib dependencies"),
1678+
staticlib_prefer_dynamic: bool = (false, parse_bool, [TRACKED],
1679+
"prefer dynamic linking to static linking for staticlibs (default: no)"),
16761680
strict_init_checks: bool = (false, parse_bool, [TRACKED],
16771681
"control if mem::uninitialized and mem::zeroed panic on more UB"),
16781682
strip: Strip = (Strip::None, parse_strip, [UNTRACKED],

tests/run-make-fulldeps/staticlib-dylib-linkage/Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ include ../tools.mk
22

33
all:
44
$(RUSTC) -C prefer-dynamic bar.rs
5-
$(RUSTC) foo.rs --crate-type staticlib --print native-static-libs 2>&1 | grep 'note: native-static-libs: ' | sed 's/note: native-static-libs: \(.*\)/\1/' > $(TMPDIR)/libs.txt
5+
$(RUSTC) foo.rs --crate-type staticlib --print native-static-libs \
6+
-Z staticlib-allow-rdylib-deps 2>&1 | grep 'note: native-static-libs: ' \
7+
| sed 's/note: native-static-libs: \(.*\)/\1/' > $(TMPDIR)/libs.txt
68
cat $(TMPDIR)/libs.txt
79

810
ifdef IS_MSVC

tests/rustdoc-ui/z-help.stdout

+2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@
170170
by the linker
171171
-Z src-hash-algorithm=val -- hash algorithm of source files in debug info (`md5`, `sha1`, or `sha256`)
172172
-Z stack-protector=val -- control stack smash protection strategy (`rustc --print stack-protector-strategies` for details)
173+
-Z staticlib-allow-rdylib-deps=val -- allow staticlibs to have rust dylib dependencies
174+
-Z staticlib-prefer-dynamic=val -- prefer dynamic linking to static linking for staticlibs (default: no)
173175
-Z strict-init-checks=val -- control if mem::uninitialized and mem::zeroed panic on more UB
174176
-Z strip=val -- tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)
175177
-Z symbol-mangling-version=val -- which mangling version to use for symbol names ('legacy' (default) or 'v0')

0 commit comments

Comments
 (0)