@@ -91,9 +91,22 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
91
91
//
92
92
// Treat cdylibs and staticlibs similarly. If `-C prefer-dynamic` is set,
93
93
// 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
+ }
97
110
}
98
111
99
112
// If the global prefer_dynamic switch is turned off, or the final
@@ -123,9 +136,10 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
123
136
124
137
// Static executables must have all static dependencies.
125
138
// 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 )
129
143
{
130
144
for & cnum in tcx. crates ( ( ) ) . iter ( ) {
131
145
if tcx. dep_kind ( cnum) . macros_only ( ) {
0 commit comments