Use build_file_content attribute of new_* repositories instead of build_file in Skylark rules

Loading those skylark rules where failing now they are in a remote repository because the
build file could not be found.

Fixes #883.

--
MOS_MIGRATED_REVID=114528630
diff --git a/tools/build_defs/d/d.bzl b/tools/build_defs/d/d.bzl
index 20281d7..1044ce3 100644
--- a/tools/build_defs/d/d.bzl
+++ b/tools/build_defs/d/d.bzl
@@ -457,17 +457,63 @@
     },
 )
 
+DMD_BUILD_FILE = """
+package(default_visibility = ["//visibility:public"])
+
+config_setting(
+    name = "darwin",
+    values = {"host_cpu": "darwin"},
+)
+
+config_setting(
+    name = "k8",
+    values = {"host_cpu": "k8"},
+)
+
+filegroup(
+    name = "dmd",
+    srcs = select({
+        ":darwin": ["dmd2/osx/bin/dmd"],
+        ":k8": ["dmd2/linux/bin64/dmd"],
+    }),
+)
+
+filegroup(
+    name = "libphobos2",
+    srcs = select({
+        ":darwin": ["dmd2/osx/lib/libphobos2.a"],
+        ":k8": [
+            "dmd2/linux/lib64/libphobos2.a",
+            "dmd2/linux/lib64/libphobos2.so",
+        ],
+    }),
+)
+
+filegroup(
+    name = "phobos-src",
+    srcs = glob(["dmd2/src/phobos/**/*.*"]),
+)
+
+filegroup(
+    name = "druntime-import-src",
+    srcs = glob([
+        "dmd2/src/druntime/import/*.*",
+        "dmd2/src/druntime/import/**/*.*",
+    ]),
+)
+"""
+
 def d_repositories():
   native.new_http_archive(
       name = "dmd_linux_x86_64",
       url = "http://downloads.dlang.org/releases/2.x/2.070.0/dmd.2.070.0.linux.tar.xz",
       sha256 = "42f48db8716f523076e881151f631e741342012881ec9b57353544ed46c4f774",
-      build_file = "tools/build_defs/d/dmd.BUILD",
+      build_file_content = DMD_BUILD_FILE,
   )
 
   native.new_http_archive(
       name = "dmd_darwin_x86_64",
       url = "http://downloads.dlang.org/releases/2.x/2.070.0/dmd.2.070.0.osx.tar.xz",
       sha256 = "c1dd14ded8e099dcb2f136379013959b07790249f440010d556e67ff59fe44a0",
-      build_file = "tools/build_defs/d/dmd.BUILD",
+      build_file_content = DMD_BUILD_FILE,
   )
diff --git a/tools/build_defs/d/dmd.BUILD b/tools/build_defs/d/dmd.BUILD
deleted file mode 100644
index fc5df60..0000000
--- a/tools/build_defs/d/dmd.BUILD
+++ /dev/null
@@ -1,43 +0,0 @@
-package(default_visibility = ["//visibility:public"])
-
-config_setting(
-    name = "darwin",
-    values = {"host_cpu": "darwin"},
-)
-
-config_setting(
-    name = "k8",
-    values = {"host_cpu": "k8"},
-)
-
-filegroup(
-    name = "dmd",
-    srcs = select({
-        ":darwin": ["dmd2/osx/bin/dmd"],
-        ":k8": ["dmd2/linux/bin64/dmd"],
-    }),
-)
-
-filegroup(
-    name = "libphobos2",
-    srcs = select({
-        ":darwin": ["dmd2/osx/lib/libphobos2.a"],
-        ":k8": [
-            "dmd2/linux/lib64/libphobos2.a",
-            "dmd2/linux/lib64/libphobos2.so",
-        ],
-    }),
-)
-
-filegroup(
-    name = "phobos-src",
-    srcs = glob(["dmd2/src/phobos/**/*.*"]),
-)
-
-filegroup(
-    name = "druntime-import-src",
-    srcs = glob([
-        "dmd2/src/druntime/import/*.*",
-        "dmd2/src/druntime/import/**/*.*",
-    ]),
-)
diff --git a/tools/build_defs/dotnet/csharp.bzl b/tools/build_defs/dotnet/csharp.bzl
index 1433cc6..a7660a6 100644
--- a/tools/build_defs/dotnet/csharp.bzl
+++ b/tools/build_defs/dotnet/csharp.bzl
@@ -282,10 +282,30 @@
     test=True
 )
 
