Land prep work to enable NaCl in the Linux x64 GN builds.

This should get most of NaCl and the PPAPI stuff needed
for NaCl building and linking. There is more work to be
done to get some of the test binaries working (and
probably fill out parts of the NaCl SDK) and possibly
some pnacl support work remaining as well.

NaCl is still disabled by default (set enable_nacl=true
to change). Enabling nacl is still mostly untested and
likely doesn't work at all :).

[email protected], [email protected]
BUG=432959
CQ_EXTRA_TRYBOTS=tryserver.chromium.linux:android_chromium_gn_compile_dbg,android_chromium_gn_compile_rel;tryserver.chromium.win:win8_chromium_gn_rel,win8_chromium_gn_dbg;tryserver.chromium.mac:mac_chromium_gn_rel,mac_chromium_gn_dbg

Review URL: https://codereview.chromium.org/877553008

Cr-Commit-Position: refs/heads/master@{#318180}
diff --git a/base/BUILD.gn b/base/BUILD.gn
index c413d54..9dbc41c6 100644
--- a/base/BUILD.gn
+++ b/base/BUILD.gn
@@ -764,7 +764,29 @@
   ]
 
   if (is_nacl) {
-    sources += [ "files/file_path_watcher_stub.cc" ]
+    # We reset sources_assignment_filter in order to explicitly include
+    # the linux file (which would otherwise be filtered out).
+    set_sources_assignment_filter([])
+    sources += [
+      "files/file_path_watcher_stub.cc",
+      "sync_socket_nacl.cc",
+      "threading/platform_thread_linux.cc",
+    ]
+    set_sources_assignment_filter(sources_assignment_filter)
+
+    sources -= [
+      "allocator/type_profiler_control.cc",
+      "allocator/type_profiler_control.h",
+      "async_socket_io_handler_posix.cc",
+      "base_paths.cc",
+      "cpu.cc",
+      "files/file_proxy.cc",
+      "files/file_util.cc",
+      "files/file_util_proxy.cc",
+      "path_service.cc",
+      "scoped_native_library.cc",
+      "files/scoped_temp_dir.cc",
+    ]
   }
 
   sources -= [
@@ -852,11 +874,12 @@
       "process/launch_posix.cc",
       "process/process_metrics_posix.cc",
       "process/process_posix.cc",
+      "rand_util_posix.cc",
       "sync_socket_posix.cc",
       "sys_info_posix.cc",
     ]
   } else {
-    # Remove nacl stuff.
+    # Remove NaCl stuff.
     sources -= [
       "memory/shared_memory_nacl.cc",
       "os_compat_nacl.cc",
diff --git a/base/third_party/dynamic_annotations/BUILD.gn b/base/third_party/dynamic_annotations/BUILD.gn
index e52938c1..d6a5123 100644
--- a/base/third_party/dynamic_annotations/BUILD.gn
+++ b/base/third_party/dynamic_annotations/BUILD.gn
@@ -2,14 +2,22 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-source_set("dynamic_annotations") {
-  sources = [
-    "../valgrind/valgrind.h",
-    "dynamic_annotations.c",
-    "dynamic_annotations.h",
-  ]
-  if (is_android && !is_debug) {
-    configs -= [ "//build/config/compiler:optimize" ]
-    configs += [ "//build/config/compiler:optimize_max" ]
+if (is_nacl) {
+  # Native client doesn't need dynamic annotations, so we provide a
+  # dummy target in order for clients to not have to special-case the
+  # dependency.
+  group("dynamic_annotations") {
+  }
+} else {
+  source_set("dynamic_annotations") {
+    sources = [
+      "../valgrind/valgrind.h",
+      "dynamic_annotations.c",
+      "dynamic_annotations.h",
+    ]
+    if (is_android && !is_debug) {
+      configs -= [ "//build/config/compiler:optimize" ]
+      configs += [ "//build/config/compiler:optimize_max" ]
+    }
   }
 }
diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn
index a554f12d..7c06e59 100644
--- a/build/config/BUILDCONFIG.gn
+++ b/build/config/BUILDCONFIG.gn
@@ -548,6 +548,12 @@
 } else if (is_ios) {
   host_toolchain = "//build/toolchain/mac:host_clang"
   set_default_toolchain("//build/toolchain/mac:clang")
+} else if (is_nacl) {
+  # TODO(GYP): This will need to change when we get NaCl working
+  # on multiple platforms, but this whole block of code (how we define
+  # host_toolchain) needs to be reworked regardless to key off of build_os
+  # and build_cpu_arch rather than the is_* variables.
+  host_toolchain = "//build/toolchain/linux:clang_x64"
 }
 
 # ==============================================================================
diff --git a/build/config/features.gni b/build/config/features.gni
index 5477674c..5ee92f7 100644
--- a/build/config/features.gni
+++ b/build/config/features.gni
@@ -22,9 +22,20 @@
   enable_plugins = !is_android && !is_ios
 
   # Enables Native Client support.
-  # TODO(GYP) enable this when nacl works in GN.
+  # TODO(GYP): Get NaCl linking on other platforms.
+  # Also, see if we can always get rid of enable_nacl_untrusted and
+  # enable_pnacl and always build them if enable_nacl is true.
+  # The "is_nacl" part of the condition is needed to ensure that
+  # the untrusted code is built properly; arguably it should be
+  # guarded by "is_nacl" directly rather than enable_nacl_untrusted, but
+  # this will go away when Mac and Win are working and we can just use
+  # the commented out logic.
+  # enable_nacl = !is_ios && !is_android
+  # Currently this *should* work:
+  # enable_nacl = (is_linux && build_cpu_arch == "x64") || is_nacl
   enable_nacl = false
-  #enable_nacl = (!is_ios && !is_android)
+  enable_nacl_untrusted = enable_nacl
+  enable_pnacl = enable_nacl_untrusted
 
   # If debug_devtools is set to true, JavaScript files for DevTools are stored
   # as is and loaded from disk. Otherwise, a concatenated file is stored in
diff --git a/chrome/BUILD.gn b/chrome/BUILD.gn
index a807c09..5b40f4f 100644
--- a/chrome/BUILD.gn
+++ b/chrome/BUILD.gn
@@ -279,9 +279,9 @@
     deps += [ "//third_party/cld_2:cld2_platform_impl" ]
   }
 
-  # TODO(gyp) if (enable_nacl) {
-  #  deps += [ "<(DEPTH)/components/nacl/renderer/plugin/plugin.gyp:nacl_trusted_plugin" ]
-  #}
+  if (enable_nacl) {
+    deps += [ "//components/nacl/renderer/plugin:nacl_trusted_plugin" ]
+  }
   if (enable_remoting) {
     deps += [ "//remoting/client/plugin" ]
   }
diff --git a/chrome/app/BUILD.gn b/chrome/app/BUILD.gn
index 12e3b12..b7dfb20 100644
--- a/chrome/app/BUILD.gn
+++ b/chrome/app/BUILD.gn
@@ -318,9 +318,9 @@
     sources += [ "chrome_main_mac.mm" ]
   }
 
-  # TODO(gyp) if (enable_plugins and enable_nacl) {
-  #  deps += [ "'<(DEPTH)/components/nacl/renderer/plugin/plugin.gyp:nacl_trusted_plugin'," ]
-  # }
+  if (enable_plugins && enable_nacl) {
+    deps += [ "//components/nacl/renderer/plugin:nacl_trusted_plugin" ]
+  }
 
   if (enable_remoting) {
     deps += [ "//remoting/client/plugin" ]
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index fc44c43..ce8af0fc 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -352,7 +352,7 @@
   if (enable_nacl) {
     sources +=
         rebase_path(gypi_values.chrome_browser_nacl_sources, ".", "//chrome")
-    #deps += [ "//components/nacl:nacl_browser" ]  TODO(GYP)
+    deps += [ "//components/nacl:nacl_browser" ]
   }
 
   if (enable_configuration_policy) {
diff --git a/chrome/browser/nacl_host/test/BUILD.gn b/chrome/browser/nacl_host/test/BUILD.gn
new file mode 100644
index 0000000..fca5c76
--- /dev/null
+++ b/chrome/browser/nacl_host/test/BUILD.gn
@@ -0,0 +1,16 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("//build/config/features.gni")
+
+if (enable_nacl && (is_linux || is_win)) {
+  executable("mock_nacl_gdb") {
+    sources = [
+      "mock_nacl_gdb.cc",
+    ]
+    deps = [
+      "//base",
+    ]
+  }
+}
diff --git a/chrome/browser/ui/BUILD.gn b/chrome/browser/ui/BUILD.gn
index fdc5342..06fbfa4 100644
--- a/chrome/browser/ui/BUILD.gn
+++ b/chrome/browser/ui/BUILD.gn
@@ -158,12 +158,10 @@
       sources -= [ "views/task_manager_view.cc" ]
     }
   }
-  if (!enable_nacl) {
+  if (enable_nacl) {
     sources +=
         rebase_path(gypi_values.chrome_browser_ui_nacl_sources, ".", "//chrome")
-    deps += [
-      #"//native_client/src/trusted/service_runtime/service_runtime.gyp:sel",  TODO(GYP)
-    ]
+    deps += [ "//native_client/src/trusted/service_runtime:sel" ]
   }
   if (enable_configuration_policy) {
     sources += rebase_path(gypi_values.chrome_browser_ui_policy_sources,
diff --git a/chrome/common/BUILD.gn b/chrome/common/BUILD.gn
index 622ce47c..eaf9767 100644
--- a/chrome/common/BUILD.gn
+++ b/chrome/common/BUILD.gn
@@ -138,9 +138,7 @@
   }
 
   if (enable_nacl) {
-    deps += [
-      #'<(DEPTH)/components/nacl.gyp:nacl_common',  TODO(GYP)
-    ]
+    deps += [ "//components/nacl:nacl_common" ]
   }
 
   # Printing.
@@ -287,9 +285,7 @@
   ]
 
   if (enable_nacl) {
-    deps += [
-      #'../components/nacl.gyp:nacl_switches',  TODO(GYP)
-    ]
+    deps += [ "//components/nacl:nacl_switches" ]
   }
 }
 
diff --git a/chrome/renderer/BUILD.gn b/chrome/renderer/BUILD.gn
index b18a392..20829dd 100644
--- a/chrome/renderer/BUILD.gn
+++ b/chrome/renderer/BUILD.gn
@@ -67,8 +67,8 @@
 
   if (enable_nacl) {
     deps += [
-      #'../components/nacl.gyp:nacl',  TODO(GYP)
-      #'../components/nacl.gyp:nacl_renderer',  TODO(GYP)
+      "//components/nacl",
+      "//components/nacl:nacl_renderer",
     ]
   }
 
diff --git a/chrome/test/BUILD.gn b/chrome/test/BUILD.gn
index 4bc1d9b..692e3ef8 100644
--- a/chrome/test/BUILD.gn
+++ b/chrome/test/BUILD.gn
@@ -328,10 +328,10 @@
       ]
 
       if (enable_nacl) {
-        # TODO(GYP) this is also under a disable_nacl_untrusted==0 condition.
         deps += [
-          # '../native_client/src/trusted/service_runtime/linux/nacl_bootstrap.gyp:nacl_helper_bootstrap',  TODO(GYP)
-          # '../components/nacl.gyp:nacl_helper',  TODO(GYP)
+          "//native_client/src/trusted/service_runtime/linux:munge_nacl_helper_bootstrap",
+          "//components/nacl:nacl_helper",
+
           # '../components/nacl_nonsfi.gyp:nacl_helper_nonsfi',  TODO(GYP)
         ]
       }
