Skip to content

generate dll file name based on target os #4328

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

Closed
wants to merge 5 commits into from
Closed
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
2 changes: 1 addition & 1 deletion src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn is_test_ignored(config: config, testfile: &Path) -> bool {
return found;

fn xfail_target() -> ~str {
~"xfail-" + os::sysname()
~"xfail-" + str::from_slice(os::SYSNAME)
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,8 @@ fn make_lib_name(config: config, auxfile: &Path, testfile: &Path) -> Path {
}

fn make_exe_name(config: config, testfile: &Path) -> Path {
Path(output_base_name(config, testfile).to_str() + os::exe_suffix())
Path(output_base_name(config, testfile).to_str() +
str::from_slice(os::EXE_SUFFIX))
}

fn make_run_args(config: config, _props: test_props, testfile: &Path) ->
Expand Down
2 changes: 1 addition & 1 deletion src/libcargo/cargo.rc
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ fn install_one_crate(c: &Cargo, path: &Path, cf: &Path) {
Some(bp) => bp
};
let newv = os::list_dir_path(&buildpath);
let exec_suffix = os::exe_suffix();
let exec_suffix = str::from_slice(os::EXE_SUFFIX);
for newv.each |ct| {
if (exec_suffix != ~"" && str::ends_with(ct.to_str(),
exec_suffix)) ||
Expand Down
112 changes: 71 additions & 41 deletions src/libcore/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,8 @@ fn dup2(src: c_int, dst: c_int) -> c_int {


pub fn dll_filename(base: &str) -> ~str {
return pre() + str::from_slice(base) + dll_suffix();

#[cfg(unix)]
fn pre() -> ~str { ~"lib" }

#[cfg(windows)]
fn pre() -> ~str { ~"" }
return str::from_slice(DLL_PREFIX) + str::from_slice(base) +
str::from_slice(DLL_SUFFIX)
}


Expand Down Expand Up @@ -874,48 +869,83 @@ extern {
pub fn _NSGetArgv() -> ***c_char;
}

#[cfg(unix)]
pub fn family() -> ~str { ~"unix" }
mod consts {

#[cfg(windows)]
pub fn family() -> ~str { ~"windows" }
#[cfg(unix)]
use os::consts::unix::*;

#[cfg(target_os = "macos")]
mod consts {
pub fn sysname() -> ~str { ~"macos" }
pub fn exe_suffix() -> ~str { ~"" }
pub fn dll_suffix() -> ~str { ~".dylib" }
}
#[cfg(windows)]
use os::consts::windows::*;

#[cfg(target_os = "freebsd")]
mod consts {
pub fn sysname() -> ~str { ~"freebsd" }
pub fn exe_suffix() -> ~str { ~"" }
pub fn dll_suffix() -> ~str { ~".so" }
}
pub mod unix {
pub const FAMILY: &str = "unix";
}

#[cfg(target_os = "linux")]
mod consts {
pub fn sysname() -> ~str { ~"linux" }
pub fn exe_suffix() -> ~str { ~"" }
pub fn dll_suffix() -> ~str { ~".so" }
}
pub mod windows {
pub const FAMILY: &str = "windows";
}

#[cfg(target_os = "win32")]
mod consts {
pub fn sysname() -> ~str { ~"win32" }
pub fn exe_suffix() -> ~str { ~".exe" }
pub fn dll_suffix() -> ~str { ~".dll" }
}

#[cfg(target_arch = "x86")]
pub fn arch() -> ~str { ~"x86" }
#[cfg(target_os = "macos")]
use os::consts::macos::*;

#[cfg(target_os = "freebsd")]
use os::consts::freebsd::*;

#[cfg(target_os = "linux")]
use os::consts::linux::*;

#[cfg(target_os = "win32")]
use os::consts::win32::*;

#[cfg(target_arch = "x86_64")]
pub fn arch() -> ~str { ~"x86_64" }
pub mod macos {
pub const SYSNAME: &str = "macos";
pub const DLL_PREFIX: &str = "lib";
pub const DLL_SUFFIX: &str = ".dylib";
pub const EXE_SUFFIX: &str = "";
}

pub mod freebsd {
pub const SYSNAME: &str = "freebsd";
pub const DLL_PREFIX: &str = "lib";
pub const DLL_SUFFIX: &str = ".so";
pub const EXE_SUFFIX: &str = "";
}

pub mod linux {
pub const SYSNAME: &str = "linux";
pub const DLL_PREFIX: &str = "lib";
pub const DLL_SUFFIX: &str = ".so";
pub const EXE_SUFFIX: &str = "";
}

#[cfg(target_arch = "arm")]
pub fn arch() -> str { ~"arm" }
pub mod win32 {
pub const SYSNAME: &str = "win32";
pub const DLL_PREFIX: &str = "";
pub const DLL_SUFFIX: &str = ".dll";
pub const EXE_SUFFIX: &str = ".exe";
}


#[cfg(target_arch = "x86")]
use os::consts::x86::*;

#[cfg(target_arch = "x86_64")]
use os::consts::x86_64::*;

#[cfg(target_arch = "arm")]
use os::consts::arm::*;

pub mod x86 {
pub const ARCH: &str = "x86";
}
pub mod x86_64 {
pub const ARCH: &str = "x86_64";
}
pub mod arm {
pub const ARCH: &str = "arm";
}
}

#[cfg(test)]
#[allow(non_implicitly_copyable_typarams)]
Expand Down
19 changes: 16 additions & 3 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ use syntax::ast_map::{path, path_mod, path_name};
use syntax::attr;
use syntax::print::pprust;

use core::os::consts::{macos, freebsd, linux, win32};

enum output_type {
output_type_none,
output_type_bitcode,
Expand Down Expand Up @@ -662,6 +664,19 @@ fn mangle_internal_name_by_seq(ccx: @crate_ctxt, flav: ~str) -> ~str {
return fmt!("%s_%u", flav, (ccx.names)(flav).repr);
}


fn output_dll_filename(os: session::os, lm: &link_meta) -> ~str {
let libname = fmt!("%s-%s-%s", lm.name, lm.extras_hash, lm.vers);
let (dll_prefix, dll_suffix) = match os {
session::os_win32 => (win32::DLL_PREFIX, win32::DLL_SUFFIX),
session::os_macos => (macos::DLL_PREFIX, macos::DLL_SUFFIX),
session::os_linux => (linux::DLL_PREFIX, linux::DLL_SUFFIX),
session::os_freebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX),
};
return str::from_slice(dll_prefix) + libname +
str::from_slice(dll_suffix);
}

// If the user wants an exe generated we need to invoke
// cc to link the object file with some libs
fn link_binary(sess: Session,
Expand All @@ -679,9 +694,7 @@ fn link_binary(sess: Session,
}

let output = if sess.building_library {
let long_libname =
os::dll_filename(fmt!("%s-%s-%s",
lm.name, lm.extras_hash, lm.vers));
let long_libname = output_dll_filename(sess.targ_cfg.os, &lm);
debug!("link_meta.name: %s", lm.name);
debug!("long_libname: %s", long_libname);
debug!("out_filename: %s", out_filename.to_str());
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ fn default_configuration(sess: Session, argv0: ~str, input: input) ->
};

return ~[ // Target bindings.
attr::mk_word_item(os::family()),
mk(~"target_os", os::sysname()),
mk(~"target_family", os::family()),
attr::mk_word_item(str::from_slice(os::FAMILY)),
mk(~"target_os", str::from_slice(os::SYSNAME)),
mk(~"target_family", str::from_slice(os::FAMILY)),
mk(~"target_arch", arch),
mk(~"target_word_size", wordsz),
mk(~"target_libc", libc),
Expand Down
16 changes: 11 additions & 5 deletions src/librustc/metadata/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ use core::str;
use core::uint;
use core::vec;

use core::os::consts::{macos, freebsd, linux, win32};

export os;
export os_macos, os_win32, os_linux, os_freebsd;
export ctxt;
Expand Down Expand Up @@ -78,11 +80,15 @@ fn find_library_crate(cx: ctxt) -> Option<{ident: ~str, data: @~[u8]}> {

fn libname(cx: ctxt) -> {prefix: ~str, suffix: ~str} {
if cx.static { return {prefix: ~"lib", suffix: ~".rlib"}; }
match cx.os {
os_win32 => return {prefix: ~"", suffix: ~".dll"},
os_macos => return {prefix: ~"lib", suffix: ~".dylib"},
os_linux => return {prefix: ~"lib", suffix: ~".so"},
os_freebsd => return {prefix: ~"lib", suffix: ~".so"}
let (dll_prefix, dll_suffix) = match cx.os {
os_win32 => (win32::DLL_PREFIX, win32::DLL_SUFFIX),
os_macos => (macos::DLL_PREFIX, macos::DLL_SUFFIX),
os_linux => (linux::DLL_PREFIX, linux::DLL_SUFFIX),
os_freebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX),
};
return {
prefix: str::from_slice(dll_prefix),
suffix: str::from_slice(dll_suffix)
}
}

Expand Down