+NUNIT_BUILD_FILE = """
+filegroup(
+    name = "nunit_exe",
+    srcs = ["NUnit-2.6.4/bin/nunit-console.exe"],
+    visibility = ["//visibility:public"],
+)
+
+filegroup(
+    name = "nunit_exe_libs",
+    srcs = glob(["NUnit-2.6.4/bin/lib/*.dll"]),
+    visibility = ["//visibility:public"],
+)
+
+filegroup(
+    name = "nunit_framework",
+    srcs = glob(["NUnit-2.6.4/bin/framework/*.dll"]),
+    visibility = ["//visibility:public"],
+)
+"""
+
 def csharp_repositories():
   native.new_http_archive(
       name = "nunit",
-      build_file = "tools/build_defs/dotnet/BUILD.nunit",
+      build_file_content = NUNIT_BUILD_FILE,
       sha256 = "1bd925514f31e7729ccde40a38a512c2accd86895f93465f3dfe6d0b593d7170",
       type = "zip",
       url = "https://github.com/nunit/nunitv2/releases/download/2.6.4/NUnit-2.6.4.zip",
diff --git a/tools/build_defs/dotnet/nunit.BUILD b/tools/build_defs/dotnet/nunit.BUILD
deleted file mode 100644
index 30be9c2..0000000
--- a/tools/build_defs/dotnet/nunit.BUILD
+++ /dev/null
@@ -1,17 +0,0 @@
-filegroup(
-    name = "nunit_exe",
-    srcs = ["NUnit-2.6.4/bin/nunit-console.exe"],
-    visibility = ["//visibility:public"],
-)
-
-filegroup(
-    name = "nunit_exe_libs",
-    srcs = glob(["NUnit-2.6.4/bin/lib/*.dll"]),
-    visibility = ["//visibility:public"],
-)
-
-filegroup(
-    name = "nunit_framework",
-    srcs = glob(["NUnit-2.6.4/bin/framework/*.dll"]),
-    visibility = ["//visibility:public"],
-)
diff --git a/tools/build_defs/groovy/groovy.BUILD b/tools/build_defs/groovy/groovy.BUILD
deleted file mode 100644
index 96de6cf..0000000
--- a/tools/build_defs/groovy/groovy.BUILD
+++ /dev/null
@@ -1,10 +0,0 @@
-filegroup(
-    name = "sdk",
-    srcs = glob(["groovy-2.4.4/**"], exclude_directories=0),
-    visibility = ["//visibility:public"],
-)
-java_import(
-    name = "groovy",
-    jars = ["groovy-2.4.4/lib/groovy-2.4.4.jar"],
-    visibility = ["//visibility:public"],
-)
diff --git a/tools/build_defs/groovy/groovy.bzl b/tools/build_defs/groovy/groovy.bzl
index e503b6b..0766325 100644
--- a/tools/build_defs/groovy/groovy.bzl
+++ b/tools/build_defs/groovy/groovy.bzl
@@ -380,7 +380,18 @@
     name = "groovy-sdk-artifact",
     url = "http://dl.bintray.com/groovy/maven/apache-groovy-binary-2.4.4.zip",
     sha256 = "a7cc1e5315a14ea38db1b2b9ce0792e35174161141a6a3e2ef49b7b2788c258c",
-    build_file = "groovy.BUILD",
+    build_file_content = """
+filegroup(
+    name = "sdk",
+    srcs = glob(["groovy-2.4.4/**"], exclude_directories=0),
+    visibility = ["//visibility:public"],
+)
+java_import(
+    name = "groovy",
+    jars = ["groovy-2.4.4/lib/groovy-2.4.4.jar"],
+    visibility = ["//visibility:public"],
+)
+""",
   )
   native.bind(
     name = "groovy-sdk",
diff --git a/tools/build_defs/sass/libsass.BUILD b/tools/build_defs/sass/libsass.BUILD
deleted file mode 100644
index 4236803..0000000
--- a/tools/build_defs/sass/libsass.BUILD
+++ /dev/null
@@ -1,17 +0,0 @@
-package(default_visibility = ["@sassc//:__pkg__"])
-
-filegroup(
-    name = "srcs",
-    srcs = glob([
-         "src/**/*.h*",
-         "src/**/*.c*",
-    ]),
-)
-
-# Includes directive may seem unnecessary here, but its needed for the weird
-# interplay between libsass/sassc projects. This is intentional.
-cc_library(
-    name = "headers",
-    includes = ["include"],
-    hdrs = glob(["include/**/*.h"]),
-)
\ No newline at end of file
diff --git a/tools/build_defs/sass/sass.bzl b/tools/build_defs/sass/sass.bzl
index 2de0d71..f7d0fbb 100644
--- a/tools/build_defs/sass/sass.bzl
+++ b/tools/build_defs/sass/sass.bzl
@@ -88,12 +88,47 @@
     },
 )
 
