Skip to content

Commit 2ff358c

Browse files
committed
auto merge of #11618 : alexcrichton/rust/force-host, r=brson
The new macro loading infrastructure needs the ability to force a procedural-macro crate to be built with the host architecture rather than the target architecture (because the compiler is just about to dlopen it).
2 parents aa67e13 + bd46934 commit 2ff358c

File tree

7 files changed

+44
-4
lines changed

7 files changed

+44
-4
lines changed

mk/tests.mk

+2-1
Original file line numberDiff line numberDiff line change
@@ -626,9 +626,10 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
626626
--aux-base $$(S)src/test/auxiliary/ \
627627
--stage-id stage$(1)-$(2) \
628628
--target $(2) \
629+
--host $(3) \
629630
--adb-path=$(CFG_ADB) \
630631
--adb-test-dir=$(CFG_ADB_TEST_DIR) \
631-
--rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) --target=$(2)" \
632+
--rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS)" \
632633
$$(CTEST_TESTARGS)
633634

634635
CTEST_DEPS_rpass_$(1)-T-$(2)-H-$(3) = $$(RPASS_TESTS)

src/compiletest/common.rs

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ pub struct config {
8686
// Target system to be tested
8787
target: ~str,
8888

89+
// Host triple for the compiler being invoked
90+
host: ~str,
91+
8992
// Extra parameter to run adb on arm-linux-androideabi
9093
adb_path: ~str,
9194

src/compiletest/compiletest.rs

+3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub fn parse_config(args: ~[~str]) -> config {
7373
"percent change in metrics to consider noise", "N"),
7474
optflag("", "jit", "run tests under the JIT"),
7575
optopt("", "target", "the target to build for", "TARGET"),
76+
optopt("", "host", "the host to build for", "HOST"),
7677
optopt("", "adb-path", "path to the android debugger", "PATH"),
7778
optopt("", "adb-test-dir", "path to tests for the android debugger", "PATH"),
7879
optopt("", "test-shard", "run shard A, of B shards, worth of the testsuite", "A.B"),
@@ -134,6 +135,7 @@ pub fn parse_config(args: ~[~str]) -> config {
134135
rustcflags: matches.opt_str("rustcflags"),
135136
jit: matches.opt_present("jit"),
136137
target: opt_str2(matches.opt_str("target")).to_str(),
138+
host: opt_str2(matches.opt_str("host")).to_str(),
137139
adb_path: opt_str2(matches.opt_str("adb-path")).to_str(),
138140
adb_test_dir:
139141
opt_str2(matches.opt_str("adb-test-dir")).to_str(),
@@ -167,6 +169,7 @@ pub fn log_config(config: &config) {
167169
logv(c, format!("rustcflags: {}", opt_str(&config.rustcflags)));
168170
logv(c, format!("jit: {}", config.jit));
169171
logv(c, format!("target: {}", config.target));
172+
logv(c, format!("host: {}", config.host));
170173
logv(c, format!("adb_path: {}", config.adb_path));
171174
logv(c, format!("adb_test_dir: {}", config.adb_test_dir));
172175
logv(c, format!("adb_device_status: {}", config.adb_device_status));

src/compiletest/header.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ pub struct TestProps {
2828
debugger_cmds: ~[~str],
2929
// Lines to check if they appear in the expected debugger output
3030
check_lines: ~[~str],
31+
// Flag to force a crate to be built with the host architecture
32+
force_host: bool,
3133
}
3234

3335
// Load any test directives embedded in the file
@@ -39,6 +41,7 @@ pub fn load_props(testfile: &Path) -> TestProps {
3941
let mut pp_exact = None;
4042
let mut debugger_cmds = ~[];
4143
let mut check_lines = ~[];
44+
let mut force_host = false;
4245
iter_header(testfile, |ln| {
4346
match parse_error_pattern(ln) {
4447
Some(ep) => error_patterns.push(ep),
@@ -53,6 +56,10 @@ pub fn load_props(testfile: &Path) -> TestProps {
5356
pp_exact = parse_pp_exact(ln, testfile);
5457
}
5558

59+
if !force_host {
60+
force_host = parse_force_host(ln);
61+
}
62+
5663
match parse_aux_build(ln) {
5764
Some(ab) => { aux_builds.push(ab); }
5865
None => {}
@@ -82,7 +89,8 @@ pub fn load_props(testfile: &Path) -> TestProps {
8289
aux_builds: aux_builds,
8390
exec_env: exec_env,
8491
debugger_cmds: debugger_cmds,
85-
check_lines: check_lines
92+
check_lines: check_lines,
93+
force_host: force_host,
8694
};
8795
}
8896

@@ -141,6 +149,10 @@ fn parse_check_line(line: &str) -> Option<~str> {
141149
parse_name_value_directive(line, ~"check")
142150
}
143151

152+
fn parse_force_host(line: &str) -> bool {
153+
parse_name_directive(line, "force-host")
154+
}
155+
144156
fn parse_exec_env(line: &str) -> Option<(~str, ~str)> {
145157
parse_name_value_directive(line, ~"exec-env").map(|nv| {
146158
// nv is either FOO or FOO=BAR

src/compiletest/runtest.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,9 @@ fn compose_and_run_compiler(
691691

692692
for rel_ab in props.aux_builds.iter() {
693693
let abs_ab = config.aux_base.join(rel_ab.as_slice());
694+
let aux_props = load_props(&abs_ab);
694695
let aux_args =
695-
make_compile_args(config, props, ~[~"--lib"] + extra_link_args,
696+
make_compile_args(config, &aux_props, ~[~"--lib"] + extra_link_args,
696697
|a,b| make_lib_name(a, b, testfile), &abs_ab);
697698
let auxres = compose_and_run(config, &abs_ab, aux_args, ~[],
698699
config.compile_lib_path, None);
@@ -738,10 +739,16 @@ fn make_compile_args(config: &config,
738739
testfile: &Path)
739740
-> ProcArgs {
740741
let xform_file = xform(config, testfile);
742+
let target = if props.force_host {
743+
config.host.as_slice()
744+
} else {
745+
config.target.as_slice()
746+
};
741747
// FIXME (#9639): This needs to handle non-utf8 paths
742748
let mut args = ~[testfile.as_str().unwrap().to_owned(),
743749
~"-o", xform_file.as_str().unwrap().to_owned(),
744-
~"-L", config.build_base.as_str().unwrap().to_owned()]
750+
~"-L", config.build_base.as_str().unwrap().to_owned(),
751+
~"--target=" + target]
745752
+ extras;
746753
args.push_all_move(split_maybe_args(&config.rustcflags));
747754
args.push_all_move(split_maybe_args(&props.compile_flags));

src/test/auxiliary/macro_crate_test.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// force-host
12+
1113
#[feature(globs, macro_registrar, macro_rules)];
1214

1315
extern mod syntax;

src/test/run-pass/phase-syntax-link-does-resolve.rs

+12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@
1111
// aux-build:macro_crate_test.rs
1212
// xfail-stage1
1313
// xfail-fast
14+
// xfail-android
15+
// force-host
16+
17+
// You'll note that there's lots of directives above. This is a very particular
18+
// test in which we're both linking to a macro crate and loading macros from it.
19+
// This implies that both versions are the host architecture, meaning this test
20+
// must also be compiled with the host arch.
21+
//
22+
// Hence, xfail-stage1 because macros are unstable around there, xfail-fast
23+
// because this doesn't work with that test runner, xfail-android because it
24+
// can't run host binaries, and force-host to make this test build as the host
25+
// arch.
1426

1527
#[feature(phase)];
1628

0 commit comments

Comments
 (0)