Enable Bazel build for ppc and arm.

External portion of internal cl/150002340.

NOTRY=true

Change-Id: Ic42ccd80bd26546b523fbdde058d8b0ee29d65f5
Reviewed-on: https://skia-review.googlesource.com/9821
Reviewed-by: Ben Wagner <benjaminwagner@google.com>
Commit-Queue: Ben Wagner <benjaminwagner@google.com>
diff --git a/public.bzl b/public.bzl
index 4fb2061..b2a3534 100644
--- a/public.bzl
+++ b/public.bzl
@@ -52,34 +52,16 @@
   return []
 
 ################################################################################
-## PRIVATE_HDRS
-################################################################################
-
-PRIVATE_HDRS_INCLUDE_LIST = [
-    "include/private/**/*.h",
-    "src/**/*.inc",
-]
-
-PRIVATE_HDRS = struct(
-    include = PRIVATE_HDRS_INCLUDE_LIST,
-)
-
-ALL_HDRS = struct(
-    include = [
-        "src/**/*.h",
-        "include/**/*.h",
-    ],
-)
-
-################################################################################
 ## BASE_SRCS
 ################################################################################
 
 # All platform-independent SRCS.
 BASE_SRCS_ALL = struct(
     include = [
+        "include/private/**/*.h",
         "src/**/*.h",
         "src/**/*.cpp",
+        "src/**/*.inc",
 
         # Third Party
         "third_party/etc1/*.cpp",
@@ -87,10 +69,7 @@
         "third_party/gif/*.cpp",
         "third_party/gif/*.h",
     ],
-    # Note: PRIVATE_HDRS_INCLUDE_LIST is excluded from BASE_SRCS_ALL here
-    # because they are required to appear in srcs for some rules but hdrs for
-    # other rules. See internal cl/119566959.
-    exclude = PRIVATE_HDRS_INCLUDE_LIST + [
+    exclude = [
         # Exclude platform-dependent files.
         "src/android/*",
         "src/codec/*",
@@ -154,10 +133,14 @@
         "src/ports/**/*.h",
     ],
     exclude = [
+        "src/opts/opts_check_x86.cpp",
         "src/opts/*arm*",
         "src/opts/*mips*",
         "src/opts/*NEON*",
         "src/opts/*neon*",
+        # Included in :opts_sse2 library.
+        "src/opts/*SSE2*",
+        "src/opts/*sse2*",
         # Included in :opts_ssse3 library.
         "src/opts/*SSSE3*",
         "src/opts/*ssse3*",
@@ -293,65 +276,137 @@
 )
 
 ################################################################################
-## SSSE3/SSE4/AVX/HSW SRCS
+## skia_{all,public}_hdrs()
 ################################################################################
+def skia_all_hdrs():
+  return native.glob(["src/**/*.h", "include/**/*.h"])
 
-SSSE3_SRCS = struct(
-    include = [
+def skia_public_hdrs():
+  return native.glob(["include/**/*.h"],
+                     exclude=[
+                         "include/private/**/*.h",
+                         "include/views/**/*",  # Not used.
+                     ])
+
+################################################################################
+## skia_opts_srcs()
+################################################################################
+# Intel
+SKIA_OPTS_SSE2 = "SSE2"
+
+SKIA_OPTS_SSSE3 = "SSSE3"
+
+SKIA_OPTS_SSE4 = "SSE4"
+
+SKIA_OPTS_AVX = "AVX"
+
+SKIA_OPTS_HSW = "HSW"
+
+# Arm
+SKIA_OPTS_ARMV7 = "ARMV7"
+
+SKIA_OPTS_NEON = "NEON"
+
+SKIA_OPTS_ARM64 = "ARM64"
+
+SKIA_OPTS_CRC32 = "CRC32"  # arm64
+
+# Other
+SKIA_OPTS_NONE = "NONE"  # not x86, arm, or arm64
+
+def skia_opts_srcs(opts):
+  if opts == SKIA_OPTS_SSE2:
+    return native.glob([
+        "src/opts/*SSE2*.cpp",
+        "src/opts/*sse2*.cpp",
+    ])
+  elif opts == SKIA_OPTS_SSSE3:
+    return native.glob([
         "src/opts/*SSSE3*.cpp",
         "src/opts/*ssse3*.cpp",
-    ],
-)
-
-SSE4_SRCS = struct(
-    include = [
+    ])
+  elif opts == SKIA_OPTS_SSE4:
+    return native.glob([
         "src/opts/*SSE4*.cpp",
         "src/opts/*sse4*.cpp",
-    ],
-)
-
-AVX_SRCS = struct(
-    include = [
+    ])
+  elif opts == SKIA_OPTS_AVX:
+    return native.glob([
         "src/opts/*_avx.cpp",
-    ],
-)
-
-HSW_SRCS = struct(
-    include = [
+    ])
+  elif opts == SKIA_OPTS_HSW:
+    return native.glob([
         "src/opts/*_hsw.cpp",
-    ],
-)
+    ])
+  elif opts == SKIA_OPTS_ARMV7:
+    return native.glob([
+        "src/opts/*_arm.cpp",
+    ])
+  elif opts == SKIA_OPTS_NEON:
+    return native.glob([
+        "src/opts/*_neon.cpp",
+    ])
+  elif opts == SKIA_OPTS_CRC32:
+    return native.glob([
+        "src/opts/*_crc32.cpp",
+    ])
+  elif opts == SKIA_OPTS_NONE:
+    return native.glob([
+        "src/opts/*_none.cpp",
+    ])
+  else:
+    fail("skia_opts_srcs parameter 'opts' must be one of SKIA_OPTS_*.")
+
+def skia_opts_cflags(opts):
+  if opts == SKIA_OPTS_SSE2:
+    return ["-msse2"]
+  elif opts == SKIA_OPTS_SSSE3:
+    return ["-mssse3"]
+  elif opts == SKIA_OPTS_SSE4:
+    return ["-msse4"]
+  elif opts == SKIA_OPTS_AVX:
+    return ["-mavx"]
+  elif opts == SKIA_OPTS_HSW:
+    return ["-mavx2", "-mbmi", "-mbmi2", "-mf16c", "-mfma"]
+  elif opts == SKIA_OPTS_CRC32:
+    return ["-march=armv8-a+crc"]
+  else:
+    return []
 
 ################################################################################
-## BASE_HDRS
+## skia_srcs()
 ################################################################################
+SKIA_OS_UNIX = "UNIX"
 
-BASE_HDRS = struct(
-    include = [
-        "include/**/*.h",
-    ],
-    exclude = PRIVATE_HDRS_INCLUDE_LIST + [
-        # Not used.
-        "include/views/**/*",
-    ],
-)
+SKIA_OS_ANDROID = "ANDROID"
 
-################################################################################
-## BASE_DEPS
-################################################################################
+SKIA_OS_IOS = "IOS"
 
-BASE_DEPS_ALL = []
+SKIA_CPU_UNSPECIFIED = "UNSPECIFIED"
 
-BASE_DEPS_UNIX = [
-    ":opts_ssse3",
-    ":opts_sse4",
-    ":opts_avx",
-    ":opts_hsw",
-]
+SKIA_CPU_PPC = "PPC"
 
-BASE_DEPS_ANDROID = []
-
-BASE_DEPS_IOS = []
+def skia_srcs(os=SKIA_OS_UNIX, cpu=SKIA_CPU_UNSPECIFIED):
+  """Sources to be compiled into the skia library."""
+  srcs = skia_glob(BASE_SRCS_ALL)
+  if os == SKIA_OS_IOS:
+    if cpu != SKIA_CPU_UNSPECIFIED:
+      fail("Do not specify IOS and a cpu.")
+    srcs = srcs + skia_glob(BASE_SRCS_IOS)
+  elif os == SKIA_OS_ANDROID:
+    if cpu != SKIA_CPU_UNSPECIFIED:
+      fail("Do not specify ANDROID and a cpu.")
+    srcs = srcs + skia_glob(BASE_SRCS_ANDROID)
+  elif os == SKIA_OS_UNIX:
+    if cpu == SKIA_CPU_UNSPECIFIED:
+      srcs = srcs + ["src/opts/opts_check_x86.cpp"] + skia_glob(BASE_SRCS_UNIX)
+    elif cpu == SKIA_CPU_PPC:
+      srcs = srcs + skia_glob(BASE_SRCS_UNIX)
+    else:
+      fail("cpu must be one of SKIA_CPU_*")
+  else:
+    fail("skia_srcs parameter 'os' must be one of SKIA_OS_{UNIX,ANDROID,IOS}.")
+  return srcs
 
 ################################################################################
 ## INCLUDES
@@ -453,25 +508,29 @@
     ],
 )
 
