Upgrade to a new Bazel version

This one has better performance and various new features. It also
prevents us from falling too far behind upstream.

Change-Id: I3b8e1c5bda886ea2e990523af9e6de2434c784be
diff --git a/tools/bazel b/tools/bazel
index 415aeff..f6f4c52 100755
--- a/tools/bazel
+++ b/tools/bazel
@@ -24,7 +24,7 @@
   exec "${BAZEL_OVERRIDE}" "$@"
 fi
 
-readonly VERSION="201607070016+7a0d360"
+readonly VERSION="201701021712+4964f2c"
 
 readonly DOWNLOAD_DIR="$(dirname "${BASH_SOURCE[0]}")/../bazel-downloads"
 # Directory to unpack bazel into.  This must change whenever bazel changes.
diff --git a/tools/bazel.rc b/tools/bazel.rc
index 7df645e..7530102 100644
--- a/tools/bazel.rc
+++ b/tools/bazel.rc
@@ -46,3 +46,5 @@
 build --show_result 5
 # Dump the output of the failing test to stdout.
 test --test_output=errors
+
+build --experimental_sandbox_shm
diff --git a/tools/build_rules/fortran.bzl b/tools/build_rules/fortran.bzl
index f8d0add..2d6e4db 100644
--- a/tools/build_rules/fortran.bzl
+++ b/tools/build_rules/fortran.bzl
@@ -36,11 +36,11 @@
     progress_message = 'Building %s' % ctx.outputs.pic_o.short_path,
   )
 
-def _define_fortran_output(attrs):
-  if not attrs.src.name.endswith('.f'):
+def _define_fortran_output(src):
+  if not src.name.endswith('.f'):
     fail('Fortran files must end in \'.f\'', 'src')
 
-  fortran_file_base = attrs.src.name[:-2]
+  fortran_file_base = src.name[:-2]
   return {
     'pic_o': fortran_file_base + '.pic.o',
   }
diff --git a/tools/build_rules/protobuf.bzl b/tools/build_rules/protobuf.bzl
index fe6af4f..d5f4284 100644
--- a/tools/build_rules/protobuf.bzl
+++ b/tools/build_rules/protobuf.bzl
@@ -19,8 +19,8 @@
     ],
   )
 
-def _do_proto_cc_library_outputs(attr):
-  basename = attr.src.name[:-len('.proto')]
+def _do_proto_cc_library_outputs(src):
+  basename = src.name[:-len('.proto')]
   return {
     'pb_h': '%s.pb.h' % basename,
     'pb_cc': '%s.pb.cc' % basename,
@@ -37,7 +37,7 @@
     '_protoc': attr.label(
       default = Label('//third_party/protobuf:protoc'),
       executable = True,
-      cfg = HOST_CFG,
+      cfg = 'host',
     ),
     '_well_known_protos': attr.label(
       default = Label('//third_party/protobuf:well_known_protos'),
diff --git a/tools/build_rules/ruby.bzl b/tools/build_rules/ruby.bzl
index 7c02745..2c93596 100644
--- a/tools/build_rules/ruby.bzl
+++ b/tools/build_rules/ruby.bzl
@@ -51,7 +51,7 @@
   ),
   'data': attr.label_list(
     allow_files = True,
-    cfg = DATA_CFG,
+    cfg = 'data',
   ),
 }
 
@@ -84,6 +84,7 @@
   attrs = _ruby_attrs + {
     '_ruby_linker': attr.label(
       executable = True,
+      cfg = 'host',
       default = Label('//tools/ruby:standalone_ruby'),
     )
   },
diff --git a/tools/cpp/BUILD b/tools/cpp/BUILD
index 40e674f..053b0e4 100644
--- a/tools/cpp/BUILD
+++ b/tools/cpp/BUILD
@@ -23,27 +23,13 @@
   srcs = [],
 )
 
-# This is the entry point for --crosstool_top.  Toolchains are found
-# by lopping off the name of --crosstool_top and searching for
-# 'cc-compiler-${CPU}' in this BUILD file, where CPU is the target CPU
-# specified in --cpu.
-#
-# This file group should include
-#   * all cc_toolchain targets supported
-#   * all file groups that said cc_toolchain might refer to,
-# including the default_grte_top setting in the CROSSTOOL
-# protobuf.
-filegroup(
+# This is the entry point for --crosstool_top.
+cc_toolchain_suite(
   name = 'toolchain',
-  srcs = [
-    ':cc-compiler-k8',
-    ':cc-compiler-roborio',
-    '@arm_frc_linux_gnueabi_repo//:compiler_components',
-    ':roborio-compiler-files',
-    ':flags_compiler_inputs',
-    '@linaro_linux_gcc_4_9_repo//:compiler_components',
-    ':linaro-gcc-files',
-  ],
+  toolchains = {
+    'k8|clang': ':cc-compiler-k8',
+    'roborio|gcc': ':cc-compiler-roborio',
+  },
 )
 
 # Compiler inputs given by --copt etc in //tools:bazel.rc.
@@ -90,6 +76,7 @@
     '//tools/cpp/arm-frc-linux-gnueabi:ld',
     '//tools/cpp/arm-frc-linux-gnueabi:ar',
     '//tools/cpp/arm-frc-linux-gnueabi:gcc',
+    '//tools/cpp/arm-frc-linux-gnueabi:libs',
     '@arm_frc_linux_gnueabi_repo//:compiler_pieces',
   ],
 )
@@ -98,6 +85,8 @@
   srcs = [
     '//tools/cpp/arm-frc-linux-gnueabi:gcc',
     '//tools/cpp/arm-frc-linux-gnueabi:ld',
+    '@arm_frc_linux_gnueabi_repo//:compiler_components',
+    '@arm_frc_linux_gnueabi_repo//:compiler_pieces',
   ],
 )
 
diff --git a/tools/cpp/CROSSTOOL b/tools/cpp/CROSSTOOL
index 96fb1b9..5a374af 100644
--- a/tools/cpp/CROSSTOOL
+++ b/tools/cpp/CROSSTOOL
@@ -351,7 +351,7 @@
   cxx_builtin_include_directory: "%package(@arm_frc_linux_gnueabi_repo//usr/arm-frc-linux-gnueabi/usr/include)%"
 
   linker_flag: "-lstdc++"
-  #linker_flag: "-B/usr/bin/"
+  linker_flag: "-Ltools/cpp/arm-frc-linux-gnueabi/libs"
 
   feature {
     name: "opt"
diff --git a/tools/cpp/arm-frc-linux-gnueabi/BUILD b/tools/cpp/arm-frc-linux-gnueabi/BUILD
index 17a10c2..95000c3 100644
--- a/tools/cpp/arm-frc-linux-gnueabi/BUILD
+++ b/tools/cpp/arm-frc-linux-gnueabi/BUILD
@@ -77,3 +77,10 @@
     ':strip',
   ],
 )
+
+filegroup(
+  name = 'libs',
+  srcs = glob([
+    'libs/**',
+  ]),
+)