about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2017-03-03 20:11:04 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2017-03-04 21:38:26 +0300
commit428f063fcdc35e048ff79d059a8963334ba2281c (patch)
treeef19c01e9179f6d455cc6c6a7b3a0cbf316f3119 /src
parentc652a4fb566ac4bec1d62c66769dd055ad239df6 (diff)
downloadrust-428f063fcdc35e048ff79d059a8963334ba2281c.tar.gz
rust-428f063fcdc35e048ff79d059a8963334ba2281c.zip
Automate timestamp creation and build skipping for native libraries
Add comments
Diffstat (limited to 'src')
-rw-r--r--src/Cargo.lock4
-rw-r--r--src/build_helper/lib.rs33
-rw-r--r--src/liballoc_jemalloc/build.rs13
-rw-r--r--src/libcompiler_builtins/build.rs15
-rw-r--r--src/librustc_asan/build.rs14
-rw-r--r--src/librustc_lsan/build.rs14
-rw-r--r--src/librustc_msan/build.rs14
-rw-r--r--src/librustc_tsan/build.rs14
-rw-r--r--src/libstd/build.rs15
9 files changed, 56 insertions, 80 deletions
diff --git a/src/Cargo.lock b/src/Cargo.lock
index aa4d65de0ac..f4174693a57 100644
--- a/src/Cargo.lock
+++ b/src/Cargo.lock
@@ -487,7 +487,7 @@ name = "libgit2-sys"
 version = "0.6.7"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "cmake 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cmake 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
  "curl-sys 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)",
  "gcc 0.3.43 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -502,7 +502,7 @@ name = "libssh2-sys"
 version = "0.2.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "cmake 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cmake 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
  "libz-sys 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
  "openssl-sys 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/src/build_helper/lib.rs b/src/build_helper/lib.rs
index 2aac5ba6a10..dffaebbd929 100644
--- a/src/build_helper/lib.rs
+++ b/src/build_helper/lib.rs
@@ -13,6 +13,7 @@
 extern crate filetime;
 
 use std::{fs, env};
+use std::fs::File;
 use std::process::{Command, Stdio};
 use std::path::{Path, PathBuf};
 
@@ -166,19 +167,29 @@ pub fn up_to_date(src: &Path, dst: &Path) -> bool {
     }
 }
 
+#[must_use]
 pub struct NativeLibBoilerplate {
-    pub skip_build: bool,
     pub src_dir: PathBuf,
     pub out_dir: PathBuf,
-    pub timestamp: PathBuf,
 }
 
+impl Drop for NativeLibBoilerplate {
+    fn drop(&mut self) {
+        t!(File::create(self.out_dir.join("rustbuild.timestamp")));
+    }
+}
+
+// Perform standard preparations for native libraries that are build only once for all stages.
+// Emit rerun-if-changed and linking attributes for Cargo, check if any source files are
+// updated, calculate paths used later in actual build with CMake/make or C/C++ compiler.
+// If Err is returned, then everything is up-to-date and further build actions can be skipped.
+// Timestamps are created automatically when the result of `native_lib_boilerplate` goes out
+// of scope, so all the build actions should be completed until then.
 pub fn native_lib_boilerplate(src_name: &str,
                               out_name: &str,
                               link_name: &str,
-                              timestamp_name: &str,
                               search_subdir: &str)