@@ -575,7 +575,10 @@
         sources -= [ "data/webui/accessibility_audit_browsertest.js" ]
       }
       if (!is_chromeos) {
-        sources -= [ "data/webui/certificate_viewer_dialog_test.js" ]
+        sources -= [
+          "data/webui/certificate_viewer_dialog_test.js",
+          "test/data/chromeos/oobe_webui_browsertest.js",
+        ]
       }
       if (!enable_app_list) {
         sources -= [ "../browser/ui/webui/app_list/start_page_browsertest.js" ]
@@ -700,28 +703,32 @@
           "nacl/pnacl_header_test.cc",
           "nacl/pnacl_header_test.h",
         ]
-        deps += [
-          #'test/data/nacl/nacl_test_data.gyp:*',  # TODO(GYP)
-          #'../ppapi/native_client/native_client.gyp:nacl_irt',  # TODO(GYP)
-          #'../ppapi/ppapi_nacl.gyp:ppapi_nacl_tests',  # TODO(GYP)
-          #'../ppapi/tests/extensions/extensions.gyp:ppapi_tests_extensions_background_keepalive',  # TODO(GYP)
-          #'../ppapi/tests/extensions/extensions.gyp:ppapi_tests_extensions_media_galleries',  # TODO(GYP)
-          #'../ppapi/tests/extensions/extensions.gyp:ppapi_tests_extensions_packaged_app',  # TODO(GYP)          #'../ppapi/ppapi_tests_mojo.gyp:ppapi_tests_mojo',  # TODO(GYP)
-          #'../ppapi/ppapi_tests_mojo.gyp:ppapi_tests_mojo',  # TODO(GYP)
+
+        # TODO(GYP): Make NaCl work in other configs and update the irt
+        # dependency as appropriate. We should probably push this
+        # dependency into ppapi/native_client so that clients don't need
+        # to know all of the different toolchain options.
+        assert(current_cpu == "x64")
+        data_deps += [
+          # "test/data/nacl:shared_test_files",  # TODO(GYP)
+          "//ppapi/native_client:nacl_irt(//native_client/build/toolchain/nacl:irt_x64)",
+          # "../ppapi/ppapi_nacl.gyp:ppapi_nacl_tests",  # TODO(GYP)
+          # "../ppapi/tests/extensions/extensions.gyp:ppapi_tests_extensions_background_keepalive",  # TODO(GYP)
+          # "../ppapi/tests/extensions/extensions.gyp:ppapi_tests_extensions_media_galleries",  # TODO(GYP)
+          # "../ppapi/tests/extensions/extensions.gyp:ppapi_tests_extensions_packaged_app",  # TODO(GYP)
+          # "../ppapi/ppapi_tests_mojo.gyp:ppapi_tests_mojo",  # TODO(GYP)
         ]
         if (is_chromeos) {
           sources += [ "//third_party/liblouis/nacl_wrapper/liblouis_wrapper_browsertest.cc" ]
+          deps += [
+            #'browser_chromeos',  TODO(GYP)
+            #'../third_party/liblouis/liblouis_nacl.gyp:liblouis_test_data',  TODO(GYP)
+          ]
         }
-        deps += [
-          #'browser_chromeos',  TODO(GYP)
-          #'../third_party/liblouis/liblouis_nacl.gyp:liblouis_test_data',  TODO(GYP)
-        ]
       }
       if (is_win || is_linux) {
         sources += [ "../browser/nacl_host/test/nacl_gdb_browsertest.cc" ]
-        deps += [
-          #'browser/nacl_host/test/mock_nacl_gdb.gyp:mock_nacl_gdb',  TODO(GYP)
-        ]
+        deps += [ "//chrome/browser/nacl_host/test:mock_nacl_gdb" ]
       }
       if (is_win) {
         # TODO(halyavin) NaCl on Windows can't open debug stub socket in
@@ -731,16 +738,14 @@
           #'chrome.gyp:chrome_nacl_win64',  TODO(GYP)
         ]
       }