+LIBSASS_BUILD_FILE = """
+package(default_visibility = ["@sassc//:__pkg__"])
+
+filegroup(
+    name = "srcs",
+    srcs = glob([
+         "src/**/*.h*",
+         "src/**/*.c*",
+    ]),
+)
+
+# Includes directive may seem unnecessary here, but its needed for the weird
+# interplay between libsass/sassc projects. This is intentional.
+cc_library(
+    name = "headers",
+    includes = ["include"],
+    hdrs = glob(["include/**/*.h"]),
+)
+"""
+
+SASSC_BUILD_FILE = """
+package(default_visibility = ["//tools/build_defs/sass:__pkg__"])
+
+cc_binary(
+    name = "sassc",
+    srcs = [
+        "@libsass//:srcs",
+        "sassc.c",
+        "sassc_version.h",
+],
+    linkopts = ["-ldl", "-lm"],
+    deps = ["@libsass//:headers"],
+)
+"""
+
 def sass_repositories():
   native.new_http_archive(
       name = "libsass",
       url = "https://github.com/sass/libsass/archive/3.3.0-beta1.tar.gz",
       sha256 = "6a4da39cc0b585f7a6ee660dc522916f0f417c890c3c0ac7ebbf6a85a16d220f",
-      build_file = "tools/build_defs/sass/libsass.BUILD",
+      build_file_content = LIBSASS_BUILD_FILE,
       strip_prefix = "libsass-3.3.0-beta1",
   )
 
@@ -101,6 +136,6 @@
       name = "sassc",
       url = "https://github.com/sass/sassc/archive/3.3.0-beta1.tar.gz",
       sha256 = "87494218eea2441a7a24b40f227330877dbba75c5fa9014ac6188711baed53f6",
-      build_file = "tools/build_defs/sass/sassc.BUILD",
+      build_file_content = SASSC_BUILD_FILE,
       strip_prefix = "sassc-3.3.0-beta1",
   )
diff --git a/tools/build_defs/sass/sassc.BUILD b/tools/build_defs/sass/sassc.BUILD
deleted file mode 100644
index 58e8708..0000000
--- a/tools/build_defs/sass/sassc.BUILD
+++ /dev/null
@@ -1,12 +0,0 @@
-package(default_visibility = ["//tools/build_defs/sass:__pkg__"])
-
-cc_binary(
-    name = "sassc",
-    srcs = [
-        "@libsass//:srcs",
-        "sassc.c",
-        "sassc_version.h",
-],
-    linkopts = ["-ldl", "-lm"],
-    deps = ["@libsass//:headers"],
-)
diff --git a/tools/build_defs/scala/README.md b/tools/build_defs/scala/README.md
index 1bf9980..2589548 100644
--- a/tools/build_defs/scala/README.md
+++ b/tools/build_defs/scala/README.md
@@ -18,23 +18,8 @@
 In order to use `scala_library`, `scala_macro_library`, and `scala_binary`,
 you must add the following to your WORKSPACE file:
 ```python
-new_http_archive(
-    name = "scala",
-    strip_prefix = "scala-2.11.7",
-    sha256 = "ffe4196f13ee98a66cf54baffb0940d29432b2bd820bd0781a8316eec22926d0",
-    url = "http://downloads.typesafe.com/scala/2.11.7/scala-2.11.7.tgz",
-    build_file = "tools/build_defs/scala/scala.BUILD",
-)
-```
-
-In addition, in order to use `scala_test`, you must add the following to your
-WORKSPACE file:
-```python
-http_file(
-    name = "scalatest",
-    url = "https://oss.sonatype.org/content/groups/public/org/scalatest/scalatest_2.11/2.2.6/scalatest_2.11-2.2.6.jar",
-    sha256 = "f198967436a5e7a69cfd182902adcfbcb9f2e41b349e1a5c8881a2407f615962",
-)
+load("@bazel_tools//tools/build_defs/scala:scala.bzl", "scala_repositories")
+scala_repositories()
 ```
 
 [scala]: http://www.scala-lang.org/