-                              -> NativeLibBoilerplate {
+                              -> Result<NativeLibBoilerplate, ()> {
     let current_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
     let src_dir = current_dir.join("..").join(src_name);
     rerun_if_changed_anything_in_dir(&src_dir);
@@ -189,15 +200,11 @@ pub fn native_lib_boilerplate(src_name: &str,
     println!("cargo:rustc-link-lib=static={}", link_name);
     println!("cargo:rustc-link-search=native={}", out_dir.join(search_subdir).display());
 
-    let timestamp = out_dir.join(timestamp_name);
-    let skip_build = up_to_date(Path::new("build.rs"), &timestamp) &&
-                     up_to_date(&src_dir, &timestamp);
-
-    NativeLibBoilerplate {
-        skip_build: skip_build,
-        src_dir: src_dir,
-        out_dir: out_dir,
-        timestamp: timestamp,
+    let timestamp = out_dir.join("rustbuild.timestamp");
+    if !up_to_date(Path::new("build.rs"), &timestamp) || !up_to_date(&src_dir, &timestamp) {
+        Ok(NativeLibBoilerplate { src_dir: src_dir, out_dir: out_dir })
+    } else {
+        Err(())
     }
 }
 
diff --git a/src/liballoc_jemalloc/build.rs b/src/liballoc_jemalloc/build.rs
index cc1e74ccbbf..ae040a23906 100644
--- a/src/liballoc_jemalloc/build.rs
+++ b/src/liballoc_jemalloc/build.rs
@@ -10,12 +10,10 @@
 
 #![deny(warnings)]
 
-#[macro_use]
 extern crate build_helper;
 extern crate gcc;
 
 use std::env;
-use std::fs::File;
 use std::path::PathBuf;
 use std::process::Command;
 use build_helper::{run, native_lib_boilerplate};
@@ -60,11 +58,10 @@ fn main() {
     }
 
     let link_name = if target.contains("windows") { "jemalloc" } else { "jemalloc_pic" };
-    let native = native_lib_boilerplate("jemalloc", "jemalloc", link_name,
-                                        "rustbuild.timestamp", "lib");
-    if native.skip_build {
-        return
-    }
+    let native = match native_lib_boilerplate("jemalloc", "jemalloc", link_name, "lib") {
+        Ok(native) => native,
+        _ => return,
+    };
 
     let compiler = gcc::Config::new().get_compiler();
     // only msvc returns None for ar so unwrap is okay
@@ -175,6 +172,4 @@ fn main() {
             .file("pthread_atfork_dummy.c")
             .compile("libpthread_atfork_dummy.a");
     }
-
-    t!(File::create(&native.timestamp));
 }
diff --git a/src/libcompiler_builtins/build.rs b/src/libcompiler_builtins/build.rs
index ff5111a15be..bcd3a92dd43 100644
--- a/src/libcompiler_builtins/build.rs
+++ b/src/libcompiler_builtins/build.rs
@@ -82,16 +82,13 @@ fn main() {
     }
 
     // Can't reuse `sources` list for the freshness check becuse it doesn't contain header files.
-    // Use the produced library itself as a timestamp.
-    let out_name = "libcompiler-rt.a";
-    let native = native_lib_boilerplate("compiler-rt", "compiler-rt", "compiler-rt",
-                                        out_name, ".");
-    if native.skip_build {
-        return
-    }
+    let native = match native_lib_boilerplate("compiler-rt", "compiler-rt", "compiler-rt", ".") {
+        Ok(native) => native,
+        _ => return,
+    };
 
     let cfg = &mut gcc::Config::new();
-    cfg.out_dir(native.out_dir);
+    cfg.out_dir(&native.out_dir);
 
     if target.contains("msvc") {
         // Don't pull in extra libraries on MSVC
@@ -416,5 +413,5 @@ fn main() {
         cfg.file(Path::new("../compiler-rt/lib/builtins").join(src));
     }
 
-    cfg.compile(out_name);
+    cfg.compile("libcompiler-rt.a");
 }
diff --git a/src/librustc_asan/build.rs b/src/librustc_asan/build.rs
index 4772d145775..2df2e001e6f 100644
--- a/src/librustc_asan/build.rs
+++ b/src/librustc_asan/build.rs
@@ -8,23 +8,21 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#[macro_use]
 extern crate build_helper;
 extern crate cmake;
 
 use std::env;
-use std::fs::File;
 use build_helper::native_lib_boilerplate;
 
 use cmake::Config;
 
 fn main() {
     if let Some(llvm_config) = env::var_os("LLVM_CONFIG") {
-        let native = native_lib_boilerplate("compiler-rt", "asan", "clang_rt.asan-x86_64",
-                                            "rustbuild.timestamp", "build/lib/linux");
-        if native.skip_build {
-            return
-        }
+        let native = match native_lib_boilerplate("compiler-rt", "asan", "clang_rt.asan-x86_64",
+                                                  "build/lib/linux") {
+            Ok(native) => native,
+            _ => return,
+        };
 
         Config::new(&native.src_dir)
             .define("COMPILER_RT_BUILD_SANITIZERS", "ON")
@@ -34,7 +32,5 @@ fn main() {
             .out_dir(&native.out_dir)
             .build_target("asan")
             .build();
-
-        t!(File::create(&native.timestamp));
     }
 }
diff --git a/src/librustc_lsan/build.rs b/src/librustc_lsan/build.rs
index b71493db49a..005163f4102 100644
--- a/src/librustc_lsan/build.rs
+++ b/src/librustc_lsan/build.rs
@@ -8,23 +8,21 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#[macro_use]
 extern crate build_helper;
 extern crate cmake;
 
 use std::env;
-use std::fs::File;
 use build_helper::native_lib_boilerplate;
 
 use cmake::Config;
 
 fn main() {
     if let Some(llvm_config) = env::var_os("LLVM_CONFIG") {
-        let native = native_lib_boilerplate("compiler-rt", "lsan", "clang_rt.lsan-x86_64",
-                                            "rustbuild.timestamp", "build/lib/linux");
-        if native.skip_build {
-            return
-        }
+        let native = match native_lib_boilerplate("compiler-rt", "lsan", "clang_rt.lsan-x86_64",
+                                                  "build/lib/linux") {
+            Ok(native) => native,
+            _ => return,
+        };
 
         Config::new(&native.src_dir)
             .define("COMPILER_RT_BUILD_SANITIZERS", "ON")
@@ -34,7 +32,5 @@ fn main() {
             .out_dir(&native.out_dir)
             .build_target("lsan")
             .build();
-
-        t!(File::create(&native.timestamp));
     }
 }
diff --git a/src/librustc_msan/build.rs b/src/librustc_msan/build.rs
index 07c4e807e7b..c438b525046 100644
--- a/src/librustc_msan/build.rs
+++ b/src/librustc_msan/build.rs
@@ -8,23 +8,21 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#[macro_use]
 extern crate build_helper;
 extern crate cmake;
 
 use std::env;
-use std::fs::File;
 use build_helper::native_lib_boilerplate;
 
 use cmake::Config;
 
 fn main() {
     if let Some(llvm_config) = env::var_os("LLVM_CONFIG") {
-        let native = native_lib_boilerplate("compiler-rt", "msan", "clang_rt.msan-x86_64",
-                                            "rustbuild.timestamp", "build/lib/linux");
-        if native.skip_build {
-            return
-        }
+        let native = match native_lib_boilerplate("compiler-rt", "msan", "clang_rt.msan-x86_64",
+                                                  "build/lib/linux") {
+            Ok(native) => native,
+            _ => return,
+        };
 
         Config::new(&native.src_dir)
             .define("COMPILER_RT_BUILD_SANITIZERS", "ON")
@@ -34,7 +32,5 @@ fn main() {
             .out_dir(&native.out_dir)
             .build_target("msan")
             .build();
-
-        t!(File::create(&native.timestamp));
     }
 }
diff --git a/src/librustc_tsan/build.rs b/src/librustc_tsan/build.rs
index 3bd30fd203c..055b344d2e9 100644
--- a/src/librustc_tsan/build.rs
+++ b/src/librustc_tsan/build.rs
@@ -8,23 +8,21 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#[macro_use]
 extern crate build_helper;
 extern crate cmake;
 
 use std::env;
-use std::fs::File;
 use build_helper::native_lib_boilerplate;
 
 use cmake::Config;
 
 fn main() {
     if let Some(llvm_config) = env::var_os("LLVM_CONFIG") {
-        let native = native_lib_boilerplate("compiler-rt", "tsan", "clang_rt.tsan-x86_64",
-                                            "rustbuild.timestamp", "build/lib/linux");
-        if native.skip_build {
-            return
-        }
+        let native = match native_lib_boilerplate("compiler-rt", "tsan", "clang_rt.tsan-x86_64",
+                                                  "build/lib/linux") {
+            Ok(native) => native,
+            _ => return,
+        };
 
         Config::new(&native.src_dir)
             .define("COMPILER_RT_BUILD_SANITIZERS", "ON")
@@ -34,7 +32,5 @@ fn main() {
             .out_dir(&native.out_dir)
             .build_target("tsan")
             .build();
-
-        t!(File::create(&native.timestamp));
     }
 }
diff --git a/src/libstd/build.rs b/src/libstd/build.rs
index ef1d3c84f2a..9fb83ad7598 100644
--- a/src/libstd/build.rs
+++ b/src/libstd/build.rs
@@ -10,12 +10,10 @@
 
 #![deny(warnings)]
 
-#[macro_use]
 extern crate build_helper;
 extern crate gcc;
 
 use std::env;
-use std::fs::File;
 use std::process::Command;
 use build_helper::{run, native_lib_boilerplate};
 
@@ -24,7 +22,7 @@ fn main() {
     let host = env::var("HOST").expect("HOST was not set");
     if cfg!(feature = "backtrace") && !target.contains("apple") && !target.contains("msvc") &&
         !target.contains("emscripten") && !target.contains("fuchsia") && !target.contains("redox") {
-        build_libbacktrace(&host, &target);
+        let _ = build_libbacktrace(&host, &target);
     }
 
     if target.contains("linux") {
@@ -66,12 +64,8 @@ fn main() {
     }
 }
 
-fn build_libbacktrace(host: &str, target: &str) {
-    let native = native_lib_boilerplate("libbacktrace", "libbacktrace", "backtrace",
-                                        "rustbuild.timestamp", ".libs");
-    if native.skip_build {
-        return
-    }
+fn build_libbacktrace(host: &str, target: &str) -> Result<(), ()> {
+    let native = native_lib_boilerplate("libbacktrace", "libbacktrace", "backtrace", ".libs")?;
 
     let compiler = gcc::Config::new().get_compiler();
     // only msvc returns None for ar so unwrap is okay
@@ -99,6 +93,5 @@ fn build_libbacktrace(host: &str, target: &str) {
                 .current_dir(&native.out_dir)
                 .arg(format!("INCDIR={}", native.src_dir.display()))
                 .arg("-j").arg(env::var("NUM_JOBS").expect("NUM_JOBS was not set")));
-
-    t!(File::create(&native.timestamp));
+    Ok(())
 }