-      is(is_linux) {
+      if (is_linux) {
         deps += [
-          #'../native_client/src/trusted/service_runtime/linux/nacl_bootstrap.gyp:nacl_helper_bootstrap', TODO(GYP)
-          #'../components/nacl.gyp:nacl_helper', TODO(GYP)
-          #'../components/nacl_nonsfi.gyp:nacl_helper_nonsfi', TODO(GYP)
+          "//native_client/src/trusted/service_runtime/linux:munge_nacl_helper_bootstrap",
+          "//components/nacl:nacl_helper",
+
+          # "//components/nacl_nonsfi.gyp:nacl_helper_nonsfi",  # TODO(GYP)
         ]
       }
-      if (!is_chromeos) {
-        sources -= [ "test/data/chromeos/oobe_webui_browsertest.js" ]
-      }
     }
     if (debug_devtools) {
       defines += [ "DEBUG_DEVTOOLS=1" ]
@@ -1288,11 +1293,7 @@
         sources -= [ "../browser/ui/views/sync/one_click_signin_bubble_view_unittest.cc" ]
       }
     }
-    if (enable_nacl) {
-      sources += rebase_path(unit_gypi_values.chrome_unit_tests_nacl_sources,
-                             ".",
-                             "//chrome")
-    }
+
     if (enable_extensions) {
       sources +=
           rebase_path(unit_gypi_values.chrome_unit_tests_extensions_sources,
diff --git a/components/nacl/BUILD.gn b/components/nacl/BUILD.gn
new file mode 100644
index 0000000..b64c157
--- /dev/null
+++ b/components/nacl/BUILD.gn
@@ -0,0 +1,268 @@
+# Copyright (c) 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("//build/config/features.gni")
+import("//build/config/ui.gni")
+
+if (enable_nacl) {
+  source_set("nacl") {
+    sources = [
+      "loader/nacl_ipc_adapter.cc",
+      "loader/nacl_ipc_adapter.h",
+      "loader/nacl_main.cc",
+      "loader/nacl_main_platform_delegate.h",
+      "loader/nacl_main_platform_delegate_linux.cc",
+      "loader/nacl_main_platform_delegate_mac.mm",
+      "loader/nacl_main_platform_delegate_win.cc",
+      "loader/nacl_listener.cc",
+      "loader/nacl_listener.h",
+      "loader/nacl_trusted_listener.cc",
+      "loader/nacl_trusted_listener.h",
+      "loader/nacl_validation_db.h",
+      "loader/nacl_validation_query.cc",
+      "loader/nacl_validation_query.h",
+    ]
+
+    deps = [
+      "//base",
+      "//base:base_static",
+      "//ipc",
+      "//mojo/nacl:monacl_sel",
+      "//native_client/src/trusted/service_runtime:sel_main_chrome",
+      "//ppapi/proxy:ipc",
+      "//ppapi/shared_impl",
+    ]
+
+    if (enable_nacl_untrusted) {
+      data_deps = [
+        # TODO(GYP): handle other cpu_arch's correctly.
+        "//ppapi/native_client:nacl_irt(//native_client/build/toolchain/nacl:irt_x64)",
+      ]
+    }
+    if (enable_pnacl) {
+      data_deps += [
+        # TODO(GYP): handle other cpu_arch's correctly.
+        "//ppapi/native_client/src/untrusted/pnacl_support_extension",
+      ]
+    }
+  }
+
+  source_set("nacl_browser") {
+    sources = [
+      "browser/nacl_broker_host_win.cc",
+      "browser/nacl_broker_host_win.h",
+      "browser/nacl_broker_service_win.cc",
+      "browser/nacl_broker_service_win.h",
+      "browser/nacl_browser.cc",
+      "browser/nacl_browser.h",
+      "browser/nacl_file_host.cc",
+      "browser/nacl_file_host.h",
+      "browser/nacl_host_message_filter.cc",
+      "browser/nacl_host_message_filter.h",
+      "browser/nacl_process_host.cc",
+      "browser/nacl_process_host.h",
+      "browser/nacl_validation_cache.cc",
+      "browser/nacl_validation_cache.h",
+      "browser/pnacl_host.cc",
+      "browser/pnacl_host.h",
+      "browser/pnacl_translation_cache.cc",
+      "browser/pnacl_translation_cache.h",
+      "common/nacl_debug_exception_handler_win.cc",
+      "common/nacl_debug_exception_handler_win.h",
+    ]
+
+    deps = [
+      ":nacl_common",
+      ":nacl_switches",
+      "//native_client/src/trusted/service_runtime:sel_main_chrome",
+      "//content//public/browser",
+    ]
+
+    if (is_linux) {
+      sources += [
+        "zygote/nacl_fork_delegate_linux.cc",
+        "zygote/nacl_fork_delegate_linux.h",
+      ]
+
+      deps += [ "//sandbox/linux:suid_sandbox_client" ]
+    }
+  }
+
+  source_set("nacl_renderer") {
+    sources = [
+      "renderer/file_downloader.cc",
+      "renderer/file_downloader.h",
+      "renderer/histogram.cc",
+      "renderer/histogram.h",
+      "renderer/manifest_downloader.cc",
+      "renderer/manifest_downloader.h",
+      "renderer/manifest_service_channel.cc",
+      "renderer/manifest_service_channel.h",
+      "renderer/nacl_helper.cc",
+      "renderer/nacl_helper.h",
+      "renderer/json_manifest.cc",
+      "renderer/json_manifest.h",
+      "renderer/nexe_load_manager.cc",
+      "renderer/nexe_load_manager.h",
+      "renderer/platform_info.cc",
+      "renderer/platform_info.h",
+      "renderer/pnacl_translation_resource_host.cc",
+      "renderer/pnacl_translation_resource_host.h",
+      "renderer/ppb_nacl_private_impl.cc",
+      "renderer/ppb_nacl_private_impl.h",
+      "renderer/progress_event.cc",
+      "renderer/progress_event.h",
+      "renderer/trusted_plugin_channel.cc",
+      "renderer/trusted_plugin_channel.h",
+    ]
+
+    deps = [
+      ":nacl_common",
+      "renderer/plugin:nacl_trusted_plugin",
+      "//content/public/renderer",
+      "//third_party/jsoncpp",
+      "//third_party/WebKit/public:blink",
+    ]
+  }
+
+  executable("nacl_loader_unittests") {
+    testonly = true
+    sources = [
+      "loader/run_all_unittests.cc",
+    ]
+
+    deps = [
+      ":nacl",
+      "//base/test:test_support",
+      "//testing/gtest",
+    ]
+  }
+
+  if (is_linux) {
+    executable("nacl_helper") {
+      sources = [
+        "loader/nacl_helper_linux.cc",
+        "loader/nacl_helper_linux.h",
+      ]
+
+      deps = [
+        ":nacl_linux",
+        "//mojo/nacl:monacl_sel",
+      ]
+
+      cflags = [ "-fPIE" ]
+
+      ldflags = [ "-pie" ]
+    }
+
+    source_set("nacl_linux") {
+      sources = [
+        "loader/nonsfi/abi_conversion.cc",
+        "loader/nonsfi/abi_conversion.h",
+        "loader/nonsfi/elf_loader.cc",
+        "loader/nonsfi/elf_loader.h",
+        "loader/nonsfi/irt_basic.cc",
+        "loader/nonsfi/irt_clock.cc",
+        "loader/nonsfi/irt_exception_handling.cc",
+        "loader/nonsfi/irt_fdio.cc",
+        "loader/nonsfi/irt_futex.cc",
+        "loader/nonsfi/irt_icache.cc",
+        "loader/nonsfi/irt_interfaces.cc",
+        "loader/nonsfi/irt_interfaces.h",
+        "loader/nonsfi/irt_memory.cc",
+        "loader/nonsfi/irt_ppapi.cc",
+        "loader/nonsfi/irt_random.cc",
+        "loader/nonsfi/irt_resource_open.cc",
+        "loader/nonsfi/irt_thread.cc",
+        "loader/nonsfi/irt_util.h",
+        "loader/nonsfi/nonsfi_listener.cc",
+        "loader/nonsfi/nonsfi_listener.h",
+        "loader/nonsfi/nonsfi_main.cc",
+        "loader/nonsfi/nonsfi_main.h",
+        "loader/nonsfi/nonsfi_sandbox.cc",
+        "loader/nonsfi/nonsfi_sandbox.h",
+        "loader/sandbox_linux/nacl_bpf_sandbox_linux.cc",
+        "loader/sandbox_linux/nacl_sandbox_linux.cc",
+        "//ppapi/nacl_irt/irt_manifest.h",
+        "//ppapi/nacl_irt/manifest_service.cc",
+        "//ppapi/nacl_irt/manifest_service.h",
+        "//ppapi/nacl_irt/plugin_main.cc",
+        "//ppapi/nacl_irt/plugin_main.h",
+        "//ppapi/nacl_irt/plugin_startup.cc",
+        "//ppapi/nacl_irt/plugin_startup.h",
+        "//ppapi/nacl_irt/ppapi_dispatcher.cc",
+        "//ppapi/nacl_irt/ppapi_dispatcher.h",
+      ]
+
+      defines = [ "IN_NACL_HELPER=1" ]
+
+      deps = [
+        ":nacl",
+        ":nacl_common",
+        ":nacl_switches",
+        "//components/tracing",
+        "//crypto",
+        "//ppapi/proxy",
+        "//sandbox/linux:libc_urandom_override",
+        "//sandbox",
+      ]
+
+      if (use_glib) {
+        configs += [ "//build/config/linux:glib" ]
+      }
+
+      if (use_seccomp_bpf) {
+        defines += [ "USE_SECCOMP_BPF" ]
+      }
+    }
+  }
+} else {
+  group("nacl") {
+  }
+}
+
+source_set("nacl_switches") {
+  sources = [
+    "common/nacl_switches.cc",
+    "common/nacl_switches.h",
+  ]
+}
+
+source_set("nacl_common") {
+  sources = [
+    "common/nacl_cmd_line.cc",
+    "common/nacl_cmd_line.h",
+    "common/nacl_constants.cc",
+    "common/nacl_constants.h",
+    "common/nacl_host_messages.h",
+    "common/nacl_host_messages.cc",
+    "common/nacl_messages.cc",
+    "common/nacl_messages.h",
+    "common/nacl_nonsfi_util.cc",
+    "common/nacl_nonsfi_util.h",
+    "common/nacl_process_type.h",
+    "common/nacl_renderer_messages.h",
+    "common/nacl_renderer_messages.cc",
+    "common/nacl_sandbox_type_mac.h",
+    "common/nacl_types.cc",
+    "common/nacl_types.h",
+    "common/nacl_types_param_traits.cc",
+    "common/nacl_types_param_traits.h",
+    "common/pnacl_types.cc",
+    "common/pnacl_types.h",
+  ]
+
+  deps = [
+    "//content/public/common",
+  ]
+
+  if (is_linux) {
+    sources += [
+      "common/nacl_paths.cc",
+      "common/nacl_paths.h",
+    ]
+
+    defines = [ "__STDC_LIMIT_MACROS=1" ]
+  }
+}
diff --git a/components/nacl/renderer/plugin/BUILD.gn b/components/nacl/renderer/plugin/BUILD.gn
new file mode 100644
index 0000000..5defb10
--- /dev/null
+++ b/components/nacl/renderer/plugin/BUILD.gn
@@ -0,0 +1,43 @@
+# Copyright (c) 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+source_set("nacl_trusted_plugin") {
+  sources = [
+    "module_ppapi.cc",
+    "nacl_subprocess.cc",
+    "plugin.cc",
+    "pnacl_coordinator.cc",
+    "pnacl_resources.cc",
+    "pnacl_translate_thread.cc",
+    "ppapi_entrypoints.cc",
+    "sel_ldr_launcher_chrome.cc",
+    "service_runtime.cc",
+    "srpc_client.cc",
+    "srpc_params.cc",
+    "temporary_file.cc",
+    "utility.cc",
+  ]
+
+  deps = [
+    "//media:shared_memory_support",
+    "//native_client/src/shared/gio",
+    "//native_client/src/shared/imc",
+    "//native_client/src/shared/platform",
+    "//native_client/src/trusted/desc:nrd_xfer",
+    "//native_client/src/trusted/nonnacl_util:sel_ldr_launcher_base",
+    "//native_client/src/trusted/platform_qualify:platform_qual_lib",
+    "//native_client/src/trusted/simple_service",
+    "//native_client/src/trusted/weak_ref",
+    "//ppapi/cpp:objects",
+    "//ppapi/cpp/private:internal_module",
+  ]
+
+  if (is_linux) {
+    cflags = [ "-Wno-long-long" ]
+
+    ldflags = [ "-Wl,-z,defs" ]
+
+    libs = [ "dl" ]
+  }
+}
diff --git a/extensions/shell/BUILD.gn b/extensions/shell/BUILD.gn
index cea781f..70aef276 100644
--- a/extensions/shell/BUILD.gn
+++ b/extensions/shell/BUILD.gn
@@ -105,6 +105,26 @@
       sources += nacl_sources
     }
   }
