Skip to content

Commit

Permalink
Enable use of syntax extensions when cross compiling.
Browse files Browse the repository at this point in the history
This adds the target triple to the crate metadata.
When searching for a crate the phase (link, syntax) is taken into account.
During link phase only crates matching the target triple are considered.
During syntax phase, either the target or host triple will be accepted, unless
the crate defines a macro_registrar, in which case only the host triple will
match.
  • Loading branch information
rcxdude committed Apr 23, 2014
1 parent 09bfb92 commit 4ac89cd
Show file tree
Hide file tree
Showing 28 changed files with 257 additions and 209 deletions.
4 changes: 1 addition & 3 deletions mk/tests.mk
Expand Up @@ -526,8 +526,6 @@ endif
# triples). The associated message will be printed as a warning
# during attempts to run those tests.

CTEST_DISABLE_NONSELFHOST_rpass-full = "run-pass-full suite is unavailable when cross-compiling."

define DEF_CTEST_VARS

# All the per-stage build rules you might want to call from the
Expand Down Expand Up @@ -573,7 +571,7 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
$$(CTEST_TESTARGS)

CTEST_DEPS_rpass_$(1)-T-$(2)-H-$(3) = $$(RPASS_TESTS)
CTEST_DEPS_rpass-full_$(1)-T-$(2)-H-$(3) = $$(RPASS_FULL_TESTS) $$(CSREQ$(1)_T_$(2)_H_$(3))
CTEST_DEPS_rpass-full_$(1)-T-$(2)-H-$(3) = $$(RPASS_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
CTEST_DEPS_rfail_$(1)-T-$(2)-H-$(3) = $$(RFAIL_TESTS)
CTEST_DEPS_cfail_$(1)-T-$(2)-H-$(3) = $$(CFAIL_TESTS)
CTEST_DEPS_bench_$(1)-T-$(2)-H-$(3) = $$(BENCH_TESTS)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/back/archive.rs
Expand Up @@ -184,7 +184,7 @@ impl<'a> Archive<'a> {
let unixlibname = format!("lib{}.a", name);

let mut rustpath = filesearch::rust_path();
rustpath.push(self.sess.filesearch().get_target_lib_path());
rustpath.push(self.sess.target_filesearch().get_lib_path());
let search = self.sess.opts.addl_lib_search_paths.borrow();
for path in search.iter().chain(rustpath.iter()) {
debug!("looking for {} inside {}", name, path.display());
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/back/link.rs
Expand Up @@ -1088,7 +1088,7 @@ fn link_args(sess: &Session,
// The default library location, we need this to find the runtime.
// The location of crates will be determined as needed.
// FIXME (#9639): This needs to handle non-utf8 paths
let lib_path = sess.filesearch().get_target_lib_path();
let lib_path = sess.target_filesearch().get_lib_path();
let stage: ~str = "-L".to_owned() + lib_path.as_str().unwrap();

let mut args = vec!(stage);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/back/rpath.rs
Expand Up @@ -40,7 +40,7 @@ pub fn get_rpath_flags(sess: &Session, out_filename: &Path) -> Vec<~str> {

debug!("preparing the RPATH!");

let sysroot = sess.filesearch().sysroot;
let sysroot = sess.sysroot();
let output = out_filename;
let libs = sess.cstore.get_used_crates(cstore::RequireDynamic);
let libs = libs.move_iter().filter_map(|(_, l)| {
Expand Down
10 changes: 4 additions & 6 deletions src/librustc/driver/driver.rs
Expand Up @@ -284,9 +284,7 @@ pub fn phase_3_run_analysis_passes(sess: Session,
let time_passes = sess.time_passes();

time(time_passes, "external crate/lib resolution", (), |_|
creader::read_crates(&sess, krate,
session::sess_os_to_meta_os(sess.targ_cfg.os),
token::get_ident_interner()));
creader::read_crates(&sess, krate));

let lang_items = time(time_passes, "language item collection", (), |_|
middle::lang_items::collect_language_items(krate, &sess));
Expand Down Expand Up @@ -794,7 +792,7 @@ pub fn build_target_config(sopts: &session::Options) -> session::Config {
}
}

pub fn host_triple() -> ~str {
pub fn host_triple() -> &'static str {
// Get the host triple out of the build environment. This ensures that our
// idea of the host triple is the same as for the set of libraries we've
// actually built. We can't just take LLVM's host triple because they
Expand All @@ -803,7 +801,7 @@ pub fn host_triple() -> ~str {
// Instead of grabbing the host triple (for the current host), we grab (at
// compile time) the target triple that this rustc is built with and
// calling that (at runtime) the host triple.
(env!("CFG_COMPILER_HOST_TRIPLE")).to_owned()
env!("CFG_COMPILER_HOST_TRIPLE")
}

pub fn build_session_options(matches: &getopts::Matches) -> session::Options {
Expand Down Expand Up @@ -895,7 +893,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> session::Options {
}

let sysroot_opt = matches.opt_str("sysroot").map(|m| Path::new(m));
let target = matches.opt_str("target").unwrap_or(host_triple());
let target = matches.opt_str("target").unwrap_or(host_triple().to_owned());
let opt_level = {
if (debugging_opts & session::NO_OPT) != 0 {
No
Expand Down
20 changes: 14 additions & 6 deletions src/librustc/driver/session.rs
Expand Up @@ -319,17 +319,25 @@ impl Session {
pub fn show_span(&self) -> bool {
self.debugging_opt(SHOW_SPAN)
}
pub fn filesearch<'a>(&'a self) -> filesearch::FileSearch<'a> {
let sysroot = match self.opts.maybe_sysroot {
Some(ref sysroot) => sysroot,
pub fn sysroot<'a>(&'a self) -> &'a Path {
match self.opts.maybe_sysroot {
Some (ref sysroot) => sysroot,
None => self.default_sysroot.as_ref()
.expect("missing sysroot and default_sysroot in Session")
};
}
}
pub fn target_filesearch<'a>(&'a self) -> filesearch::FileSearch<'a> {
filesearch::FileSearch::new(
sysroot,
self.sysroot(),
self.opts.target_triple,
&self.opts.addl_lib_search_paths)
}
pub fn host_filesearch<'a>(&'a self) -> filesearch::FileSearch<'a> {
filesearch::FileSearch::new(
self.sysroot(),
host_triple(),
&self.opts.addl_lib_search_paths)
}
}

/// Some reasonable defaults
Expand All @@ -343,7 +351,7 @@ pub fn basic_options() -> Options {
output_types: Vec::new(),
addl_lib_search_paths: RefCell::new(HashSet::new()),
maybe_sysroot: None,
target_triple: host_triple(),
target_triple: host_triple().to_owned(),
cfg: Vec::new(),
test: false,
parse_only: false,
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/metadata/common.rs
Expand Up @@ -200,6 +200,8 @@ pub static tag_macro_registrar_fn: uint = 0x8b;
pub static tag_exported_macros: uint = 0x8c;
pub static tag_macro_def: uint = 0x8d;

pub static tag_crate_triple: uint = 0x66;

#[deriving(Clone, Show)]
pub struct LinkMeta {
pub crateid: CrateId,
Expand Down

5 comments on commit 4ac89cd

@bors
Copy link
Contributor

@bors bors commented on 4ac89cd Apr 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at rcxdude@4ac89cd

@bors
Copy link
Contributor

@bors bors commented on 4ac89cd Apr 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging rcxdude/rust/cross-syntax-ext = 4ac89cd into auto

@bors
Copy link
Contributor

@bors bors commented on 4ac89cd Apr 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rcxdude/rust/cross-syntax-ext = 4ac89cd merged ok, testing candidate = 07aef98

@bors
Copy link
Contributor

@bors bors commented on 4ac89cd Apr 23, 2014

@bors
Copy link
Contributor

@bors bors commented on 4ac89cd Apr 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 07aef98

Please sign in to comment.