Don't link build scripts dynamically
authorAlex Crichton <alex@alexcrichton.com>
Tue, 1 Sep 2015 02:49:41 +0000 (19:49 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 1 Sep 2015 03:14:06 +0000 (20:14 -0700)
There's no real reason to eagerly link build scripts dynamically as they're not
going to benefit that much from dynamic linking. Most of the time they only have
one dynamic dependency, libstd, and most other Rust programs don't link it
dynamically so there's not really many space savings either.

src/cargo/ops/cargo_rustc/mod.rs
tests/test_cargo_compile_custom_build.rs

index 25d9f2a02fe99b1f92cae49ce6adacfe3c7653b4..f7a749bb941b79eba42b67c1f320255b5ce51dcd 100644 (file)
@@ -600,7 +600,7 @@ fn build_base_args(cx: &Context,
         cmd.arg("--crate-type").arg(crate_type);
     }
 
-    let prefer_dynamic = target.for_host() ||
+    let prefer_dynamic = (target.for_host() && !target.is_custom_build()) ||
                          (crate_types.contains(&"dylib") &&
                           pkg.package_id() != cx.resolve.root());
     if prefer_dynamic {
index 28aed813b8523befbe7044cd5e13262e17308ad7..f172e34be496f4122902a4af5961dc53a3d39b33 100644 (file)
@@ -761,7 +761,7 @@ test!(build_cmd_with_a_build_cmd {
     -L [..]target[..]deps -L [..]target[..]deps`
 {compiling} foo v0.5.0 (file://[..])
 {running} `rustc build.rs --crate-name build_script_build --crate-type bin \
-    -C prefer-dynamic -g \
+    -g \
     --out-dir [..]build[..]foo-[..] --emit=dep-info,link \
     -L [..]target[..]debug -L [..]target[..]deps \
     --extern a=[..]liba-[..].rlib`
@@ -1109,6 +1109,7 @@ test!(build_script_with_dynamic_native_dependency {
             [lib]
             name = "builder"
             crate-type = ["dylib"]
+            plugin = true
         "#)
         .file("src/lib.rs", r#"
             #[no_mangle]