+
+  if (enable_nacl) {
+    sources += [
+      "browser/shell_nacl_browser_delegate.cc",
+      "browser/shell_nacl_browser_delegate.h",
+    ]
+
+    deps += [
+      "//components/nacl",
+      "//components/nacl:nacl_browser",
+      "//components/nacl:nacl_common",
+      "//components/nacl:nacl_renderer",
+      "//components/nacl:nacl_switches",
+      "//components/nacl/renderer/plugin:nacl_trusted_plugin",
+    ]
+
+    if (is_linux) {
+      deps += [ "//components/nacl:nacl_helper" ]
+    }
+  }
 }
 
 if (!(is_chromeos && !use_ozone) && (!is_win || link_chrome_on_windows)) {
diff --git a/ipc/BUILD.gn b/ipc/BUILD.gn
index 0ff1279..439d461a 100644
--- a/ipc/BUILD.gn
+++ b/ipc/BUILD.gn
@@ -67,7 +67,13 @@
     "unix_domain_socket_util.h",
   ]
 
-  if (!is_nacl) {
+  if (is_nacl) {
+    sources -= [
+      "ipc_channel.cc",
+      "ipc_channel_posix.cc",
+      "unix_domain_socket_util.cc",
+    ]
+  } else {
     sources -= [
       "ipc_channel_nacl.cc",
       "ipc_channel_nacl.h",
@@ -88,7 +94,7 @@
   ]
 }
 
-# TODO(dpranke): crbug.com/360936. Get this to build and run on Android.
+# TODO(GYP): crbug.com/360936. Get this to build and run on Android.
 if (!is_android) {
   test("ipc_tests") {
     sources = [
@@ -149,7 +155,6 @@
     #    deps += "//base/allocator"
     #  }
     #}
-
     deps = [
       ":ipc",
       ":test_support",
diff --git a/mojo/nacl/BUILD.gn b/mojo/nacl/BUILD.gn
index 222d45f6..6a6373c8 100644
--- a/mojo/nacl/BUILD.gn
+++ b/mojo/nacl/BUILD.gn
@@ -35,6 +35,7 @@
       "$gen_dir/mojo_syscall.cc",
       "monacl_sel_main.cc",
     ]
+
     deps = [
       # This target makes sure we have all the pre-processor defines needed to
       # use NaCl's headers.
@@ -43,20 +44,8 @@
       "//native_client/src/trusted/service_runtime:sel_main_chrome",
       ":mojo_nacl_codegen($default_toolchain)",
     ]
-  }
-
-  # A simple shell for running untrusted binaries that talk to the Mojo
-  # embedder. (No services.)
-  executable("monacl_shell") {
-    testonly = true
-    sources = [
-      "monacl_shell.cc",
-    ]
-    deps = [
-      "//base:base",
-      "//third_party/mojo/src/mojo/edk/system:system",
-      ":monacl_sel",
-    ]
+    public_configs =
+        [ "//third_party/mojo/src/mojo/public/build/config:mojo_sdk" ]
   }
 }
 
@@ -68,37 +57,22 @@
       "$gen_dir/libmojo.cc",
       "$gen_dir/mojo_irt.h",
     ]
-    include_dirs = [ "$root_build_dir/gen" ]
-    deps = [
+
+    public_configs =
+        [ "//third_party/mojo/src/mojo/public/build/config:mojo_sdk" ]
+
+    public_deps = [
       ":mojo_nacl_codegen($default_toolchain)",
     ]
   }
 
-  # Unit test for the Mojo public API.
-  executable("monacl_test") {
-    testonly = true
-    sources = [
-      "//third_party/mojo/src/mojo/public/cpp/system/tests/core_unittest.cc",
-      "//third_party/mojo/src/mojo/public/cpp/system/tests/macros_unittest.cc",
-    ]
-    deps = [
-      "//testing/gtest:gtest",
-      "//testing/gtest:gtest_main",
-      "//third_party/mojo/src/mojo/public/c/system/tests:tests",
-      "//third_party/mojo/src/mojo/public/cpp/system:system",
-      ":mojo",
-    ]
-  }
-
-  executable("irt_mojo") {
+  source_set("irt_mojo_sources") {
     cflags_c = [ "-std=c99" ]
     sources = [
-      "irt_entry_mojo.c",
       "$gen_dir/mojo_irt.c",
       "$gen_dir/mojo_irt.h",
     ]
-    include_dirs = [ "$root_build_dir/gen" ]
-    deps = [
+    public_deps = [
       "//native_client/build/config/nacl:nacl_base",
       "//native_client/src/untrusted/irt:irt_core_lib",
       "//native_client/src/untrusted/nacl:imc_syscalls",
@@ -106,17 +80,3 @@
     ]
   }
 }
-
-group("mojo_nacl") {
-  deps = [
-    ":irt_mojo(//native_client/build/toolchain/nacl:irt_${current_cpu})",
-  ]
-}
-
-group("mojo_nacl_tests") {
-  testonly = true
-  deps = [
-    ":monacl_shell",
-    ":monacl_test(//native_client/build/toolchain/nacl:clang_newlib_${current_cpu})",
-  ]
-}
diff --git a/ppapi/native_client/BUILD.gn b/ppapi/native_client/BUILD.gn
new file mode 100644
index 0000000..b67b0525
--- /dev/null
+++ b/ppapi/native_client/BUILD.gn
@@ -0,0 +1,38 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("//build/config/features.gni")
+
+if (enable_nacl && enable_nacl_untrusted) {
+  group("ppapi_lib") {
+    deps = [
+      "//native_client/src/untrusted/pthread",
+      "//ppapi/native_client/src/untrusted/irt_stub:ppapi_stub_lib",
+    ]
+  }
+
+  executable("nacl_irt") {
+    deps = [
+      "//base",
+      "//components/tracing",
+      "//gpu/command_buffer/client",
+      "//gpu/command_buffer/common",
+      "//gpu/command_buffer/client:gles2_implementation",
+      "//gpu/ipc",
+      "//ipc",
+      "//media:shared_memory_support",
+      "//mojo/nacl:irt_mojo_sources",
+      "//native_client/src/untrusted/irt:irt_core_lib",
+      "//native_client/src/shared/srpc",
+      "//native_client/src/shared/platform",
+      "//native_client/src/tools/tls_edit($host_toolchain)",
+      "//native_client/src/untrusted/nacl:imc_syscalls",
+      "//native_client/src/shared/gio",
+      "//ppai/native_client/src/untrusted/pnacl_irt_shim:irt",
+      "//ppapi/proxy",
+      "//ppapi/proxy:ipc",
+      "//ppapi/shared_impl",
+    ]
+  }
+}
diff --git a/ppapi/native_client/src/untrusted/irt_stub/BUILD.gn b/ppapi/native_client/src/untrusted/irt_stub/BUILD.gn
new file mode 100644
index 0000000..443f080
--- /dev/null
+++ b/ppapi/native_client/src/untrusted/irt_stub/BUILD.gn
@@ -0,0 +1,15 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+assert(is_nacl,
+       "These targets must only be built using the untrusted NaCl toolchains.")
+
+source_set("ppapi_stub_lib") {
+  sources = [
+    "ppapi_plugin_main.c",
+    "ppapi_plugin_start.c",
+    "plugin_main_irt.c",
+    "thread_creator.c",
+  ]
+}
diff --git a/ppapi/native_client/src/untrusted/pnacl_irt_shim/BUILD.gn b/ppapi/native_client/src/untrusted/pnacl_irt_shim/BUILD.gn
new file mode 100644
index 0000000..4a6050d
--- /dev/null
+++ b/ppapi/native_client/src/untrusted/pnacl_irt_shim/BUILD.gn
@@ -0,0 +1,29 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+assert(is_nacl,
+       "These targets must only be built using the untrusted NaCl toolchains.")
+
+source_set("aot") {
+  sources = [
+    "irt_shim_ppapi.c",
+    "pnacl_shim.c",
+    "shim_entry.c",
+    "shim_ppapi.c",
+  ]
+}
+
+source_set("browser") {
+  sources = [
+    "shim_entry.c",
+    "shim_ppapi.c",
+  ]
+}
+
+source_set("irt") {
+  sources = [
+    "irt_shim_ppapi.c",
+    "pnacl_shim.c",
+  ]
+}
diff --git a/ppapi/native_client/src/untrusted/pnacl_support_extension/BUILD.gn b/ppapi/native_client/src/untrusted/pnacl_support_extension/BUILD.gn
new file mode 100644
index 0000000..50e9b7c
--- /dev/null
+++ b/ppapi/native_client/src/untrusted/pnacl_support_extension/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("//build/config/features.gni")
+
+if (enable_nacl && enable_nacl_untrusted && enable_pnacl) {
+  group("pnacl_support_extension") {
+    # TODO(GYP): implement me ...
+  }
+}
diff --git a/ppapi/proxy/BUILD.gn b/ppapi/proxy/BUILD.gn
index a475780..1cab50c 100644
--- a/ppapi/proxy/BUILD.gn
+++ b/ppapi/proxy/BUILD.gn
@@ -184,8 +184,12 @@
     "url_response_info_resource.cc",
     "url_response_info_resource.h",
     "var_serialization_rules.h",
+    "video_decoder_resource.cc",
+    "video_decoder_resource.h",
     "video_destination_resource.cc",
     "video_destination_resource.h",
+    "video_encoder_resource.cc",
+    "video_encoder_resource.h",
     "video_frame_resource.cc",
     "video_frame_resource.h",
     "video_source_resource.cc",
@@ -258,10 +262,6 @@
       "talk_resource.h",
       "video_capture_resource.cc",
       "video_capture_resource.h",
-      "video_decoder_resource.cc",
-      "video_decoder_resource.h",
-      "video_encoder_resource.cc",
-      "video_encoder_resource.h",
     ]
   }
 