diff --git a/tools/build_defs/scala/scala.BUILD b/tools/build_defs/scala/scala.BUILD
deleted file mode 100644
index 4206777..0000000
--- a/tools/build_defs/scala/scala.BUILD
+++ /dev/null
@@ -1,26 +0,0 @@
-# scala.BUILD
-exports_files([
-  "bin/scala",
-  "bin/scalac",
-  "bin/scaladoc",
-  "lib/akka-actor_2.11-2.3.10.jar",
-  "lib/config-1.2.1.jar",
-  "lib/jline-2.12.1.jar",
-  "lib/scala-actors-2.11.0.jar",
-  "lib/scala-actors-migration_2.11-1.1.0.jar",
-  "lib/scala-compiler.jar",
-  "lib/scala-continuations-library_2.11-1.0.2.jar",
-  "lib/scala-continuations-plugin_2.11.7-1.0.2.jar",
-  "lib/scala-library.jar",
-  "lib/scala-parser-comscala-2.11.7/binators_2.11-1.0.4.jar",
-  "lib/scala-reflect.jar",
-  "lib/scala-swing_2.11-1.0.2.jar",
-  "lib/scala-xml_2.11-1.0.4.jar",
-  "lib/scalap-2.11.7.jar",
-])
-
-filegroup(
-    name = "sdk",
-    srcs = glob(["**"]),
-    visibility = ["//visibility:public"],
-)
diff --git a/tools/build_defs/scala/scala.bzl b/tools/build_defs/scala/scala.bzl
index 452dc92..39b20e6 100644
--- a/tools/build_defs/scala/scala.bzl
+++ b/tools/build_defs/scala/scala.bzl
@@ -263,3 +263,46 @@
   executable=True,
   test=True,
 )
+
+SCALA_BUILD_FILE = """
+# scala.BUILD
+exports_files([
+  "bin/scala",
+  "bin/scalac",
+  "bin/scaladoc",
+  "lib/akka-actor_2.11-2.3.10.jar",
+  "lib/config-1.2.1.jar",
+  "lib/jline-2.12.1.jar",
+  "lib/scala-actors-2.11.0.jar",
+  "lib/scala-actors-migration_2.11-1.1.0.jar",
+  "lib/scala-compiler.jar",
+  "lib/scala-continuations-library_2.11-1.0.2.jar",
+  "lib/scala-continuations-plugin_2.11.7-1.0.2.jar",
+  "lib/scala-library.jar",
+  "lib/scala-parser-comscala-2.11.7/binators_2.11-1.0.4.jar",
+  "lib/scala-reflect.jar",
+  "lib/scala-swing_2.11-1.0.2.jar",
+  "lib/scala-xml_2.11-1.0.4.jar",
+  "lib/scalap-2.11.7.jar",
+])
+
+filegroup(
+    name = "sdk",
+    srcs = glob(["**"]),
+    visibility = ["//visibility:public"],
+)
+"""
+
+def scala_repositories():
+  native.new_http_archive(
+    name = "scala",
+    strip_prefix = "scala-2.11.7",
+    sha256 = "ffe4196f13ee98a66cf54baffb0940d29432b2bd820bd0781a8316eec22926d0",
+    url = "http://downloads.typesafe.com/scala/2.11.7/scala-2.11.7.tgz",
+    build_file_content = SCALA_BUILD_FILE,
+  )
+  native.http_file(
+    name = "scalatest",
+    url = "https://oss.sonatype.org/content/groups/public/org/scalatest/scalatest_2.11/2.2.6/scalatest_2.11-2.2.6.jar",
+    sha256 = "f198967436a5e7a69cfd182902adcfbcb9f2e41b349e1a5c8881a2407f615962",
+  )
diff --git a/tools/build_rules/appengine/appengine.BUILD b/tools/build_rules/appengine/appengine.BUILD
deleted file mode 100644
index c1942a2..0000000
--- a/tools/build_rules/appengine/appengine.BUILD
+++ /dev/null
@@ -1,34 +0,0 @@
-# Copyright 2015 The Bazel Authors. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#    http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# BUILD file to use the Java AppEngine SDK with a remote repository.
-java_import(
-    name = "jars",
-    jars = glob(["**/*.jar"]),
-    visibility = ["//visibility:public"],
-)
-
-java_import(
-    name = "api",
-    jars = ["appengine-java-sdk-1.9.23/lib/impl/appengine-api.jar"],
-    visibility = ["//visibility:public"],
-    neverlink = 1,
-)
-
-filegroup(
-    name = "sdk",
-    srcs = glob(["appengine-java-sdk-1.9.23/**"]),
-    visibility = ["//visibility:public"],
-    path = "appengine-java-sdk-1.9.23",
-)
\ No newline at end of file
diff --git a/tools/build_rules/appengine/appengine.bzl b/tools/build_rules/appengine/appengine.bzl
index a9f5b47..62e8437 100644
--- a/tools/build_rules/appengine/appengine.bzl
+++ b/tools/build_rules/appengine/appengine.bzl
@@ -233,12 +233,35 @@
                 data=data,
                 data_path=data_path)
 
