Skip to content

Commit 74508d6

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 74508d6

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

mk/target.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_RUSTLLVM_$(3)): \
6262
@$$(call E, cp: $$@)
6363
$$(Q)cp $$< $$@
6464

65+
# This is the compile-time target-triple for the compiler. For the compiler at
66+
# runtime, this should be considered the host-triple. More explanation for why
67+
# this exists can be found on issue #2400
68+
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(3)): export CFG_COMPILER_TRIPLE := $(2)
6569
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(3)): \
6670
$$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
6771
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBSYNTAX_$(3)) \

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)