diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index 497533602799b..730e863d04d4e 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -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) } } diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 357d3c6cfb488..a7dbfb9a3b279 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -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) -> diff --git a/src/libcargo/cargo.rc b/src/libcargo/cargo.rc index d4e68746fd4c4..8d81f75e0da79 100644 --- a/src/libcargo/cargo.rc +++ b/src/libcargo/cargo.rc @@ -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)) || diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 3b340d6de791d..ea39ef7ed8de5 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -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) } @@ -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)] diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index a2b67e8380bd0..39ddf64495227 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -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, @@ -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, @@ -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()); diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index db15a57208218..0938d2dcc6f2c 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -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), diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index e75329340c2fe..d451017cd1ea0 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -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; @@ -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) } }