commit 5be41831b52795ee87c57cdbd18da68bf73fe1cc
Author: Georg Koppen <g...@torproject.org>
Date:   Fri Apr 13 14:29:20 2018 +0000

    Bug 25481: Enable rust support in Linux nightlies
    
    We enable Rust support for tor in our Linux nightly builds as a first
    step to enabling it on all supported platforms.
---
 keyring/rust.gpg             | Bin 0 -> 5311 bytes
 projects/cmake/config        |   2 +-
 projects/rust/binaryen.patch |  22 +++++++++++++++
 projects/rust/build          |  38 ++++++++++++++++++++++++++
 projects/rust/config         |  62 +++++++++++++++++++++++++++++++++++++++++++
 projects/tor/build           |   8 ++++--
 projects/tor/config          |   4 +++
 7 files changed, 133 insertions(+), 3 deletions(-)

diff --git a/keyring/rust.gpg b/keyring/rust.gpg
new file mode 100644
index 0000000..e81f452
Binary files /dev/null and b/keyring/rust.gpg differ
diff --git a/projects/cmake/config b/projects/cmake/config
index 357370d..492b99c 100644
--- a/projects/cmake/config
+++ b/projects/cmake/config
@@ -1,5 +1,5 @@
 # vim: filetype=yaml sw=2
-version: 2.8.12.2
+version: 3.4.3
 git_url: https://cmake.org/cmake.git
 git_hash: 'v[% c("version") %]'
 tag_gpg_id: 1
diff --git a/projects/rust/binaryen.patch b/projects/rust/binaryen.patch
new file mode 100644
index 0000000..fee9b6a
--- /dev/null
+++ b/projects/rust/binaryen.patch
@@ -0,0 +1,22 @@
+From 820f26810baf35c1961763f6b0013e4f7e7380da Mon Sep 17 00:00:00 2001
+From: Georg Koppen <g...@torproject.org>
+Date: Thu, 12 Apr 2018 13:10:13 +0000
+Subject: [PATCH] Use our gcc/c++
+
+
+diff --git a/src/librustc_binaryen/build.rs b/src/librustc_binaryen/build.rs
+index f23ff3cee5..2496dd1be9 100644
+--- a/src/librustc_binaryen/build.rs
++++ b/src/librustc_binaryen/build.rs
+@@ -26,6 +26,8 @@ fn main() {
+ 
+     Config::new("../binaryen")
+         .define("BUILD_STATIC_LIB", "ON")
++        .define("CMAKE_C_COMPILER", "gcc")
++        .define("CMAKE_CXX_COMPILER", "c++")
+         .build_target("binaryen")
+         .build();
+ 
+-- 
+2.16.3
+
diff --git a/projects/rust/build b/projects/rust/build
new file mode 100644
index 0000000..e20df55
--- /dev/null
+++ b/projects/rust/build
@@ -0,0 +1,38 @@
+#!/bin/bash
+[% c('var/setarch') %]
+[% c("var/set_default_env") -%]
+distdir=/var/tmp/dist/[% project %]
+mkdir -p /var/tmp/dist
+tar -C /var/tmp/dist -xf [% c('input_files_by_name/cmake') %]
+export PATH="/var/tmp/dist/cmake/bin:$PATH"
+tar -C /var/tmp/dist -xf [% c('input_files_by_name/prev_rust') %]
+cd /var/tmp/dist/rust-[% c('var/prev_version') %]-[% c('arch') 
%]-unknown-linux-gnu
+./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') 
}) %]
+[% END -%]
+
+cd $rootdir
+mkdir /var/tmp/build
+tar -C /var/tmp/build -xf  [% c('input_files_by_name/rust') %]
+cd /var/tmp/build/rustc-[% c('version') %]-src
+
+[% IF c("var/linux") %]
+  # binaryen hardcodes /usr/bin/cc and /usr/bin/c++ as the C and C++ compiler.
+  # But that is too old on Debian Wheezy which is why we need to patch it, so
+  # we can use our own GCC instead.
+  patch -p1 < $rootdir/binaryen.patch
+[% END %]
+
+mkdir build
+cd build
+../configure --prefix=$distdir [% c("var/configure_opt") %]
+make -j[% c("buildconf/num_procs") %]
+make install
+cd /var/tmp/dist
+[% c('tar', {
+        tar_src => [ project ],
+        tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
+        }) %]
diff --git a/projects/rust/config b/projects/rust/config
new file mode 100644
index 0000000..49fc3ab
--- /dev/null
+++ b/projects/rust/config
@@ -0,0 +1,62 @@
+# vim: filetype=yaml sw=2
+filename: '[% project %]-[% c("version") %]-[% c("var/osname") %]-[% 
c("var/build_id") %].tar.gz'
+version: 1.25.0
+var:
+  prev_version: 1.24.1
+  container:
+    use_container: 1
+
+targets:
+  linux:
+    var:
+      arch_deps:
+        - hardening-wrapper
+        - libssl-dev
+        - pkg-config
+      # We use
+      # `--enable-local-rust` to avoid downloading the required compiler during
+      # build time
+      #
+      # `--enable-vendor` to avoid downloading crates during build time and 
just
+      # use the ones which are shipped with the source
+      #
+      # `--enable-extended` to build not only rustc but cargo as well
+      #
+      # `--release-channel=stable` to just include stable features in the
+      # compiler
+      #
+      # `--sysconfdir=etc` to avoid install failures as |make install| wants to
+      # write to /etc otherwise
+      #
+      # the `target` triple to explicitly specify the architecture and platform
+      # for the compiler/std lib. Ideally, it should not be needed unless one 
is
+      # cross-compiling, but compiling `alloc_jemalloc` fails without that in a
+      # 32bit container. "--host=x86_64-unknown-linux-gnu" is used in its
+      # configure script in this case.
+      # `--set=` to explicitly specify the C compiler. We need to compile the
+      # bundled LLVM and it wants to use `cc`. However, we don't have that in
+      # our compiled GCC resulting in weird errors due to C and C++ compiler
+      # version mismatch. We avoid that with this configure option. We need to
+      # build our own GCC in the first place as 4.7.2 is too old to get all the
+      # 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
+
+input_files:
+  - project: container-image
+  - project: cmake
+    name: cmake
+  - project: gcc
+    name: gcc
+    enable: '[% c("var/linux") %]'
+  - URL: 'https://static.rust-lang.org/dist/rustc-[% c("version") 
%]-src.tar.gz'
+    name: rust
+    sig_ext: asc
+    file_gpg_id: 1
+    gpg_keyring: rust.gpg
+  - URL: 'https://static.rust-lang.org/dist/rust-[% c("var/prev_version") 
%]-[% c("arch") %]-unknown-linux-gnu.tar.xz'
+    name: prev_rust
+    sig_ext: asc
+    file_gpg_id: 1
+    gpg_keyring: rust.gpg
+  - filename: binaryen.patch
+    enable: '[% c("var/linux") %]'
diff --git a/projects/tor/build b/projects/tor/build
index e52e43b..bf7db83 100644
--- a/projects/tor/build
+++ b/projects/tor/build
@@ -20,6 +20,10 @@ mkdir -p /var/tmp/build
 
 tar -C /var/tmp/dist -xf [% c('input_files_by_name/openssl') %]
 tar -C /var/tmp/dist -xf [% c('input_files_by_name/libevent') %]