@@ -269,8 +269,6 @@
 
   deps = [
     "//base",
-    "//base/third_party/dynamic_annotations",
-    "//gin",
     "//gpu/command_buffer/client:gles2_implementation",
     "//gpu/ipc",
     "//ipc",
@@ -278,19 +276,23 @@
     "//ppapi/c",
     "//ppapi/proxy:ipc",
     "//ppapi/shared_impl",
-    "//skia",
     "//third_party/icu",
-    "//ui/events:events_base",
-    "//ui/surface",
   ]
 
-  # TODO(GYP) support chrome_multiple_dll
-  #if (chrome_multiple_dll) {
-  #  deps += [ "//third_party/WebKit/public:blink_minimal" ]
-  #} else {
-  deps += [ "//third_party/WebKit/public:blink" ]
-
-  #}
+  if (is_nacl) {
+    deps += [
+      "//ui/events:latency_info",
+      "//mojo/nacl:mojo",
+    ]
+  } else {
+    deps += [
+      "//base/third_party/dynamic_annotations",
+      "//gin",
+      "//skia",
+      "//ui/events:events_base",
+      "//ui/surface",
+    ]
+  }
 }
 
 source_set("ipc") {
@@ -327,9 +329,13 @@
     "//ipc",
     "//ppapi/c",
     "//ppapi/shared_impl",
-    "//skia",
-    "//ui/events/ipc",
   ]