+APPENGINE_BUILD_FILE = """
+# BUILD file to use the Java AppEngine SDK with a remote repository.
+java_import(
+    name = "jars",
+    jars = glob(["**/*.jar"]),
+    visibility = ["//visibility:public"],
+)
+
+java_import(
+    name = "api",
+    jars = ["appengine-java-sdk-1.9.23/lib/impl/appengine-api.jar"],
+    visibility = ["//visibility:public"],
+    neverlink = 1,
+)
+
+filegroup(
+    name = "sdk",
+    srcs = glob(["appengine-java-sdk-1.9.23/**"]),
+    visibility = ["//visibility:public"],
+    path = "appengine-java-sdk-1.9.23",
+)
+"""
+
 def appengine_repositories():
   native.new_http_archive(
       name = "com_google_appengine_java",
       url = "http://central.maven.org/maven2/com/google/appengine/appengine-java-sdk/1.9.23/appengine-java-sdk-1.9.23.zip",
       sha256 = "05e667036e9ef4f999b829fc08f8e5395b33a5a3c30afa9919213088db2b2e89",
-      build_file = "tools/build_rules/appengine/appengine.BUILD",
+      build_file_content = APPENGINE_BUILD_FILE,
   )
 
   native.bind(
diff --git a/tools/build_rules/closure/closure_compiler.BUILD b/tools/build_rules/closure/closure_compiler.BUILD
deleted file mode 100644
index dfc5411..0000000
--- a/tools/build_rules/closure/closure_compiler.BUILD
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright 2015 The Bazel Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-java_import(
-    name = "closure_compiler_jar",
-    jars = ["compiler.jar"],
-)
-
-java_binary(
-    name = "closure_compiler",
-    main_class = "com.google.javascript.jscomp.CommandLineRunner",
-    visibility = ["//visibility:public"],
-    runtime_deps = [":closure_compiler_jar"],
-)
diff --git a/tools/build_rules/closure/closure_library.BUILD b/tools/build_rules/closure/closure_library.BUILD
deleted file mode 100644
index a480453..0000000
--- a/tools/build_rules/closure/closure_library.BUILD
+++ /dev/null
@@ -1,38 +0,0 @@
-# Copyright 2015 The Bazel Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-load("/tools/build_rules/closure/closure_js_library", "closure_js_library")
-load("/tools/build_rules/closure/closure_stylesheet_library", "closure_stylesheet_library")
-
-closure_js_library(
-    name = "closure_library",
-    srcs = glob(
-        [
-            "closure/goog/**/*.js",
-            "third_party/closure/goog/**/*.js",
-        ],
-        exclude = [
-            "closure/goog/**/*_test.js",
-            "closure/goog/demos/**/*.js",
-            "third_party/closure/goog/**/*_test.js",
-        ],
-    ),
-    visibility = ["//visibility:public"],
-)
-
-closure_stylesheet_library(
-    name = "closure_library_css",
-    srcs = glob(["closure/goog/css/**/*.css"]),
-    visibility = ["//visibility:public"],
-)
diff --git a/tools/build_rules/closure/closure_repositories.bzl b/tools/build_rules/closure/closure_repositories.bzl
index 38aee02..29ab5f1 100644
--- a/tools/build_rules/closure/closure_repositories.bzl
+++ b/tools/build_rules/closure/closure_repositories.bzl
@@ -12,17 +12,80 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+CLOSURE_COMPILER_BUILD_FILE = """
+java_import(
+    name = "closure_compiler_jar",
+    jars = ["compiler.jar"],
+)
+
+java_binary(
+    name = "closure_compiler",
+    main_class = "com.google.javascript.jscomp.CommandLineRunner",
+    visibility = ["//visibility:public"],
+    runtime_deps = [":closure_compiler_jar"],
+)
+"""
+
+CLOSURE_LIBRARY_BUILD_FILE = """
+load("@bazel_tools//tools/build_rules/closure:closure_js_library.bzl", "closure_js_library")
+load("@bazel_tools//tools/build_rules/closure:closure_stylesheet_library.bzl", "closure_stylesheet_library")
+
+closure_js_library(
+    name = "closure_library",
+    srcs = glob(
+        [
+            "closure/goog/**/*.js",
+            "third_party/closure/goog/**/*.js",
+        ],
+        exclude = [
+            "closure/goog/**/*_test.js",
+            "closure/goog/demos/**/*.js",
+            "third_party/closure/goog/**/*_test.js",
+        ],
+    ),
+    visibility = ["//visibility:public"],
+)
+
+closure_stylesheet_library(
+    name = "closure_library_css",
+    srcs = glob(["closure/goog/css/**/*.css"]),
+    visibility = ["//visibility:public"],
+)
+"""
+
+CLOSURE_TEMPLATES_BUILD_FILE = """
+load("@bazel_tools//tools/build_rules/closure:closure_js_library.bzl", "closure_js_library")
+
+java_import(
+    name = "closure_templates_jar",
+    jars = ["SoyToJsSrcCompiler.jar"],
+)
+
+java_binary(
+    name = "closure_templates",
+    main_class = "com.google.template.soy.SoyToJsSrcCompiler",
+    visibility = ["//visibility:public"],
+    runtime_deps = [":closure_templates_jar"],
+)
+
+closure_js_library(
+    name = "closure_templates_js",
+    srcs = ["soyutils_usegoog.js"],
+    visibility = ["//visibility:public"],
+)
+"""
+
 def closure_repositories():
   native.new_http_archive(
       name = "closure_compiler",
-      build_file = "tools/build_rules/closure/closure_compiler.BUILD",
+      build_file_content = CLOSURE_COMPILER_BUILD_FILE,
       sha256 = "e4e0cb49ad21ec26dd47693bdbd48f67aefe2d94fe8d9239312d2bcc74986538",
       url = "http://dl.google.com/closure-compiler/compiler-20150729.zip",
   )
 
   native.new_git_repository(
       name = "closure_library",
-      build_file = "tools/build_rules/closure/closure_library.BUILD",
+      build_file_content = CLOSURE_LIBRARY_BUILD_FILE,
       commit = "748b32441093c1474db2e0b3d074250e0bc47778",
       remote = "https://github.com/google/closure-library.git",
   )
@@ -35,7 +98,7 @@
 
   native.new_http_archive(
       name = "closure_templates",
-      build_file = "tools/build_rules/closure/closure_templates.BUILD",
+      build_file_content = CLOSURE_TEMPLATES_BUILD_FILE,
       sha256 = "cdd94123cd0d1c3a183c15e855739c0aa5390297c22dddc731b8d7b23815e8a2",
       url = "http://dl.google.com/closure-templates/closure-templates-for-javascript-latest.zip",
   )
diff --git a/tools/build_rules/closure/closure_templates.BUILD b/tools/build_rules/closure/closure_templates.BUILD
deleted file mode 100644
index 7037b8b..0000000
--- a/tools/build_rules/closure/closure_templates.BUILD
+++ /dev/null
@@ -1,33 +0,0 @@
-# Copyright 2015 The Bazel Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-load("/tools/build_rules/closure/closure_js_library", "closure_js_library")
-
-java_import(
-    name = "closure_templates_jar",
-    jars = ["SoyToJsSrcCompiler.jar"],
-)
-
-java_binary(
-    name = "closure_templates",
-    main_class = "com.google.template.soy.SoyToJsSrcCompiler",
-    visibility = ["//visibility:public"],
-    runtime_deps = [":closure_templates_jar"],
-)
-
-closure_js_library(
-    name = "closure_templates_js",
-    srcs = ["soyutils_usegoog.js"],
-    visibility = ["//visibility:public"],
-)
diff --git a/tools/build_rules/go/def.bzl b/tools/build_rules/go/def.bzl
index 1ce3477..647371f 100644
--- a/tools/build_rules/go/def.bzl
+++ b/tools/build_rules/go/def.bzl
@@ -380,17 +380,32 @@
     test = True,
 )
 
