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]
This commit is contained in:
bors 2014-11-05 07:01:38 +00:00
commit eca8f11315
20 changed files with 108 additions and 44 deletions

View file

@ -123,6 +123,16 @@ fn calculate_type(sess: &session::Session,
return Vec::new();
}
// 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::CrateTypeDylib if !sess.opts.cg.prefer_dynamic => {
match attempt_static(sess) {
Some(v) => return v,
None => {}
}
}
// Everything else falls through below
config::CrateTypeExecutable | config::CrateTypeDylib => {},
}

View file

@ -8,6 +8,4 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// no-prefer-dynamic
#![crate_type = "dylib"]

View file

@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// no-prefer-dynamic
// force-host
#![crate_type = "dylib"]

View file

@ -9,7 +9,6 @@
// except according to those terms.
// force-host
// no-prefer-dynamic
#![crate_type = "dylib"]
#![feature(plugin_registrar, quote, globs)]

View file

@ -6,7 +6,7 @@ all:
echo ignored
else
all: $(call DYLIB,cfoo)
$(RUSTC) foo.rs
$(RUSTC) foo.rs -C prefer-dynamic
$(RUSTC) bar.rs
$(call RUN,bar)
$(call REMOVE_DYLIBS,cfoo)

View file

@ -1,7 +1,7 @@
-include ../tools.mk
all: $(call STATICLIB,cfoo)
$(RUSTC) foo.rs
$(RUSTC) foo.rs -C prefer-dynamic
$(RUSTC) bar.rs
rm $(TMPDIR)/$(call STATICLIB_GLOB,cfoo)
$(call RUN,bar)

View file

@ -1,9 +1,9 @@
-include ../tools.mk
all:
$(RUSTC) m1.rs
$(RUSTC) m2.rs
$(RUSTC) m3.rs
$(RUSTC) m1.rs -C prefer-dynamic
$(RUSTC) m2.rs -C prefer-dynamic
$(RUSTC) m3.rs -C prefer-dynamic
$(RUSTC) m4.rs
$(call RUN,m4)
$(call REMOVE_DYLIBS,m1)

View file

@ -1,6 +1,6 @@
-include ../tools.mk
all: $(TMPDIR)/libfoo.a
$(RUSTC) foo.rs -C extra-filename=-383hf8
$(RUSTC) foo.rs -C extra-filename=-383hf8 -C prefer-dynamic
$(RUSTC) bar.rs
$(call RUN,bar)

View file

@ -1,7 +1,7 @@
-include ../tools.mk
all:
$(RUSTC) both.rs
$(RUSTC) both.rs -C prefer-dynamic
$(RUSTC) dylib.rs -C prefer-dynamic
$(RUSTC) prog.rs
$(call RUN,prog)

View file