+  if (!is_nacl) {
+    deps += [
+      "//skia",
+      "//ui/events/ipc",
+    ]
+  }
 }
 
 source_set("test_support") {
diff --git a/ppapi/shared_impl/BUILD.gn b/ppapi/shared_impl/BUILD.gn
index 14c65bc..59f4ec05 100644
--- a/ppapi/shared_impl/BUILD.gn
+++ b/ppapi/shared_impl/BUILD.gn
@@ -172,13 +172,18 @@
     "//media:shared_memory_support",
     "//ppapi/c",
     "//ppapi/thunk",
-    "//skia",
     "//third_party/icu:icuuc",
-    "//ui/events:events_base",
-    "//ui/surface",
     "//url",
   ]
 
+  if (!is_nacl) {
+    deps += [
+      "//skia",
+      "//ui/events:events_base",
+      "//ui/surface",
+    ]
+  }
+
   if (is_mac) {
     libs = [ "QuartzCore.framework" ]
   }
diff --git a/ppapi/thunk/BUILD.gn b/ppapi/thunk/BUILD.gn
index 43128cc1..eef06a2 100644
--- a/ppapi/thunk/BUILD.gn
+++ b/ppapi/thunk/BUILD.gn
@@ -120,7 +120,6 @@
     "ppb_var_array_thunk.cc",
     "ppb_var_dictionary_thunk.cc",
     "ppb_video_capture_api.h",
