-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Stabilize --extern flag without a path. #64882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b47e3d8
e0058ce
4bf411e
b54e8ec
41e051d
f9e4f0f
845ec5d
ee459c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,7 @@ to `#[cfg(verbose)]` and `#[cfg(feature = "serde")]` respectively. | |
<a id="option-l-search-path"></a> | ||
## `-L`: add a directory to the library search path | ||
|
||
When looking for external crates or libraries, a directory passed to this flag | ||
will be searched. | ||
The `-L` flag adds a path to search for external crates and libraries. | ||
|
||
The kind of search path can optionally be specified with the form `-L | ||
KIND=PATH` where `KIND` may be one of: | ||
|
@@ -262,9 +261,30 @@ This flag, when combined with other flags, makes them produce extra output. | |
<a id="option-extern"></a> | ||
## `--extern`: specify where an external library is located | ||
|
||
This flag allows you to pass the name and location of an external crate that | ||
will be linked into the crate you are building. This flag may be specified | ||
multiple times. The format of the value should be `CRATENAME=PATH`. | ||
This flag allows you to pass the name and location for an external crate of a | ||
direct dependency. Indirect dependencies (dependencies of dependencies) are | ||
located using the [`-L` flag](#option-l-search-path). The given crate name is | ||
added to the [extern prelude], which is the same as specifying `extern crate` | ||
within the root module. The given crate name does not need to match the name | ||
the library was built with. | ||
|
||
This flag may be specified multiple times. This flag takes an argument with | ||
either of the following formats: | ||
|
||
* `CRATENAME=PATH` — Indicates the given crate is found at the given path. | ||
* `CRATENAME` — Indicates the given crate may be found in the search path, | ||
such as within the sysroot or via the `-L` flag. | ||
|
||
|
||
The same crate name may be specified multiple times for different crate types. | ||
If both an `rlib` and `dylib` are found, an internal algorithm is used to | ||
decide which to use for linking. The [`-C prefer-dynamic` | ||
flag][prefer-dynamic] may be used to influence which is used. | ||
|
||
If the same crate name is specified with and without a path, the one with the | ||
path is used and the pathless flag has no effect. | ||
|
||
[extern prelude]: ../reference/items/extern-crates.html#extern-prelude | ||
[prefer-dynamic]: codegen-options/index.md#prefer-dynamic | ||
|
||
<a id="option-sysroot"></a> | ||
## `--sysroot`: Override the system root | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ all: | |
$(RUSTC) bar.rs --crate-type=rlib | ||
|
||
$(RUSTC) bar.rs --crate-type=rlib -C extra-filename=-a | ||
$(RUSTC) bar-alt.rs --crate-type=rlib | ||
$(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 \ | ||
|
@@ -15,3 +14,6 @@ all: | |
--extern bar=$(TMPDIR)/libbar.rlib \ | ||
--extern bar=$(TMPDIR)/libbar-a.rlib | ||
$(RUSTC) foo.rs --extern bar=$(TMPDIR)/libbar.rlib | ||
# Try to be sneaky and load a private crate from with a non-private name. | ||
$(RUSTC) rustc.rs -Zforce-unstable-if-unmarked --crate-type=rlib | ||
$(RUSTC) gated_unstable.rs --extern alloc=$(TMPDIR)/librustc.rlib 2>&1 | $(CGREP) 'rustc_private' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
extern crate alloc; | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub fn foo() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-include ../tools.mk | ||
|
||
# Test mixing pathless --extern with paths. | ||
|
||
all: | ||
$(RUSTC) bar-static.rs --crate-name=bar --crate-type=rlib | ||
$(RUSTC) bar-dynamic.rs --crate-name=bar --crate-type=dylib -C prefer-dynamic | ||
# rlib preferred over dylib | ||
$(RUSTC) foo.rs --extern bar | ||
$(call RUN,foo) | $(CGREP) 'static' | ||
$(RUSTC) foo.rs --extern bar=$(TMPDIR)/libbar.rlib --extern bar | ||
$(call RUN,foo) | $(CGREP) 'static' | ||
# explicit --extern overrides pathless | ||
$(RUSTC) foo.rs --extern bar=$(call DYLIB,bar) --extern bar | ||
$(call RUN,foo) | $(CGREP) 'dynamic' | ||
# prefer-dynamic does what it says | ||
$(RUSTC) foo.rs --extern bar -C prefer-dynamic | ||
$(call RUN,foo) | $(CGREP) 'dynamic' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub fn f() { | ||
println!("dynamic"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub fn f() { | ||
println!("static"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
bar::f(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// ignore-stage1 | ||
// edition:2018 | ||
// compile-flags:--extern rustc | ||
Centril marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
// Test that `--extern rustc` fails with `rustc_private`. | ||
|
||
pub use rustc; | ||
//~^ ERROR use of unstable library feature 'rustc_private' | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead? | ||
--> $DIR/pathless-extern-unstable.rs:7:9 | ||
| | ||
LL | pub use rustc; | ||
| ^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/27812 | ||
= help: add `#![feature(rustc_private)]` to the crate attributes to enable | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// edition:2018 | ||
// compile-flags:--extern alloc | ||
|
||
// build-pass | ||
|
||
// Test that `--extern alloc` will load from the sysroot without error. | ||
|
||
fn main() { | ||
let _: Vec<i32> = alloc::vec::Vec::new(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is making the html check fails because the id is not unique.