+GO_TOOLCHAIN_BUILD_FILE = """
+package(
+  default_visibility = [ "//visibility:public" ])
+
+filegroup(
+  name = "toolchain",
+  srcs = glob(["go/bin/*", "go/pkg/**", ]),
+)
+
+filegroup(
+  name = "go_tool",
+  srcs = [ "go/bin/go" ],
+)
+"""
+
 def go_repositories():
   native.new_http_archive(
     name=  "golang_linux_amd64",
     url = "https://storage.googleapis.com/golang/go1.5.1.linux-amd64.tar.gz",
-    build_file = "tools/build_rules/go/toolchain/BUILD.go-toolchain",
+    build_file_content = GO_TOOLCHAIN_BUILD_FILE,
     sha256 = "2593132ca490b9ee17509d65ee2cd078441ff544899f6afb97a03d08c25524e7"
   )
 
   native.new_http_archive(
     name=  "golang_darwin_amd64",
     url = "https://storage.googleapis.com/golang/go1.5.1.darwin-amd64.tar.gz",
-    build_file = "tools/build_rules/go/toolchain/BUILD.go-toolchain",
+    build_file_content = GO_TOOLCHAIN_BUILD_FILE,
     sha256 = "e94487b8cd2e0239f27dc51e6c6464383b10acb491f753584605e9b28abf48fb"
   )
