about summary refs log tree commit diff
path: root/src/librustc_metadata
diff options
context:
space:
mode:
authorMatthew Maurer <matthew.r.maurer@gmail.com>2020-01-21 22:47:03 -0800
committerMatthew Maurer <mmaurer@google.com>2020-01-23 13:10:04 -0800
commit72aaa3a414d17aa0c4f19feafa5bab5f84b60e63 (patch)
tree4f86655cc705cfe1256293da4487ca735898fc0c /src/librustc_metadata
parentc0e02ad724f05f73b957b3d6f6314a9a2e5c284e (diff)
downloadrust-72aaa3a414d17aa0c4f19feafa5bab5f84b60e63.tar.gz
rust-72aaa3a414d17aa0c4f19feafa5bab5f84b60e63.zip
rustc: Allow cdylibs to link against dylibs
Previously, rustc mandated that cdylibs could only link against rlibs as
dependencies (not dylibs).
This commit disables that restriction and tests that it works in a
simple case.
Diffstat (limited to 'src/librustc_metadata')
-rw-r--r--src/librustc_metadata/dependency_format.rs20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/librustc_metadata/dependency_format.rs b/src/librustc_metadata/dependency_format.rs
index 3427de19daa..375f372005f 100644
--- a/src/librustc_metadata/dependency_format.rs
+++ b/src/librustc_metadata/dependency_format.rs
@@ -83,14 +83,17 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: config::CrateType) -> DependencyList {
     }
 
     let preferred_linkage = match ty {
-        // cdylibs must have all static dependencies.
-        config::CrateType::Cdylib => Linkage::Static,
-
         // Generating a dylib without `-C prefer-dynamic` means that we're going
         // to try to eagerly statically link all dependencies. This is normally
         // done for end-product dylibs, not intermediate products.
-        config::CrateType::Dylib if !sess.opts.cg.prefer_dynamic => Linkage::Static,
-        config::CrateType::Dylib => Linkage::Dynamic,
+        //
+        // Treat cdylibs similarly. If `-C prefer-dynamic` is set, the caller may
+        // be code-size conscious, but without it, it makes sense to statically
+        // link a cdylib.
+        config::CrateType::Dylib | config::CrateType::Cdylib if !sess.opts.cg.prefer_dynamic => {
+            Linkage::Static
+        }
+        config::CrateType::Dylib | config::CrateType::Cdylib => Linkage::Dynamic,
 
         // If the global prefer_dynamic switch is turned off, or the final
         // executable will be statically linked, prefer static crate linkage.
@@ -122,10 +125,9 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: config::CrateType) -> DependencyList {
             return v;
         }
 
-        // Staticlibs, cdylibs, and static executables must have all static
-        // dependencies. If any are not found, generate some nice pretty errors.
-        if ty == config::CrateType::Cdylib
-            || ty == config::CrateType::Staticlib
+        // Staticlibs and static executables must have all static dependencies.
+        // If any are not found, generate some nice pretty errors.
+        if ty == config::CrateType::Staticlib
             || (ty == config::CrateType::Executable
                 && sess.crt_static()
                 && !sess.target.target.options.crt_static_allows_dylibs)