diff options
| author | Daniil Belov <belov.dv@phystech.edu> | 2022-07-19 12:00:28 +0300 |
|---|---|---|
| committer | Daniil Belov <belov.dv@phystech.edu> | 2022-07-26 13:55:27 +0300 |
| commit | 7d4a98e61aef8622ab4fa0cec0810171cf17b1bf (patch) | |
| tree | 5b86a093fccc2504f4fc907569eec38055c9ffc6 /compiler | |
| parent | 9ed0bf9f2bd63933785fb8a380c177d2d70e88ec (diff) | |
| download | rust-7d4a98e61aef8622ab4fa0cec0810171cf17b1bf.tar.gz rust-7d4a98e61aef8622ab4fa0cec0810171cf17b1bf.zip | |
Lib kind -l link-arg:
arbitrary link argument like -C link-arg, but respecting relative order to other `-l` options, unstable
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/link.rs | 38 | ||||
| -rw-r--r-- | compiler/rustc_session/src/config.rs | 17 | ||||
| -rw-r--r-- | compiler/rustc_session/src/utils.rs | 5 |
3 files changed, 48 insertions, 12 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 878a670cba3..663a6f3a277 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -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 { @@ -1287,6 +1288,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, } }) @@ -2225,6 +2227,9 @@ fn add_local_native_libraries( // FIXME(#58713): Proper handling for raw dylibs. bug!("raw_dylib feature not yet implemented"); } + NativeLibKind::LinkArg => { + cmd.arg(name); + } } } } @@ -2362,19 +2367,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: _, + } => {} } } } @@ -2565,7 +2585,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 => {} } } } diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 55307b9cebb..0c3322a7953 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1942,9 +1942,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 { @@ -2043,7 +2056,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. diff --git a/compiler/rustc_session/src/utils.rs b/compiler/rustc_session/src/utils.rs index bda7b314308..9a4f6f9f9ef 100644 --- a/compiler/rustc_session/src/utils.rs +++ b/compiler/rustc_session/src/utils.rs @@ -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, } } } |
