[tbb-commits] [tor-browser-build/master] Bug 25975: Get a Rust cross-compiler for macOS

gk at torproject.org gk at torproject.org
Fri May 25 06:54:56 UTC 2018


commit e7f9f6f11e45d1ba15fbbb183ef1ae8b0c3b20c5
Author: Georg Koppen <gk at torproject.org>
Date:   Fri May 25 06:53:05 2018 +0000

    Bug 25975: Get a Rust cross-compiler for macOS
---
 projects/rust/build  | 39 +++++++++++++++++++++++++++++++++++++--
 projects/rust/config | 12 +++++++++---
 2 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/projects/rust/build b/projects/rust/build
index e20df55..4c81ad8 100644
--- a/projects/rust/build
+++ b/projects/rust/build
@@ -10,10 +10,45 @@ cd /var/tmp/dist/rust-[% c('var/prev_version') %]-[% c('arch') %]-unknown-linux-
 ./install.sh --prefix=$distdir-rust-old
 export PATH="$distdir-rust-old/bin:$PATH"
 
-[% IF c("var/linux") %]
-  [% pc('gcc', 'var/setup', { compiler_tarfile => c('input_files_by_name/gcc') }) %]
+[% IF ! c("var/windows") %]
+  [% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
 [% END -%]
 
+[% IF c("var/osx") %]
+  # We need to clear `CC` and `LDFLAGS` as they are used for the host platform
+  # (i.e. Linux).
+  unset CC
+  unset LDFLAGS
+  # Target 10.6 as our toolchain does. Without this explicit declaration Bad
+  # Things will happen, as a lot of dependent code then assumes that the
+  # official macOS target, x86_64-apple-darwin, essentially means 10.4.
+  export MACOSX_DEPLOYMENT_TARGET=10.6
+  # The Rust target for macOS is x86_64-apple-darwin, yet our toolchain is built
+  # for x86_64-apple-darwin10. We can't mix those targets as clang gets confused
+  # that way. Changing the Rust target to x86_64-apple-darwin10 would require a
+  # fair amount of patching, thus we create symlinks to prvoide Rust with the
+  # necessary tools while using our toolchain underneath, targeting 10.6.
+  cd $cctoolsdir
+  for f in `ls x86_64-apple-darwin10-*`; do
+    ln -s $f ${f//x86_64-apple-darwin10/x86_64-apple-darwin}
+  done
+  cd ..
+  ln -s x86_64-apple-darwin10 x86_64-apple-darwin
+  mkdir -p $distdir/helper
+
+  # We need to adapt our CFLAGS and make sure our flags are passed down to all
+  # dependencies. Using `CFLAGS_x86_apple-darwin` did not do the trick, so resort
+  # to a wrapper script.
+  cat > $distdir/helper/x86_64-apple-darwin-clang << 'EOF'
+#!/bin/sh
+BASEDIR=/var/tmp/dist/macosx-toolchain
+$BASEDIR/cctools/bin/x86_64-apple-darwin-clang -target x86_64-apple-darwin -mlinker-version=136 -B $BASEDIR/cctools/bin -isysroot $BASEDIR/SDK/ -Wl,-syslibroot,$BASEDIR/SDK/ -Wl,-dead_strip -Wl,-pie "$@"
+EOF
+
+  chmod +x $distdir/helper/x86_64-apple-darwin-clang
+  export PATH=$distdir/helper:$PATH
+[% END %]
+
 cd $rootdir
 mkdir /var/tmp/build
 tar -C /var/tmp/build -xf  [% c('input_files_by_name/rust') %]
diff --git a/projects/rust/config b/projects/rust/config
index 49fc3ab..ae2290b 100644
--- a/projects/rust/config
+++ b/projects/rust/config
@@ -41,13 +41,19 @@ targets:
       # Rust pieces compiled.
       configure_opt: --enable-local-rust --enable-vendor --enable-extended --release-channel=stable --sysconfdir=etc --target=[% c("arch") %]-unknown-linux-gnu --set=target.[% c("arch") %]-unknown-linux-gnu.cc=gcc
 
+  osx-x86_64:
+    var:
+      arch_deps:
+        - libssl-dev
+        - pkg-config
+      configure_opt: --enable-local-rust --enable-vendor --enable-extended --release-channel=stable --sysconfdir=etc --target=x86_64-apple-darwin --set=target.x86_64-apple-darwin.cc=x86_64-apple-darwin-clang
+
 input_files:
   - project: container-image
   - project: cmake
     name: cmake
-  - project: gcc
-    name: gcc
-    enable: '[% c("var/linux") %]'
+  - project: '[% c("var/compiler") %]'
+    name: '[% c("var/compiler") %]'
   - URL: 'https://static.rust-lang.org/dist/rustc-[% c("version") %]-src.tar.gz'
     name: rust
     sig_ext: asc



More information about the tbb-commits mailing list