about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2016-01-21 15:36:25 -0800
committerAlex Crichton <alex@alexcrichton.com>2016-02-11 11:12:32 -0800
commiteac0a8bc3070e45047fff57e7b024a059289a36d (patch)
treecbcaa9dc371f2b11fe2e9b9d3ee7a3f7a9cfdb8e
parent4da4970767ae8fc2e3b6d0c280312bb0f4efeed6 (diff)
downloadrust-eac0a8bc3070e45047fff57e7b024a059289a36d.tar.gz
rust-eac0a8bc3070e45047fff57e7b024a059289a36d.zip
bootstrap: Add directives to not double-link libs
Have all Cargo-built crates pass `--cfg cargobuild` and then add appropriate
`#[cfg]` definitions to all crates to avoid linking anything if this is passed.
This should help allow libstd to compile with both the makefiles and with Cargo.
-rw-r--r--src/liballoc_jemalloc/build.rs2
-rw-r--r--src/liballoc_jemalloc/lib.rs5
-rw-r--r--src/libflate/build.rs1
-rw-r--r--src/libflate/lib.rs5
-rw-r--r--src/librustc_llvm/build.rs2
-rw-r--r--src/librustc_llvm/lib.rs4
-rw-r--r--src/librustdoc/build.rs1
-rw-r--r--src/librustdoc/html/markdown.rs3
-rw-r--r--src/libstd/build.rs2
-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
15 files changed, 38 insertions, 5 deletions
diff --git a/src/liballoc_jemalloc/build.rs b/src/liballoc_jemalloc/build.rs
index 18f0527425a..4bc752af48e 100644
--- a/src/liballoc_jemalloc/build.rs
+++ b/src/liballoc_jemalloc/build.rs
@@ -17,6 +17,8 @@ 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();
     let build_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
diff --git a/src/liballoc_jemalloc/lib.rs b/src/liballoc_jemalloc/lib.rs
index d02e9e4ba13..2c46e37ac32 100644
--- a/src/liballoc_jemalloc/lib.rs
+++ b/src/liballoc_jemalloc/lib.rs
@@ -38,7 +38,10 @@ use libc::{c_int, c_void, size_t};
                not(target_os = "android"),
                not(target_env = "musl")),
            link(name = "pthread"))]
-extern "C" {
+#[cfg(not(cargobuild))]
+extern {}
+
+extern {
     fn je_mallocx(size: size_t, flags: c_int) -> *mut c_void;
     fn je_rallocx(ptr: *mut c_void, size: size_t, flags: c_int) -> *mut c_void;
     fn je_xallocx(ptr: *mut c_void, size: size_t, extra: size_t, flags: c_int) -> size_t;
diff --git a/src/libflate/build.rs b/src/libflate/build.rs
index 12016980a2c..245c705dfcc 100644
--- a/src/libflate/build.rs
+++ b/src/libflate/build.rs
@@ -11,6 +11,7 @@
 extern crate gcc;
 
 fn main() {
+    println!("cargo:rustc-cfg=cargobuild");
     gcc::Config::new()
         .file("../rt/miniz.c")
         .compile("libminiz.a");
diff --git a/src/libflate/lib.rs b/src/libflate/lib.rs
index f316250d96d..a6bf735e459 100644
--- a/src/libflate/lib.rs
+++ b/src/libflate/lib.rs
@@ -79,7 +79,10 @@ impl Drop for Bytes {
 }
 
 #[link(name = "miniz", kind = "static")]
-extern "C" {
+#[cfg(not(cargobuild))]
+extern {}
+
+extern {
     /// Raw miniz compression function.
     fn tdefl_compress_mem_to_heap(psrc_buf: *const c_void,
                                   src_buf_len: size_t,
diff --git a/src/librustc_llvm/build.rs b/src/librustc_llvm/build.rs
index 4f2fee6943f..1c9982790cf 100644
--- a/src/librustc_llvm/build.rs
+++ b/src/librustc_llvm/build.rs
@@ -18,6 +18,8 @@ use std::path::PathBuf;
 use build_helper::output;
 
 fn main() {
+    println!("cargo:rustc-cfg=cargobuild");
+
     let target = env::var("TARGET").unwrap();
     let llvm_config = env::var_os("LLVM_CONFIG").map(PathBuf::from)
                            .unwrap_or_else(|| {
diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs
index 059287ccb5e..8877479104e 100644
--- a/src/librustc_llvm/lib.rs
+++ b/src/librustc_llvm/lib.rs
@@ -609,6 +609,9 @@ pub mod debuginfo {
 // automatically updated whenever LLVM is updated to include an up-to-date
 // set of the libraries we need to link to LLVM for.
 #[link(name = "rustllvm", kind = "static")]
+#[cfg(not(cargobuild))]
+extern {}
+
 #[linked_from = "rustllvm"] // not quite true but good enough
 extern {
     /* Create and destroy contexts. */
@@ -2486,6 +2489,7 @@ impl Drop for OperandBundleDef {
 // parts of LLVM that rustllvm depends on aren't thrown away by the linker.
 // Works to the above fix for #15460 to ensure LLVM dependencies that
 // are only used by rustllvm don't get stripped by the linker.
+#[cfg(not(cargobuild))]
 mod llvmdeps {
     include! { env!("CFG_LLVM_LINKAGE_FILE") }
 }
diff --git a/src/librustdoc/build.rs b/src/librustdoc/build.rs
index fcb7af11dce..171954f325a 100644
--- a/src/librustdoc/build.rs
+++ b/src/librustdoc/build.rs
@@ -11,6 +11,7 @@
 extern crate gcc;
 
 fn main() {
+    println!("cargo:rustc-cfg=cargobuild");
     let mut cfg = gcc::Config::new();
     cfg.file("../rt/hoedown/src/autolink.c")
        .file("../rt/hoedown/src/buffer.c")
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs
index a5436886a7e..c0846cae687 100644
--- a/src/librustdoc/html/markdown.rs
+++ b/src/librustdoc/html/markdown.rs
@@ -157,6 +157,9 @@ struct hoedown_buffer {
 
 // hoedown FFI
 #[link(name = "hoedown", kind = "static")]
+#[cfg(not(cargobuild))]
+extern {}
+
 extern {
     fn hoedown_html_renderer_new(render_flags: libc::c_uint,
                                  nesting_level: libc::c_int)
diff --git a/src/libstd/build.rs b/src/libstd/build.rs
index 8561d53a0d3..8fb49a1be4e 100644
--- a/src/libstd/build.rs
+++ b/src/libstd/build.rs
@@ -19,6 +19,8 @@ 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") {
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;