Bug 1181441 - Configure check for no-tls rust toolchain. r=ted
authorRalph Giles <giles@mozilla.com>
Tue, 07 Jul 2015 15:14:53 -0700
changeset 253194 74244131ca06df5c95f0461bfde1d6008faca321
parent 253193 7bdacc3df33dd96c63c183bb5b798b1e1d3b06a3
child 253195 93790126b8516fdd7e768ffc0f9b44c38826e528
push id14068
push userryanvm@gmail.com
push dateThu, 16 Jul 2015 20:23:33 +0000
treeherderfx-team@2f46831a7b7b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs1181441
milestone42.0a1
Bug 1181441 - Configure check for no-tls rust toolchain. r=ted By default the rust standard library uses linker-assisted thread-local storage, which isn't supported on MacOS X 10.6. If we're targetting that version make sure we can link code built with $RUSTC. If so it's presumedly been built with alternate support.
configure.in
--- a/configure.in
+++ b/configure.in
@@ -471,26 +471,46 @@ esac
 
 AC_SUBST(MACOSX_DEPLOYMENT_TARGET)
 
 dnl ========================================================
 dnl Special MacOS X checks
 dnl ========================================================
 
 if test -n "$MACOSX_DEPLOYMENT_TARGET" -a -n "$MOZ_RUST"; then
-  AC_MSG_CHECKING([MacOS X compatibility with rust])
-  # rustc doesn't support MacOS X 10.6 or earlier.
+  AC_MSG_CHECKING([rustc compatibility with MacOS X])
+  # Stock rustc doesn't support MacOS X 10.6 or earlier.
   # https://github.com/rust-lang/rust/issues/25342
   _MACOSX_TARGET_MINOR=`echo "$MACOSX_DEPLOYMENT_TARGET" | cut -d. -f2`
   if test "$_MACOSX_TARGET_MINOR" -lt 7; then
+    dnl Test C linkage against rust code to see if the rust
+    dnl toolchain output is compatible.
+    cat > conftest.rs <<EOF
+      [#[no_mangle]]
+      pub extern fn rusty_answer() -> u8 { 42 }
+EOF
+    ac_try="$RUSTC --crate-type staticlib -o conftest.a conftest.rs >/dev/null"
+    AC_TRY_EVAL(ac_try)
+    save_LDFLAGS=$LDFLAGS
+    LDFLAGS="$LDFLAGS conftest.a -lpthread -lm"
+    AC_TRY_LINK_FUNC([rusty_answer], [
+      AC_MSG_RESULT([$MACOSX_DEPLOYMENT_TARGET is ok with this rustc])
+    ], [
+      AC_MSG_RESULT([cannot link on $MACOSX_DEPLOYMENT_TARGET])
+      MOZ_RUST=
+    ])
+    LDFLAGS=$save_LDFLAGS
+    rm -rf conftest*
+  else
+    AC_MSG_RESULT([$MACOSX_DEPLOYMENT_TARGET is ok])
+  fi
+  if test -z "$MOZ_RUST"; then
     AC_MSG_ERROR([rustc does not support MacOS X $MACOSX_DEPLOYMENT_TARGET
       Add 'ac_add_options --enable-macos-target=10.7' (or later)
-      to mozconfig, or disable rust support.])
-  else
-    AC_MSG_RESULT([$MACOSX_DEPLOYMENT_TARGET is ok])
+      to mozconfig, disable rust support, or use an alternate toolchain.])
   fi
 fi
 
 dnl ========================================================
 dnl Special win32 checks
 dnl ========================================================
 
 # Target the Windows 8.1 SDK by default