]>
git.proxmox.com Git - rustc.git/blob - src/bootstrap/build/sanity.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use std
::collections
::HashSet
;
13 use std
::ffi
::{OsStr, OsString}
;
15 use std
::process
::Command
;
17 use build_helper
::output
;
21 pub fn check(build
: &mut Build
) {
22 let mut checked
= HashSet
::new();
23 let path
= env
::var_os("PATH").unwrap_or(OsString
::new());
24 let mut need_cmd
= |cmd
: &OsStr
| {
25 if !checked
.insert(cmd
.to_owned()) {
28 for path
in env
::split_paths(&path
).map(|p
| p
.join(cmd
)) {
29 if fs
::metadata(&path
).is_ok() ||
30 fs
::metadata(path
.with_extension("exe")).is_ok() {
34 panic
!("\n\ncouldn't find required command: {:?}\n\n", cmd
);
37 // If we've got a git directory we're gona need git to update
38 // submodules and learn about various other aspects.
39 if fs
::metadata(build
.src
.join(".git")).is_ok() {
40 need_cmd("git".as_ref());
43 // We need cmake, but only if we're actually building LLVM
44 for host
in build
.config
.host
.iter() {
45 if let Some(config
) = build
.config
.target_config
.get(host
) {
46 if config
.llvm_config
.is_some() {
50 need_cmd("cmake".as_ref());
54 need_cmd("python".as_ref());
56 // We're gonna build some custom C code here and there, host triples
57 // also build some C++ shims for LLVM so we need a C++ compiler.
58 for target
in build
.config
.target
.iter() {
59 need_cmd(build
.cc(target
).as_ref());
60 need_cmd(build
.ar(target
).as_ref());
62 for host
in build
.config
.host
.iter() {
63 need_cmd(build
.cxx(host
).as_ref());
66 for target
in build
.config
.target
.iter() {
67 // Either can't build or don't want to run jemalloc on these targets
68 if target
.contains("rumprun") ||
69 target
.contains("bitrig") ||
70 target
.contains("openbsd") ||
71 target
.contains("msvc") {
72 build
.config
.use_jemalloc
= false;
75 // Can't compile for iOS unless we're on OSX
76 if target
.contains("apple-ios") &&
77 !build
.config
.build
.contains("apple-darwin") {
78 panic
!("the iOS target is only supported on OSX");
81 // Make sure musl-root is valid if specified
82 if target
.contains("musl") && (target
.contains("x86_64") || target
.contains("i686")) {
83 match build
.config
.musl_root
{
85 if fs
::metadata(root
.join("lib/libc.a")).is_err() {
86 panic
!("couldn't find libc.a in musl dir: {}",
87 root
.join("lib").display());
89 if fs
::metadata(root
.join("lib/libunwind.a")).is_err() {
90 panic
!("couldn't find libunwind.a in musl dir: {}",
91 root
.join("lib").display());
95 panic
!("when targeting MUSL the build.musl-root option \
96 must be specified in config.toml")
101 if target
.contains("msvc") {
102 // There are three builds of cmake on windows: MSVC, MinGW, and
103 // Cygwin. The Cygwin build does not have generators for Visual
104 // Studio, so detect that here and error.
105 let out
= output(Command
::new("cmake").arg("--help"));
106 if !out
.contains("Visual Studio") {
108 cmake does not support Visual Studio generators.
110 This is likely due to it being an msys/cygwin build of cmake,
111 rather than the required windows version, built using MinGW
114 If you are building under msys2 try installing the mingw-w64-x86_64-cmake
115 package instead of cmake:
117 $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake
123 for host
in build
.flags
.host
.iter() {
124 if !build
.config
.host
.contains(host
) {
125 panic
!("specified host `{}` is not in the ./configure list", host
);
128 for target
in build
.flags
.target
.iter() {
129 if !build
.config
.target
.contains(target
) {
130 panic
!("specified target `{}` is not in the ./configure list",