2015-11-19 15:20:12 -08:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2016-05-02 15:16:15 -07:00
|
|
|
//! Compilation of native dependencies like LLVM.
|
|
|
|
//!
|
|
|
|
//! Native projects like LLVM unfortunately aren't suited just yet for
|
2017-08-15 21:45:21 +02:00
|
|
|
//! compilation in build scripts that Cargo has. This is because the
|
2016-05-02 15:16:15 -07:00
|
|
|
//! compilation takes a *very* long time but also because we don't want to
|
|
|
|
//! compile LLVM 3 times as part of a normal bootstrap (we want it cached).
|
|
|
|
//!
|
|
|
|
//! LLVM and compiler-rt are essentially just wired up to everything else to
|
|
|
|
//! ensure that they're always in place if needed.
|
|
|
|
|
2017-03-20 14:29:14 -07:00
|
|
|
use std::env;
|
2017-02-25 09:53:46 -08:00
|
|
|
use std::ffi::OsString;
|
2016-10-07 09:43:26 -07:00
|
|
|
use std::fs::{self, File};
|
|
|
|
use std::io::{Read, Write};
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
use std::path::{Path, PathBuf};
|
2015-11-19 15:20:12 -08:00
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
use build_helper::output;
|
|
|
|
use cmake;
|
2017-09-22 21:34:27 -07:00
|
|
|
use cc;
|
2015-11-19 15:20:12 -08:00
|
|
|
|
2016-07-05 21:58:20 -07:00
|
|
|
use Build;
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
use util::{self, exe};
|
2017-02-01 00:27:51 +03:00
|
|
|
use build_helper::up_to_date;
|
2017-07-20 17:51:07 -06:00
|
|
|
use builder::{Builder, RunConfig, ShouldRun, Step};
|
2017-07-13 18:48:44 -06:00
|
|
|
use cache::Interned;
|
2015-11-19 15:20:12 -08:00
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub struct Llvm {
|
|
|
|
pub target: Interned<String>,
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
pub emscripten: bool,
|
2017-07-04 19:41:43 -06:00
|
|
|
}
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
impl Step for Llvm {
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
type Output = PathBuf; // path to llvm-config
|
|
|
|
|
2017-07-05 06:41:27 -06:00
|
|
|
const ONLY_HOSTS: bool = true;
|
2017-07-04 19:41:43 -06:00
|
|
|
|
2017-07-18 18:03:38 -06:00
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
run.path("src/llvm").path("src/llvm-emscripten")
|
2017-07-14 06:30:16 -06:00
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:43 -07:00
|
|
|
fn make_run(run: RunConfig) {
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
let emscripten = run.path.map(|p| {
|
|
|
|
p.ends_with("llvm-emscripten")
|
|
|
|
}).unwrap_or(false);
|
|
|
|
run.builder.ensure(Llvm {
|
|
|
|
target: run.target,
|
|
|
|
emscripten,
|
|
|
|
});
|
2017-07-29 13:39:43 -07:00
|
|
|
}
|
|
|
|
|
2017-07-04 19:41:43 -06:00
|
|
|
/// Compile LLVM for `target`.
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
fn run(self, builder: &Builder) -> PathBuf {
|
2017-07-04 19:41:43 -06:00
|
|
|
let build = builder.build;
|
|
|
|
let target = self.target;
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
let emscripten = self.emscripten;
|
2017-06-18 16:00:10 +02:00
|
|
|
|
2017-07-04 19:41:43 -06:00
|
|
|
// If we're using a custom LLVM bail out here, but we can only use a
|
|
|
|
// custom LLVM for the build triple.
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
if !self.emscripten {
|
|
|
|
if let Some(config) = build.config.target_config.get(&target) {
|
|
|
|
if let Some(ref s) = config.llvm_config {
|
|
|
|
check_llvm_version(build, s);
|
|
|
|
return s.to_path_buf()
|
|
|
|
}
|
2017-07-04 19:41:43 -06:00
|
|
|
}
|
2015-11-19 15:20:12 -08:00
|
|
|
}
|
|
|
|
|
2017-07-04 19:41:43 -06:00
|
|
|
let rebuild_trigger = build.src.join("src/rustllvm/llvm-rebuild-trigger");
|
|
|
|
let mut rebuild_trigger_contents = String::new();
|
|
|
|
t!(t!(File::open(&rebuild_trigger)).read_to_string(&mut rebuild_trigger_contents));
|
2017-03-03 17:18:44 +03:00
|
|
|
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
let (out_dir, llvm_config_ret_dir) = if emscripten {
|
|
|
|
let dir = build.emscripten_llvm_out(target);
|
|
|
|
let config_dir = dir.join("bin");
|
|
|
|
(dir, config_dir)
|
|
|
|
} else {
|
|
|
|
(build.llvm_out(target),
|
|
|
|
build.llvm_out(build.config.build).join("bin"))
|
|
|
|
};
|
2017-07-04 19:41:43 -06:00
|
|
|
let done_stamp = out_dir.join("llvm-finished-building");
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
let build_llvm_config = llvm_config_ret_dir
|
|
|
|
.join(exe("llvm-config", &*build.config.build));
|
2017-07-04 19:41:43 -06:00
|
|
|
if done_stamp.exists() {
|
|
|
|
let mut done_contents = String::new();
|
|
|
|
t!(t!(File::open(&done_stamp)).read_to_string(&mut done_contents));
|
2017-03-03 17:18:44 +03:00
|
|
|
|
2017-07-04 19:41:43 -06:00
|
|
|
// If LLVM was already built previously and contents of the rebuild-trigger file
|
|
|
|
// didn't change from the previous build, then no action is required.
|
|
|
|
if done_contents == rebuild_trigger_contents {
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
return build_llvm_config
|
2017-07-04 19:41:43 -06:00
|
|
|
}
|
|
|
|
}
|
2015-11-19 15:20:12 -08:00
|
|
|
|
2017-07-04 19:41:43 -06:00
|
|
|
let _folder = build.fold_output(|| "llvm");
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
let descriptor = if emscripten { "Emscripten " } else { "" };
|
|
|
|
println!("Building {}LLVM for {}", descriptor, target);
|
2017-07-04 19:41:43 -06:00
|
|
|
let _time = util::timeit();
|
|
|
|
t!(fs::create_dir_all(&out_dir));
|
2015-11-19 15:20:12 -08:00
|
|
|
|
2017-07-04 19:41:43 -06:00
|
|
|
// http://llvm.org/docs/CMake.html
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
let root = if self.emscripten { "src/llvm-emscripten" } else { "src/llvm" };
|
|
|
|
let mut cfg = cmake::Config::new(build.src.join(root));
|
2017-07-04 19:41:43 -06:00
|
|
|
if build.config.ninja {
|
|
|
|
cfg.generator("Ninja");
|
|
|
|
}
|
2016-11-10 17:30:06 +01:00
|
|
|
|
2017-07-04 19:41:43 -06:00
|
|
|
let profile = match (build.config.llvm_optimize, build.config.llvm_release_debuginfo) {
|
|
|
|
(false, _) => "Debug",
|
|
|
|
(true, false) => "Release",
|
|
|
|
(true, true) => "RelWithDebInfo",
|
|
|
|
};
|
2017-02-14 14:30:39 -08:00
|
|
|
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
// NOTE: remember to also update `config.toml.example` when changing the
|
|
|
|
// defaults!
|
|
|
|
let llvm_targets = if self.emscripten {
|
|
|
|
"JSBackend"
|
|
|
|
} else {
|
|
|
|
match build.config.llvm_targets {
|
|
|
|
Some(ref s) => s,
|
|
|
|
None => "X86;ARM;AArch64;Mips;PowerPC;SystemZ;MSP430;Sparc;NVPTX;Hexagon",
|
|
|
|
}
|
2017-07-04 19:41:43 -06:00
|
|
|
};
|
2015-11-19 15:20:12 -08:00
|
|
|
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
let llvm_exp_targets = if self.emscripten {
|
|
|
|
""
|
|
|
|
} else {
|
|
|
|
&build.config.llvm_experimental_targets[..]
|
|
|
|
};
|
2017-03-05 16:11:11 +01:00
|
|
|
|
2017-07-04 19:41:43 -06:00
|
|
|
let assertions = if build.config.llvm_assertions {"ON"} else {"OFF"};
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
cfg.target(&target)
|
2017-07-04 19:41:43 -06:00
|
|
|
.host(&build.build)
|
|
|
|
.out_dir(&out_dir)
|
|
|
|
.profile(profile)
|
|
|
|
.define("LLVM_ENABLE_ASSERTIONS", assertions)
|
|
|
|
.define("LLVM_TARGETS_TO_BUILD", llvm_targets)
|
|
|
|
.define("LLVM_EXPERIMENTAL_TARGETS_TO_BUILD", llvm_exp_targets)
|
|
|
|
.define("LLVM_INCLUDE_EXAMPLES", "OFF")
|
|
|
|
.define("LLVM_INCLUDE_TESTS", "OFF")
|
|
|
|
.define("LLVM_INCLUDE_DOCS", "OFF")
|
|
|
|
.define("LLVM_ENABLE_ZLIB", "OFF")
|
|
|
|
.define("WITH_POLLY", "OFF")
|
|
|
|
.define("LLVM_ENABLE_TERMINFO", "OFF")
|
|
|
|
.define("LLVM_ENABLE_LIBEDIT", "OFF")
|
|
|
|
.define("LLVM_PARALLEL_COMPILE_JOBS", build.jobs().to_string())
|
|
|
|
.define("LLVM_TARGET_ARCH", target.split('-').next().unwrap())
|
|
|
|
.define("LLVM_DEFAULT_TARGET_TRIPLE", target);
|
2015-11-19 15:20:12 -08:00
|
|
|
|
2017-08-03 15:42:05 -07:00
|
|
|
|
|
|
|
// This setting makes the LLVM tools link to the dynamic LLVM library,
|
|
|
|
// which saves both memory during parallel links and overall disk space
|
|
|
|
// for the tools. We don't distribute any of those tools, so this is
|
2017-08-04 00:13:11 -07:00
|
|
|
// just a local concern. However, it doesn't work well everywhere.
|
|
|
|
if target.contains("linux-gnu") || target.contains("apple-darwin") {
|
2017-08-03 15:42:05 -07:00
|
|
|
cfg.define("LLVM_LINK_LLVM_DYLIB", "ON");
|
|
|
|
}
|
|
|
|
|
2017-02-25 09:53:46 -08:00
|
|
|
if target.contains("msvc") {
|
2017-07-04 19:41:43 -06:00
|
|
|
cfg.define("LLVM_USE_CRT_DEBUG", "MT");
|
|
|
|
cfg.define("LLVM_USE_CRT_RELEASE", "MT");
|
|
|
|
cfg.define("LLVM_USE_CRT_RELWITHDEBINFO", "MT");
|
|
|
|
cfg.static_crt(true);
|
2017-02-25 09:53:46 -08:00
|
|
|
}
|
|
|
|
|
2017-07-04 19:41:43 -06:00
|
|
|
if target.starts_with("i686") {
|
|
|
|
cfg.define("LLVM_BUILD_32_BITS", "ON");
|
2017-02-25 09:53:46 -08:00
|
|
|
}
|
|
|
|
|
2017-07-04 19:41:43 -06:00
|
|
|
if let Some(num_linkers) = build.config.llvm_link_jobs {
|
|
|
|
if num_linkers > 0 {
|
|
|
|
cfg.define("LLVM_PARALLEL_LINK_JOBS", num_linkers.to_string());
|
|
|
|
}
|
2015-11-19 15:20:12 -08:00
|
|
|
}
|
2016-03-29 21:51:00 -07:00
|
|
|
|
2017-07-04 19:41:43 -06:00
|
|
|
// http://llvm.org/docs/HowToCrossCompileLLVM.html
|
rustc: Upgrade to LLVM 6
The following submodules have been updated for a new version of LLVM:
- `src/llvm`
- `src/libcompiler_builtins` - transitively contains compiler-rt
- `src/dlmalloc`
This also updates the docker container for dist-i686-freebsd as the old 16.04
container is no longer capable of building LLVM. The
compiler-rt/compiler-builtins and dlmalloc updates are pretty routine without
much interesting happening, but the LLVM update here is of particular note.
Unlike previous updates I haven't cherry-picked all existing patches we had on
top of our LLVM branch as we have a [huge amount][patches4] and have at this
point forgotten what most of them are for. Instead I started from the current
`release_60` branch in LLVM and only applied patches that were necessary to get
our tests working and building.
The current set of custom rustc-specific patches included in this LLVM update are:
* rust-lang/llvm@1187443 - this is how we actually implement
`cfg(target_feature)` for now and continues to not be upstreamed. While a
hazard for SIMD stabilization this commit is otherwise keeping the status
quo of a small rustc-specific feature.
* rust-lang/llvm@013f2ec - this is a rustc-specific optimization that we haven't
upstreamed, notably teaching LLVM about our allocation-related routines (which
aren't malloc/free). Once we stabilize the global allocator routines we will
likely want to upstream this patch, but for now it seems reasonable to keep it
on our fork.
* rust-lang/llvm@a65bbfd - I found this necessary to fix compilation of LLVM in
our 32-bit linux container. I'm not really sure why it's necessary but my
guess is that it's because of the absolutely ancient glibc that we're using.
In any case it's only updating pieces we're not actually using in LLVM so I'm
hoping it'll turn out alright. This doesn't seem like something we'll want to
upstream.c
* rust-lang/llvm@77ab1f0 - this is what's actually enabling LLVM to build in our
i686-freebsd container, I'm not really sure what's going on but we for sure
probably don't want to upstream this and otherwise it seems not too bad for
now at least.
* rust-lang/llvm@9eb9267 - we currently suffer on MSVC from an [upstream bug]
which although diagnosed to a particular revision isn't currently fixed
upstream (and the bug itself doesn't seem too active). This commit is a
partial revert of the suspected cause of this regression (found via a
bisection). I'm sort of hoping that this eventually gets fixed upstream with a
similar fix (which we can replace in our branch), but for now I'm also hoping
it's a relatively harmless change to have.
After applying these patches (plus one [backport] which should be [backported
upstream][llvm-back]) I believe we should have all tests working on all
platforms in our current test suite. I'm like 99% sure that we'll need some more
backports as issues are reported for LLVM 6 when this propagates through
nightlies, but that's sort of just par for the course nowadays!
In any case though some extra scrutiny of the patches here would definitely be
welcome, along with scrutiny of the "missing patches" like a [change to pass
manager order](rust-lang/llvm@27174447533), [another change to pass manager
order](rust-lang/llvm@c782febb7b9), some [compile fixes for
sparc](rust-lang/llvm@1a83de63c42), and some [fixes for
solaris](rust-lang/llvm@c2bfe0abb).
[patches4]: https://github.com/rust-lang/llvm/compare/5401fdf23...rust-llvm-release-4-0-1
[backport]: https://github.com/rust-lang/llvm/commit/5c54c252db
[llvm-back]: https://bugs.llvm.org/show_bug.cgi?id=36114
[upstream bug]: https://bugs.llvm.org/show_bug.cgi?id=36096
---
The update to LLVM 6 is desirable for a number of reasons, notably:
* This'll allow us to keep up with the upstream wasm backend, picking up new
features as they start landing.
* Upstream LLVM has fixed a number of SIMD-related compilation errors,
especially around AVX-512 and such.
* There's a few assorted known bugs which are fixed in LLVM 5 and aren't fixed
in the LLVM 4 branch we're using.
* Overall it's not a great idea to stagnate with our codegen backend!
This update is mostly powered by #47730 which is allowing us to update LLVM
*independent* of the version of LLVM that Emscripten is locked to. This means
that when compiling code for Emscripten we'll still be using the old LLVM 4
backend, but when compiling code for any other target we'll be using the new
LLVM 6 target. Once Emscripten updates we may no longer need this distinction,
but we're not sure when that will happen!
Closes #43370
Closes #43418
Closes #47015
Closes #47683
Closes rust-lang-nursery/stdsimd#157
Closes rust-lang-nursery/rust-wasm#3
2018-01-22 14:23:30 -08:00
|
|
|
if target != build.build && !emscripten {
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
builder.ensure(Llvm {
|
|
|
|
target: build.build,
|
|
|
|
emscripten: false,
|
|
|
|
});
|
2017-07-04 19:41:43 -06:00
|
|
|
// FIXME: if the llvm root for the build triple is overridden then we
|
|
|
|
// should use llvm-tblgen from there, also should verify that it
|
|
|
|
// actually exists most of the time in normal installs of LLVM.
|
2017-07-13 18:48:44 -06:00
|
|
|
let host = build.llvm_out(build.build).join("bin/llvm-tblgen");
|
2017-07-04 19:41:43 -06:00
|
|
|
cfg.define("CMAKE_CROSSCOMPILING", "True")
|
|
|
|
.define("LLVM_TABLEGEN", &host);
|
2017-07-28 12:17:52 -07:00
|
|
|
|
|
|
|
if target.contains("netbsd") {
|
|
|
|
cfg.define("CMAKE_SYSTEM_NAME", "NetBSD");
|
|
|
|
} else if target.contains("freebsd") {
|
|
|
|
cfg.define("CMAKE_SYSTEM_NAME", "FreeBSD");
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg.define("LLVM_NATIVE_BUILD", build.llvm_out(build.build).join("build"));
|
2017-07-04 19:41:43 -06:00
|
|
|
}
|
2017-02-25 09:53:46 -08:00
|
|
|
|
2017-07-04 19:41:43 -06:00
|
|
|
let sanitize_cc = |cc: &Path| {
|
|
|
|
if target.contains("msvc") {
|
|
|
|
OsString::from(cc.to_str().unwrap().replace("\\", "/"))
|
|
|
|
} else {
|
|
|
|
cc.as_os_str().to_owned()
|
|
|
|
}
|
|
|
|
};
|
2015-11-19 15:20:12 -08:00
|
|
|
|
2017-07-04 19:41:43 -06:00
|
|
|
let configure_compilers = |cfg: &mut cmake::Config| {
|
|
|
|
// MSVC with CMake uses msbuild by default which doesn't respect these
|
|
|
|
// vars that we'd otherwise configure. In that case we just skip this
|
|
|
|
// entirely.
|
|
|
|
if target.contains("msvc") && !build.config.ninja {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let cc = build.cc(target);
|
|
|
|
let cxx = build.cxx(target).unwrap();
|
|
|
|
|
|
|
|
// Handle msvc + ninja + ccache specially (this is what the bots use)
|
|
|
|
if target.contains("msvc") &&
|
|
|
|
build.config.ninja &&
|
|
|
|
build.config.ccache.is_some() {
|
|
|
|
let mut cc = env::current_exe().expect("failed to get cwd");
|
|
|
|
cc.set_file_name("sccache-plus-cl.exe");
|
|
|
|
|
|
|
|
cfg.define("CMAKE_C_COMPILER", sanitize_cc(&cc))
|
|
|
|
.define("CMAKE_CXX_COMPILER", sanitize_cc(&cc));
|
|
|
|
cfg.env("SCCACHE_PATH",
|
|
|
|
build.config.ccache.as_ref().unwrap())
|
|
|
|
.env("SCCACHE_TARGET", target);
|
|
|
|
|
|
|
|
// If ccache is configured we inform the build a little differently hwo
|
|
|
|
// to invoke ccache while also invoking our compilers.
|
|
|
|
} else if let Some(ref ccache) = build.config.ccache {
|
|
|
|
cfg.define("CMAKE_C_COMPILER", ccache)
|
|
|
|
.define("CMAKE_C_COMPILER_ARG1", sanitize_cc(cc))
|
|
|
|
.define("CMAKE_CXX_COMPILER", ccache)
|
|
|
|
.define("CMAKE_CXX_COMPILER_ARG1", sanitize_cc(cxx));
|
|
|
|
} else {
|
|
|
|
cfg.define("CMAKE_C_COMPILER", sanitize_cc(cc))
|
|
|
|
.define("CMAKE_CXX_COMPILER", sanitize_cc(cxx));
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg.build_arg("-j").build_arg(build.jobs().to_string());
|
|
|
|
cfg.define("CMAKE_C_FLAGS", build.cflags(target).join(" "));
|
|
|
|
cfg.define("CMAKE_CXX_FLAGS", build.cflags(target).join(" "));
|
2017-10-10 23:06:22 +03:00
|
|
|
if let Some(ar) = build.ar(target) {
|
|
|
|
if ar.is_absolute() {
|
|
|
|
// LLVM build breaks if `CMAKE_AR` is a relative path, for some reason it
|
|
|
|
// tries to resolve this path in the LLVM build directory.
|
|
|
|
cfg.define("CMAKE_AR", sanitize_cc(ar));
|
|
|
|
}
|
|
|
|
}
|
2017-07-04 19:41:43 -06:00
|
|
|
};
|
2017-03-20 14:29:14 -07:00
|
|
|
|
2017-07-04 19:41:43 -06:00
|
|
|
configure_compilers(&mut cfg);
|
2016-06-29 13:45:18 -07:00
|
|
|
|
2017-07-04 19:41:43 -06:00
|
|
|
if env::var_os("SCCACHE_ERROR_LOG").is_some() {
|
|
|
|
cfg.env("RUST_LOG", "sccache=warn");
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: we don't actually need to build all LLVM tools and all LLVM
|
|
|
|
// libraries here, e.g. we just want a few components and a few
|
|
|
|
// tools. Figure out how to filter them down and only build the right
|
|
|
|
// tools and libs on all platforms.
|
|
|
|
cfg.build();
|
|
|
|
|
|
|
|
t!(t!(File::create(&done_stamp)).write_all(rebuild_trigger_contents.as_bytes()));
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
|
|
|
|
build_llvm_config
|
2017-07-04 19:41:43 -06:00
|
|
|
}
|
2015-11-19 15:20:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn check_llvm_version(build: &Build, llvm_config: &Path) {
|
|
|
|
if !build.config.llvm_version_check {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut cmd = Command::new(llvm_config);
|
|
|
|
let version = output(cmd.arg("--version"));
|
2017-10-16 12:57:37 -07:00
|
|
|
let mut parts = version.split('.').take(2)
|
|
|
|
.filter_map(|s| s.parse::<u32>().ok());
|
|
|
|
if let (Some(major), Some(minor)) = (parts.next(), parts.next()) {
|
|
|
|
if major > 3 || (major == 3 && minor >= 9) {
|
|
|
|
return
|
|
|
|
}
|
2015-11-19 15:20:12 -08:00
|
|
|
}
|
2017-10-16 12:57:37 -07:00
|
|
|
panic!("\n\nbad LLVM version: {}, need >=3.9\n\n", version)
|
2015-11-19 15:20:12 -08:00
|
|
|
}
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
|
|
|
pub struct TestHelpers {
|
|
|
|
pub target: Interned<String>,
|
2017-07-04 19:41:43 -06:00
|
|
|
}
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
impl Step for TestHelpers {
|
2017-07-04 19:41:43 -06:00
|
|
|
type Output = ();
|
|
|
|
|
2017-07-18 18:03:38 -06:00
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
|
|
|
run.path("src/rt/rust_test_helpers.c")
|
2017-07-05 06:41:27 -06:00
|
|
|
}
|
|
|
|
|
2017-07-20 17:51:07 -06:00
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
run.builder.ensure(TestHelpers { target: run.target })
|
2017-07-05 06:41:27 -06:00
|
|
|
}
|
|
|
|
|
2017-07-04 19:41:43 -06:00
|
|
|
/// Compiles the `rust_test_helpers.c` library which we used in various
|
|
|
|
/// `run-pass` test suites for ABI testing.
|
|
|
|
fn run(self, builder: &Builder) {
|
|
|
|
let build = builder.build;
|
|
|
|
let target = self.target;
|
|
|
|
let dst = build.test_helpers_out(target);
|
|
|
|
let src = build.src.join("src/rt/rust_test_helpers.c");
|
|
|
|
if up_to_date(&src, &dst.join("librust_test_helpers.a")) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let _folder = build.fold_output(|| "build_test_helpers");
|
|
|
|
println!("Building test helpers");
|
|
|
|
t!(fs::create_dir_all(&dst));
|
2017-09-22 21:34:27 -07:00
|
|
|
let mut cfg = cc::Build::new();
|
2017-07-04 19:41:43 -06:00
|
|
|
|
|
|
|
// We may have found various cross-compilers a little differently due to our
|
|
|
|
// extra configuration, so inform gcc of these compilers. Note, though, that
|
|
|
|
// on MSVC we still need gcc's detection of env vars (ugh).
|
|
|
|
if !target.contains("msvc") {
|
|
|
|
if let Some(ar) = build.ar(target) {
|
|
|
|
cfg.archiver(ar);
|
|
|
|
}
|
|
|
|
cfg.compiler(build.cc(target));
|
2016-11-16 12:31:19 -08:00
|
|
|
}
|
|
|
|
|
2017-07-04 19:41:43 -06:00
|
|
|
cfg.cargo_metadata(false)
|
|
|
|
.out_dir(&dst)
|
2017-07-13 18:48:44 -06:00
|
|
|
.target(&target)
|
2017-07-04 19:41:43 -06:00
|
|
|
.host(&build.build)
|
|
|
|
.opt_level(0)
|
2017-09-05 17:48:47 +02:00
|
|
|
.warnings(false)
|
2017-07-04 19:41:43 -06:00
|
|
|
.debug(false)
|
|
|
|
.file(build.src.join("src/rt/rust_test_helpers.c"))
|
2017-11-26 16:43:24 -05:00
|
|
|
.compile("rust_test_helpers");
|
2017-07-04 19:41:43 -06:00
|
|
|
}
|
2016-04-05 11:34:23 -07:00
|
|
|
}
|
2017-07-04 19:41:43 -06:00
|
|
|
|
2017-11-04 08:05:46 -07:00
|
|
|
const OPENSSL_VERS: &'static str = "1.0.2m";
|
2017-02-15 15:57:06 -08:00
|
|
|
const OPENSSL_SHA256: &'static str =
|
2017-11-04 08:05:46 -07:00
|
|
|
"8c6ff15ec6b319b50788f42c7abc2890c08ba5a1cdcd3810eb9092deada37b0f";
|
2017-02-15 15:57:06 -08:00
|
|
|
|
2017-07-20 16:41:26 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
2017-07-13 18:48:44 -06:00
|
|
|
pub struct Openssl {
|
|
|
|
pub target: Interned<String>,
|
2017-07-04 19:41:43 -06:00
|
|
|
}
|
2017-02-15 15:57:06 -08:00
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
impl Step for Openssl {
|
2017-07-04 19:41:43 -06:00
|
|
|
type Output = ();
|
|
|
|
|
2017-07-18 18:03:38 -06:00
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
|
|
|
run.never()
|
2017-07-05 06:41:27 -06:00
|
|
|
}
|
|
|
|
|
2017-07-04 19:41:43 -06:00
|
|
|
fn run(self, builder: &Builder) {
|
2017-07-05 10:46:41 -06:00
|
|
|
let build = builder.build;
|
2017-07-04 19:41:43 -06:00
|
|
|
let target = self.target;
|
|
|
|
let out = match build.openssl_dir(target) {
|
|
|
|
Some(dir) => dir,
|
|
|
|
None => return,
|
|
|
|
};
|
|
|
|
|
|
|
|
let stamp = out.join(".stamp");
|
|
|
|
let mut contents = String::new();
|
|
|
|
drop(File::open(&stamp).and_then(|mut f| f.read_to_string(&mut contents)));
|
|
|
|
if contents == OPENSSL_VERS {
|
|
|
|
return
|
2017-03-15 07:13:59 -07:00
|
|
|
}
|
2017-07-04 19:41:43 -06:00
|
|
|
t!(fs::create_dir_all(&out));
|
|
|
|
|
|
|
|
let name = format!("openssl-{}.tar.gz", OPENSSL_VERS);
|
|
|
|
let tarball = out.join(&name);
|
|
|
|
if !tarball.exists() {
|
|
|
|
let tmp = tarball.with_extension("tmp");
|
|
|
|
// originally from https://www.openssl.org/source/...
|
2017-09-15 16:04:13 -07:00
|
|
|
let url = format!("https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror/{}",
|
2017-07-04 19:41:43 -06:00
|
|
|
name);
|
2017-10-12 01:20:55 +08:00
|
|
|
let mut last_error = None;
|
2017-07-04 19:41:43 -06:00
|
|
|
for _ in 0..3 {
|
|
|
|
let status = Command::new("curl")
|
|
|
|
.arg("-o").arg(&tmp)
|
2017-10-12 01:20:55 +08:00
|
|
|
.arg("-f") // make curl fail if the URL does not return HTTP 200
|
2017-07-04 19:41:43 -06:00
|
|
|
.arg(&url)
|
|
|
|
.status()
|
|
|
|
.expect("failed to spawn curl");
|
2017-10-12 01:20:55 +08:00
|
|
|
|
|
|
|
// Retry if download failed.
|
|
|
|
if !status.success() {
|
|
|
|
last_error = Some(status.to_string());
|
|
|
|
continue;
|
2017-07-04 19:41:43 -06:00
|
|
|
}
|
2017-10-12 01:20:55 +08:00
|
|
|
|
|
|
|
// Ensure the hash is correct.
|
|
|
|
let mut shasum = if target.contains("apple") || build.build.contains("netbsd") {
|
|
|
|
let mut cmd = Command::new("shasum");
|
|
|
|
cmd.arg("-a").arg("256");
|
|
|
|
cmd
|
|
|
|
} else {
|
|
|
|
Command::new("sha256sum")
|
|
|
|
};
|
|
|
|
let output = output(&mut shasum.arg(&tmp));
|
|
|
|
let found = output.split_whitespace().next().unwrap();
|
|
|
|
|
|
|
|
// If the hash is wrong, probably the download is incomplete or S3 served an error
|
|
|
|
// page. In any case, retry.
|
|
|
|
if found != OPENSSL_SHA256 {
|
|
|
|
last_error = Some(format!(
|
|
|
|
"downloaded openssl sha256 different\n\
|
|
|
|
expected: {}\n\
|
|
|
|
found: {}\n",
|
|
|
|
OPENSSL_SHA256,
|
|
|
|
found
|
|
|
|
));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Everything is fine, so exit the retry loop.
|
|
|
|
last_error = None;
|
|
|
|
break;
|
2017-07-04 19:41:43 -06:00
|
|
|
}
|
2017-10-12 01:20:55 +08:00
|
|
|
if let Some(error) = last_error {
|
|
|
|
panic!("failed to download openssl source: {}", error);
|
2017-07-04 19:41:43 -06:00
|
|
|
}
|
|
|
|
t!(fs::rename(&tmp, &tarball));
|
2017-03-15 07:13:59 -07:00
|
|
|
}
|
2017-07-04 19:41:43 -06:00
|
|
|
let obj = out.join(format!("openssl-{}", OPENSSL_VERS));
|
|
|
|
let dst = build.openssl_install_dir(target).unwrap();
|
|
|
|
drop(fs::remove_dir_all(&obj));
|
|
|
|
drop(fs::remove_dir_all(&dst));
|
2017-08-31 09:22:39 -05:00
|
|
|
build.run(Command::new("tar").arg("zxf").arg(&tarball).current_dir(&out));
|
2017-07-04 19:41:43 -06:00
|
|
|
|
2017-08-28 11:22:11 -05:00
|
|
|
let mut configure = Command::new("perl");
|
|
|
|
configure.arg(obj.join("Configure"));
|
2017-07-04 19:41:43 -06:00
|
|
|
configure.arg(format!("--prefix={}", dst.display()));
|
|
|
|
configure.arg("no-dso");
|
|
|
|
configure.arg("no-ssl2");
|
|
|
|
configure.arg("no-ssl3");
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
let os = match &*target {
|
2017-07-04 19:41:43 -06:00
|
|
|
"aarch64-linux-android" => "linux-aarch64",
|
|
|
|
"aarch64-unknown-linux-gnu" => "linux-aarch64",
|
2017-09-05 16:55:25 +00:00
|
|
|
"aarch64-unknown-linux-musl" => "linux-aarch64",
|
2017-07-04 19:41:43 -06:00
|
|
|
"arm-linux-androideabi" => "android",
|
|
|
|
"arm-unknown-linux-gnueabi" => "linux-armv4",
|
|
|
|
"arm-unknown-linux-gnueabihf" => "linux-armv4",
|
|
|
|
"armv7-linux-androideabi" => "android-armv7",
|
|
|
|
"armv7-unknown-linux-gnueabihf" => "linux-armv4",
|
2018-01-04 14:55:04 -02:00
|
|
|
"i586-unknown-linux-gnu" => "linux-elf",
|
|
|
|
"i586-unknown-linux-musl" => "linux-elf",
|
2017-07-04 19:41:43 -06:00
|
|
|
"i686-apple-darwin" => "darwin-i386-cc",
|
|
|
|
"i686-linux-android" => "android-x86",
|
|
|
|
"i686-unknown-freebsd" => "BSD-x86-elf",
|
|
|
|
"i686-unknown-linux-gnu" => "linux-elf",
|
|
|
|
"i686-unknown-linux-musl" => "linux-elf",
|
2017-08-30 18:22:46 -05:00
|
|
|
"i686-unknown-netbsd" => "BSD-x86-elf",
|
2017-07-04 19:41:43 -06:00
|
|
|
"mips-unknown-linux-gnu" => "linux-mips32",
|
|
|
|
"mips64-unknown-linux-gnuabi64" => "linux64-mips64",
|
|
|
|
"mips64el-unknown-linux-gnuabi64" => "linux64-mips64",
|
|
|
|
"mipsel-unknown-linux-gnu" => "linux-mips32",
|
|
|
|
"powerpc-unknown-linux-gnu" => "linux-ppc",
|
|
|
|
"powerpc64-unknown-linux-gnu" => "linux-ppc64",
|
|
|
|
"powerpc64le-unknown-linux-gnu" => "linux-ppc64le",
|
|
|
|
"s390x-unknown-linux-gnu" => "linux64-s390x",
|
2017-10-23 11:45:02 +02:00
|
|
|
"sparc64-unknown-linux-gnu" => "linux64-sparcv9",
|
2017-08-31 09:34:03 -05:00
|
|
|
"sparc64-unknown-netbsd" => "BSD-sparc64",
|
2017-07-04 19:41:43 -06:00
|
|
|
"x86_64-apple-darwin" => "darwin64-x86_64-cc",
|
|
|
|
"x86_64-linux-android" => "linux-x86_64",
|
|
|
|
"x86_64-unknown-freebsd" => "BSD-x86_64",
|
2017-10-29 18:42:04 +01:00
|
|
|
"x86_64-unknown-dragonfly" => "BSD-x86_64",
|
2017-07-04 19:41:43 -06:00
|
|
|
"x86_64-unknown-linux-gnu" => "linux-x86_64",
|
|
|
|
"x86_64-unknown-linux-musl" => "linux-x86_64",
|
|
|
|
"x86_64-unknown-netbsd" => "BSD-x86_64",
|
|
|
|
_ => panic!("don't know how to configure OpenSSL for {}", target),
|
2017-02-15 15:57:06 -08:00
|
|
|
};
|
2017-07-04 19:41:43 -06:00
|
|
|
configure.arg(os);
|
|
|
|
configure.env("CC", build.cc(target));
|
|
|
|
for flag in build.cflags(target) {
|
|
|
|
configure.arg(flag);
|
2017-02-15 15:57:06 -08:00
|
|
|
}
|
2017-07-04 19:41:43 -06:00
|
|
|
// There is no specific os target for android aarch64 or x86_64,
|
|
|
|
// so we need to pass some extra cflags
|
|
|
|
if target == "aarch64-linux-android" || target == "x86_64-linux-android" {
|
|
|
|
configure.arg("-mandroid");
|
|
|
|
configure.arg("-fomit-frame-pointer");
|
|
|
|
}
|
2017-08-31 09:34:03 -05:00
|
|
|
if target == "sparc64-unknown-netbsd" {
|
|
|
|
// Need -m64 to get assembly generated correctly for sparc64.
|
|
|
|
configure.arg("-m64");
|
2017-08-31 09:36:10 -05:00
|
|
|
if build.build.contains("netbsd") {
|
|
|
|
// Disable sparc64 asm on NetBSD builders, it uses
|
|
|
|
// m4(1)'s -B flag, which NetBSD m4 does not support.
|
|
|
|
configure.arg("no-asm");
|
|
|
|
}
|
2017-08-31 09:34:03 -05:00
|
|
|
}
|
2017-07-04 19:41:43 -06:00
|
|
|
// Make PIE binaries
|
|
|
|
// Non-PIE linker support was removed in Lollipop
|
|
|
|
// https://source.android.com/security/enhancements/enhancements50
|
|
|
|
if target == "i686-linux-android" {
|
|
|
|
configure.arg("no-asm");
|
|
|
|
}
|
|
|
|
configure.current_dir(&obj);
|
|
|
|
println!("Configuring openssl for {}", target);
|
|
|
|
build.run_quiet(&mut configure);
|
|
|
|
println!("Building openssl for {}", target);
|
|
|
|
build.run_quiet(Command::new("make").arg("-j1").current_dir(&obj));
|
|
|
|
println!("Installing openssl for {}", target);
|
|
|
|
build.run_quiet(Command::new("make").arg("install").current_dir(&obj));
|
|
|
|
|
|
|
|
let mut f = t!(File::create(&stamp));
|
|
|
|
t!(f.write_all(OPENSSL_VERS.as_bytes()));
|
2017-05-05 17:12:05 -03:00
|
|
|
}
|
2017-02-15 15:57:06 -08:00
|
|
|
}
|