Skip to content

Commit 07aef98

Browse files
committed
auto merge of #13584 : rcxdude/rust/cross-syntax-ext, r=alexcrichton
This allows the use of syntax extensions when cross-compiling (fixing #12102). It does this by encoding the target triple in the crate metadata and checking it when searching for files. Currently the crate triple must match the host triple when there is a macro_registrar_fn, it must match the target triple when linking, and can match either when only macro_rules! macros are used. due to carelessness, this is pretty much a duplicate of #13450.
2 parents 6beb376 + 4ac89cd commit 07aef98

28 files changed

+257
-209
lines changed

mk/tests.mk

+1-3
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,6 @@ endif
526526
# triples). The associated message will be printed as a warning
527527
# during attempts to run those tests.
528528

529-
CTEST_DISABLE_NONSELFHOST_rpass-full = "run-pass-full suite is unavailable when cross-compiling."
530-
531529
define DEF_CTEST_VARS
532530

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

575573
CTEST_DEPS_rpass_$(1)-T-$(2)-H-$(3) = $$(RPASS_TESTS)
576-
CTEST_DEPS_rpass-full_$(1)-T-$(2)-H-$(3) = $$(RPASS_FULL_TESTS) $$(CSREQ$(1)_T_$(2)_H_$(3))
574+
CTEST_DEPS_rpass-full_$(1)-T-$(2)-H-$(3) = $$(RPASS_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
577575
CTEST_DEPS_rfail_$(1)-T-$(2)-H-$(3) = $$(RFAIL_TESTS)
578576
CTEST_DEPS_cfail_$(1)-T-$(2)-H-$(3) = $$(CFAIL_TESTS)
579577
CTEST_DEPS_bench_$(1)-T-$(2)-H-$(3) = $$(BENCH_TESTS)

src/librustc/back/archive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl<'a> Archive<'a> {
184184
let unixlibname = format!("lib{}.a", name);
185185

186186
let mut rustpath = filesearch::rust_path();
187-
rustpath.push(self.sess.filesearch().get_target_lib_path());
187+
rustpath.push(self.sess.target_filesearch().get_lib_path());
188188
let search = self.sess.opts.addl_lib_search_paths.borrow();
189189
for path in search.iter().chain(rustpath.iter()) {
190190
debug!("looking for {} inside {}", name, path.display());

src/librustc/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ fn link_args(sess: &Session,
10881088
// The default library location, we need this to find the runtime.
10891089
// The location of crates will be determined as needed.
10901090
// FIXME (#9639): This needs to handle non-utf8 paths
1091-
let lib_path = sess.filesearch().get_target_lib_path();
1091+
let lib_path = sess.target_filesearch().get_lib_path();
10921092
let stage: ~str = "-L".to_owned() + lib_path.as_str().unwrap();
10931093

10941094
let mut args = vec!(stage);

src/librustc/back/rpath.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn get_rpath_flags(sess: &Session, out_filename: &Path) -> Vec<~str> {
4040

4141
debug!("preparing the RPATH!");
4242

43-
let sysroot = sess.filesearch().sysroot;
43+
let sysroot = sess.sysroot();
4444
let output = out_filename;
4545
let libs = sess.cstore.get_used_crates(cstore::RequireDynamic);
4646
let libs = libs.move_iter().filter_map(|(_, l)| {

src/librustc/driver/driver.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,7 @@ pub fn phase_3_run_analysis_passes(sess: Session,
284284
let time_passes = sess.time_passes();
285285

286286
time(time_passes, "external crate/lib resolution", (), |_|
287-
creader::read_crates(&sess, krate,
288-
session::sess_os_to_meta_os(sess.targ_cfg.os),
289-
token::get_ident_interner()));
287+
creader::read_crates(&sess, krate));
290288

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

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

809807
pub fn build_session_options(matches: &getopts::Matches) -> session::Options {
@@ -895,7 +893,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> session::Options {
895893
}
896894

897895
let sysroot_opt = matches.opt_str("sysroot").map(|m| Path::new(m));
898-
let target = matches.opt_str("target").unwrap_or(host_triple());
896+
let target = matches.opt_str("target").unwrap_or(host_triple().to_owned());
899897
let opt_level = {
900898
if (debugging_opts & session::NO_OPT) != 0 {
901899
No

src/librustc/driver/session.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -319,17 +319,25 @@ impl Session {
319319
pub fn show_span(&self) -> bool {
320320
self.debugging_opt(SHOW_SPAN)
321321
}
322-
pub fn filesearch<'a>(&'a self) -> filesearch::FileSearch<'a> {
323-
let sysroot = match self.opts.maybe_sysroot {
324-
Some(ref sysroot) => sysroot,
322+
pub fn sysroot<'a>(&'a self) -> &'a Path {
323+
match self.opts.maybe_sysroot {
324+
Some (ref sysroot) => sysroot,
325325
None => self.default_sysroot.as_ref()
326326
.expect("missing sysroot and default_sysroot in Session")
327-
};
327+
}
328+
}
329+
pub fn target_filesearch<'a>(&'a self) -> filesearch::FileSearch<'a> {
328330
filesearch::FileSearch::new(
329-
sysroot,
331+
self.sysroot(),
330332
self.opts.target_triple,
331333
&self.opts.addl_lib_search_paths)
332334
}
335+
pub fn host_filesearch<'a>(&'a self) -> filesearch::FileSearch<'a> {
336+
filesearch::FileSearch::new(
337+
self.sysroot(),
338+
host_triple(),
339+
&self.opts.addl_lib_search_paths)
340+
}
333341
}
334342

335343
/// Some reasonable defaults
@@ -343,7 +351,7 @@ pub fn basic_options() -> Options {
343351
output_types: Vec::new(),
344352
addl_lib_search_paths: RefCell::new(HashSet::new()),
345353
maybe_sysroot: None,
346-
target_triple: host_triple(),
354+
target_triple: host_triple().to_owned(),
347355
cfg: Vec::new(),
348356
test: false,
349357
parse_only: false,

src/librustc/metadata/common.rs

+2
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ pub static tag_macro_registrar_fn: uint = 0x8b;
201201
pub static tag_exported_macros: uint = 0x8c;
202202
pub static tag_macro_def: uint = 0x8d;
203203

204+
pub static tag_crate_triple: uint = 0x66;
205+
204206
#[deriving(Clone, Show)]
205207
pub struct LinkMeta {
206208
pub crateid: CrateId,

0 commit comments

Comments
 (0)