зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1716518 - Upgrade cmake to v0.1.45. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D117773
This commit is contained in:
Родитель
785d88ba93
Коммит
b6117a481b
|
@ -622,9 +622,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "cmake"
|
||||
version = "0.1.29"
|
||||
version = "0.1.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56d741ea7a69e577f6d06b36b7dff4738f680593dc27a701ffa8506b73ce28bb"
|
||||
checksum = "eb6210b637171dfba4cda12e579ac6dc73f5165ad56133e5d72ef3131f320855"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"Cargo.toml":"159a1f1908654ee80dcab59e9eacee17525697b98cc99a8a4834ab423dfeaddb","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"07a575f3911ae3563dd87a8cc693d9af232e9b55e9c0b170bc49f37869a07f7f","src/lib.rs":"36af1560f494fc1e159253b4a8334f58937d7a3a3c2b7120d42d1c78b9e4b518"},"package":"56d741ea7a69e577f6d06b36b7dff4738f680593dc27a701ffa8506b73ce28bb"}
|
||||
{"files":{"Cargo.toml":"4182af7fa91eef3d48d5458708e038b85a24ebed85408cd9ef0f86e1e05d2cc5","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"a4ad0b734acb4d50db72782207587552c5e33c52500318c202776cd32dbdea4a","src/lib.rs":"3268897f8bc77f8caf3e0eb293c4e522021600cd07ba40b6abf94c679baa8529"},"package":"eb6210b637171dfba4cda12e579ac6dc73f5165ad56133e5d72ef3131f320855"}
|
|
@ -3,7 +3,7 @@
|
|||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g. crates.io) dependencies
|
||||
# to registry (e.g., crates.io) dependencies
|
||||
#
|
||||
# If you believe there's an error in this file please file an
|
||||
# issue against the rust-lang/cargo repository. If you're
|
||||
|
@ -12,14 +12,15 @@
|
|||
|
||||
[package]
|
||||
name = "cmake"
|
||||
version = "0.1.29"
|
||||
version = "0.1.45"
|
||||
authors = ["Alex Crichton <alex@alexcrichton.com>"]
|
||||
description = "A build dependency for running `cmake` to build a native library\n"
|
||||
homepage = "https://github.com/alexcrichton/cmake-rs"
|
||||
documentation = "http://alexcrichton.com/cmake-rs"
|
||||
documentation = "https://docs.rs/cmake"
|
||||
readme = "README.md"
|
||||
keywords = ["build-dependencies"]
|
||||
categories = ["development-tools::build-utils"]
|
||||
license = "MIT/Apache-2.0"
|
||||
repository = "https://github.com/alexcrichton/cmake-rs"
|
||||
[dependencies.cc]
|
||||
version = "1.0"
|
||||
version = "1.0.41"
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
# cmake
|
||||
|
||||
[![Build Status](https://travis-ci.org/alexcrichton/cmake-rs.svg?branch=master)](https://travis-ci.org/alexcrichton/cmake-rs)
|
||||
|
||||
[Documentation](http://alexcrichton.com/cmake-rs)
|
||||
[Documentation](https://docs.rs/cmake)
|
||||
|
||||
A build dependency for running the `cmake` build tool to compile a native
|
||||
library.
|
||||
|
@ -10,7 +8,7 @@ library.
|
|||
```toml
|
||||
# Cargo.toml
|
||||
[build-dependencies]
|
||||
cmake = "0.2"
|
||||
cmake = "0.1"
|
||||
```
|
||||
|
||||
The CMake executable is assumed to be `cmake` unless the `CMAKE`
|
||||
|
@ -30,5 +28,5 @@ at your option.
|
|||
### Contribution
|
||||
|
||||
Unless you explicitly state otherwise, any contribution intentionally submitted
|
||||
for inclusion in Serde by you, as defined in the Apache-2.0 license, shall be
|
||||
for inclusion in cmake by you, as defined in the Apache-2.0 license, shall be
|
||||
dual licensed as above, without any additional terms or conditions.
|
||||
|
|
|
@ -47,10 +47,10 @@
|
|||
extern crate cc;
|
||||
|
||||
use std::env;
|
||||
use std::ffi::{OsString, OsStr};
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::fs::{self, File};
|
||||
use std::io::ErrorKind;
|
||||
use std::io::prelude::*;
|
||||
use std::io::ErrorKind;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
|
||||
|
@ -60,6 +60,7 @@ pub struct Config {
|
|||
generator: Option<OsString>,
|
||||
cflags: OsString,
|
||||
cxxflags: OsString,
|
||||
asmflags: OsString,
|
||||
defines: Vec<(OsString, OsString)>,
|
||||
deps: Vec<String>,
|
||||
target: Option<String>,
|
||||
|
@ -71,6 +72,11 @@ pub struct Config {
|
|||
env: Vec<(OsString, OsString)>,
|
||||
static_crt: Option<bool>,
|
||||
uses_cxx11: bool,
|
||||
always_configure: bool,
|
||||
no_build_target: bool,
|
||||
verbose_cmake: bool,
|
||||
verbose_make: bool,
|
||||
pic: Option<bool>,
|
||||
}
|
||||
|
||||
/// Builds the native library rooted at `path` with the default cmake options.
|
||||
|
@ -94,6 +100,77 @@ pub fn build<P: AsRef<Path>>(path: P) -> PathBuf {
|
|||
}
|
||||
|
||||
impl Config {
|
||||
/// Return explicitly set profile or infer `CMAKE_BUILD_TYPE` from Rust's compilation profile.
|
||||
///
|
||||
/// * if `opt-level=0` then `CMAKE_BUILD_TYPE=Debug`,
|
||||
/// * if `opt-level={1,2,3}` and:
|
||||
/// * `debug=false` then `CMAKE_BUILD_TYPE=Release`
|
||||
/// * otherwise `CMAKE_BUILD_TYPE=RelWithDebInfo`
|
||||
/// * if `opt-level={s,z}` then `CMAKE_BUILD_TYPE=MinSizeRel`
|
||||
pub fn get_profile(&self) -> &str {
|
||||
if let Some(profile) = self.profile.as_ref() {
|
||||
profile
|
||||
} else {
|
||||
// Determine Rust's profile, optimization level, and debug info:
|
||||
#[derive(PartialEq)]
|
||||
enum RustProfile {
|
||||
Debug,
|
||||
Release,
|
||||
}
|
||||
#[derive(PartialEq, Debug)]
|
||||
enum OptLevel {
|
||||
Debug,
|
||||
Release,
|
||||
Size,
|
||||
}
|
||||
|
||||
let rust_profile = match &getenv_unwrap("PROFILE")[..] {
|
||||
"debug" => RustProfile::Debug,
|
||||
"release" | "bench" => RustProfile::Release,
|
||||
unknown => {
|
||||
eprintln!(
|
||||
"Warning: unknown Rust profile={}; defaulting to a release build.",
|
||||
unknown
|
||||
);
|
||||
RustProfile::Release
|
||||
}
|
||||
};
|
||||
|
||||
let opt_level = match &getenv_unwrap("OPT_LEVEL")[..] {
|
||||
"0" => OptLevel::Debug,
|
||||
"1" | "2" | "3" => OptLevel::Release,
|
||||
"s" | "z" => OptLevel::Size,
|
||||
unknown => {
|
||||
let default_opt_level = match rust_profile {
|
||||
RustProfile::Debug => OptLevel::Debug,
|
||||
RustProfile::Release => OptLevel::Release,
|
||||
};
|
||||
eprintln!(
|
||||
"Warning: unknown opt-level={}; defaulting to a {:?} build.",
|
||||
unknown, default_opt_level
|
||||
);
|
||||
default_opt_level
|
||||
}
|
||||
};
|
||||
|
||||
let debug_info: bool = match &getenv_unwrap("DEBUG")[..] {
|
||||
"false" => false,
|
||||
"true" => true,
|
||||
unknown => {
|
||||
eprintln!("Warning: unknown debug={}; defaulting to `true`.", unknown);
|
||||
true
|
||||
}
|
||||
};
|
||||
|
||||
match (opt_level, debug_info) {
|
||||
(OptLevel::Debug, _) => "Debug",
|
||||
(OptLevel::Release, false) => "Release",
|
||||
(OptLevel::Release, true) => "RelWithDebInfo",
|
||||
(OptLevel::Size, _) => "MinSizeRel",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new blank set of configuration to build the project specified
|
||||
/// at the path `path`.
|
||||
pub fn new<P: AsRef<Path>>(path: P) -> Config {
|
||||
|
@ -102,6 +179,7 @@ impl Config {
|
|||
generator: None,
|
||||
cflags: OsString::new(),
|
||||
cxxflags: OsString::new(),
|
||||
asmflags: OsString::new(),
|
||||
defines: Vec::new(),
|
||||
deps: Vec::new(),
|
||||
profile: None,
|
||||
|
@ -112,10 +190,21 @@ impl Config {
|
|||
cmake_target: None,
|
||||
env: Vec::new(),
|
||||
static_crt: None,
|
||||
uses_cxx11: false
|
||||
uses_cxx11: false,
|
||||
always_configure: true,
|
||||
no_build_target: false,
|
||||
verbose_cmake: false,
|
||||
verbose_make: false,
|
||||
pic: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets flag for PIC. Otherwise use cc::Build platform default
|
||||
pub fn pic(&mut self, explicit_flag: bool) -> &mut Config {
|
||||
self.pic = Some(explicit_flag);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the build-tool generator (`-G`) for this compilation.
|
||||
pub fn generator<T: AsRef<OsStr>>(&mut self, generator: T) -> &mut Config {
|
||||
self.generator = Some(generator.as_ref().to_owned());
|
||||
|
@ -138,11 +227,22 @@ impl Config {
|
|||
self
|
||||
}
|
||||
|
||||
/// Adds a custom flag to pass down to the ASM compiler, supplementing those
|
||||
/// that this library already passes.
|
||||
pub fn asmflag<P: AsRef<OsStr>>(&mut self, flag: P) -> &mut Config {
|
||||
self.asmflags.push(" ");
|
||||
self.asmflags.push(flag.as_ref());
|
||||
self
|
||||
}
|
||||
|
||||
/// Adds a new `-D` flag to pass to cmake during the generation step.
|
||||
pub fn define<K, V>(&mut self, k: K, v: V) -> &mut Config
|
||||
where K: AsRef<OsStr>, V: AsRef<OsStr>
|
||||
where
|
||||
K: AsRef<OsStr>,
|
||||
V: AsRef<OsStr>,
|
||||
{
|
||||
self.defines.push((k.as_ref().to_owned(), v.as_ref().to_owned()));
|
||||
self.defines
|
||||
.push((k.as_ref().to_owned(), v.as_ref().to_owned()));
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -165,6 +265,14 @@ impl Config {
|
|||
self
|
||||
}
|
||||
|
||||
/// Disables the cmake target option for this compilation.
|
||||
///
|
||||
/// Note that this isn't related to the target triple passed to the compiler!
|
||||
pub fn no_build_target(&mut self, no_build_target: bool) -> &mut Config {
|
||||
self.no_build_target = no_build_target;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the host triple for this compilation.
|
||||
///
|
||||
/// This is automatically scraped from `$HOST` which is set for Cargo
|
||||
|
@ -183,10 +291,16 @@ impl Config {
|
|||
self
|
||||
}
|
||||
|
||||
/// Sets the profile for this compilation.
|
||||
/// Sets the `CMAKE_BUILD_TYPE=build_type` variable.
|
||||
///
|
||||
/// This is automatically scraped from `$PROFILE` which is set for Cargo
|
||||
/// build scripts so it's not necessary to call this from a build script.
|
||||
/// By default, this value is automatically inferred from Rust's compilation
|
||||
/// profile as follows:
|
||||
///
|
||||
/// * if `opt-level=0` then `CMAKE_BUILD_TYPE=Debug`,
|
||||
/// * if `opt-level={1,2,3}` and:
|
||||
/// * `debug=false` then `CMAKE_BUILD_TYPE=Release`
|
||||
/// * otherwise `CMAKE_BUILD_TYPE=RelWithDebInfo`
|
||||
/// * if `opt-level={s,z}` then `CMAKE_BUILD_TYPE=MinSizeRel`
|
||||
pub fn profile(&mut self, profile: &str) -> &mut Config {
|
||||
self.profile = Some(profile.to_string());
|
||||
self
|
||||
|
@ -209,10 +323,12 @@ impl Config {
|
|||
/// Configure an environment variable for the `cmake` processes spawned by
|
||||
/// this crate in the `build` step.
|
||||
pub fn env<K, V>(&mut self, key: K, value: V) -> &mut Config
|
||||
where K: AsRef<OsStr>,
|
||||
V: AsRef<OsStr>,
|
||||
where
|
||||
K: AsRef<OsStr>,
|
||||
V: AsRef<OsStr>,
|
||||
{
|
||||
self.env.push((key.as_ref().to_owned(), value.as_ref().to_owned()));
|
||||
self.env
|
||||
.push((key.as_ref().to_owned(), value.as_ref().to_owned()));
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -234,6 +350,34 @@ impl Config {
|
|||
self
|
||||
}
|
||||
|
||||
/// Forces CMake to always run before building the custom target.
|
||||
///
|
||||
/// In some cases, when you have a big project, you can disable
|
||||
/// subsequents runs of cmake to make `cargo build` faster.
|
||||
pub fn always_configure(&mut self, always_configure: bool) -> &mut Config {
|
||||
self.always_configure = always_configure;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets very verbose output.
|
||||
pub fn very_verbose(&mut self, value: bool) -> &mut Config {
|
||||
self.verbose_cmake = value;
|
||||
self.verbose_make = value;
|
||||
self
|
||||
}
|
||||
|
||||
// Simple heuristic to determine if we're cross-compiling using the Android
|
||||
// NDK toolchain file.
|
||||
fn uses_android_ndk(&self) -> bool {
|
||||
// `ANDROID_ABI` is the only required flag:
|
||||
// https://developer.android.com/ndk/guides/cmake#android_abi
|
||||
self.defined("ANDROID_ABI")
|
||||
&& self.defines.iter().any(|(flag, value)| {
|
||||
flag == "CMAKE_TOOLCHAIN_FILE"
|
||||
&& Path::new(value).file_name() == Some("android.toolchain.cmake".as_ref())
|
||||
})
|
||||
}
|
||||
|
||||
/// Run this configuration, compiling the library with all the configured
|
||||
/// options.
|
||||
///
|
||||
|
@ -250,35 +394,48 @@ impl Config {
|
|||
t
|
||||
}
|
||||
};
|
||||
let host = self.host.clone().unwrap_or_else(|| {
|
||||
getenv_unwrap("HOST")
|
||||
});
|
||||
let host = self.host.clone().unwrap_or_else(|| getenv_unwrap("HOST"));
|
||||
let msvc = target.contains("msvc");
|
||||
let ndk = self.uses_android_ndk();
|
||||
let mut c_cfg = cc::Build::new();
|
||||
c_cfg.cargo_metadata(false)
|
||||
c_cfg
|
||||
.cargo_metadata(false)
|
||||
.opt_level(0)
|
||||
.debug(false)
|
||||
.target(&target)
|
||||
.warnings(false)
|
||||
.host(&host);
|
||||
.host(&host)
|
||||
.no_default_flags(ndk);
|
||||
if !ndk {
|
||||
c_cfg.target(&target);
|
||||
}
|
||||
let mut cxx_cfg = cc::Build::new();
|
||||
cxx_cfg.cargo_metadata(false)
|
||||
cxx_cfg
|
||||
.cargo_metadata(false)
|
||||
.cpp(true)
|
||||
.opt_level(0)
|
||||
.debug(false)
|
||||
.target(&target)
|
||||
.warnings(false)
|
||||
.host(&host);
|
||||
.host(&host)
|
||||
.no_default_flags(ndk);
|
||||
if !ndk {
|
||||
cxx_cfg.target(&target);
|
||||
}
|
||||
if let Some(static_crt) = self.static_crt {
|
||||
c_cfg.static_crt(static_crt);
|
||||
cxx_cfg.static_crt(static_crt);
|
||||
}
|
||||
if let Some(explicit_flag) = self.pic {
|
||||
c_cfg.pic(explicit_flag);
|
||||
cxx_cfg.pic(explicit_flag);
|
||||
}
|
||||
let c_compiler = c_cfg.get_compiler();
|
||||
let cxx_compiler = cxx_cfg.get_compiler();
|
||||
let asm_compiler = c_cfg.get_compiler();
|
||||
|
||||
let dst = self.out_dir.clone().unwrap_or_else(|| {
|
||||
PathBuf::from(getenv_unwrap("OUT_DIR"))
|
||||
});
|
||||
let dst = self
|
||||
.out_dir
|
||||
.clone()
|
||||
.unwrap_or_else(|| PathBuf::from(getenv_unwrap("OUT_DIR")));
|
||||
let build = dst.join("build");
|
||||
self.maybe_clear(&build);
|
||||
let _ = fs::create_dir(&build);
|
||||
|
@ -286,28 +443,58 @@ impl Config {
|
|||
// Add all our dependencies to our cmake paths
|
||||
let mut cmake_prefix_path = Vec::new();
|
||||
for dep in &self.deps {
|
||||
let dep = dep.to_uppercase().replace('-', "_");
|
||||
if let Some(root) = env::var_os(&format!("DEP_{}_ROOT", dep)) {
|
||||
cmake_prefix_path.push(PathBuf::from(root));
|
||||
}
|
||||
}
|
||||
let system_prefix = env::var_os("CMAKE_PREFIX_PATH")
|
||||
.unwrap_or(OsString::new());
|
||||
cmake_prefix_path.extend(env::split_paths(&system_prefix)
|
||||
.map(|s| s.to_owned()));
|
||||
let system_prefix = env::var_os("CMAKE_PREFIX_PATH").unwrap_or(OsString::new());
|
||||
cmake_prefix_path.extend(env::split_paths(&system_prefix).map(|s| s.to_owned()));
|
||||
let cmake_prefix_path = env::join_paths(&cmake_prefix_path).unwrap();
|
||||
|
||||
// Build up the first cmake command to build the build system.
|
||||
let executable = env::var("CMAKE").unwrap_or("cmake".to_owned());
|
||||
let mut cmd = Command::new(executable);
|
||||
cmd.arg(&self.path)
|
||||
.current_dir(&build);
|
||||
let mut cmd = Command::new(&executable);
|
||||
|
||||
if self.verbose_cmake {
|
||||
cmd.arg("-Wdev");
|
||||
cmd.arg("--debug-output");
|
||||
}
|
||||
|
||||
cmd.arg(&self.path).current_dir(&build);
|
||||
let mut is_ninja = false;
|
||||
if let Some(ref generator) = self.generator {
|
||||
is_ninja = generator.to_string_lossy().contains("Ninja");
|
||||
}
|
||||
if target.contains("windows-gnu") {
|
||||
if host.contains("windows") {
|
||||
// On MinGW we need to coerce cmake to not generate a visual
|
||||
// studio build system but instead use makefiles that MinGW can
|
||||
// use to build.
|
||||
if self.generator.is_none() {
|
||||
cmd.arg("-G").arg("MSYS Makefiles");
|
||||
// If make.exe isn't found, that means we may be using a MinGW
|
||||
// toolchain instead of a MSYS2 toolchain. If neither is found,
|
||||
// the build cannot continue.
|
||||
let has_msys2 = Command::new("make")
|
||||
.arg("--version")
|
||||
.output()
|
||||
.err()
|
||||
.map(|e| e.kind() != ErrorKind::NotFound)
|
||||
.unwrap_or(true);
|
||||
let has_mingw32 = Command::new("mingw32-make")
|
||||
.arg("--version")
|
||||
.output()
|
||||
.err()
|
||||
.map(|e| e.kind() != ErrorKind::NotFound)
|
||||
.unwrap_or(true);
|
||||
|
||||
let generator = match (has_msys2, has_mingw32) {
|
||||
(true, _) => "MSYS Makefiles",
|
||||
(false, true) => "MinGW Makefiles",
|
||||
(false, false) => fail("no valid generator found for GNU toolchain; MSYS or MinGW must be installed")
|
||||
};
|
||||
|
||||
cmd.arg("-G").arg(generator);
|
||||
}
|
||||
} else {
|
||||
// If we're cross compiling onto windows, then set some
|
||||
|
@ -334,25 +521,52 @@ impl Config {
|
|||
// If we're on MSVC we need to be sure to use the right generator or
|
||||
// otherwise we won't get 32/64 bit correct automatically.
|
||||
// This also guarantees that NMake generator isn't chosen implicitly.
|
||||
let using_nmake_generator;
|
||||
if self.generator.is_none() {
|
||||
cmd.arg("-G").arg(self.visual_studio_generator(&target));
|
||||
using_nmake_generator = false;
|
||||
} else {
|
||||
using_nmake_generator = self.generator.as_ref().unwrap() == "NMake Makefiles";
|
||||
}
|
||||
if !is_ninja && !using_nmake_generator {
|
||||
if target.contains("x86_64") {
|
||||
cmd.arg("-Thost=x64");
|
||||
cmd.arg("-Ax64");
|
||||
} else if target.contains("thumbv7a") {
|
||||
cmd.arg("-Thost=x64");
|
||||
cmd.arg("-Aarm");
|
||||
} else if target.contains("aarch64") {
|
||||
cmd.arg("-Thost=x64");
|
||||
cmd.arg("-AARM64");
|
||||
} else if target.contains("i686") {
|
||||
use cc::windows_registry::{find_vs_version, VsVers};
|
||||
match find_vs_version() {
|
||||
Ok(VsVers::Vs16) => {
|
||||
// 32-bit x86 toolset used to be the default for all hosts,
|
||||
// but Visual Studio 2019 changed the default toolset to match the host,
|
||||
// so we need to manually override it for x86 targets
|
||||
cmd.arg("-Thost=x86");
|
||||
cmd.arg("-AWin32");
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
} else {
|
||||
panic!("unsupported msvc target: {}", target);
|
||||
}
|
||||
}
|
||||
} else if target.contains("redox") {
|
||||
if !self.defined("CMAKE_SYSTEM_NAME") {
|
||||
cmd.arg("-DCMAKE_SYSTEM_NAME=Generic");
|
||||
}
|
||||
} else if target.contains("solaris") {
|
||||
if !self.defined("CMAKE_SYSTEM_NAME") {
|
||||
cmd.arg("-DCMAKE_SYSTEM_NAME=SunOS");
|
||||
}
|
||||
}
|
||||
let mut is_ninja = false;
|
||||
if let Some(ref generator) = self.generator {
|
||||
cmd.arg("-G").arg(generator);
|
||||
is_ninja = generator.to_string_lossy().contains("Ninja");
|
||||
}
|
||||
let profile = self.profile.clone().unwrap_or_else(|| {
|
||||
match &getenv_unwrap("PROFILE")[..] {
|
||||
"bench" | "release" => "Release",
|
||||
_ => "Debug",
|
||||
}.to_string()
|
||||
});
|
||||
let profile = self.get_profile();
|
||||
for &(ref k, ref v) in &self.defines {
|
||||
let mut os = OsString::from("-D");
|
||||
os.push(k);
|
||||
|
@ -367,26 +581,24 @@ impl Config {
|
|||
cmd.arg(dstflag);
|
||||
}
|
||||
|
||||
let build_type = self.defines.iter().find(|&&(ref a, _)| {
|
||||
a == "CMAKE_BUILD_TYPE"
|
||||
}).map(|x| x.1.to_str().unwrap()).unwrap_or(&profile);
|
||||
let build_type_upcase = build_type.chars()
|
||||
.flat_map(|c| c.to_uppercase())
|
||||
.collect::<String>();
|
||||
let build_type = self
|
||||
.defines
|
||||
.iter()
|
||||
.find(|&&(ref a, _)| a == "CMAKE_BUILD_TYPE")
|
||||
.map(|x| x.1.to_str().unwrap())
|
||||
.unwrap_or(&profile);
|
||||
let build_type_upcase = build_type
|
||||
.chars()
|
||||
.flat_map(|c| c.to_uppercase())
|
||||
.collect::<String>();
|
||||
|
||||
{
|
||||
// let cmake deal with optimization/debuginfo
|
||||
let skip_arg = |arg: &OsStr| {
|
||||
match arg.to_str() {
|
||||
Some(s) => {
|
||||
s.starts_with("-O") || s.starts_with("/O") || s == "-g"
|
||||
}
|
||||
None => false,
|
||||
}
|
||||
let skip_arg = |arg: &OsStr| match arg.to_str() {
|
||||
Some(s) => s.starts_with("-O") || s.starts_with("/O") || s == "-g",
|
||||
None => false,
|
||||
};
|
||||
let mut set_compiler = |kind: &str,
|
||||
compiler: &cc::Tool,
|
||||
extra: &OsString| {
|
||||
let mut set_compiler = |kind: &str, compiler: &cc::Tool, extra: &OsString| {
|
||||
let flag_var = format!("CMAKE_{}_FLAGS", kind);
|
||||
let tool_var = format!("CMAKE_{}_COMPILER", kind);
|
||||
if !self.defined(&flag_var) {
|
||||
|
@ -396,7 +608,7 @@ impl Config {
|
|||
flagsflag.push(extra);
|
||||
for arg in compiler.args() {
|
||||
if skip_arg(arg) {
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
flagsflag.push(" ");
|
||||
flagsflag.push(arg);
|
||||
|
@ -412,8 +624,7 @@ impl Config {
|
|||
// Note that for other generators, though, this *overrides*
|
||||
// things like the optimization flags, which is bad.
|
||||
if self.generator.is_none() && msvc {
|
||||
let flag_var_alt = format!("CMAKE_{}_FLAGS_{}", kind,
|
||||
build_type_upcase);
|
||||
let flag_var_alt = format!("CMAKE_{}_FLAGS_{}", kind, build_type_upcase);
|
||||
if !self.defined(&flag_var_alt) {
|
||||
let mut flagsflag = OsString::from("-D");
|
||||
flagsflag.push(&flag_var_alt);
|
||||
|
@ -421,7 +632,7 @@ impl Config {
|
|||
flagsflag.push(extra);
|
||||
for arg in compiler.args() {
|
||||
if skip_arg(arg) {
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
flagsflag.push(" ");
|
||||
flagsflag.push(arg);
|
||||
|
@ -441,19 +652,28 @@ impl Config {
|
|||
// as it's not needed for MSVC with Visual Studio generators and
|
||||
// for MinGW it doesn't really vary.
|
||||
if !self.defined("CMAKE_TOOLCHAIN_FILE")
|
||||
&& !self.defined(&tool_var)
|
||||
&& (env::consts::FAMILY != "windows" || (msvc && is_ninja)) {
|
||||
&& !self.defined(&tool_var)
|
||||
&& (env::consts::FAMILY != "windows" || (msvc && is_ninja))
|
||||
{
|
||||
let mut ccompiler = OsString::from("-D");
|
||||
ccompiler.push(&tool_var);
|
||||
ccompiler.push("=");
|
||||
ccompiler.push(find_exe(compiler.path()));
|
||||
#[cfg(windows)] {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
// CMake doesn't like unescaped `\`s in compiler paths
|
||||
// so we either have to escape them or replace with `/`s.
|
||||
use std::os::windows::ffi::{OsStrExt, OsStringExt};
|
||||
let wchars = ccompiler.encode_wide().map(|wchar| {
|
||||
if wchar == b'\\' as u16 { '/' as u16 } else { wchar }
|
||||
}).collect::<Vec<_>>();
|
||||
let wchars = ccompiler
|
||||
.encode_wide()
|
||||
.map(|wchar| {
|
||||
if wchar == b'\\' as u16 {
|
||||
'/' as u16
|
||||
} else {
|
||||
wchar
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
ccompiler = OsString::from_wide(&wchars);
|
||||
}
|
||||
cmd.arg(ccompiler);
|
||||
|
@ -462,12 +682,17 @@ impl Config {
|
|||
|
||||
set_compiler("C", &c_compiler, &self.cflags);
|
||||
set_compiler("CXX", &cxx_compiler, &self.cxxflags);
|
||||
set_compiler("ASM", &asm_compiler, &self.asmflags);
|
||||
}
|
||||
|
||||
if !self.defined("CMAKE_BUILD_TYPE") {
|
||||
cmd.arg(&format!("-DCMAKE_BUILD_TYPE={}", profile));
|
||||
}
|
||||
|
||||
if self.verbose_make {
|
||||
cmd.arg("-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON");
|
||||
}
|
||||
|
||||
if !self.defined("CMAKE_TOOLCHAIN_FILE") {
|
||||
if let Ok(s) = env::var("CMAKE_TOOLCHAIN_FILE") {
|
||||
cmd.arg(&format!("-DCMAKE_TOOLCHAIN_FILE={}", s));
|
||||
|
@ -478,30 +703,45 @@ impl Config {
|
|||
cmd.env(k, v);
|
||||
}
|
||||
|
||||
run(cmd.env("CMAKE_PREFIX_PATH", cmake_prefix_path), "cmake");
|
||||
if self.always_configure || !build.join("CMakeCache.txt").exists() {
|
||||
run(cmd.env("CMAKE_PREFIX_PATH", cmake_prefix_path), "cmake");
|
||||
} else {
|
||||
println!("CMake project was already configured. Skipping configuration step.");
|
||||
}
|
||||
|
||||
let mut makeflags = None;
|
||||
let mut parallel_args = Vec::new();
|
||||
let mut parallel_flags = None;
|
||||
|
||||
if let Ok(s) = env::var("NUM_JOBS") {
|
||||
match self.generator.as_ref().map(|g| g.to_string_lossy()) {
|
||||
Some(ref g) if g.contains("Ninja") => {
|
||||
parallel_args.push(format!("-j{}", s));
|
||||
parallel_flags = Some(format!("-j{}", s));
|
||||
}
|
||||
Some(ref g) if g.contains("Visual Studio") => {
|
||||
parallel_args.push(format!("/m:{}", s));
|
||||
}
|
||||
Some(ref g) if g.contains("NMake") => {
|
||||
// NMake creates `Makefile`s, but doesn't understand `-jN`.
|
||||
}
|
||||
_ if fs::metadata(&dst.join("build/Makefile")).is_ok() => {
|
||||
parallel_flags = Some(format!("/m:{}", s));
|
||||
}
|
||||
Some(ref g) if g.contains("NMake") => {
|
||||
// NMake creates `Makefile`s, but doesn't understand `-jN`.
|
||||
}
|
||||
_ if fs::metadata(&build.join("Makefile")).is_ok() => {
|
||||
match env::var_os("CARGO_MAKEFLAGS") {
|
||||
// Only do this on non-windows as we could actually be
|
||||
// invoking make instead of mingw32-make which doesn't
|
||||
// work with our jobserver
|
||||
Some(ref s) if !cfg!(windows) => makeflags = Some(s.clone()),
|
||||
// Only do this on non-windows and non-bsd
|
||||
// On Windows, we could be invoking make instead of
|
||||
// mingw32-make which doesn't work with our jobserver
|
||||
// bsdmake also does not work with our job server
|
||||
Some(ref s)
|
||||
if !(cfg!(windows)
|
||||
|| cfg!(target_os = "openbsd")
|
||||
|| cfg!(target_os = "netbsd")
|
||||
|| cfg!(target_os = "freebsd")
|
||||
|| cfg!(target_os = "bitrig")
|
||||
|| cfg!(target_os = "dragonflybsd")) =>
|
||||
{
|
||||
makeflags = Some(s.clone())
|
||||
}
|
||||
|
||||
// This looks like `make`, let's hope it understands `-jN`.
|
||||
_ => parallel_args.push(format!("-j{}", s)),
|
||||
_ => makeflags = Some(OsString::from(format!("-j{}", s))),
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
@ -510,40 +750,57 @@ impl Config {
|
|||
|
||||
// And build!
|
||||
let target = self.cmake_target.clone().unwrap_or("install".to_string());
|
||||
let mut cmd = Command::new("cmake");
|
||||
let mut cmd = Command::new(&executable);
|
||||
for &(ref k, ref v) in c_compiler.env().iter().chain(&self.env) {
|
||||
cmd.env(k, v);
|
||||
}
|
||||
|
||||
if let Some(flags) = makeflags {
|
||||
cmd.env("MAKEFLAGS", flags);
|
||||
}
|
||||
run(cmd.arg("--build").arg(".")
|
||||
.arg("--target").arg(target)
|
||||
.arg("--config").arg(&profile)
|
||||
.arg("--").args(&self.build_args)
|
||||
.args(¶llel_args)
|
||||
.current_dir(&build), "cmake");
|
||||
|
||||
cmd.arg("--build").arg(".");
|
||||
|
||||
if !self.no_build_target {
|
||||
cmd.arg("--target").arg(target);
|
||||
}
|
||||
|
||||
cmd.arg("--config")
|
||||
.arg(&profile)
|
||||
.arg("--")
|
||||
.args(&self.build_args)
|
||||
.current_dir(&build);
|
||||
|
||||
if let Some(flags) = parallel_flags {
|
||||
cmd.arg(flags);
|
||||
}
|
||||
|
||||
run(&mut cmd, "cmake");
|
||||
|
||||
println!("cargo:root={}", dst.display());
|
||||
return dst
|
||||
return dst;
|
||||
}
|
||||
|
||||
fn visual_studio_generator(&self, target: &str) -> String {
|
||||
use cc::windows_registry::{find_vs_version, VsVers};
|
||||
|
||||
let base = match find_vs_version() {
|
||||
Ok(VsVers::Vs16) => "Visual Studio 16 2019",
|
||||
Ok(VsVers::Vs15) => "Visual Studio 15 2017",
|
||||
Ok(VsVers::Vs14) => "Visual Studio 14 2015",
|
||||
Ok(VsVers::Vs12) => "Visual Studio 12 2013",
|
||||
Ok(_) => panic!("Visual studio version detected but this crate \
|
||||
doesn't know how to generate cmake files for it, \
|
||||
can the `cmake` crate be updated?"),
|
||||
Ok(_) => panic!(
|
||||
"Visual studio version detected but this crate \
|
||||
doesn't know how to generate cmake files for it, \
|
||||
can the `cmake` crate be updated?"
|
||||
),
|
||||
Err(msg) => panic!(msg),
|
||||
};
|
||||
if target.contains("i686") {
|
||||
if ["i686", "x86_64", "thumbv7a", "aarch64"]
|
||||
.iter()
|
||||
.any(|t| target.contains(t))
|
||||
{
|
||||
base.to_string()
|
||||
} else if target.contains("x86_64") {
|
||||
format!("{} Win64", base)
|
||||
} else {
|
||||
panic!("unsupported msvc target: {}", target);
|
||||
}
|
||||
|
@ -580,20 +837,20 @@ impl Config {
|
|||
for line in contents.lines() {
|
||||
if line.starts_with("CMAKE_HOME_DIRECTORY") {
|
||||
let needs_cleanup = match line.split('=').next_back() {
|
||||
Some(cmake_home) => {
|
||||
fs::canonicalize(cmake_home)
|
||||
.ok()
|
||||
.map(|cmake_home| cmake_home != path)
|
||||
.unwrap_or(true)
|
||||
},
|
||||
None => true
|
||||
Some(cmake_home) => fs::canonicalize(cmake_home)
|
||||
.ok()
|
||||
.map(|cmake_home| cmake_home != path)
|
||||
.unwrap_or(true),
|
||||
None => true,
|
||||
};
|
||||
if needs_cleanup {
|
||||
println!("detected home dir change, cleaning out entire build \
|
||||
directory");
|
||||
println!(
|
||||
"detected home dir change, cleaning out entire build \
|
||||
directory"
|
||||
);
|
||||
fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
break
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -604,13 +861,18 @@ fn run(cmd: &mut Command, program: &str) {
|
|||
let status = match cmd.status() {
|
||||
Ok(status) => status,
|
||||
Err(ref e) if e.kind() == ErrorKind::NotFound => {
|
||||
fail(&format!("failed to execute command: {}\nis `{}` not installed?",
|
||||
e, program));
|
||||
fail(&format!(
|
||||
"failed to execute command: {}\nis `{}` not installed?",
|
||||
e, program
|
||||
));
|
||||
}
|
||||
Err(e) => fail(&format!("failed to execute command: {}", e)),
|
||||
};
|
||||
if !status.success() {
|
||||
fail(&format!("command did not execute successfully, got: {}", status));
|
||||
fail(&format!(
|
||||
"command did not execute successfully, got: {}",
|
||||
status
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче