diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-07-01 08:37:54 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-07-05 12:45:42 -0700 |
| commit | cc3c8bbfaf5af19caf3deb131a995a65ca4674f9 (patch) | |
| tree | 736c2fddddef10a410d8cafa4092b754504aafbd /src/test | |
| parent | df4ea9c39a355e4cff425cca7d58e7758cb3461c (diff) | |
| download | rust-cc3c8bbfaf5af19caf3deb131a995a65ca4674f9.tar.gz rust-cc3c8bbfaf5af19caf3deb131a995a65ca4674f9.zip | |
rustc: Add a flag for specifying dependencies
This comit implements a new flag, --extern, which is used to specify where a crate is located. The purpose of this flag is to bypass the normal crate loading/matching of the compiler to point it directly at the right file. This flag takes the form `--extern foo=bar` where `foo` is the name of a crate and `bar` is the location at which to find the crate. Multiple `--extern` directives are allowed with the same crate name to specify the rlib/dylib pair for a crate. It is invalid to specify more than one rlib or more than one dylib, and it's required that the crates are valid rust crates. I have also added some extensive documentation to metadata::loader about how crate loading should work. RFC: 0035-remove-crate-id
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/run-make/extern-flag-disambiguates/Makefile | 24 | ||||
| -rw-r--r-- | src/test/run-make/extern-flag-disambiguates/a.rs | 6 | ||||
| -rw-r--r-- | src/test/run-make/extern-flag-disambiguates/b.rs | 9 | ||||
| -rw-r--r-- | src/test/run-make/extern-flag-disambiguates/c.rs | 9 | ||||
| -rw-r--r-- | src/test/run-make/extern-flag-disambiguates/d.rs | 11 | ||||
| -rw-r--r-- | src/test/run-make/extern-flag-fun/Makefile | 16 | ||||
| -rw-r--r-- | src/test/run-make/extern-flag-fun/bar.rs | 0 | ||||
| -rw-r--r-- | src/test/run-make/extern-flag-fun/foo.rs | 3 | ||||
| -rw-r--r-- | src/test/run-make/metadata-flag-frobs-symbols/Makefile | 10 | ||||
| -rw-r--r-- | src/test/run-make/metadata-flag-frobs-symbols/bar.rs | 8 | ||||
| -rw-r--r-- | src/test/run-make/metadata-flag-frobs-symbols/foo.rs | 6 |
11 files changed, 102 insertions, 0 deletions
diff --git a/src/test/run-make/extern-flag-disambiguates/Makefile b/src/test/run-make/extern-flag-disambiguates/Makefile new file mode 100644 index 00000000000..9b86bf97549 --- /dev/null +++ b/src/test/run-make/extern-flag-disambiguates/Makefile @@ -0,0 +1,24 @@ +-include ../tools.mk + +# Attempt to build this dependency tree: +# +# A.1 A.2 +# |\ | +# | \ | +# B \ C +# \ | / +# \|/ +# D +# +# Note that A.1 and A.2 are crates with the same name. + +all: + $(RUSTC) -C metadata=1 -C extra-filename=-1 a.rs + $(RUSTC) -C metadata=2 -C extra-filename=-2 a.rs + $(RUSTC) b.rs --extern a=$(TMPDIR)/liba-1.rlib + $(RUSTC) c.rs --extern a=$(TMPDIR)/liba-2.rlib + $(RUSTC) --cfg before d.rs --extern a=$(TMPDIR)/liba-1.rlib + $(call RUN,d) + $(RUSTC) --cfg after d.rs --extern a=$(TMPDIR)/liba-1.rlib + $(call RUN,d) + diff --git a/src/test/run-make/extern-flag-disambiguates/a.rs b/src/test/run-make/extern-flag-disambiguates/a.rs new file mode 100644 index 00000000000..db1a0e0433e --- /dev/null +++ b/src/test/run-make/extern-flag-disambiguates/a.rs @@ -0,0 +1,6 @@ +#![crate_name = "a"] +#![crate_type = "rlib"] + +static FOO: uint = 3; + +pub fn token() -> &'static uint { &FOO } diff --git a/src/test/run-make/extern-flag-disambiguates/b.rs b/src/test/run-make/extern-flag-disambiguates/b.rs new file mode 100644 index 00000000000..f4fb09631a9 --- /dev/null +++ b/src/test/run-make/extern-flag-disambiguates/b.rs @@ -0,0 +1,9 @@ +#![crate_name = "b"] +#![crate_type = "rlib"] + +extern crate a; + +static FOO: uint = 3; + +pub fn token() -> &'static uint { &FOO } +pub fn a_token() -> &'static uint { a::token() } diff --git a/src/test/run-make/extern-flag-disambiguates/c.rs b/src/test/run-make/extern-flag-disambiguates/c.rs new file mode 100644 index 00000000000..e017d747e6f --- /dev/null +++ b/src/test/run-make/extern-flag-disambiguates/c.rs @@ -0,0 +1,9 @@ +#![crate_name = "c"] +#![crate_type = "rlib"] + +extern crate a; + +static FOO: uint = 3; + +pub fn token() -> &'static uint { &FOO } +pub fn a_token() -> &'static uint { a::token() } diff --git a/src/test/run-make/extern-flag-disambiguates/d.rs b/src/test/run-make/extern-flag-disambiguates/d.rs new file mode 100644 index 00000000000..e3c968edb6a --- /dev/null +++ b/src/test/run-make/extern-flag-disambiguates/d.rs @@ -0,0 +1,11 @@ +#[cfg(before)] extern crate a; +extern crate b; +extern crate c; +#[cfg(after)] extern crate a; + +fn t(a: &'static uint) -> uint { a as *const _ as uint } + +fn main() { + assert!(t(a::token()) == t(b::a_token())); + assert!(t(a::token()) != t(c::a_token())); +} diff --git a/src/test/run-make/extern-flag-fun/Makefile b/src/test/run-make/extern-flag-fun/Makefile new file mode 100644 index 00000000000..ca5aa052a7b --- /dev/null +++ b/src/test/run-make/extern-flag-fun/Makefile @@ -0,0 +1,16 @@ +-include ../tools.mk + +all: + $(RUSTC) bar.rs --crate-type=rlib + $(RUSTC) bar.rs --crate-type=rlib -C extra-filename=-a + $(RUSTC) foo.rs --extern hello && exit 1 || exit 0 + $(RUSTC) foo.rs --extern bar=no-exist && exit 1 || exit 0 + $(RUSTC) foo.rs --extern bar=foo.rs && exit 1 || exit 0 + $(RUSTC) foo.rs \ + --extern bar=$(TMPDIR)/libbar.rlib \ + --extern bar=$(TMPDIR)/libbar-a.rlib \ + && exit 1 || exit 0 + $(RUSTC) foo.rs \ + --extern bar=$(TMPDIR)/libbar.rlib \ + --extern bar=$(TMPDIR)/libbar.rlib + $(RUSTC) foo.rs --extern bar=$(TMPDIR)/libbar.rlib diff --git a/src/test/run-make/extern-flag-fun/bar.rs b/src/test/run-make/extern-flag-fun/bar.rs new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/src/test/run-make/extern-flag-fun/bar.rs diff --git a/src/test/run-make/extern-flag-fun/foo.rs b/src/test/run-make/extern-flag-fun/foo.rs new file mode 100644 index 00000000000..0edda7d7b88 --- /dev/null +++ b/src/test/run-make/extern-flag-fun/foo.rs @@ -0,0 +1,3 @@ +extern crate bar; + +fn main() {} diff --git a/src/test/run-make/metadata-flag-frobs-symbols/Makefile b/src/test/run-make/metadata-flag-frobs-symbols/Makefile new file mode 100644 index 00000000000..09e6ae0bbf7 --- /dev/null +++ b/src/test/run-make/metadata-flag-frobs-symbols/Makefile @@ -0,0 +1,10 @@ +-include ../tools.mk + +all: + $(RUSTC) foo.rs -C metadata=a -C extra-filename=-a + $(RUSTC) foo.rs -C metadata=b -C extra-filename=-b + $(RUSTC) bar.rs \ + --extern foo1=$(TMPDIR)/libfoo-a.rlib \ + --extern foo2=$(TMPDIR)/libfoo-b.rlib \ + -Z print-link-args + $(call RUN,bar) diff --git a/src/test/run-make/metadata-flag-frobs-symbols/bar.rs b/src/test/run-make/metadata-flag-frobs-symbols/bar.rs new file mode 100644 index 00000000000..1e6957a3694 --- /dev/null +++ b/src/test/run-make/metadata-flag-frobs-symbols/bar.rs @@ -0,0 +1,8 @@ +extern crate foo1; +extern crate foo2; + +fn main() { + let a = foo1::foo(); + let b = foo2::foo(); + assert!(a as *const _ != b as *const _); +} diff --git a/src/test/run-make/metadata-flag-frobs-symbols/foo.rs b/src/test/run-make/metadata-flag-frobs-symbols/foo.rs new file mode 100644 index 00000000000..1974f4bc562 --- /dev/null +++ b/src/test/run-make/metadata-flag-frobs-symbols/foo.rs @@ -0,0 +1,6 @@ +#![crate_name = "foo"] +#![crate_type = "rlib"] + +static FOO: uint = 3; + +pub fn foo() -> &'static uint { &FOO } |