-    "ppb_video_capture_thunk.cc",
     "ppb_video_decoder_api.h",
     "ppb_video_decoder_dev_api.h",
     "ppb_video_decoder_thunk.cc",
@@ -169,6 +168,7 @@
       "ppb_scrollbar_thunk.cc",
       "ppb_talk_private_thunk.cc",
       "ppb_url_util_thunk.cc",
+      "ppb_video_capture_thunk.cc",
       "ppb_video_decoder_dev_thunk.cc",
     ]
   }
diff --git a/third_party/harfbuzz-ng/BUILD.gn b/third_party/harfbuzz-ng/BUILD.gn
index 71213fd4..90b200f 100644
--- a/third_party/harfbuzz-ng/BUILD.gn
+++ b/third_party/harfbuzz-ng/BUILD.gn
@@ -13,27 +13,20 @@
 # don't want to bloat the binary more by including another copy.
 
 declare_args() {
-  if (is_linux && (!is_official_build || is_chromeos)) {
-    # Since version 1.31.0, pangoft2 which we depend on pulls in harfbuzz
-    # anyways. However, we want to have control of the version of harfbuzz
-    # we use, so don't use system harfbuzz for official builds, unless we
-    # are building for chrome os, where we have the system harfbuzz under
-    # control as well.
-    use_system_harfbuzz = exec_script(pkg_config_script,
-                                      pkg_config_args + [
-                                            "--atleast-version=1.31.0",
-                                            "pangoft2",
-                                          ],
-                                      "value")
-  } else {
-    use_system_harfbuzz = false
-  }
-  if (is_linux && current_cpu == "arm" && !is_chromeos) {
-    # Override use_system_harfbuzz for ARM cross compiling so system
-    # harfbuzz is not used because the corresponding package is not
-    # available.
-    use_system_harfbuzz = false
-  }
+  # Since version 1.31.0, pangoft2 which we depend on pulls in harfbuzz
+  # anyways. However, we want to have control of the version of harfbuzz
+  # we use, so don't use system harfbuzz for official builds, unless we
+  # are building for chrome os, where we have the system harfbuzz under
+  # control as well. We also do not want to use the system harfbuzz
+  # when cross-compiling for ARM.
+  use_system_harfbuzz = is_linux && (is_chromeos || (!is_official_build &&
+                                                     current_cpu != "arm")) &&
+                        exec_script(pkg_config_script,
+                                    pkg_config_args + [
+                                          "--atleast-version=1.31.0",
+                                          "pangoft2",
+                                        ],
+                                    "value")
 }
 
 if (use_system_harfbuzz) {
diff --git a/third_party/libxml/BUILD.gn b/third_party/libxml/BUILD.gn
index 17ea09aa..992e92a 100644
--- a/third_party/libxml/BUILD.gn
+++ b/third_party/libxml/BUILD.gn
@@ -4,7 +4,7 @@
 
 # Define an "os_include" variable that points at the OS-specific generated
 # headers.  These were generated by running the configure script offline.
-if (is_linux || is_android) {
+if (is_linux || is_android || is_nacl) {
   os_include = "linux"
 } else if (is_mac || is_ios) {
   os_include = "mac"
diff --git a/ui/events/BUILD.gn b/ui/events/BUILD.gn
index 4681e62..f42595b 100644
--- a/ui/events/BUILD.gn
+++ b/ui/events/BUILD.gn
@@ -349,3 +349,14 @@
     sources += [ "gestures/gesture_provider_aura_unittest.cc" ]
   }
 }
+
+if (is_nacl) {
+  source_set("latency_info") {
+    sources = [
+      "latency_info.cc",
+      "latency_info.h",
+      "ipc/latency_info_param_traits.cc",
+      "ipc/latency_info_param_traits.h",
+    ]
+  }
+}
diff --git a/url/BUILD.gn b/url/BUILD.gn
index 964a08b..4f6b637 100644
--- a/url/BUILD.gn
+++ b/url/BUILD.gn
@@ -60,6 +60,7 @@
 
   configs += [
     ":url_icu_config",
+
     # TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
     "//build/config/compiler:no_size_t_to_int_warning",
   ]