Skip to content

rustbuild: Enable WebAssembly backend by default #46115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@
# LLVM experimental targets to build support for. These targets are specified in
# the same format as above, but since these targets are experimental, they are
# not built by default and the experimental Rust compilation targets that depend
# on them will not work unless the user opts in to building them. Possible
# experimental LLVM targets include WebAssembly for the
# wasm32-experimental-emscripten Rust target.
#experimental-targets = ""
# on them will not work unless the user opts in to building them. By default the
# `WebAssembly` target is enabled when compiling LLVM from scratch.
#experimental-targets = "WebAssembly"

# Cap the number of parallel linker invocations when compiling LLVM.
# This can be useful when building LLVM with debug info, which significantly
Expand Down
5 changes: 3 additions & 2 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct Config {
pub llvm_static_stdcpp: bool,
pub llvm_link_shared: bool,
pub llvm_targets: Option<String>,
pub llvm_experimental_targets: Option<String>,
pub llvm_experimental_targets: String,
pub llvm_link_jobs: Option<u32>,

// rust codegen options
Expand Down Expand Up @@ -447,7 +447,8 @@ impl Config {
set(&mut config.llvm_static_stdcpp, llvm.static_libstdcpp);
set(&mut config.llvm_link_shared, llvm.link_shared);
config.llvm_targets = llvm.targets.clone();
config.llvm_experimental_targets = llvm.experimental_targets.clone();
config.llvm_experimental_targets = llvm.experimental_targets.clone()
.unwrap_or("WebAssembly".to_string());
config.llvm_link_jobs = llvm.link_jobs;
}

Expand Down
5 changes: 1 addition & 4 deletions src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,7 @@ impl Step for Llvm {
None => "X86;ARM;AArch64;Mips;PowerPC;SystemZ;JSBackend;MSP430;Sparc;NVPTX;Hexagon",
};

let llvm_exp_targets = match build.config.llvm_experimental_targets {
Some(ref s) => s,
None => "",
};
let llvm_exp_targets = &build.config.llvm_experimental_targets;

let assertions = if build.config.llvm_assertions {"ON"} else {"OFF"};

Expand Down
1 change: 1 addition & 0 deletions src/ci/docker/cross2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ ENV \
ENV TARGETS=x86_64-unknown-fuchsia
ENV TARGETS=$TARGETS,aarch64-unknown-fuchsia
ENV TARGETS=$TARGETS,sparcv9-sun-solaris
ENV TARGETS=$TARGETS,wasm32-unknown-unknown
ENV TARGETS=$TARGETS,x86_64-sun-solaris
ENV TARGETS=$TARGETS,x86_64-unknown-linux-gnux32

Expand Down
8 changes: 8 additions & 0 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ use std::sync::mpsc;
use syntax::{ast, diagnostics, visit};
use syntax::attr;
use syntax::ext::base::ExtCtxt;
use syntax::fold::Folder;
use syntax::parse::{self, PResult};
use syntax::util::node_count::NodeCounter;
use syntax;
use syntax_ext;
use arena::DroplessArena;

use derive_registrar;
use pretty::ReplaceBodyWithLoop;

use profile;

Expand Down Expand Up @@ -809,6 +811,12 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
sess.diagnostic())
});

// If we're actually rustdoc then there's no need to actually compile
// anything, so switch everything to just looping
if sess.opts.actually_rustdoc {
krate = ReplaceBodyWithLoop::new(sess).fold_crate(krate);
}

// If we're in rustdoc we're always compiling as an rlib, but that'll trip a
// bunch of checks in the `modify` function below. For now just skip this
// step entirely if we're rustdoc as it's not too useful anyway.
Expand Down
6 changes: 4 additions & 2 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,9 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
control.after_hir_lowering.stop = Compilation::Stop;

