Add native support for linux on ARM Cpu (32 bits)

--
Change-Id: Ia70ca1b8482e10bc1ac91799aa238f8613e5c824
Reviewed-on: https://bazel-review.googlesource.com/#/c/1801
MOS_MIGRATED_REVID=100476467
diff --git a/scripts/bootstrap/buildenv.sh b/scripts/bootstrap/buildenv.sh
index 336785d..ab4dbea 100755
--- a/scripts/bootstrap/buildenv.sh
+++ b/scripts/bootstrap/buildenv.sh
@@ -31,6 +31,11 @@
   MACHINE_IS_64BIT='yes'
 fi
 
+MACHINE_IS_ARM='no'
+if [ "${MACHINE_TYPE}" = 'arm' -o "${MACHINE_TYPE}" = 'armv7l' ]; then
+  MACHINE_IS_ARM='yes'
+fi
+
 ATEXIT_=""
 function atexit() {
   ATEXIT_="$1; ${ATEXIT_}"
diff --git a/scripts/bootstrap/compile.sh b/scripts/bootstrap/compile.sh
index 3db29f7..cd7a5b3 100755
--- a/scripts/bootstrap/compile.sh
+++ b/scripts/bootstrap/compile.sh
@@ -93,7 +93,11 @@
   if [ "${MACHINE_IS_64BIT}" = 'yes' ]; then
     PROTOC=${PROTOC:-third_party/protobuf/protoc-linux-x86_64.exe}
   else
-    PROTOC=${PROTOC:-third_party/protobuf/protoc-linux-x86_32.exe}
+    if [ "${MACHINE_IS_ARM}" = 'yes' ]; then
+      PROTOC=${PROTOC:-third_party/protobuf/protoc-linux-arm32.exe}
+    else
+      PROTOC=${PROTOC:-third_party/protobuf/protoc-linux-x86_32.exe}
+    fi
   fi
   ;;
 
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java
index b2e9f1a..8b526ff 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java
@@ -405,6 +405,8 @@
                 return "piii";
               case X86_64:
                 return "k8";
+              case ARM:
+                return "arm";
             }
         }
         return "unknown";
diff --git a/src/main/java/com/google/devtools/build/lib/util/CPU.java b/src/main/java/com/google/devtools/build/lib/util/CPU.java
index fd54ddd..0bfce8a 100644
--- a/src/main/java/com/google/devtools/build/lib/util/CPU.java
+++ b/src/main/java/com/google/devtools/build/lib/util/CPU.java
@@ -23,6 +23,7 @@
 public enum CPU {
   X86_32("x86_32", ImmutableSet.of("i386", "i486", "i586", "i686", "i786", "x86")),
   X86_64("x86_64", ImmutableSet.of("amd64", "x86_64", "x64")),
+  ARM("arm", ImmutableSet.of("arm", "armv7l")),
   UNKNOWN("unknown", ImmutableSet.<String>of());
 
   private final String canonicalName;
diff --git a/third_party/BUILD b/third_party/BUILD
index fd44a9c..5c59287 100644
--- a/third_party/BUILD
+++ b/third_party/BUILD
@@ -14,6 +14,7 @@
         ":darwin": ["protobuf/protoc-osx-x86_32.exe"],
         ":k8": ["protobuf/protoc-linux-x86_64.exe"],
         ":piii": ["protobuf/protoc-linux-x86_32.exe"],
+        ":arm": ["protobuf/protoc-linux-arm32.exe"],
     }),
 )
 
@@ -369,3 +370,8 @@
     name = "piii",
     values = {"host_cpu": "piii"},
 )
+
+config_setting(
+    name = "arm",
+    values = {"host_cpu": "arm"},
+)
diff --git a/third_party/protobuf/README.md b/third_party/protobuf/README.md
index c46cf4a..8e200e7d 100644
--- a/third_party/protobuf/README.md
+++ b/third_party/protobuf/README.md
@@ -9,3 +9,14 @@
 7. Update third_party/BUILD to point to the new jar file.
 8. Done.
 
+
+Because maven.org doesn't have a prebuilt binary for linux on ARM, you need to build the binary
+yourself on the target system. Follow the build steps of protocol buffer to create the binary,
+copy it to this directory and rename it to "protoc-linux-arm32.exe".
+
+For example:
+
+$ cp /usr/bin/protoc $BAZEL/third_party/protobuf/protoc-linux-arm32.exe
+
+This should be done before you run ./compile.sh.
+
diff --git a/tools/cpp/CROSSTOOL b/tools/cpp/CROSSTOOL
index 25368e9..86442c9 100644
--- a/tools/cpp/CROSSTOOL
+++ b/tools/cpp/CROSSTOOL
@@ -18,6 +18,44 @@
   cpu: "armeabi-v7a"
   toolchain_identifier: "stub_armeabi-v7a"
 }
+default_toolchain {
+  cpu: "arm"
+  toolchain_identifier: "local_linux"
+}
+
+toolchain {
+  abi_version: "arm"
+  abi_libc_version: "armeabi-v7a"
+  builtin_sysroot: ""
+  compiler: "compiler"
+  host_system_name: "armeabi-v7a"
+  needsPic: true
+  supports_gold_linker: false
+  supports_incremental_linker: false
+  supports_fission: false
+  supports_interface_shared_objects: false
+  supports_normalizing_ar: false
+  supports_start_end_lib: false
+  supports_thin_archives: false
+  target_libc: "armeabi-v7a"
+  target_cpu: "armeabi-v7a"
+  target_system_name: "armeabi-v7a"
+  toolchain_identifier: "stub_armeabi-v7a"
+
+  tool_path { name: "ar" path: "/bin/false" }
+  tool_path { name: "compat-ld" path: "/bin/false" }
+  tool_path { name: "cpp" path: "/bin/false" }
+  tool_path { name: "dwp" path: "/bin/false" }
+  tool_path { name: "gcc" path: "/bin/false" }
+  tool_path { name: "gcov" path: "/bin/false" }
+  tool_path { name: "ld" path: "/bin/false" }
+
+  tool_path { name: "nm" path: "/bin/false" }
+  tool_path { name: "objcopy" path: "/bin/false" }
+  tool_path { name: "objdump" path: "/bin/false" }
+  tool_path { name: "strip" path: "/bin/false" }
+}
+
 
 toolchain {
   abi_version: "armeabi-v7a"