diff --git a/tools/build_rules/go/toolchain/BUILD b/tools/build_rules/go/toolchain/BUILD
index d7d8be8..c3afba9 100644
--- a/tools/build_rules/go/toolchain/BUILD
+++ b/tools/build_rules/go/toolchain/BUILD
@@ -34,7 +34,6 @@
     name = "srcs",
     srcs = [
         "BUILD",
-        "BUILD.go-toolchain",
     ],
     visibility = [
         "//src:__subpackages__",
diff --git a/tools/build_rules/go/toolchain/BUILD.go-toolchain b/tools/build_rules/go/toolchain/BUILD.go-toolchain
deleted file mode 100644
index 5624a3b..0000000
--- a/tools/build_rules/go/toolchain/BUILD.go-toolchain
+++ /dev/null
@@ -1,12 +0,0 @@
-package(
-  default_visibility = [ "//visibility:public" ])
-
-filegroup(
-  name = "toolchain",
-  srcs = glob(["go/bin/*", "go/pkg/**", ]),
-)
-
-filegroup(
-  name = "go_tool",
-  srcs = [ "go/bin/go" ],
-)
diff --git a/tools/build_rules/rust/rust.BUILD b/tools/build_rules/rust/rust.BUILD
deleted file mode 100644
index 86d2c7a..0000000
--- a/tools/build_rules/rust/rust.BUILD
+++ /dev/null
@@ -1,59 +0,0 @@
-config_setting(
-    name = "darwin",
-    values = {"host_cpu": "darwin"},
-)
-
-config_setting(
-    name = "k8",
-    values = {"host_cpu": "k8"},
-)
-
-filegroup(
-    name = "rustc",
-    srcs = select({
-        ":darwin": ["rustc/bin/rustc"],
-        ":k8": ["rustc/bin/rustc"],
-    }),
-    visibility = ["//visibility:public"],
-)
-
-filegroup(
-    name = "rustc_lib",
-    srcs = select({
-        ":darwin": glob(["rustc/lib/*.dylib"]),
-        ":k8": glob(["rustc/lib/*.so"]),
-    }),
-    visibility = ["//visibility:public"],
-)
-
-filegroup(
-    name = "rustdoc",
-    srcs = select({
-        ":darwin": ["rustc/bin/rustdoc"],
-        ":k8": ["rustc/bin/rustdoc"],
-    }),
-    visibility = ["//visibility:public"],
-)
-
-filegroup(
-    name = "rustlib",
-    srcs = select({
-        ":darwin": glob([
-            "rust-std-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/*.rlib",
-            "rust-std-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/*.dylib",
-            "rust-std-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/*.a",
-            "rustc/lib/rustlib/x86_64-apple-darwin/lib/*.rlib",
-            "rustc/lib/rustlib/x86_64-apple-darwin/lib/*.dylib",
-            "rustc/lib/rustlib/x86_64-apple-darwin/lib/*.a",
-        ]),
-        ":k8": glob([
-            "rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.rlib",
-            "rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.so",
-            "rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.a",
-            "rustc/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.rlib",
-            "rustc/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.so",
-            "rustc/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.a",
-        ]),
-    }),
-    visibility = ["//visibility:public"],
-)
diff --git a/tools/build_rules/rust/rust.bzl b/tools/build_rules/rust/rust.bzl
index 8b96051..84b6c28 100644
--- a/tools/build_rules/rust/rust.bzl
+++ b/tools/build_rules/rust/rust.bzl
@@ -673,13 +673,75 @@
     test = True,
 )
 
