Skip to content

Commit ff86830

Browse files
committed
Define rustc's host triple at compile time
This way a cross-compiled rustc's answer to host_triple() is correct. The return value of host_triple() reflects the actual host triple that the compiler was build for, not the triple the compiler is being built on
1 parent 5f90f1c commit ff86830

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

mk/target.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
# option. This file may not be copied, modified, or distributed
99
# except according to those terms.
1010

11+
# This is the compile-time target-triple for the compiler. For the compiler at
12+
# runtime, this should be considered the host-triple. More explanation for why
13+
# this exists can be found on issue #2400
14+
export CFG_COMPILER_TRIPLE
15+
1116
# TARGET_STAGE_N template: This defines how target artifacts are built
1217
# for all stage/target architecture combinations. The arguments:
1318
# $(1) is the stage
@@ -62,6 +67,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_RUSTLLVM_$(3)): \
6267
@$$(call E, cp: $$@)
6368
$$(Q)cp $$< $$@
6469

70+
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(3)): CFG_COMPILER_TRIPLE = $(2)
6571
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(3)): \
6672
$$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
6773
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBSYNTAX_$(3)) \

mk/tests.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ $(3)/stage$(1)/test/syntaxtest-$(2)$$(X_$(2)): \
307307
@$$(call E, compile_and_link: $$@)
308308
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
309309

310+
$(3)/stage$(1)/test/rustctest-$(2)$$(X_$(2)): CFG_COMPILER_TRIPLE = $(2)
310311
$(3)/stage$(1)/test/rustctest-$(2)$$(X_$(2)): \
311312
$$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
312313
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUSTLLVM_$(2)) \

src/librustc/driver/driver.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -516,15 +516,15 @@ pub fn host_triple() -> ~str {
516516
// idea of the host triple is the same as for the set of libraries we've
517517
// actually built. We can't just take LLVM's host triple because they
518518
// normalize all ix86 architectures to i386.
519-
520-
// FIXME (#2400): Instead of grabbing the host triple we really should
521-
// be grabbing (at compile time) the target triple that this rustc is
522-
// built with and calling that (at runtime) the host triple.
523-
let ht = env!("CFG_BUILD_TRIPLE");
519+
//
520+
// Instead of grabbing the host triple (for the current host), we grab (at
521+
// compile time) the target triple that this rustc is built with and
522+
// calling that (at runtime) the host triple.
523+
let ht = env!("CFG_COMPILER_TRIPLE");
524524
return if ht != ~"" {
525525
ht
526526
} else {
527-
fail!("rustc built without CFG_BUILD_TRIPLE")
527+
fail!("rustc built without CFG_COMPILER_TRIPLE")
528528
};
529529
}
530530

@@ -534,15 +534,15 @@ pub fn host_triple() -> ~str {
534534
// idea of the host triple is the same as for the set of libraries we've
535535
// actually built. We can't just take LLVM's host triple because they
536536
// normalize all ix86 architectures to i386.
537-
538-
// FIXME (#2400): Instead of grabbing the host triple we really should
539-
// be grabbing (at compile time) the target triple that this rustc is
540-
// built with and calling that (at runtime) the host triple.
541-
let ht = env!("CFG_BUILD_TRIPLE");
537+
//
538+
// Instead of grabbing the host triple (for the current host), we grab (at
539+
// compile time) the target triple that this rustc is built with and
540+
// calling that (at runtime) the host triple.
541+
let ht = env!("CFG_COMPILER_TRIPLE");
542542
return if ht != "" {
543543
ht.to_owned()
544544
} else {
545-
fail!("rustc built without CFG_BUILD_TRIPLE")
545+
fail!("rustc built without CFG_COMPILER_TRIPLE")
546546
};
547547
}
548548

0 commit comments

Comments
 (0)