Skip to content

Commit cfec900

Browse files
committed
---
yaml --- r: 223339 b: refs/heads/beta c: 9e3cb64 h: refs/heads/master i: 223337: 23f2d00 223335: e627ea1 v: v3
1 parent f1dc1b8 commit cfec900

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 91d799eab0d7f6784fb4366182b5007cf055519d
26+
refs/heads/beta: 9e3cb6447596049464292c0afa8c4b9a0cb8c806
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: 938f5d7af401e2d8238522fed4a612943b6e77fd
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/librustc_trans/back/link.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,11 +1214,13 @@ fn add_upstream_rust_crates(cmd: &mut Linker, sess: &Session,
12141214

12151215
// Just need to tell the linker about where the library lives and
12161216
// what its name is
1217-
if let Some(dir) = cratepath.parent() {
1217+
let parent = cratepath.parent();
1218+
if let Some(dir) = parent {
12181219
cmd.include_path(&fix_windows_verbatim_for_gcc(dir));
12191220
}
12201221
let filestem = cratepath.file_stem().unwrap().to_str().unwrap();
1221-
cmd.link_dylib(&unlib(&sess.target, filestem));
1222+
cmd.link_rust_dylib(&unlib(&sess.target, filestem),
1223+
parent.unwrap_or(Path::new("")));
12221224
}
12231225
}
12241226

branches/beta/src/librustc_trans/back/linker.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use std::ffi::OsString;
1212
use std::path::{Path, PathBuf};
1313
use std::process::Command;
14+
use std::fs;
1415

1516
use rustc_back::archive;
1617
use session::Session;
@@ -25,6 +26,7 @@ use session::config;
2526
/// MSVC linker (e.g. `link.exe`) is being used.
2627
pub trait Linker {
2728
fn link_dylib(&mut self, lib: &str);
29+
fn link_rust_dylib(&mut self, lib: &str, path: &Path);
2830
fn link_framework(&mut self, framework: &str);
2931
fn link_staticlib(&mut self, lib: &str);
3032
fn link_rlib(&mut self, lib: &Path);
@@ -67,6 +69,10 @@ impl<'a> Linker for GnuLinker<'a> {
6769
fn position_independent_executable(&mut self) { self.cmd.arg("-pie"); }
6870
fn args(&mut self, args: &[String]) { self.cmd.args(args); }
6971

72+
fn link_rust_dylib(&mut self, lib: &str, _path: &Path) {
73+
self.cmd.arg("-l").arg(lib);
74+
}
75+
7076
fn link_framework(&mut self, framework: &str) {
7177
self.cmd.arg("-framework").arg(framework);
7278
}
@@ -189,6 +195,18 @@ impl<'a> Linker for MsvcLinker<'a> {
189195
fn link_dylib(&mut self, lib: &str) {
190196
self.cmd.arg(&format!("{}.lib", lib));
191197
}
198+
199+
fn link_rust_dylib(&mut self, lib: &str, path: &Path) {
200+
// When producing a dll, the MSVC linker may not actually emit a
201+
// `foo.lib` file if the dll doesn't actually export any symbols, so we
202+
// check to see if the file is there and just omit linking to it if it's
203+
// not present.
204+
let name = format!("{}.lib", lib);
205+
if fs::metadata(&path.join(&name)).is_ok() {
206+
self.cmd.arg(name);
207+
}
208+
}
209+
192210
fn link_staticlib(&mut self, lib: &str) {
193211
self.cmd.arg(&format!("{}.lib", lib));
194212
}

0 commit comments

Comments
 (0)