+RUST_BUILD_FILE = """
+config_setting(
+    name = "darwin",
+    values = {"host_cpu": "darwin"},
+)
+
+config_setting(
+    name = "k8",
+    values = {"host_cpu": "k8"},
+)
+
+filegroup(
+    name = "rustc",
+    srcs = select({
+        ":darwin": ["rustc/bin/rustc"],
+        ":k8": ["rustc/bin/rustc"],
+    }),
+    visibility = ["//visibility:public"],
+)
+
+filegroup(
+    name = "rustc_lib",
+    srcs = select({
+        ":darwin": glob(["rustc/lib/*.dylib"]),
+        ":k8": glob(["rustc/lib/*.so"]),
+    }),
+    visibility = ["//visibility:public"],
+)
+
+filegroup(
+    name = "rustdoc",
+    srcs = select({
+        ":darwin": ["rustc/bin/rustdoc"],
+        ":k8": ["rustc/bin/rustdoc"],
+    }),
+    visibility = ["//visibility:public"],
+)
+
+filegroup(
+    name = "rustlib",
+    srcs = select({
+        ":darwin": glob([
+            "rust-std-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/*.rlib",
+            "rust-std-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/*.dylib",
+            "rust-std-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/*.a",
+            "rustc/lib/rustlib/x86_64-apple-darwin/lib/*.rlib",
+            "rustc/lib/rustlib/x86_64-apple-darwin/lib/*.dylib",
+            "rustc/lib/rustlib/x86_64-apple-darwin/lib/*.a",
+        ]),
+        ":k8": glob([
+            "rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.rlib",
+            "rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.so",
+            "rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.a",
+            "rustc/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.rlib",
+            "rustc/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.so",
+            "rustc/lib/rustlib/x86_64-unknown-linux-gnu/lib/*.a",
+        ]),
+    }),
+    visibility = ["//visibility:public"],
+)
+"""
+
 def rust_repositories():
   native.new_http_archive(
       name = "rust_linux_x86_64",
       url = "https://static.rust-lang.org/dist/rust-1.6.0-x86_64-unknown-linux-gnu.tar.gz",
       strip_prefix = "rust-1.6.0-x86_64-unknown-linux-gnu",
       sha256 = "8630cc02432b4423d64eeae4ef071ec58e5dd1f3d555a3a3cc34b759202813f6",
-      build_file = "tools/build_rules/rust/rust.BUILD",
+      build_file_content = RUST_BUILD_FILE,
   )
 
   native.new_http_archive(
@@ -687,5 +749,5 @@
       url = "https://static.rust-lang.org/dist/rust-1.6.0-x86_64-apple-darwin.tar.gz",
       strip_prefix = "rust-1.6.0-x86_64-apple-darwin",
       sha256 = "8c6897ed37ef6fd2890b176afa65306cc8943e3c770c9530a701f1aefd3942b1",
-      build_file = "tools/build_rules/rust/rust.BUILD",
+      build_file_content = RUST_BUILD_FILE,
   )