mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Auto merge of #99467 - BelovDV:add_option_link_arg, r=petrochenkov
flag '-l link-arg=___ was added #99427
This commit is contained in:
commit
5dda74a48c
@ -336,6 +336,7 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
|
||||
| NativeLibKind::Dylib { .. }
|
||||
| NativeLibKind::Framework { .. }
|
||||
| NativeLibKind::RawDylib
|
||||
| NativeLibKind::LinkArg
|
||||
| NativeLibKind::Unspecified => continue,
|
||||
}
|
||||
if let Some(name) = lib.name {
|
||||
@ -1289,6 +1290,7 @@ fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLib]) {
|
||||
}
|
||||
// These are included, no need to print them
|
||||
NativeLibKind::Static { bundle: None | Some(true), .. }
|
||||
| NativeLibKind::LinkArg
|
||||
| NativeLibKind::RawDylib => None,
|
||||
}
|
||||
})
|
||||
@ -2243,6 +2245,9 @@ fn add_local_native_libraries(
|
||||
NativeLibKind::RawDylib => {
|
||||
// Ignore RawDylib here, they are handled separately in linker_with_args().
|
||||
}
|
||||
NativeLibKind::LinkArg => {
|
||||
cmd.arg(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2380,19 +2385,34 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
|
||||
(lib.name, lib.kind, lib.verbatim)
|
||||
};
|
||||
|
||||
if let NativeLibKind::Static { bundle: Some(false), whole_archive } =
|
||||
lib.kind
|
||||
{
|
||||
let verbatim = lib.verbatim.unwrap_or(false);
|
||||
if whole_archive == Some(true) {
|
||||
match lib.kind {
|
||||
NativeLibKind::Static {
|
||||
bundle: Some(false),
|
||||
whole_archive: Some(true),
|
||||
} => {
|
||||
cmd.link_whole_staticlib(
|
||||
name,
|
||||
verbatim,
|
||||
lib.verbatim.unwrap_or(false),
|
||||
search_path.get_or_init(|| archive_search_paths(sess)),
|
||||
);
|
||||
} else {
|
||||
cmd.link_staticlib(name, verbatim);
|
||||
}
|
||||
NativeLibKind::Static {
|
||||
bundle: Some(false),
|
||||
whole_archive: Some(false) | None,
|
||||
} => {
|
||||
cmd.link_staticlib(name, lib.verbatim.unwrap_or(false));
|
||||
}
|
||||
NativeLibKind::LinkArg => {
|
||||
cmd.arg(name);
|
||||
}
|
||||
NativeLibKind::Dylib { .. }
|
||||
| NativeLibKind::Framework { .. }
|
||||
| NativeLibKind::Unspecified
|
||||
| NativeLibKind::RawDylib => {}
|
||||
NativeLibKind::Static {
|
||||
bundle: Some(true) | None,
|
||||
whole_archive: _,
|
||||
} => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2583,7 +2603,7 @@ fn add_upstream_native_libraries(
|
||||
// already included them in add_local_native_libraries and
|
||||
// add_upstream_rust_crates
|
||||
NativeLibKind::Static { .. } => {}
|
||||
NativeLibKind::RawDylib => {}
|
||||
NativeLibKind::RawDylib | NativeLibKind::LinkArg => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1944,9 +1944,22 @@ fn parse_native_lib_kind(
|
||||
"static" => NativeLibKind::Static { bundle: None, whole_archive: None },
|
||||
"dylib" => NativeLibKind::Dylib { as_needed: None },
|
||||
"framework" => NativeLibKind::Framework { as_needed: None },
|
||||
"link-arg" => {
|
||||
if !nightly_options::is_unstable_enabled(matches) {
|
||||
let why = if nightly_options::match_is_nightly_build(matches) {
|
||||
" and only accepted on the nightly compiler"
|
||||
} else {
|
||||
", the `-Z unstable-options` flag must also be passed to use it"
|
||||
};
|
||||
early_error(error_format, &format!("library kind `link-arg` is unstable{why}"))
|
||||
}
|
||||
NativeLibKind::LinkArg
|
||||
}
|
||||
_ => early_error(
|
||||
error_format,
|
||||
&format!("unknown library kind `{kind}`, expected one of: static, dylib, framework"),
|
||||
&format!(
|
||||
"unknown library kind `{kind}`, expected one of: static, dylib, framework, link-arg"
|
||||
),
|
||||
),
|
||||
};
|
||||
match modifiers {
|
||||
@ -2045,7 +2058,7 @@ fn parse_libs(matches: &getopts::Matches, error_format: ErrorOutputType) -> Vec<
|
||||
.into_iter()
|
||||
.map(|s| {
|
||||
// Parse string of the form "[KIND[:MODIFIERS]=]lib[:new_name]",
|
||||
// where KIND is one of "dylib", "framework", "static" and
|
||||
// where KIND is one of "dylib", "framework", "static", "link-arg" and
|
||||
// where MODIFIERS are a comma separated list of supported modifiers
|
||||
// (bundle, verbatim, whole-archive, as-needed). Each modifier is prefixed
|
||||
// with either + or - to indicate whether it is enabled or disabled.
|
||||
|
@ -34,6 +34,9 @@ pub enum NativeLibKind {
|
||||
/// Whether the framework will be linked only if it satisfies some undefined symbols
|
||||
as_needed: Option<bool>,
|
||||
},
|
||||
/// Argument which is passed to linker, relative order with libraries and other arguments
|
||||
/// is preserved
|
||||
LinkArg,
|
||||
/// The library kind wasn't specified, `Dylib` is currently used as a default.
|
||||
Unspecified,
|
||||
}
|
||||
@ -47,7 +50,7 @@ impl NativeLibKind {
|
||||
NativeLibKind::Dylib { as_needed } | NativeLibKind::Framework { as_needed } => {
|
||||
as_needed.is_some()
|
||||
}
|
||||
NativeLibKind::RawDylib | NativeLibKind::Unspecified => false,
|
||||
NativeLibKind::RawDylib | NativeLibKind::Unspecified | NativeLibKind::LinkArg => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
10
src/test/run-make/pass-linker-flags-from-dep/Makefile
Normal file
10
src/test/run-make/pass-linker-flags-from-dep/Makefile
Normal file
@ -0,0 +1,10 @@
|
||||
-include ../../run-make-fulldeps/tools.mk
|
||||
|
||||
all:
|
||||
# Build deps
|
||||
$(RUSTC) native_dep_1.rs --crate-type=staticlib
|
||||
$(RUSTC) native_dep_2.rs --crate-type=staticlib
|
||||
$(RUSTC) rust_dep.rs -l static:-bundle=native_dep_1 -l link-arg=some_flag -l static:-bundle=native_dep_2 --crate-type=lib -Z unstable-options
|
||||
|
||||
# Check sequence of linker args
|
||||
$(RUSTC) main.rs --extern lib=$(TMPDIR)/librust_dep.rlib --crate-type=bin --print link-args | $(CGREP) -e 'native_dep_1.*some_flag.*native_dep_2'
|
3
src/test/run-make/pass-linker-flags-from-dep/main.rs
Normal file
3
src/test/run-make/pass-linker-flags-from-dep/main.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
lib::f();
|
||||
}
|
@ -0,0 +1 @@
|
||||
pub fn f1() {}
|
@ -0,0 +1 @@
|
||||
pub fn f2() {}
|
9
src/test/run-make/pass-linker-flags-from-dep/rust_dep.rs
Normal file
9
src/test/run-make/pass-linker-flags-from-dep/rust_dep.rs
Normal file
@ -0,0 +1,9 @@
|
||||
extern "C" {
|
||||
pub fn foo();
|
||||
}
|
||||
|
||||
pub fn f() {
|
||||
unsafe {
|
||||
foo();
|
||||
}
|
||||
}
|
4
src/test/run-make/pass-linker-flags/Makefile
Normal file
4
src/test/run-make/pass-linker-flags/Makefile
Normal file
@ -0,0 +1,4 @@
|
||||
-include ../../run-make-fulldeps/tools.mk
|
||||
|
||||
all:
|
||||
$(RUSTC) rs.rs -Z unstable-options -l static=l1 -l link-arg=a1 -l static=l2 -l link-arg=a2 -l dylib=d1 -l link-arg=a3 --print link-args | $(CGREP) -e 'l1.*a1.*l2.*a2.*d1.*a3'
|
1
src/test/run-make/pass-linker-flags/rs.rs
Normal file
1
src/test/run-make/pass-linker-flags/rs.rs
Normal file
@ -0,0 +1 @@
|
||||
fn main() {}
|
@ -1,5 +1,5 @@
|
||||
// compile-flags:-l bar=foo
|
||||
// error-pattern: unknown library kind `bar`, expected one of: static, dylib, framework
|
||||
// error-pattern: unknown library kind `bar`, expected one of: static, dylib, framework, link-arg
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
@ -1,2 +1,2 @@
|
||||
error: unknown library kind `bar`, expected one of: static, dylib, framework
|
||||
error: unknown library kind `bar`, expected one of: static, dylib, framework, link-arg
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// compile-flags:-l raw-dylib=foo
|
||||
// error-pattern: unknown library kind `raw-dylib`, expected one of: static, dylib, framework
|
||||
// error-pattern: unknown library kind `raw-dylib`, expected one of: static, dylib, framework, link-arg
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
@ -1,2 +1,2 @@
|
||||
error: unknown library kind `raw-dylib`, expected one of: static, dylib, framework
|
||||
error: unknown library kind `raw-dylib`, expected one of: static, dylib, framework, link-arg
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Unspecified kind should fail with an error
|
||||
|
||||
// compile-flags: -l =mylib
|
||||
// error-pattern: unknown library kind ``, expected one of: static, dylib, framework
|
||||
// error-pattern: unknown library kind ``, expected one of: static, dylib, framework, link-arg
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,2 +1,2 @@
|
||||
error: unknown library kind ``, expected one of: static, dylib, framework
|
||||
error: unknown library kind ``, expected one of: static, dylib, framework, link-arg
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Unspecified kind should fail with an error
|
||||
|
||||
// compile-flags: -l :+bundle=mylib
|
||||
// error-pattern: unknown library kind ``, expected one of: static, dylib, framework
|
||||
// error-pattern: unknown library kind ``, expected one of: static, dylib, framework, link-arg
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,2 +1,2 @@
|
||||
error: unknown library kind ``, expected one of: static, dylib, framework
|
||||
error: unknown library kind ``, expected one of: static, dylib, framework, link-arg
|
||||
|
||||
|
4
src/test/ui/native-library-link-flags/link-arg-error.rs
Normal file
4
src/test/ui/native-library-link-flags/link-arg-error.rs
Normal file
@ -0,0 +1,4 @@
|
||||
// compile-flags: -l link-arg:+bundle=arg -Z unstable-options
|
||||
// error-pattern: linking modifier `bundle` is only compatible with `static` linking kind
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,2 @@
|
||||
error: linking modifier `bundle` is only compatible with `static` linking kind
|
||||
|
@ -0,0 +1,8 @@
|
||||
// link-arg is not supposed to be usable in #[link] attributes
|
||||
|
||||
// compile-flags:
|
||||
// error-pattern: error[E0458]: unknown link kind `link-arg`, expected one of: static, dylib, framework, raw-dylib
|
||||
|
||||
#[link(kind = "link-arg")]
|
||||
extern "C" {}
|
||||
pub fn main() {}
|
@ -0,0 +1,16 @@
|
||||
error[E0458]: unknown link kind `link-arg`, expected one of: static, dylib, framework, raw-dylib
|
||||
--> $DIR/link-arg-from-rs.rs:6:15
|
||||
|
|
||||
LL | #[link(kind = "link-arg")]
|
||||
| ^^^^^^^^^^ unknown link kind
|
||||
|
||||
error[E0459]: `#[link]` attribute requires a `name = "string"` argument
|
||||
--> $DIR/link-arg-from-rs.rs:6:1
|
||||
|
|
||||
LL | #[link(kind = "link-arg")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `name` argument
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0458, E0459.
|
||||
For more information about an error, try `rustc --explain E0458`.
|
Loading…
Reference in New Issue
Block a user