control.after_parse.callback = box move |state| {
state.krate = Some(pretty::fold_crate(state.krate.take().unwrap(), ppm));
state.krate = Some(pretty::fold_crate(state.session,
state.krate.take().unwrap(),
ppm));
};
control.after_hir_lowering.callback = box move |state| {
pretty::print_after_hir_lowering(state.session,
Expand All @@ -587,7 +589,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
control.after_parse.stop = Compilation::Stop;

control.after_parse.callback = box move |state| {
let krate = pretty::fold_crate(state.krate.take().unwrap(), ppm);
let krate = pretty::fold_crate(state.session, state.krate.take().unwrap(), ppm);
pretty::print_after_parsing(state.session,
state.input,
&krate,
Expand Down
29 changes: 16 additions & 13 deletions src/librustc_driver/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,13 +638,14 @@ impl UserIdentifiedItem {
// ambitious form of the closed RFC #1637. See also [#34511].
//
// [#34511]: https://github.com/rust-lang/rust/issues/34511#issuecomment-322340401
pub struct ReplaceBodyWithLoop {
pub struct ReplaceBodyWithLoop<'a> {
within_static_or_const: bool,
sess: &'a Session,
}

impl ReplaceBodyWithLoop {
pub fn new() -> ReplaceBodyWithLoop {
ReplaceBodyWithLoop { within_static_or_const: false }
impl<'a> ReplaceBodyWithLoop<'a> {
pub fn new(sess: &'a Session) -> ReplaceBodyWithLoop<'a> {
ReplaceBodyWithLoop { within_static_or_const: false, sess }
}

fn run<R, F: FnOnce(&mut Self) -> R>(&mut self, is_const: bool, action: F) -> R {
Expand Down Expand Up @@ -691,7 +692,7 @@ impl ReplaceBodyWithLoop {
}
}

impl fold::Folder for ReplaceBodyWithLoop {
impl<'a> fold::Folder for ReplaceBodyWithLoop<'a> {
fn fold_item_kind(&mut self, i: ast::ItemKind) -> ast::ItemKind {
let is_const = match i {
ast::ItemKind::Static(..) | ast::ItemKind::Const(..) => true,
Expand Down Expand Up @@ -723,34 +724,36 @@ impl fold::Folder for ReplaceBodyWithLoop {
}

fn fold_block(&mut self, b: P<ast::Block>) -> P<ast::Block> {
fn expr_to_block(rules: ast::BlockCheckMode, e: Option<P<ast::Expr>>) -> P<ast::Block> {
fn expr_to_block(rules: ast::BlockCheckMode,
e: Option<P<ast::Expr>>,
sess: &Session) -> P<ast::Block> {
P(ast::Block {
stmts: e.map(|e| {
ast::Stmt {
id: ast::DUMMY_NODE_ID,
id: sess.next_node_id(),
span: e.span,
node: ast::StmtKind::Expr(e),
}
})
.into_iter()
.collect(),
rules,
id: ast::DUMMY_NODE_ID,
id: sess.next_node_id(),
span: syntax_pos::DUMMY_SP,
})
}

if !self.within_static_or_const {

let empty_block = expr_to_block(BlockCheckMode::Default, None);
let empty_block = expr_to_block(BlockCheckMode::Default, None, self.sess);
let loop_expr = P(ast::Expr {
node: ast::ExprKind::Loop(empty_block, None),
id: ast::DUMMY_NODE_ID,
id: self.sess.next_node_id(),
span: syntax_pos::DUMMY_SP,
attrs: ast::ThinVec::new(),
});

expr_to_block(b.rules, Some(loop_expr))
expr_to_block(b.rules, Some(loop_expr), self.sess)

} else {
fold::noop_fold_block(b, self)
Expand Down Expand Up @@ -829,9 +832,9 @@ fn print_flowgraph<'a, 'tcx, W: Write>(variants: Vec<borrowck_dot::Variant>,
}
}

pub fn fold_crate(krate: ast::Crate, ppm: PpMode) -> ast::Crate {
pub fn fold_crate(sess: &Session, krate: ast::Crate, ppm: PpMode) -> ast::Crate {
if let PpmSource(PpmEveryBodyLoops) = ppm {
let mut fold = ReplaceBodyWithLoop::new();
let mut fold = ReplaceBodyWithLoop::new(sess);
fold.fold_crate(krate)
} else {
krate
Expand Down
3 changes: 0 additions & 3 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use rustc_lint;
use rustc_driver::{driver, target_features, abort_on_err};
use rustc_driver::pretty::ReplaceBodyWithLoop;
use rustc::session::{self, config};
use rustc::hir::def_id::DefId;
use rustc::hir::def::Def;
Expand All @@ -26,7 +25,6 @@ use rustc_metadata::cstore::CStore;

use syntax::codemap;
use syntax::feature_gate::UnstableFeatures;
use syntax::fold::Folder;
use errors;
use errors::emitter::ColorConfig;

Expand Down Expand Up @@ -157,7 +155,6 @@ pub fn run_core(search_paths: SearchPaths,
let control = &driver::CompileController::basic();

let krate = panictry!(driver::phase_1_parse_input(control, &sess, &input));
let krate = ReplaceBodyWithLoop::new().fold_crate(krate);

let name = link::find_crate_name(Some(&sess), &krate.attrs, &input);

Expand Down
3 changes: 0 additions & 3 deletions src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ use rustc_back::dynamic_lib::DynamicLibrary;
use rustc_back::tempdir::TempDir;
use rustc_driver::{self, driver, Compilation};
use rustc_driver::driver::phase_2_configure_and_expand;
use rustc_driver::pretty::ReplaceBodyWithLoop;
use rustc_metadata::cstore::CStore;
use rustc_resolve::MakeGlobMap;
use rustc_trans;
use rustc_trans::back::link;
use syntax::ast;
use syntax::codemap::CodeMap;
use syntax::feature_gate::UnstableFeatures;
use syntax::fold::Folder;
use syntax_pos::{BytePos, DUMMY_SP, Pos, Span};
use errors;
use errors::emitter::ColorConfig;
Expand Down Expand Up @@ -97,7 +95,6 @@ pub fn run(input: &str,
let krate = panictry!(driver::phase_1_parse_input(&driver::CompileController::basic(),
&sess,
&input));
let krate = ReplaceBodyWithLoop::new().fold_crate(krate);
let driver::ExpansionResult { defs, mut hir_forest, .. } = {
phase_2_configure_and_expand(
&sess,
Expand Down
78 changes: 48 additions & 30 deletions src/libstd/os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,53 @@
#![stable(feature = "os", since = "1.0.0")]
#![allow(missing_docs, bad_style, missing_debug_implementations)]

#[cfg(all(not(dox), any(target_os = "redox", unix)))]
#[stable(feature = "rust1", since = "1.0.0")]
pub use sys::ext as unix;
#[cfg(all(not(dox), windows))]
#[stable(feature = "rust1", since = "1.0.0")]
pub use sys::ext as windows;

#[cfg(dox)]
#[stable(feature = "rust1", since = "1.0.0")]
pub use sys::unix_ext as unix;
#[cfg(dox)]
#[stable(feature = "rust1", since = "1.0.0")]
pub use sys::windows_ext as windows;

#[cfg(any(dox, target_os = "linux", target_os = "l4re"))]
#[doc(cfg(target_os = "linux"))]
pub mod linux;

#[cfg(all(not(dox), target_os = "android"))] pub mod android;
#[cfg(all(not(dox), target_os = "bitrig"))] pub mod bitrig;
#[cfg(all(not(dox), target_os = "dragonfly"))] pub mod dragonfly;
#[cfg(all(not(dox), target_os = "freebsd"))] pub mod freebsd;
#[cfg(all(not(dox), target_os = "haiku"))] pub mod haiku;
#[cfg(all(not(dox), target_os = "ios"))] pub mod ios;
#[cfg(all(not(dox), target_os = "macos"))] pub mod macos;
#[cfg(all(not(dox), target_os = "netbsd"))] pub mod netbsd;
#[cfg(all(not(dox), target_os = "openbsd"))] pub mod openbsd;
#[cfg(all(not(dox), target_os = "solaris"))] pub mod solaris;
#[cfg(all(not(dox), target_os = "emscripten"))] pub mod emscripten;
#[cfg(all(not(dox), target_os = "fuchsia"))] pub mod fuchsia;
cfg_if! {
if #[cfg(dox)] {

// When documenting libstd we want to show unix/windows/linux modules as
// these are the "main modules" that are used across platforms. This
// should help show platform-specific functionality in a hopefully
// cross-platform way in the documentation

#[stable(feature = "rust1", since = "1.0.0")]
pub use sys::unix_ext as unix;

#[stable(feature = "rust1", since = "1.0.0")]
pub use sys::windows_ext as windows;

#[doc(cfg(target_os = "linux"))]
pub mod linux;

} else {

// If we're not documenting libstd then we just expose everything as we
// otherwise would.

#[cfg(target_os = "android")] pub mod android;
#[cfg(target_os = "bitrig")] pub mod bitrig;
#[cfg(target_os = "dragonfly")] pub mod dragonfly;
#[cfg(target_os = "freebsd")] pub mod freebsd;
#[cfg(target_os = "haiku")] pub mod haiku;
#[cfg(target_os = "ios")] pub mod ios;
#[cfg(target_os = "macos")] pub mod macos;
#[cfg(target_os = "netbsd")] pub mod netbsd;
#[cfg(target_os = "openbsd")] pub mod openbsd;
#[cfg(target_os = "solaris")] pub mod solaris;
#[cfg(target_os = "emscripten")] pub mod emscripten;
#[cfg(target_os = "fuchsia")] pub mod fuchsia;

#[cfg(any(target_os = "redox", unix))]
#[stable(feature = "rust1", since = "1.0.0")]
pub use sys::ext as unix;

#[cfg(windows)]
#[stable(feature = "rust1", since = "1.0.0")]
pub use sys::ext as windows;

#[cfg(any(target_os = "linux", target_os = "l4re"))]
pub mod linux;

}
}

pub mod raw;
Loading