]> git.lizzy.rs Git - rust.git/commitdiff
bootstrap: Add directives to not double-link libs
authorAlex Crichton <alex@alexcrichton.com>
Thu, 21 Jan 2016 23:36:25 +0000 (15:36 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 11 Feb 2016 19:12:32 +0000 (11:12 -0800)
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.

15 files changed:
src/liballoc_jemalloc/build.rs
src/liballoc_jemalloc/lib.rs
src/libflate/build.rs
src/libflate/lib.rs
src/librustc_llvm/build.rs
src/librustc_llvm/lib.rs
src/librustdoc/build.rs
src/librustdoc/html/markdown.rs
src/libstd/build.rs
src/libstd/rand/os.rs
src/libstd/rtdeps.rs
src/libstd/sys/common/gnu/libbacktrace.rs
src/libstd/sys/common/unwind/gcc.rs
src/libstd/sys/unix/os.rs
src/libstd/sys/windows/c.rs

index 18f0527425a15c115e75f2a6e144020f640fe70e..4bc752af48eee5fdfb58a41b5fbb5b37ea987bc5 100644 (file)
@@ -17,6 +17,8 @@
 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());
index d02e9e4ba130b94819e71798e569fe3d6c4c13e9..2c46e37ac32b20e7aa7efe7c83975c8f1da58990 100644 (file)
                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;
index 12016980a2c656be8c5ace4d6ea27285865ca26a..245c705dfcc2a41c657ec505d62107fdf94f30b6 100644 (file)
@@ -11,6 +11,7 @@
 extern crate gcc;
 
 fn main() {
+    println!("cargo:rustc-cfg=cargobuild");
     gcc::Config::new()
         .file("../rt/miniz.c")
         .compile("libminiz.a");
index f316250d96d710c3eb296784f48fcaab0f7df703..a6bf735e459de53f4945f381c0d96bf9778843c5 100644 (file)
@@ -79,7 +79,10 @@ fn drop(&mut self) {
 }
 
 #[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,
index 4f2fee6943f388910a2b2cad79cd18abed29066a..1c9982790cf4ae15e10465980341610422439d28 100644 (file)
@@ -18,6 +18,8 @@
 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(|| {
index 059287ccb5ec3c3eb62b1789d791df30d0d1e5fe..8877479104e5539cd1e9c0d63b7cac963f9cede4 100644 (file)
@@ -609,6 +609,9 @@ pub enum DIDescriptorFlags {
 // 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 @@ fn drop(&mut self) {
 // 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") }
 }
index fcb7af11dce2f061d2abbfd0bcc1e0af72ee6ad0..171954f325a5e5dbcafd82003efb2283109cd06d 100644 (file)
@@ -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")
index a5436886a7e8c62173070057d3e489646f889c11..c0846cae687014291d5a5f6703d75e1e6f2cd271 100644 (file)
@@ -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)
index 8561d53a0d3611c78b611fdde6f402aa89ed1f29..8fb49a1be4ea6add15f85bcf006551066b403938 100644 (file)
@@ -19,6 +19,8 @@
 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") {
index 8d92909faf52884d73f11adc71b97a7d786ad3bd..8a422246514bcc833c3734cc08b24c705a77fcbe 100644 (file)
@@ -269,7 +269,10 @@ enum SecRandom {}
     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;
     }
index b1b9ffc4dc63d696d96e726a7a4f8a7392ab4f70..a11200873d500b980ea89326f7f621689e0f87c1 100644 (file)
@@ -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.
 //
index f8463388384f529bff2e98c25611c39d1188cba4..8b3cb04030c8272753e8e62a790551f29c40e2ac 100644 (file)
@@ -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 {
index 12cd07a4f4f181ab615488802403e6ba3d52da34..7cf9e2a54bd900ff7d575dd0ecded2fe9cffc3f7 100644 (file)
@@ -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);
index 9def3adc303435a16d2bba07fa5cbc851c4ddba1..b6a0bd844094b1ddeeb9999aa4ae8c6bff4169db 100644 (file)
@@ -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;
index 6e8090a223516434662df5b4f5497422cce35a2b..9fdeb0aef14c8317527531f07ee8b12ee8ecb584 100644 (file)
@@ -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;