Skip to content
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

Implement -Zlink-native-libraries #70095

Merged
merged 1 commit into from
Mar 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/librustc_codegen_ssa/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1379,10 +1379,17 @@ fn link_args<'a, B: ArchiveBuilder<'a>>(
// link line. And finally upstream native libraries can't depend on anything
// in this DAG so far because they're only dylibs and dylibs can only depend
// on other dylibs (e.g., other native deps).
add_local_native_libraries(cmd, sess, codegen_results);
//
// If -Zlink-native-libraries=false is set, then the assumption is that an
// external build system already has the native dependencies defined, and it
// will provide them to the linker itself.
if sess.opts.debugging_opts.link_native_libraries.unwrap_or(true) {
add_local_native_libraries(cmd, sess, codegen_results);
}
add_upstream_rust_crates::<B>(cmd, sess, codegen_results, crate_type, tmpdir);
add_upstream_native_libraries(cmd, sess, codegen_results, crate_type);

if sess.opts.debugging_opts.link_native_libraries.unwrap_or(true) {
add_upstream_native_libraries(cmd, sess, codegen_results, crate_type);
}
// Tell the linker what we're doing.
if crate_type != config::CrateType::Executable {
cmd.build_dylib(out_filename);
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_session/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,4 +959,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"link the `.rlink` file generated by `-Z no-link`"),
new_llvm_pass_manager: Option<bool> = (None, parse_opt_bool, [TRACKED],
"use new LLVM pass manager"),
link_native_libraries: Option<bool> = (None, parse_opt_bool, [UNTRACKED],
"Link native libraries in the linker invocation."),
}
8 changes: 8 additions & 0 deletions src/test/ui/issues/issue-70093.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// run-pass
// compile-flags: -Zlink-native-libraries=no -Cdefault-linker-libraries=yes
// ignore-windows - this will probably only work on unixish systems

#[link(name = "some-random-non-existent-library", kind = "static")]
extern "C" {}

fn main() {}