+[% IF c("var/linux") && c("var/nightly") %]
+  tar -C /var/tmp/dist -xf [% c('input_files_by_name/rust') %]
+  export PATH=/var/tmp/dist/rust/bin:$PATH
+[% END %]
 tar -C /var/tmp/build -xf [% project %]-[% c('version') %].tar.gz
 libeventdir=/var/tmp/dist/libevent
 openssldir=/var/tmp/dist/openssl
@@ -31,7 +35,6 @@ openssldir=/var/tmp/dist/openssl
       $gcclibs/*.dll $distdir/Tor/
 [% END %]
 
-
 [% IF c("var/linux") %]
   mkdir -p "$distdir/Debug/Tor"
   cp $openssldir/lib/libssl.so.1.0.0 "$distdir/Tor/"
@@ -62,10 +65,11 @@ cd /var/tmp/build/[% project %]-[% c('version') %]
 echo '"[% c("abbrev", { abbrev_length => 16 }) %]"' > micro-revision.i
 ./autogen.sh
 find -type f -print0 | xargs -0 [% c("var/touch") %]
-./configure --disable-asciidoc --with-libevent-dir="$libeventdir" 
--with-openssl-dir="$openssldir" \
+[% IF c("var/linux") && c("var/nightly") 
%]TOR_RUST_DEPENDENCIES=`pwd`/src/ext/rust/crates[% END %] ./configure 
--disable-asciidoc --with-libevent-dir="$libeventdir" 
--with-openssl-dir="$openssldir" \
     [% IF c("var/asan") %]--enable-fragile-hardening[% END %] \
     [% IF c("var/windows") %]--with-zlib-dir="$zlibdir"[% END %] \
     [% IF c("var/osx") %]--enable-static-openssl[% END %] \
+    [% IF c("var/linux") && c("var/nightly") %]--enable-rust[% END %] \
     --prefix="$distdir" [% c("var/configure_opt") %]
 [% IF c("var/osx") || c("var/windows") -%]
   export LD_PRELOAD=[% c("var/faketime_path") %]
diff --git a/projects/tor/config b/projects/tor/config
index e650b6e..7029880 100644
--- a/projects/tor/config
+++ b/projects/tor/config
@@ -3,6 +3,7 @@ filename: '[% project %]-[% c("version") %]-[% c("var/osname") 
%]-[% c("var/buil
 version: 0.3.3.3-alpha
 git_hash: 'tor-[% c("version") %]'
 git_url: https://git.torproject.org/tor.git
+git_submodule: 1
 gpg_keyring: tor.gpg
 tag_gpg_id: 1
 
@@ -57,3 +58,6 @@ input_files:
     enable: '[% c("var/windows") %]'
   - name: '[% c("var/compiler") %]'
     project: '[% c("var/compiler") %]'
+  - name: rust
+    project: rust
+    enable: '[% c("var/linux") && c("var/nightly") %]'

_______________________________________________
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to