about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/Cargo.toml30
-rw-r--r--src/libstd/build.rs112
-rw-r--r--src/libstd/rand/os.rs5
-rw-r--r--src/libstd/rtdeps.rs2
-rw-r--r--src/libstd/sys/common/gnu/libbacktrace.rs2
-rw-r--r--src/libstd/sys/common/unwind/gcc.rs3
-rw-r--r--src/libstd/sys/unix/os.rs3
-rw-r--r--src/libstd/sys/windows/c.rs3
8 files changed, 157 insertions, 3 deletions
diff --git a/src/libstd/Cargo.toml b/src/libstd/Cargo.toml
new file mode 100644
index 00000000000..390c64d7408
--- /dev/null
+++ b/src/libstd/Cargo.toml
@@ -0,0 +1,30 @@
+[package]
+authors = ["The Rust Project Developers"]
+name = "std"
+version = "0.0.0"
+build = "build.rs"
+
+[lib]
+name = "std"
+path = "lib.rs"
+crate-type = ["dylib", "rlib"]
+test = false
+
+[dependencies]
+alloc = { path = "../liballoc" }
+alloc_jemalloc = { path = "../liballoc_jemalloc", optional = true }
+alloc_system = { path = "../liballoc_system" }
+collections = { path = "../libcollections" }
+core = { path = "../libcore" }
+libc = { path = "../rustc/libc_shim" }
+rand = { path = "../librand" }
+rustc_bitflags = { path = "../librustc_bitflags" }
+rustc_unicode = { path = "../librustc_unicode" }
+
+[build-dependencies]
+build_helper = { path = "../build_helper" }
+gcc = "0.3"
+
+[features]
+jemalloc = ["alloc_jemalloc"]
+debug-jemalloc = ["alloc_jemalloc/debug"]
diff --git a/src/libstd/build.rs b/src/libstd/build.rs
new file mode 100644
index 00000000000..8fb49a1be4e
--- /dev/null
+++ b/src/libstd/build.rs
@@ -0,0 +1,112 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+extern crate gcc;
+extern crate build_helper;
+
+use std::env;
+use std::fs;
+use std::path::PathBuf;
+use std::process::Command;
+
+use build_helper::run;
+
+fn main() {
+    println!("cargo:rustc-cfg=cargobuild");
+
+    let target = env::var("TARGET").unwrap();
+    let host = env::var("HOST").unwrap();
+    if !target.contains("apple") && !target.contains("msvc") {
+        build_libbacktrace(&host, &target);
+    }
+
+    if target.contains("unknown-linux") {
+        if target.contains("musl") {
+            println!("cargo:rustc-link-lib=static=unwind");
+        } else {
+            println!("cargo:rustc-link-lib=dl");
+            println!("cargo:rustc-link-lib=rt");
+            println!("cargo:rustc-link-lib=pthread");
+            println!("cargo:rustc-link-lib=gcc_s");
+        }
+    } else if target.contains("android") {
+        println!("cargo:rustc-link-lib=dl");
+        println!("cargo:rustc-link-lib=log");
+        println!("cargo:rustc-link-lib=gcc");
+    } else if target.contains("freebsd") {
+        println!("cargo:rustc-link-lib=execinfo");
+        println!("cargo:rustc-link-lib=pthread");
+        println!("cargo:rustc-link-lib=gcc_s");
+    } else if target.contains("dragonfly") || target.contains("bitrig") ||
+              target.contains("netbsd") || target.contains("openbsd") {
+        println!("cargo:rustc-link-lib=pthread");
+
+        if target.contains("rumprun") {
+            println!("cargo:rustc-link-lib=unwind");
+        } else if target.contains("netbsd") || target.contains("openbsd") {
+            println!("cargo:rustc-link-lib=gcc");
+        } else if target.contains("bitrig") {
+            println!("cargo:rustc-link-lib=c++abi");
+        } else if target.contains("dragonfly") {
+            println!("cargo:rustc-link-lib=gcc_pic");
+        }
+    } else if target.contains("apple-darwin") {
+        println!("cargo:rustc-link-lib=System");
+    } else if target.contains("apple-ios") {
+        println!("cargo:rustc-link-lib=System");
+        println!("cargo:rustc-link-lib=objc");
+        println!("cargo:rustc-link-lib=framework=Security");
+        println!("cargo:rustc-link-lib=framework=Foundation");
+    } else if target.contains("windows") {
+        if target.contains("windows-gnu") {
+            println!("cargo:rustc-link-lib=gcc_eh");
+        }
+        println!("cargo:rustc-link-lib=advapi32");
+        println!("cargo:rustc-link-lib=ws2_32");
+        println!("cargo:rustc-link-lib=userenv");
+        println!("cargo:rustc-link-lib=shell32");
+    }
+}
+
+fn build_libbacktrace(host: &str, target: &str) {
+    let src_dir = env::current_dir().unwrap().join("../libbacktrace");
+    let build_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
+
+    println!("cargo:rustc-link-lib=static=backtrace");
+    println!("cargo:rustc-link-search=native={}/.libs", build_dir.display());
+
+    if fs::metadata(&build_dir.join(".libs/libbacktrace.a")).is_ok() {
+        return
+    }
+
+    let compiler = gcc::Config::new().get_compiler();
+    let ar = build_helper::cc2ar(compiler.path(), target);
+    let cflags = compiler.args().iter().map(|s| s.to_str().unwrap())
+                         .collect::<Vec<_>>().join(" ");
+    run(Command::new("sh")
+                .current_dir(&build_dir)
+                .arg(src_dir.join("configure").to_str().unwrap()
+                            .replace("C:\\", "/c/")
+                            .replace("\\", "/"))
+                .arg("--with-pic")
+                .arg("--disable-multilib")
+                .arg("--disable-shared")
+                .arg("--disable-host-shared")
+                .arg(format!("--host={}", build_helper::gnu_target(target)))
+                .arg(format!("--build={}", build_helper::gnu_target(host)))
+                .env("CC", compiler.path())
+                .env("AR", &ar)
+                .env("RANLIB", format!("{} s", ar.display()))
+                .env("CFLAGS", cflags));
+    run(Command::new("make")
+                .current_dir(&build_dir)
+                .arg(format!("INCDIR={}", src_dir.display()))
+                .arg("-j").arg(env::var("NUM_JOBS").unwrap()));
+}
diff --git a/src/libstd/rand/os.rs b/src/libstd/rand/os.rs
index 8d92909faf5..8a422246514 100644
--- a/src/libstd/rand/os.rs
+++ b/src/libstd/rand/os.rs
@@ -269,7 +269,10 @@ mod imp {
     const kSecRandomDefault: *const SecRandom = ptr::null();
 
     #[link(name = "Security", kind = "framework")]
-    extern "C" {
+    #[cfg(not(cargobuild))]
+    extern {}
+
+    extern {
         fn SecRandomCopyBytes(rnd: *const SecRandom,
                               count: size_t, bytes: *mut u8) -> c_int;
     }
diff --git a/src/libstd/rtdeps.rs b/src/libstd/rtdeps.rs
index b1b9ffc4dc6..a11200873d5 100644
--- a/src/libstd/rtdeps.rs
+++ b/src/libstd/rtdeps.rs
@@ -12,6 +12,8 @@
 //! the standard library This varies per-platform, but these libraries are
 //! necessary for running libstd.
 
+#![cfg(not(cargobuild))]
+
 // LLVM implements the `frem` instruction as a call to `fmod`, which lives in
 // libm. Hence, we must explicitly link to it.
 //
diff --git a/src/libstd/sys/common/gnu/libbacktrace.rs b/src/libstd/sys/common/gnu/libbacktrace.rs
index f8463388384..8b3cb04030c 100644
--- a/src/libstd/sys/common/gnu/libbacktrace.rs
+++ b/src/libstd/sys/common/gnu/libbacktrace.rs
@@ -40,7 +40,7 @@ pub fn print(w: &mut Write, idx: isize, addr: *mut libc::c_void,
                       errnum: libc::c_int);
     enum backtrace_state {}
     #[link(name = "backtrace", kind = "static")]
-    #[cfg(not(test))]
+    #[cfg(all(not(test), not(cargobuild)))]
     extern {}
 
     extern {
diff --git a/src/libstd/sys/common/unwind/gcc.rs b/src/libstd/sys/common/unwind/gcc.rs
index 12cd07a4f4f..7cf9e2a54bd 100644
--- a/src/libstd/sys/common/unwind/gcc.rs
+++ b/src/libstd/sys/common/unwind/gcc.rs
@@ -252,6 +252,9 @@ pub mod eh_frame_registry {
     // See also: rtbegin.rs, `unwind` module.
 
     #[link(name = "gcc_eh")]
+    #[cfg(not(cargobuild))]
+    extern {}
+
     extern {
         fn __register_frame_info(eh_frame_begin: *const u8, object: *mut u8);
         fn __deregister_frame_info(eh_frame_begin: *const u8, object: *mut u8);
diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs
index 9def3adc303..b6a0bd84409 100644
--- a/src/libstd/sys/unix/os.rs
+++ b/src/libstd/sys/unix/os.rs
@@ -339,7 +339,6 @@ pub fn args() -> Args {
 pub fn args() -> Args {
     use mem;
 
-    #[link(name = "objc")]
     extern {
         fn sel_registerName(name: *const libc::c_uchar) -> Sel;
         fn objc_msgSend(obj: NsId, sel: Sel, ...) -> NsId;
@@ -347,6 +346,8 @@ pub fn args() -> Args {
     }
 
     #[link(name = "Foundation", kind = "framework")]
+    #[link(name = "objc")]
+    #[cfg(not(cargobuild))]
     extern {}
 
     type Sel = *const libc::c_void;
diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs
index 6e8090a2235..9fdeb0aef14 100644
--- a/src/libstd/sys/windows/c.rs
+++ b/src/libstd/sys/windows/c.rs
@@ -966,6 +966,9 @@ pub enum EXCEPTION_DISPOSITION {
 #[link(name = "userenv")]
 #[link(name = "shell32")]
 #[link(name = "advapi32")]
+#[cfg(not(cargobuild))]
+extern {}
+
 extern "system" {
     pub fn WSAStartup(wVersionRequested: WORD,
                       lpWSAData: LPWSADATA) -> c_int;