@ -15,60 +15,60 @@
all:
# Building just baz
$(RUSTC) --crate-type=rlib foo.rs
$(RUSTC) --crate-type=dylib bar1.rs
$(RUSTC) --crate-type=dylib,rlib baz.rs
$(RUSTC) --crate-type=dylib bar1.rs -C prefer-dynamic
$(RUSTC) --crate-type=dylib,rlib baz.rs -C prefer-dynamic
$(RUSTC) --crate-type=bin baz.rs
rm $(TMPDIR)/*
$(RUSTC) --crate-type=dylib foo.rs
$(RUSTC) --crate-type=dylib foo.rs -C prefer-dynamic
$(RUSTC) --crate-type=rlib bar1.rs
$(RUSTC) --crate-type=dylib,rlib baz.rs
$(RUSTC) --crate-type=dylib,rlib baz.rs -C prefer-dynamic
$(RUSTC) --crate-type=bin baz.rs
rm $(TMPDIR)/*
# Building baz2
$(RUSTC) --crate-type=rlib foo.rs
$(RUSTC) --crate-type=dylib bar1.rs
$(RUSTC) --crate-type=dylib bar2.rs
$(RUSTC) --crate-type=dylib bar1.rs -C prefer-dynamic
$(RUSTC) --crate-type=dylib bar2.rs -C prefer-dynamic
$(RUSTC) --crate-type=dylib baz2.rs && exit 1 || exit 0
$(RUSTC) --crate-type=bin baz2.rs && exit 1 || exit 0
rm $(TMPDIR)/*
$(RUSTC) --crate-type=rlib foo.rs
$(RUSTC) --crate-type=rlib bar1.rs
$(RUSTC) --crate-type=dylib bar2.rs
$(RUSTC) --crate-type=dylib bar2.rs -C prefer-dynamic
$(RUSTC) --crate-type=dylib,rlib baz2.rs
$(RUSTC) --crate-type=bin baz2.rs
rm $(TMPDIR)/*
$(RUSTC) --crate-type=rlib foo.rs
$(RUSTC) --crate-type=dylib bar1.rs
$(RUSTC) --crate-type=dylib bar1.rs -C prefer-dynamic
$(RUSTC) --crate-type=rlib bar2.rs
$(RUSTC) --crate-type=dylib,rlib baz2.rs
$(RUSTC) --crate-type=dylib,rlib baz2.rs -C prefer-dynamic
$(RUSTC) --crate-type=bin baz2.rs
rm $(TMPDIR)/*
$(RUSTC) --crate-type=rlib foo.rs
$(RUSTC) --crate-type=rlib bar1.rs
$(RUSTC) --crate-type=rlib bar2.rs
$(RUSTC) --crate-type=dylib,rlib baz2.rs
$(RUSTC) --crate-type=dylib,rlib baz2.rs -C prefer-dynamic
$(RUSTC) --crate-type=bin baz2.rs
rm $(TMPDIR)/*
$(RUSTC) --crate-type=dylib foo.rs
$(RUSTC) --crate-type=dylib foo.rs -C prefer-dynamic
$(RUSTC) --crate-type=rlib bar1.rs
$(RUSTC) --crate-type=rlib bar2.rs
$(RUSTC) --crate-type=dylib,rlib baz2.rs -C prefer-dynamic
$(RUSTC) --crate-type=bin baz2.rs
rm $(TMPDIR)/*
$(RUSTC) --crate-type=dylib foo.rs -C prefer-dynamic
$(RUSTC) --crate-type=dylib bar1.rs -C prefer-dynamic
$(RUSTC) --crate-type=rlib bar2.rs
$(RUSTC) --crate-type=dylib,rlib baz2.rs
$(RUSTC) --crate-type=bin baz2.rs
rm $(TMPDIR)/*
$(RUSTC) --crate-type=dylib foo.rs
$(RUSTC) --crate-type=dylib bar1.rs
$(RUSTC) --crate-type=rlib bar2.rs
$(RUSTC) --crate-type=dylib,rlib baz2.rs
$(RUSTC) --crate-type=bin baz2.rs
rm $(TMPDIR)/*
$(RUSTC) --crate-type=dylib foo.rs
$(RUSTC) --crate-type=dylib foo.rs -C prefer-dynamic
$(RUSTC) --crate-type=rlib bar1.rs
$(RUSTC) --crate-type=dylib bar2.rs
$(RUSTC) --crate-type=dylib bar2.rs -C prefer-dynamic
$(RUSTC) --crate-type=dylib,rlib baz2.rs
$(RUSTC) --crate-type=bin baz2.rs
rm $(TMPDIR)/*
$(RUSTC) --crate-type=dylib foo.rs
$(RUSTC) --crate-type=dylib bar1.rs
$(RUSTC) --crate-type=dylib bar2.rs
$(RUSTC) --crate-type=dylib foo.rs -C prefer-dynamic
$(RUSTC) --crate-type=dylib bar1.rs -C prefer-dynamic
$(RUSTC) --crate-type=dylib bar2.rs -C prefer-dynamic
$(RUSTC) --crate-type=dylib,rlib baz2.rs
$(RUSTC) --crate-type=bin baz2.rs

View file

@ -1,7 +1,7 @@
-include ../tools.mk
all:
$(RUSTC) bar.rs --crate-type=dylib --crate-type=rlib
$(RUSTC) bar.rs --crate-type=dylib --crate-type=rlib -C prefer-dynamic
$(RUSTC) foo.rs -C prefer-dynamic
$(call RUN,foo)
rm $(TMPDIR)/*bar*

View file

@ -1,5 +1,5 @@
-include ../tools.mk
all:
$(RUSTC) bar.rs --crate-type=dylib
$(RUSTC) bar.rs --crate-type=dylib -C prefer-dynamic
$(RUSTC) foo.rs
$(call RUN,foo)

View file

@ -0,0 +1,9 @@
-include ../tools.mk
all:
$(RUSTC) foo.rs
$(RUSTC) bar.rs
$(CC) main.c -o $(call RUN_BINFILE,main) -lbar
rm $(TMPDIR)/*.rlib
rm $(call DYLIB,foo)
$(call RUN,main)

View file

@ -0,0 +1,18 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![crate_type = "dylib"]
extern crate foo;
#[no_mangle]
pub extern fn bar() {
foo::foo();
}

View file

@ -0,0 +1,14 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![crate_type = "rlib"]
#![crate_type = "dylib"]
pub fn foo() {}

View file

@ -0,0 +1,16 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern void bar();
int main() {
bar();
return 0;
}

View file

@ -1,7 +1,7 @@
-include ../tools.mk
all:
$(RUSTC) foo.rs
$(RUSTC) foo.rs -C prefer-dynamic
touch $(call DYLIB,foo-something-special)
touch $(call DYLIB,foo-something-special2)
$(RUSTC) bar.rs

View file

@ -4,7 +4,7 @@
ifndef IS_WINDOWS
all:
$(RUSTC) foo.rs
$(RUSTC) foo.rs -C prefer-dynamic
mkdir -p $(TMPDIR)/other
ln -nsf $(TMPDIR)/$(call DYLIB_GLOB,foo) $(TMPDIR)/other
$(RUSTC) bar.rs -L $(TMPDIR)/other