Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1177599 - always pass --target to rustc; r=mshal
Browse files Browse the repository at this point in the history
rustc, unlike our typical C++ compilers, can target multiple platforms
with ease through its use of the --target flag.  To support
cross-compiling, we just need to pass the appropriate --target option.

rustc uses specific names for its accepted --target option, however, and
they are slightly different from the values we get out of autoconf.  So
in addition to checking whether rustc can accept --target for our chosen
platform, we also need to munge autoconf's idea of the target into
something rustc understands.
  • Loading branch information
froydnj committed Jan 25, 2016
1 parent b92fea3 commit 04c3e21
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
82 changes: 82 additions & 0 deletions build/autoconf/rust.m4
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,87 @@ AC_DEFUN([MOZ_RUST_SUPPORT], [
first in your path.
You can verify this by typing 'rustc --version'.])
fi
if test -n "$RUSTC" -a -n "$MOZ_RUST"; then
# Rust's --target options are similar to, but not exactly the same
# as, the autoconf-derived targets we use. An example would be that
# Rust uses distinct target triples for targetting the GNU C++ ABI
# and the MSVC C++ ABI on Win32, whereas autoconf has a single
# triple and relies on the user to ensure that everything is
# compiled for the appropriate ABI. We need to perform appropriate
# munging to get the correct option to rustc.
#
# The canonical list of targets supported can be derived from:
#
# https://github.com/rust-lang/rust/tree/master/mk/cfg
rust_target=
case "$target" in
# Linux
i*86*linux-gnu)
rust_target=i686-unknown-linux-gnu
;;
x86_64*linux-gnu)
rust_target=x86_64-unknown-linux-gnu
;;
# OS X and iOS
i*86-apple-darwin*)
rust_target=i686-apple-darwin
;;
i*86-apple-ios*)
rust_target=i386-apple-ios
;;
x86_64-apple-darwin*)
rust_target=x86_64-apple-darwin
;;
# Android
i*86*linux-android)
rust_target=i686-linux-android
;;
arm*linux-android*)
rust_target=arm-linux-androideabi
;;
# Windows
i*86-pc-mingw32)
# XXX better detection of CXX needed here, to figure out whether
# we need i686-pc-windows-gnu instead, since mingw32 builds work.
rust_target=i686-pc-windows-msvc
;;
x86_64-pc-mingw32)
# XXX and here as well
rust_target=x86_64-pc-windows-msvc
;;
*)
AC_ERROR([don't know how to translate $target for rustc])
esac
# Check to see whether we need to pass --target to RUSTC. This can
# happen when building Firefox on Windows: js's configure will receive
# a RUSTC from the toplevel configure that already has --target added to
# it.
rustc_target_arg=
case "$RUSTC" in
*--target=${rust_target}*)
;;
*)
rustc_target_arg=--target=${rust_target}
;;
esac
# Check to see whether our rustc has a reasonably functional stdlib
# for our chosen target.
echo 'pub extern fn hello() { println!("Hello world"); }' > conftest.rs
if AC_TRY_COMMAND(${RUSTC} --crate-type staticlib ${rustc_target_arg} -o conftest.rlib conftest.rs > /dev/null) && test -s conftest.rlib; then
RUSTC="${RUSTC} ${rustc_target_arg}"
else
AC_ERROR([cannot compile for ${rust_target} with ${RUSTC}])
fi
rm -f conftest.rs conftest.rlib
fi
# TODO: separate HOST_RUSTC and RUSTC variables
AC_SUBST(MOZ_RUST)
])
1 change: 0 additions & 1 deletion configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,6 @@ dnl ========================================================
if test -n "$MACOSX_DEPLOYMENT_TARGET" -a -n "$MOZ_RUST"; then
AC_MSG_CHECKING([if we're targeting 32-bit])
if test -z "$HAVE_64BIT_BUILD"; then
RUSTC="$RUSTC --target=i686-apple-darwin"
AC_MSG_RESULT([using $RUSTC])
else
AC_MSG_RESULT([no])
Expand Down

0 comments on commit 04c3e21

Please sign in to comment.