-DM_SRCS_UNIX = struct(
-    include = [
-        "tools/gpu/gl/CreatePlatformGLContext_none.cpp",
-    ],
-)
+################################################################################
+## dm_srcs()
+################################################################################
+# SKIA_OS_* definitions can be found above.
 
-DM_SRCS_ANDROID = struct(
-    include = [
+def dm_srcs(os):
+  """Sources for the dm binary for the specified os."""
+  srcs = skia_glob(DM_SRCS_ALL)
+  # TODO(benjaminwagner): None of the CreatePlatformGLContext_*.cpp files exist.
+  # TODO(jwg): Remove the globs if possible, they only select single files.
+  if os == SKIA_OS_IOS:
+    srcs = srcs + native.glob(["tools/gpu/iOS/CreatePlatformGLContext_iOS.cpp"])
+  elif os == SKIA_OS_ANDROID:
+    srcs = srcs + native.glob([
         "tests/FontMgrAndroidParserTest.cpp",
         # TODO(benjaminwagner): Figure out how to compile with EGL.
         "tools/gpu/gl/CreatePlatformGLContext_none.cpp",
-    ],
-)
-
-DM_SRCS_IOS = struct(
-    include = [
-        "tools/gpu/iOS/CreatePlatformGLContext_iOS.cpp",
-    ],
-)
+    ])
+  elif os == SKIA_OS_UNIX:
+    srcs = srcs + native.glob(["tools/gpu/gl/CreatePlatformGLContext_none.cpp"])
+  else:
+    fail("dm_srcs parameter 'os' must be one of SKIA_OS_{UNIX,ANDROID,IOS}.")
+  return srcs
 
 ################################################################################
 ## DM_INCLUDES