aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--WORKSPACE6
-rw-r--r--examples/jsonnet/BUILD67
-rw-r--r--examples/jsonnet/intersection.jsonnet60
-rw-r--r--examples/jsonnet/intersection_golden.json48
-rw-r--r--examples/jsonnet/invalid.jsonnet15
-rw-r--r--examples/jsonnet/invalid.out2
-rw-r--r--examples/jsonnet/shell-workflows.jsonnet21
-rw-r--r--examples/jsonnet/wordcount.jsonnet59
-rw-r--r--examples/jsonnet/wordcount_golden.json53
-rw-r--r--examples/jsonnet/workflow.jsonnet46
-rw-r--r--examples/rust/fibonacci/BUILD36
-rw-r--r--examples/rust/fibonacci/benches/fibonacci_bench.rs25
-rw-r--r--examples/rust/fibonacci/src/lib.rs48
-rw-r--r--examples/rust/hello_lib/BUILD38
-rw-r--r--examples/rust/hello_lib/src/greeter.rs73
-rw-r--r--examples/rust/hello_lib/src/lib.rs15
-rw-r--r--examples/rust/hello_lib/tests/greeting.rs23
-rw-r--r--examples/rust/hello_world/BUILD19
-rw-r--r--examples/rust/hello_world/src/main.rs22
-rw-r--r--src/test/shell/bazel/BUILD6
-rwxr-xr-xsrc/test/shell/bazel/bazel_rust_example_test.sh52
-rw-r--r--tools/BUILD7
-rw-r--r--tools/build_defs/jsonnet/BUILD16
-rw-r--r--tools/build_defs/jsonnet/README.md553
-rw-r--r--tools/build_defs/jsonnet/jsonnet.bzl248
-rw-r--r--tools/build_defs/scala/BUILD5
-rw-r--r--tools/build_defs/scala/README.md3
-rw-r--r--tools/build_defs/scala/scala.bzl57
-rw-r--r--tools/build_rules/closure/BUILD26
-rw-r--r--tools/build_rules/closure/README.md128
-rw-r--r--tools/build_rules/closure/closure_js_binary.bzl124
-rw-r--r--tools/build_rules/closure/closure_js_library.bzl49
-rw-r--r--tools/build_rules/closure/closure_repositories.bzl114
-rw-r--r--tools/build_rules/closure/closure_stylesheet_library.bzl82
-rw-r--r--tools/build_rules/closure/closure_template_library.bzl59
-rw-r--r--tools/build_rules/rust/BUILD49
-rw-r--r--tools/build_rules/rust/README.md1008
-rw-r--r--tools/build_rules/rust/rust.bzl755
-rw-r--r--tools/build_rules/rust/test/BUILD3
-rw-r--r--tools/build_rules/rust/test/rust_rule_test.bzl58
40 files changed, 0 insertions, 4078 deletions
diff --git a/WORKSPACE b/WORKSPACE
index dfa7ca5b18..8a8dc2cb2b 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -1,11 +1,5 @@
workspace(name = "io_bazel")
-load("/tools/build_defs/jsonnet/jsonnet", "jsonnet_repositories")
-load("/tools/build_rules/rust/rust", "rust_repositories")
-
-jsonnet_repositories()
-rust_repositories()
-
# Protobuf expects an //external:python_headers label which would contain the
# Python headers if fast Python protos is enabled. Since we are not using fast
# Python protos, bind python_headers to a dummy target.
diff --git a/examples/jsonnet/BUILD b/examples/jsonnet/BUILD
deleted file mode 100644
index 72bc4eee69..0000000000
--- a/examples/jsonnet/BUILD
+++ /dev/null
@@ -1,67 +0,0 @@
-package(default_visibility = ["//visibility:public"])
-
-load(
- "//tools/build_defs/jsonnet:jsonnet.bzl",
- "jsonnet_library",
- "jsonnet_to_json",
- "jsonnet_to_json_test",
-)
-
-jsonnet_library(
- name = "workflow",
- srcs = ["workflow.jsonnet"],
-)
-
-jsonnet_to_json(
- name = "wordcount",
- src = "wordcount.jsonnet",
- outs = ["wordcount.json"],
- deps = [":workflow"],
-)
-
-jsonnet_to_json_test(
- name = "wordcount_test",
- src = "wordcount.jsonnet",
- golden = "wordcount_golden.json",
- deps = [":workflow"],
-)
-
-jsonnet_to_json(
- name = "intersection",
- src = "intersection.jsonnet",
- outs = ["intersection.json"],
- deps = [":workflow"],
-)
-
-jsonnet_to_json_test(
- name = "intersection_test",
- src = "intersection.jsonnet",
- golden = "intersection_golden.json",
- deps = [":workflow"],
-)
-
-jsonnet_library(
- name = "shell-workflows-lib",
- srcs = [
- "intersection.jsonnet",
- "wordcount.jsonnet",
- ],
- deps = [":workflow"],
-)
-
-jsonnet_to_json(
- name = "shell-workflows",
- src = "shell-workflows.jsonnet",
- outs = [
- "intersection-workflow.json",
- "wordcount-workflow.json",
- ],
- deps = [":shell-workflows-lib"],
-)
-
-jsonnet_to_json_test(
- name = "invalid_test",
- src = "invalid.jsonnet",
- error = 1,
- golden = "invalid.out",
-)
diff --git a/examples/jsonnet/intersection.jsonnet b/examples/jsonnet/intersection.jsonnet
deleted file mode 100644
index 17aa6a36ba..0000000000
--- a/examples/jsonnet/intersection.jsonnet
+++ /dev/null
@@ -1,60 +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.
-
-local workflow = import "examples/jsonnet/workflow.jsonnet";
-
-// Workflow that performs an intersection of two files using shell commands.
-{
- intersection: workflow.Workflow {
- jobs: {
- local input_file1 = "/tmp/list1",
- local input_file2 = "/tmp/list2",
- local sorted_file1 = "/tmp/list1_sorted",
- local sorted_file2 = "/tmp/list2_sorted",
- local intersection = "/tmp/intersection",
-
- SortJob:: workflow.ShJob {
- input_file:: "",
- output_file:: "",
- command: "sort %s > %s" % [self.input_file, self.output_file],
- inputs: [self.input_file],
- outputs: [self.output_file],
- },
-
- sort_file1: self.SortJob {
- input_file:: input_file1,
- output_file:: sorted_file1,
- },
-
- sort_file2: self.SortJob {
- input_file:: input_file2,
- output_file:: sorted_file2,
- },
-
- intersect: workflow.ShJob {
- deps: [
- ":sort_file1",
- ":sort_file2",
- ],
- command: "comm -12 %s %s > %s" %
- [sorted_file1, sorted_file2, intersection],
- inputs: [
- sorted_file1,
- sorted_file2,
- ],
- outputs: [intersection],
- },
- }
- }
-}
diff --git a/examples/jsonnet/intersection_golden.json b/examples/jsonnet/intersection_golden.json
deleted file mode 100644
index 6e8fa63864..0000000000
--- a/examples/jsonnet/intersection_golden.json
+++ /dev/null
@@ -1,48 +0,0 @@
-{
- "intersection": {
- "jobs": {
- "intersect": {
- "command": "comm -12 /tmp/list1_sorted /tmp/list2_sorted > /tmp/intersection",
- "deps": [
- ":sort_file1",
- ":sort_file2"
- ],
- "inputs": [
- "/tmp/list1_sorted",
- "/tmp/list2_sorted"
- ],
- "outputs": [
- "/tmp/intersection"
- ],
- "type": "sh",
- "vars": { }
- },
- "sort_file1": {
- "command": "sort /tmp/list1 > /tmp/list1_sorted",
- "deps": [ ],
- "inputs": [
- "/tmp/list1"
- ],
- "outputs": [
- "/tmp/list1_sorted"
- ],
- "type": "sh",
- "vars": { }
- },
- "sort_file2": {
- "command": "sort /tmp/list2 > /tmp/list2_sorted",
- "deps": [ ],
- "inputs": [
- "/tmp/list2"
- ],
- "outputs": [
- "/tmp/list2_sorted"
- ],
- "type": "sh",
- "vars": { }
- }
- },
- "retries": 5,
- "schedule": { }
- }
-}
diff --git a/examples/jsonnet/invalid.jsonnet b/examples/jsonnet/invalid.jsonnet
deleted file mode 100644
index e911037832..0000000000
--- a/examples/jsonnet/invalid.jsonnet
+++ /dev/null
@@ -1,15 +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.
-
-error "Foo."
diff --git a/examples/jsonnet/invalid.out b/examples/jsonnet/invalid.out
deleted file mode 100644
index 6c220f5170..0000000000
--- a/examples/jsonnet/invalid.out
+++ /dev/null
@@ -1,2 +0,0 @@
-RUNTIME ERROR: Foo.
- examples/jsonnet/invalid.jsonnet:15:1-12
diff --git a/examples/jsonnet/shell-workflows.jsonnet b/examples/jsonnet/shell-workflows.jsonnet
deleted file mode 100644
index bcf44c76ec..0000000000
--- a/examples/jsonnet/shell-workflows.jsonnet
+++ /dev/null
@@ -1,21 +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.
-
-local wordcount = import "examples/jsonnet/wordcount.jsonnet";
-local intersection = import "examples/jsonnet/intersection.jsonnet";
-
-{
- "wordcount-workflow.json": wordcount,
- "intersection-workflow.json": intersection,
-}
diff --git a/examples/jsonnet/wordcount.jsonnet b/examples/jsonnet/wordcount.jsonnet
deleted file mode 100644
index f1dfe2bfef..0000000000
--- a/examples/jsonnet/wordcount.jsonnet
+++ /dev/null
@@ -1,59 +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.
-
-local workflow = import "examples/jsonnet/workflow.jsonnet";
-
-// Workflow that performs a wordcount using shell commands.
-{
- wordcount: workflow.Workflow {
- retries: 12,
- schedule: workflow.Schedule {
- start_date: "2015-11-15",
- start_time: "17:30",
- repeat_frequency: 1,
- repeat_type: "week",
- },
- jobs: {
- local input_file = "/tmp/passage_test",
- local tokens_file = "/tmp/tokens",
- local sorted_tokens_file = "/tmp/sorted_tokens",
- local counts_file = "/tmp/counts",
-
- // Reads the input file and produces an output file with one word per
- // line.
- tokenize: workflow.ShJob {
- command: "tr ' ' '\n' < %s > %s" % [input_file, tokens_file],
- inputs: [input_file],
- outputs: [tokens_file],
- },
-
- // Takes the tokens file and produces a file with the tokens sorted.
- sort: workflow.ShJob {
- deps: [":tokenize"],
- command: "sort %s > %s" % [tokens_file, sorted_tokens_file],
- inputs: [tokens_file],
- outputs: [sorted_tokens_file],
- },
-
- // Takes the file containing sorted tokens and produces a file containing
- // the counts for each word.
- count: workflow.ShJob {
- deps: [":sort"],
- command: "uniq -c %s > %s" % [sorted_tokens_file, counts_file],
- inputs: [sorted_tokens_file],
- outputs: [counts_file],
- },
- }
- }
-}
diff --git a/examples/jsonnet/wordcount_golden.json b/examples/jsonnet/wordcount_golden.json
deleted file mode 100644
index 25d99cf3ab..0000000000
--- a/examples/jsonnet/wordcount_golden.json
+++ /dev/null
@@ -1,53 +0,0 @@
-{
- "wordcount": {
- "jobs": {
- "count": {
- "command": "uniq -c /tmp/sorted_tokens > /tmp/counts",
- "deps": [
- ":sort"
- ],
- "inputs": [
- "/tmp/sorted_tokens"
- ],
- "outputs": [
- "/tmp/counts"
- ],
- "type": "sh",
- "vars": { }
- },
- "sort": {
- "command": "sort /tmp/tokens > /tmp/sorted_tokens",
- "deps": [
- ":tokenize"
- ],
- "inputs": [
- "/tmp/tokens"
- ],
- "outputs": [
- "/tmp/sorted_tokens"
- ],
- "type": "sh",
- "vars": { }
- },
- "tokenize": {
- "command": "tr ' ' '\n' < /tmp/passage_test > /tmp/tokens",
- "deps": [ ],
- "inputs": [
- "/tmp/passage_test"
- ],
- "outputs": [
- "/tmp/tokens"
- ],
- "type": "sh",
- "vars": { }
- }
- },
- "retries": 12,
- "schedule": {
- "repeat_frequency": 1,
- "repeat_type": "week",
- "start_date": "2015-11-15",
- "start_time": "17:30"
- }
- }
-}
diff --git a/examples/jsonnet/workflow.jsonnet b/examples/jsonnet/workflow.jsonnet
deleted file mode 100644
index a093a0ec38..0000000000
--- a/examples/jsonnet/workflow.jsonnet
+++ /dev/null
@@ -1,46 +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.
-
-// Configuration for a hypothetical workflow scheduling system.
-{
- // Configuration for a workflow.
- Workflow:: {
- schedule: {},
- retries: 5,
- jobs: {},
- },
-
- // Scheduling configuration for a workflow.
- Schedule:: {
- start_date: "",
- start_time: "",
- repeat_frequency: 0,
- repeat_type: "",
- },
-
- // Base configuration for a Job in a workflow.
- Job:: {
- type: "base",
- deps: [],
- inputs: [],
- outputs: [],
- },
-
- // Configuration for a job that runs a shell command.
- ShJob:: self.Job {
- type: "sh",
- command: "",
- vars: {},
- }
-}
diff --git a/examples/rust/fibonacci/BUILD b/examples/rust/fibonacci/BUILD
deleted file mode 100644
index 74f7914217..0000000000
--- a/examples/rust/fibonacci/BUILD
+++ /dev/null
@@ -1,36 +0,0 @@
-package(default_visibility = ["//visibility:public"])
-
-load(
- "//tools/build_rules/rust:rust.bzl",
- "rust_library",
- "rust_test",
- "rust_bench_test",
- "rust_doc",
- "rust_doc_test",
-)
-
-rust_library(
- name = "fibonacci",
- srcs = ["src/lib.rs"],
-)
-
-rust_test(
- name = "fibonacci_test",
- deps = [":fibonacci"],
-)
-
-rust_bench_test(
- name = "fibonacci_bench",
- srcs = ["benches/fibonacci_bench.rs"],
- deps = [":fibonacci"],
-)
-
-rust_doc(
- name = "fibonacci_doc",
- dep = ":fibonacci",
-)
-
-rust_doc_test(
- name = "fibonacci_doc_test",
- dep = ":fibonacci",
-)
diff --git a/examples/rust/fibonacci/benches/fibonacci_bench.rs b/examples/rust/fibonacci/benches/fibonacci_bench.rs
deleted file mode 100644
index 80aa1a84ce..0000000000
--- a/examples/rust/fibonacci/benches/fibonacci_bench.rs
+++ /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.
-
-#![feature(test)]
-
-extern crate test;
-extern crate fibonacci;
-
-use test::Bencher;
-
-#[bench]
-fn bench_fibonacci(b: &mut Bencher) {
- b.iter(|| fibonacci::fibonacci(40));
-}
diff --git a/examples/rust/fibonacci/src/lib.rs b/examples/rust/fibonacci/src/lib.rs
deleted file mode 100644
index d8ae6e3fca..0000000000
--- a/examples/rust/fibonacci/src/lib.rs
+++ /dev/null
@@ -1,48 +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.
-
-/// Returns the nth Fibonacci number.
-///
-/// # Examples
-///
-/// ```
-/// fibonacci::fibonacci(5)
-/// ```
-pub fn fibonacci(n: u64) -> u64 {
- if n < 2 {
- return n;
- }
- let mut n1: u64 = 0;
- let mut n2: u64 = 1;
- for _ in 1..n {
- let sum = n1 + n2;
- n1 = n2;
- n2 = sum;
- }
- n2
-}
-
-#[cfg(test)]
-mod test {
- use super::fibonacci;
-
- #[test]
- fn test_fibonacci() {
- let numbers : Vec<u64> =
- vec![0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144];
- for (i, number) in numbers.iter().enumerate() {
- assert_eq!(*number, fibonacci(i as u64));
- }
- }
-}
diff --git a/examples/rust/hello_lib/BUILD b/examples/rust/hello_lib/BUILD
deleted file mode 100644
index c47368727a..0000000000
--- a/examples/rust/hello_lib/BUILD
+++ /dev/null
@@ -1,38 +0,0 @@
-package(default_visibility = ["//visibility:public"])
-
-load(
- "//tools/build_rules/rust:rust.bzl",
- "rust_library",
- "rust_test",
- "rust_doc",
- "rust_doc_test",
-)
-
-rust_library(
- name = "hello_lib",
- srcs = [
- "src/greeter.rs",
- "src/lib.rs",
- ],
-)
-
-rust_test(
- name = "hello_lib_test",
- deps = [":hello_lib"],
-)
-
-rust_test(
- name = "greeting_test",
- srcs = ["tests/greeting.rs"],
- deps = [":hello_lib"],
-)
-
-rust_doc(
- name = "hello_lib_doc",
- dep = ":hello_lib",
-)
-
-rust_doc_test(
- name = "hello_lib_doc_test",
- dep = ":hello_lib",
-)
diff --git a/examples/rust/hello_lib/src/greeter.rs b/examples/rust/hello_lib/src/greeter.rs
deleted file mode 100644
index bf332e4bd1..0000000000
--- a/examples/rust/hello_lib/src/greeter.rs
+++ /dev/null
@@ -1,73 +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.
-
-/// Object that displays a greeting.
-pub struct Greeter {
- greeting: String,
-}
-
-/// Implementation of Greeter.
-impl Greeter {
- /// Constructs a new `Greeter`.
- ///
- /// # Examples
- ///
- /// ```
- /// use hello_lib::greeter;
- ///
- /// let greeter = Greeter::new("Hello");
- /// ```
- pub fn new(greeting: &str) -> Greeter {
- Greeter { greeting: greeting.to_string(), }
- }
-
- /// Returns the greeting as a string.
- ///
- /// # Examples
- ///
- /// ```
- /// use hello_lib::greeter;
- ///
- /// let greeter = Greeter::new("Hello");
- /// let greeting = greeter.greeting("World");
- /// ```
- pub fn greeting(&self, thing: &str) -> String {
- format!("{} {}", &self.greeting, thing)
- }
-
- /// Prints the greeting.
- ///
- /// # Examples
- ///
- /// ```
- /// use hello_lib::greeter;
- ///
- /// let greeter = Greeter::new("Hello");
- /// greeter.greet("World");
- /// ```
- pub fn greet(&self, thing: &str) {
- println!("{} {}", &self.greeting, thing);
- }
-}
-
-#[cfg(test)]
-mod test {
- use super::Greeter;
-
- #[test]
- fn test_greeting() {
- let hello = Greeter::new("Hi");
- assert_eq!("Hi Rust", hello.greeting("Rust"));
- }
-}
diff --git a/examples/rust/hello_lib/src/lib.rs b/examples/rust/hello_lib/src/lib.rs
deleted file mode 100644
index 9dc608911f..0000000000
--- a/examples/rust/hello_lib/src/lib.rs
+++ /dev/null
@@ -1,15 +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.
-
-pub mod greeter;
diff --git a/examples/rust/hello_lib/tests/greeting.rs b/examples/rust/hello_lib/tests/greeting.rs
deleted file mode 100644
index be3435681b..0000000000
--- a/examples/rust/hello_lib/tests/greeting.rs
+++ /dev/null
@@ -1,23 +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.
-
-extern crate hello_lib;
-
-use hello_lib::greeter;
-
-#[test]
-fn test_greeting() {
- let hello = greeter::Greeter::new("Hello");
- assert_eq!("Hello world", hello.greeting("world"));
-}
diff --git a/examples/rust/hello_world/BUILD b/examples/rust/hello_world/BUILD
deleted file mode 100644
index e78362915c..0000000000
--- a/examples/rust/hello_world/BUILD
+++ /dev/null
@@ -1,19 +0,0 @@
-package(default_visibility = ["//visibility:public"])
-
-load("//tools/build_rules/rust:rust.bzl", "rust_binary", "rust_doc", "rust_doc_test")
-
-rust_binary(
- name = "hello_world",
- srcs = ["src/main.rs"],
- deps = ["//examples/rust/hello_lib"],
-)
-
-rust_doc(
- name = "hello_world_doc",
- dep = ":hello_world",
-)
-
-rust_doc_test(
- name = "hello_world_doc_test",
- dep = ":hello_world",
-)
diff --git a/examples/rust/hello_world/src/main.rs b/examples/rust/hello_world/src/main.rs
deleted file mode 100644
index 03cf43fcfe..0000000000
--- a/examples/rust/hello_world/src/main.rs
+++ /dev/null
@@ -1,22 +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.
-
-extern crate hello_lib;
-
-use hello_lib::greeter;
-
-fn main() {
- let hello = greeter::Greeter::new("Hello");
- hello.greet("world");
-}
diff --git a/src/test/shell/bazel/BUILD b/src/test/shell/bazel/BUILD
index cccd7874e6..9c7b5562ec 100644
--- a/src/test/shell/bazel/BUILD
+++ b/src/test/shell/bazel/BUILD
@@ -88,12 +88,6 @@ sh_test(
)
sh_test(
- name = "bazel_rust_example_test",
- srcs = ["bazel_rust_example_test.sh"],
- data = [":test-deps"],
-)
-
-sh_test(
name = "bazel_apple_test",
srcs = ["bazel_apple_test.sh"],
data = [
diff --git a/src/test/shell/bazel/bazel_rust_example_test.sh b/src/test/shell/bazel/bazel_rust_example_test.sh
deleted file mode 100755
index 0293a64f96..0000000000
--- a/src/test/shell/bazel/bazel_rust_example_test.sh
+++ /dev/null
@@ -1,52 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-# Tests the examples provided in Bazel
-#
-
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
-
-function set_up() {
- copy_examples
-}
-
-function check_has_rustc() {
- PATH=/usr/bin:/usr/local/bin:$PATH
- if [ ! -x "$(which rustc)" ]; then
- echo "No rustc found. Skipping..."
- return 1
- fi
-}
-
-function test_rust() {
- local hello_lib_pkg=examples/rust/hello_lib
- assert_build_output ./bazel-bin/${hello_lib_pkg}/libhello_lib.rlib ${hello_lib_pkg}:hello_lib
-
- local hello_world_pkg=examples/rust/hello_world
- assert_build_output ./bazel-bin/${hello_world_pkg}/hello_world ${hello_world_pkg}:hello_world
- assert_binary_run_from_subdir "bazel-bin/${hello_world_pkg}/hello_data" "Hello world"
-}
-
-function test_rust_test() {
- hello_lib_test=examples/rust/hello_lib
- assert_build //${hello_lib_test}:greeting
- assert_test_ok //${hello_lib_test}:greeting
-}
-
-check_has_rustc || exit 0
-run_suite "rust_examples"
diff --git a/tools/BUILD b/tools/BUILD
index c55c0ad9e1..668957498d 100644
--- a/tools/BUILD
+++ b/tools/BUILD
@@ -12,12 +12,8 @@ filegroup(
"//tools/buildstamp:srcs",
"//tools/build_defs/apple:srcs",
"//tools/build_defs/docker:srcs",
- "//tools/build_defs/jsonnet:srcs",
"//tools/build_defs/pkg:srcs",
- "//tools/build_defs/scala:srcs",
"//tools/build_rules:srcs",
- "//tools/build_rules/closure:srcs",
- "//tools/build_rules/rust:srcs",
"//tools/jdk:srcs",
"//tools/genrule:srcs",
"//tools/cpp:srcs",
@@ -37,10 +33,7 @@ filegroup(
"//tools/android:srcs",
"//tools/build_defs/apple:srcs",
"//tools/build_defs/docker:srcs",
- "//tools/build_defs/jsonnet:srcs",
"//tools/build_defs/pkg:srcs",
- "//tools/build_rules/closure:srcs",
- "//tools/build_rules/rust:srcs",
"//tools/build_rules:embedded_tools_srcs",
"//tools/buildstamp:srcs",
"//tools/cpp:srcs",
diff --git a/tools/build_defs/jsonnet/BUILD b/tools/build_defs/jsonnet/BUILD
deleted file mode 100644
index 7f38b97020..0000000000
--- a/tools/build_defs/jsonnet/BUILD
+++ /dev/null
@@ -1,16 +0,0 @@
-package(default_visibility = ["//visibility:public"])
-
-filegroup(
- name = "srcs",
- srcs = glob(["**"]),
-)
-
-filegroup(
- name = "jsonnet",
- srcs = ["@jsonnet//:jsonnet"],
-)
-
-filegroup(
- name = "std",
- srcs = ["@jsonnet//:std"],
-)
diff --git a/tools/build_defs/jsonnet/README.md b/tools/build_defs/jsonnet/README.md
deleted file mode 100644
index 59db1888c8..0000000000
--- a/tools/build_defs/jsonnet/README.md
+++ /dev/null
@@ -1,553 +0,0 @@
-# Jsonnet Rules
-
-<div class="toc">
- <h2>Rules</h2>
- <ul>
- <li><a href="#jsonnet_library">jsonnet_library</a></li>
- <li><a href="#jsonnet_to_json">jsonnet_to_json</a></li>
- <li><a href="#jsonnet_to_json_test">jsonnet_to_json_test</a></li>
- </ul>
-</div>
-
-## Overview
-
-These are build rules for working with [Jsonnet][jsonnet] files with Bazel.
-
-[jsonnet]: http://google.github.io/jsonnet/doc/
-
-## Setup
-
-To use the Jsonnet rules, add the following to your `WORKSPACE` file to add the
-external repositories for Jsonnet:
-
-```python
-load("@bazel_tools//tools/build_defs/jsonnet:jsonnet.bzl", "jsonnet_repositories")
-
-jsonnet_repositories()
-```
-
-<a name="#jsonnet_library"></a>
-## jsonnet_library
-
-```python
-jsonnet_library(name, srcs, deps, imports)
-```
-
-<table class="table table-condensed table-bordered table-params">
- <colgroup>
- <col class="col-param" />
- <col class="param-description" />
- </colgroup>
- <thead>
- <tr>
- <th colspan="2">Attributes</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><code>name</code></td>
- <td>
- <code>Name, required</code>
- <p>A unique name for this rule.</p>
- </td>
- </tr>
- <tr>
- <td><code>srcs</code></td>
- <td>
- <code>List of Labels, required</code>
- <p>
- List of <code>.jsonnet</code> files that comprises this Jsonnet
- library.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>deps</code></td>
- <td>
- <code>List of labels, optional</code>
- <p>
- List of targets that are required by the <code>srcs</code> Jsonnet
- files.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>imports</code></td>
- <td>
- <code>List of strings, optional</code>
- <p>
- List of import <code>-J</code> flags to be passed to the
- <code>jsonnet</code> compiler.
- </p>
- </td>
- </tr>
- </tbody>
-</table>
-
-### Example
-
-Suppose you have the following directory structure:
-
-```
-[workspace]/
- WORKSPACE
- configs/
- BUILD
- backend.jsonnet
- frontend.jsonnet
-```
-
-You can use the `jsonnet_library` rule to build a collection of `.jsonnet`
-files that can be imported by other `.jsonnet` files as dependencies:
-
-`configs/BUILD`:
-
-```python
-load("@bazel_tools//tools/build_defs/jsonnet:jsonnet.bzl", "jsonnet_library")
-
-jsonnet_library(
- name = "configs",
- srcs = [
- "backend.jsonnet",
- "frontend.jsonnet",
- ],
-)
-```
-
-<a name="#jsonnet_to_json"></a>
-## jsonnet\_to\_json
-
-```python
-jsonnet_to_json(name, src, deps, outs, multiple_outputs, imports, vars, code_vars)
-```
-
-<table class="table table-condensed table-bordered table-params">
- <colgroup>
- <col class="col-param" />
- <col class="param-description" />
- </colgroup>
- <thead>
- <tr>
- <th colspan="2">Attributes</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><code>name</code></td>
- <td>
- <code>Name, required</code>
- <p>A unique name for this rule.</p>
- <p>
- This name will be used as the name of the JSON file generated by this
- rule.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>src</code></td>
- <td>
- <code>Label, required</code>
- <p>
- The <code>.jsonnet</code> file to convert to JSON.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>deps</code></td>
- <td>
- <code>List of labels, optional</code>
- <p>
- List of targets that are required by the <code>src</code> Jsonnet
- file.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>outs</code></td>
- <td>
- <code>List of Filenames, optional</code>
- <p>
- Names of the output .json files to be generated by this rule.
- </p>
- <p>
- If you are generating only a single JSON file and are not using
- jsonnet multiple output files, then this attribute should only
- contain the file name of the JSON file you are generating.
- </p>
- <p>
- If you are generating multiple JSON files using jsonnet multiple file
- output (<code>jsonnet -m</code>), then list the file names of all the
- JSON files to be generated. The file names specified here must match
- the file names specified in your <code>src</code> Jsonnet file.
- </p>
- <p>
- For the case where multiple file output is used but only for
- generating one output file, set the <code>multiple_outputs</code>
- attribute to 1 to explicitly enable the <code>-m</code> flag for
- multiple file output.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>multiple_outputs</code></td>
- <td>
- <code>bool, optional, default 0</code>
- <p>
- Set to 1 to explicitly enable multiple file output via the
- <code>jsonnet -m</code> flag.
- </p>
- <p>
- This is used for the case where multiple file output is used but only
- for generating a single output file. For example:
- </p>
-<pre>
-local foo = import "foo.jsonnet";
-
-{
- "foo.json": foo,
-}
-</pre>
- </p>
- </td>
- </tr>
- <tr>
- <td><code>imports</code></td>
- <td>
- <code>List of strings, optional</code>
- <p>
- List of import <code>-J</code> flags to be passed to the
- <code>jsonnet</code> compiler.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>vars</code></td>
- <td>
- <code>String dict, optional</code>
- <p>
- Map of variables to pass to jsonnet via <code>--var key=value</code>.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>code_vars</code></td>
- <td>
- <code>String dict, optional</code>
- <p>
- Map of code variables to pass to jsonnet via
- <code>--code-var key=value</code>.
- </p>
- </td>
- </tr>
- </tbody>
-</table>
-
-### Example
-
-Suppose you have the following directory structure:
-
-```
-[workspace]/
- WORKSPACE
- workflows/
- BUILD
- workflow.jsonnet
- wordcount.jsonnet
- intersection.jsonnet
-```
-
-Say that `workflow.jsonnet` is a base configuration library for a workflow
-scheduling system and `wordcount.jsonnet` and `intersection.jsonnet` both
-import `workflow.jsonnet` to define workflows for performing a wordcount and
-intersection of two files, respectively.
-
-First, create a `jsonnet_library` target with `workflow.jsonnet`:
-
-`workflows/BUILD`:
-
-```python
-load("@bazel_tools//tools/build_defs/jsonnet:jsonnet.bzl", "jsonnet_library")
-
-jsonnet_library(
- name = "workflow",
- srcs = ["workflow.jsonnet"],
-)
-```
-
-To compile `wordcount.jsonnet` and `intersection.jsonnet` to JSON, define two
-`jsonnet_to_json` targets:
-
-```python
-jsonnet_to_json(
- name = "wordcount",
- src = "wordcount.jsonnet",
- outs = ["wordcount.json"],
- deps = [":workflow"],
-)
-
-jsonnet_to_json(
- name = "intersection",
- src = "intersection.jsonnet",
- outs = ["intersection.json"],
- deps = [":workflow"],
-)
-```
-
-### Example: Multiple output files
-
-To use Jsonnet's [multiple output files][multiple-output-files], suppose you
-add a file `shell-workflows.jsonnet` that imports `wordcount.jsonnet` and
-`intersection.jsonnet`:
-
-`workflows/shell-workflows.jsonnet`:
-
-```
-local wordcount = import "workflows/wordcount.jsonnet";
-local intersection = import "workflows/intersection.jsonnet";
-
-{
- "wordcount-workflow.json": wordcount,
- "intersection-workflow.json": intersection,
-}
-```
-
-To compile `shell-workflows.jsonnet` into the two JSON files,
-`wordcount-workflow.json` and `intersection-workflow.json`, first create a
-`jsonnet_library` target containing the two files that
-`shell-workflows.jsonnet` depends on:
-
-```python
-jsonnet_library(
- name = "shell-workflows-lib",
- srcs = [
- "wordcount.jsonnet",
- "intersection.jsonnet",
- ],
- deps = [":workflow"],
-)
-```
-
-Then, create a `jsonnet_to_json` target and set `outs` to the list of output
-files to indicate that multiple output JSON files are generated:
-
-```python
-jsonnet_to_json(
- name = "shell-workflows",
- src = "shell-workflows.jsonnet",
- deps = [":shell-workflows-lib"],
- outs = [
- "wordcount-workflow.jsonnet",
- "intersection-workflow.jsonnet",
- ],
-)
-```
-
-[multiple-output-files]: http://google.github.io/jsonnet/doc/commandline.html
-
-<a name="#jsonnet_to_json_test"></a>
-## jsonnet\_to\_json\_test
-
-```python
-jsonnet_to_json_test(name, src, deps, imports, golden, error=0, regex=False)
-```
-
-<table class="table table-condensed table-bordered table-params">
- <colgroup>
- <col class="col-param" />
- <col class="param-description" />
- </colgroup>
- <thead>
- <tr>
- <th colspan="2">Attributes</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><code>name</code></td>
- <td>
- <code>Name, required</code>
- <p>A unique name for this rule.</p>
- <p>
- This name will be used as the name of the JSON file generated by this
- rule.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>src</code></td>
- <td>
- <code>Label, required</code>
- <p>
- The <code>.jsonnet</code> file to convert to JSON.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>deps</code></td>
- <td>
- <code>List of labels, optional</code>
- <p>
- List of targets that are required by the <code>src</code> Jsonnet
- file.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>imports</code></td>
- <td>
- <code>List of strings, optional</code>
- <p>
- List of import <code>-J</code> flags to be passed to the
- <code>jsonnet</code> compiler.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>vars</code></td>
- <td>
- <code>String dict, optional</code>
- <p>
- Map of variables to pass to jsonnet via <code>--var key=value</code>.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>code_vars</code></td>
- <td>
- <code>String dict, optional</code>
- <p>
- Map of code variables to pass to jsonnet via
- <code>--code-var key=value</code>.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>golden</code></td>
- <td>
- <code>Label, optional</code>
- <p>
- The expected (combined stdout and stderr) output to compare to the
- output of running <code>jsonnet</code> on <code>src</code>.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>error</code></td>
- <td>
- <code>Integer, optional, default is 0</code>
- <p>
- The expected error code from running <code>jsonnet</code> on
- <code>src</code>.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>regex</code></td>
- <td>
- <code>bool, optional, default is False</code>
- <p>
- Set to 1 if <code>golden</code> contains a regex used to match
- the output of running <code>jsonnet</code> on <code>src</code>.
- </p>
- </td>
- </tr>
- </tbody>
-</table>
-
-### Example
-
-Suppose you have the following directory structure:
-
-```
-[workspace]/
- WORKSPACE
- config/
- BUILD
- base_config.jsonnet
- test_config.jsonnet
- test_config.json
-```
-
-Suppose that `base_config.jsonnet` is a library Jsonnet file, containing the
-base configuration for a service. Suppose that `test_config.jsonnet` is a test
-configuration file that is used to test `base_config.jsonnet`, and
-`test_config.json` is the expected JSON output from compiling
-`test_config.jsonnet`.
-
-The `jsonnet_to_json_test` rule can be used to verify that compiling a Jsonnet
-file produces the expected JSON output. Simply define a `jsonnet_to_json_test`
-target and provide the input test Jsonnet file and the `golden` file containing
-the expected JSON output:
-
-`config/BUILD`:
-
-```python
-load(
- "@bazel_tools//tools/build_defs/jsonnet:jsonnet.bzl",
- "jsonnet_library",
- "jsonnet_to_json_test",
-)
-
-jsonnet_library(
- name = "base_config",
- srcs = ["base_config.jsonnet"],
-)
-
-jsonnet_to_json_test(
- name = "test_config_test",
- src = "test_config",
- deps = [":base_config"],
- golden = "test_config.json",
-)
-```
-
-To run the test: `bazel test //config:test_config_test`
-
-### Example: Negative tests
-
-Suppose you have the following directory structure:
-
-```
-[workspace]/
- WORKSPACE
- config/
- BUILD
- base_config.jsonnet
- invalid_config.jsonnet
- invalid_config.output
-```
-
-Suppose that `invalid_config.jsonnet` is a Jsonnet file used to verify that
-an invalid config triggers an assertion in `base_config.jsonnet`, and
-`invalid_config.output` is the expected error output.
-
-The `jsonnet_to_json_test` rule can be used to verify that compiling a Jsonnet
-file results in an expected error code and error output. Simply define a
-`jsonnet_to_json_test` target and provide the input test Jsonnet file, the
-expected error code in the `error` attribute, and the `golden` file containing
-the expected error output:
-
-`config/BUILD`:
-
-```python
-load(
- "@bazel_tools//tools/build_defs/jsonnet:jsonnet.bzl",
- "jsonnet_library",
- "jsonnet_to_json_test",
-)
-
-jsonnet_library(
- name = "base_config",
- srcs = ["base_config.jsonnet"],
-)
-
-jsonnet_to_json_test(
- name = "invalid_config_test",
- src = "invalid_config",
- deps = [":base_config"],
- golden = "invalid_config.output",
- error = 1,
-)
-```
-
-To run the test: `bazel test //config:invalid_config_test`
diff --git a/tools/build_defs/jsonnet/jsonnet.bzl b/tools/build_defs/jsonnet/jsonnet.bzl
deleted file mode 100644
index 23b9a9914d..0000000000
--- a/tools/build_defs/jsonnet/jsonnet.bzl
+++ /dev/null
@@ -1,248 +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.
-
-"""Jsonnet rules for Bazel."""
-
-_JSONNET_FILETYPE = FileType([".jsonnet"])
-
-def _setup_deps(deps):
- """Collects source files and import flags of transitive dependencies.
-
- Args:
- deps: List of deps labels from ctx.attr.deps.
-
- Returns:
- Returns a struct containing the following fields:
- transitive_sources: List of Files containing sources of transitive
- dependencies
- imports: List of Strings containing import flags set by transitive
- dependency targets.
- """
- transitive_sources = set(order="compile")
- imports = set()
- for dep in deps:
- transitive_sources += dep.transitive_jsonnet_files
- imports += ["%s/%s" % (dep.label.package, im) for im in dep.imports]
-
- return struct(
- transitive_sources = transitive_sources,
- imports = imports)
-
-def _jsonnet_library_impl(ctx):
- """Implementation of the jsonnet_library rule."""
- depinfo = _setup_deps(ctx.attr.deps)
- sources = depinfo.transitive_sources + ctx.files.srcs
- imports = depinfo.imports + ctx.attr.imports
- return struct(files = set(),
- transitive_jsonnet_files = sources,
- imports = imports)
-
-def _jsonnet_toolchain(ctx):
- return struct(
- jsonnet_path = ctx.file.jsonnet.path,
- imports = ["-J %s" % ctx.file.std.dirname])
-
-def _jsonnet_to_json_impl(ctx):
- """Implementation of the jsonnet_to_json rule."""
- depinfo = _setup_deps(ctx.attr.deps)
- toolchain = _jsonnet_toolchain(ctx)
- jsonnet_vars = ctx.attr.vars
- jsonnet_code_vars = ctx.attr.code_vars
- command = (
- [
- "set -e;",
- toolchain.jsonnet_path,
- ] +
- ["-J %s/%s" % (ctx.label.package, im) for im in ctx.attr.imports] +
- ["-J %s" % im for im in depinfo.imports] +
- toolchain.imports +
- ["-J ."] +
- ["--var '%s'='%s'"
- % (var, jsonnet_vars[var]) for var in jsonnet_vars.keys()] +
- ["--code-var '%s'='%s'"
- % (var, jsonnet_code_vars[var]) for var in jsonnet_code_vars.keys()])
-
- outputs = []
- # If multiple_outputs is set to true, then jsonnet will be invoked with the
- # -m flag for multiple outputs. Otherwise, jsonnet will write the resulting
- # JSON to stdout, which is redirected into a single JSON output file.
- if len(ctx.attr.outs) > 1 or ctx.attr.multiple_outputs:
- output_json_files = [ctx.new_file(ctx.configuration.bin_dir, out.name)
- for out in ctx.attr.outs]
- outputs += output_json_files
- command += ["-m", output_json_files[0].dirname, ctx.file.src.path]
- else:
- if len(ctx.attr.outs) > 1:
- fail("Only one file can be specified in outs if multiple_outputs is " +
- "not set.")
-
- compiled_json = ctx.new_file(ctx.configuration.bin_dir,
- ctx.attr.outs[0].name)
- outputs += [compiled_json]
- command += [ctx.file.src.path, "-o", compiled_json.path]
-
- compile_inputs = (
- [ctx.file.src, ctx.file.jsonnet, ctx.file.std] +
- list(depinfo.transitive_sources))
-
- ctx.action(
- inputs = compile_inputs,
- outputs = outputs,
- mnemonic = "Jsonnet",
- command = " ".join(command),
- use_default_shell_env = True,
- progress_message = "Compiling Jsonnet to JSON for " + ctx.label.name);
-
-_EXIT_CODE_COMPARE_COMMAND = """
-EXIT_CODE=$?
-EXPECTED_EXIT_CODE=%d
-if [ $EXIT_CODE -ne $EXPECTED_EXIT_CODE ] ; then
- echo "FAIL (exit code): %s"
- echo "Expected: $EXPECTED_EXIT_CODE"
- echo "Actual: $EXIT_CODE"
- echo "Output: $OUTPUT"
- exit 1
-fi
-"""
-
-_DIFF_COMMAND = """
-GOLDEN=$(cat %s)
-if [ "$OUTPUT" != "$GOLDEN" ]; then
- echo "FAIL (output mismatch): %s"
- echo "Diff:"
- diff <(echo $GOLDEN) <(echo $OUTPUT)
- echo "Expected: $GOLDEN"
- echo "Actual: $OUTPUT"
- exit 1
-fi
-"""
-
-_REGEX_DIFF_COMMAND = """
-GOLDEN_REGEX=$(cat %s)
-if [[ ! "$OUTPUT" =~ $GOLDEN_REGEX ]]; then
- echo "FAIL (regex mismatch): %s"
- echo "Output: $OUTPUT"
- exit 1
-fi
-"""
-
-def _jsonnet_to_json_test_impl(ctx):
- """Implementation of the jsonnet_to_json_test rule."""
- depinfo = _setup_deps(ctx.attr.deps)
- toolchain = _jsonnet_toolchain(ctx)
-
- golden_files = []
- if ctx.file.golden:
- golden_files += [ctx.file.golden]
- if ctx.attr.regex:
- diff_command = _REGEX_DIFF_COMMAND % (ctx.file.golden.short_path,
- ctx.label.name)
- else:
- diff_command = _DIFF_COMMAND % (ctx.file.golden.short_path,
- ctx.label.name)
-
- jsonnet_vars = ctx.attr.vars
- jsonnet_code_vars = ctx.attr.code_vars
- jsonnet_command = " ".join(
- ["OUTPUT=$(%s" % ctx.file.jsonnet.short_path] +
- ["-J %s/%s" % (ctx.label.package, im) for im in ctx.attr.imports] +
- ["-J %s" % im for im in depinfo.imports] +
- toolchain.imports +
- ["-J ."] +
- ["--var %s=%s"
- % (var, jsonnet_vars[var]) for var in jsonnet_vars.keys()] +
- ["--code-var %s=%s"
- % (var, jsonnet_code_vars[var]) for var in jsonnet_code_vars.keys()] +
- [
- ctx.file.src.path,
- "2>&1)",
- ])
-
- command = "\n".join([
- "#!/bin/bash",
- jsonnet_command,
- _EXIT_CODE_COMPARE_COMMAND % (ctx.attr.error, ctx.label.name),
- diff_command])
-
- ctx.file_action(output = ctx.outputs.executable,
- content = command,
- executable = True);
-
- test_inputs = (
- [ctx.file.src, ctx.file.jsonnet, ctx.file.std] +
- golden_files +
- list(depinfo.transitive_sources))
-
- return struct(
- runfiles = ctx.runfiles(files = test_inputs, collect_data = True))
-
-_jsonnet_common_attrs = {
- "deps": attr.label_list(providers = ["transitive_jsonnet_files"],
- allow_files = False),
- "imports": attr.string_list(),
- "jsonnet": attr.label(
- default = Label("@bazel_tools//tools/build_defs/jsonnet:jsonnet"),
- cfg = HOST_CFG,
- executable = True,
- single_file = True),
- "std": attr.label(
- default = Label("@bazel_tools//tools/build_defs/jsonnet:std"),
- single_file = True),
-}
-
-_jsonnet_library_attrs = {
- "srcs": attr.label_list(allow_files = _JSONNET_FILETYPE),
-}
-
-jsonnet_library = rule(
- _jsonnet_library_impl,
- attrs = _jsonnet_library_attrs + _jsonnet_common_attrs,
-)
-
-_jsonnet_compile_attrs = {
- "src": attr.label(allow_files = _JSONNET_FILETYPE,
- single_file = True),
- "vars": attr.string_dict(),
- "code_vars": attr.string_dict(),
-}
-
-_jsonnet_to_json_attrs = _jsonnet_compile_attrs + {
- "outs": attr.output_list(mandatory = True),
- "multiple_outputs": attr.bool(),
-}
-
-jsonnet_to_json = rule(
- _jsonnet_to_json_impl,
- attrs = _jsonnet_to_json_attrs + _jsonnet_common_attrs,
-)
-
-_jsonnet_to_json_test_attrs = _jsonnet_compile_attrs + {
- "golden": attr.label(allow_files = True, single_file = True),
- "error": attr.int(),
- "regex": attr.bool(),
-}
-
-jsonnet_to_json_test = rule(
- _jsonnet_to_json_test_impl,
- attrs = _jsonnet_to_json_test_attrs + _jsonnet_common_attrs,
- executable = True,
- test = True,
-)
-
-def jsonnet_repositories():
- native.git_repository(
- name = "jsonnet",
- remote = "https://github.com/google/jsonnet.git",
- tag = "v0.8.1",
- )
diff --git a/tools/build_defs/scala/BUILD b/tools/build_defs/scala/BUILD
deleted file mode 100644
index 10af39ce64..0000000000
--- a/tools/build_defs/scala/BUILD
+++ /dev/null
@@ -1,5 +0,0 @@
-filegroup(
- name = "srcs",
- srcs = glob(["**"]),
- visibility = ["//tools:__pkg__"],
-)
diff --git a/tools/build_defs/scala/README.md b/tools/build_defs/scala/README.md
deleted file mode 100644
index 542e018555..0000000000
--- a/tools/build_defs/scala/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# Scala Rules for Bazel
-
-This has page has moved to [bazelbuid/rules_scala](https://github.com/bazelbuild/rules_scala/blob/master/README.md).
diff --git a/tools/build_defs/scala/scala.bzl b/tools/build_defs/scala/scala.bzl
deleted file mode 100644
index fbb107351e..0000000000
--- a/tools/build_defs/scala/scala.bzl
+++ /dev/null
@@ -1,57 +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.
-
-"""Rules for supporting the Scala language."""
-
-load(
- "@io_bazel_rules_scala//scala:scala.bzl",
- orig_scala_library="scala_library",
- orig_scala_macro_library="scala_macro_library",
- orig_scala_binary="scala_binary",
- orig_scala_test="scala_test",
- orig_scala_repositories="scala_repositories",
-)
-
-def warning(rule):
- return """This rule has moved out of @bazel_tools!
-
-The scala rules have moved to https://github.com/bazelbuild/rules_scala, you
-should now refer them via @io_bazel_rules_scala, use:
-
-load('@io_bazel_rules_scala//scala:scala.bzl', '%s')
-
-instead of:
-
-load('@bazel_tools//tools/build_defs/scala:scala.bzl', '%s')
-""" % (rule, rule)
-
-def scala_library(**kwargs):
- print(warning("scala_library"))
- original_scala_library(**kwargs)
-
-def scala_macro_library(**kwargs):
- print(warning("scala_macro_library"))
- orig_scala_macro_library(**kwargs)
-
-def scala_binary(**kwargs):
- print(warning("scala_binary"))
- original_scala_binary(**kwargs)
-
-def scala_test(**kwargs):
- print(warning("scala_test"))
- original_scala_test(**kwargs)
-
-def scala_repositories():
- print(warning("scala_repositories"))
- original_scala_repositories()
diff --git a/tools/build_rules/closure/BUILD b/tools/build_rules/closure/BUILD
deleted file mode 100644
index 486a8aadd8..0000000000
--- a/tools/build_rules/closure/BUILD
+++ /dev/null
@@ -1,26 +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_binary(
- name = "closure_stylesheets",
- main_class = "com.google.common.css.compiler.commandline.ClosureCommandLineCompiler",
- visibility = ["//visibility:public"],
- runtime_deps = ["@closure_stylesheets//jar"],
-)
-
-filegroup(
- name = "srcs",
- srcs = glob(["**"]),
- visibility = ["//tools:__pkg__"],
-)
diff --git a/tools/build_rules/closure/README.md b/tools/build_rules/closure/README.md
deleted file mode 100644
index 0f7c979443..0000000000
--- a/tools/build_rules/closure/README.md
+++ /dev/null
@@ -1,128 +0,0 @@
-# Closure Tools for Bazel
-
-## Deprecation notice
-
-Please note, Closure Tools for Bazel is deprecated, and will be moved soon.
-Please see [github.com/bazelbuild/rules_closure](https://github.com/bazelbuild/rules_closure/)
-for the new rules.
-
-## Overview
-
-These rules define targets for JavaScript, stylesheets, and templates that will
-be compiled with the Closure Tools toolchain.
-
-* `closure_js_binary`
-* `closure_js_library`
-* `closure_stylesheet_library`
-* `closure_template_library`
-
-## Setup
-
-Add the following to your `WORKSPACE` file to add the external repositories
-for the various Closure Tools binaries and the Closure Library:
-
-```python
-load("@bazel_tools//tools/build_rules/closure:closure_repositories.bzl", "closure_repositories")
-
-closure_repositories()
-```
-
-## Usage
-
-Suppose we are building a web application with template, stylesheet, and
-JavaScript files: `hello.soy`, `hello.gss`, and `hello.js`.
-
-`hello.soy`
-
-```
-{namespace hello.templates autoescape="strict"}
-
-/**
- * Renders an element containing the text "hello".
- */
-{template .hello}
- <div class="{css hello-container}">Hello.</div>
-{/template}
-```
-
-`hello.gss`
-
-```css
-.hello-container {
- color: red;
- font-weight: bold;
-}
-```
-
-`hello.js`
-
-```javascript
-goog.provide('hello');
-
-goog.require('goog.soy');
-goog.require('hello.templates');
-
-goog.soy.renderElement(document.body, hello.templates.hello);
-```
-
-We can create a BUILD file to compile these and produce two files:
-
-* `hello_combined.css`
-* `hello_combined.js`
-
-`BUILD`
-
-```python
-load("@bazel_tools//tools/build_rules/closure:closure_js_binary.bzl", "closure_js_binary")
-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")
-load("@bazel_tools//tools/build_rules/closure:closure_template_library.bzl", "closure_template_library")
-
-closure_js_binary(
- name = "hello",
- main = "hello",
- deps = [":hello_lib"],
-)
-
-closure_js_library(
- name = "hello_lib",
- srcs = ["hello.js"],
- deps = [
- "@closure_library//:closure_library",
- "@closure_templates//:closure_templates_js",
- ":hello_css",
- ":hello_soy",
- ]
-)
-
-closure_stylesheet_library(
- name = "hello_css",
- srcs = ["hello.gss"],
- deps = ["@closure_library//:closure_library_css"],
-)
-
-closure_template_library(
- name = "hello_soy",
- srcs = ["hello.soy"],
-)
-```
-
-## Known Issues
-
-The version of the Closure Templates compiler that is used will emit warnings
-about protected property access and about a missing enum value. These issues
-have been fixed in the source, but are not yet available as a downloadable
-archive. These warnings are safe to ignore.
-
-You may define a new_local_repository target if you wish to check out the source
-from Github yourself. Otherwise you may wish to wait until the Closure tools are
-available as Bazel workspaces. e.g.
-
-```python
-new_local_repository(
- name = "closure_templates",
- build_file = "tools/build_rules/closure/closure_templates.BUILD",
- path = "/home/user/src/github/google/closure-templates/target",
-)
-```
-
diff --git a/tools/build_rules/closure/closure_js_binary.bzl b/tools/build_rules/closure/closure_js_binary.bzl
deleted file mode 100644
index c4453ffb10..0000000000
--- a/tools/build_rules/closure/closure_js_binary.bzl
+++ /dev/null
@@ -1,124 +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 definitions for JavaScript binaries compiled with the Closure Compiler.
-
-A single file is produced with the _compiled.js suffix.
-
-By default, the name of the entry point is assumed to be the same as that of the
-build target. This behaviour may be overridden with the "main" attribute.
-
-The optimization level may be set with the "compilation_level" attribute.
-Supported values are: unobfuscated, simple, and advanced.
-
-Example:
-
- closure_js_binary(
- name = "hello",
- compilation_level = "simple",
- language_in = "ecmascript6",
- language_out = "ecmascript3",
- externs = ["//third_party/javascript/google_cast/cast.js"],
- deps = [
- "@closure_library//:closure_library",
- ":hello_lib",
- ],
- )
-
-This rule will produce hello_combined.js.
-"""
-
-_COMPILATION_LEVELS = {
- "whitespace_only": [
- "--compilation_level=WHITESPACE_ONLY",
- "--formatting=PRETTY_PRINT"
- ],
- "simple": ["--compilation_level=SIMPLE"],
- "advanced": ["--compilation_level=ADVANCED"]
-}
-
-_SUPPORTED_LANGUAGES = {
- "es3": ["ES3"],
- "ecmascript3": ["ECMASCRIPT3"],
- "es5": ["ES5"],
- "ecmascript5": ["ECMASCRIPT5"],
- "es5_strict": ["ES5_STRICT"],
- "ecmascript5_strict": ["ECMASCRIPT5_STRICT"],
- "es6": ["ES6"],
- "ecmascript6": ["ECMASCRIPT6"],
- "es6_strict": ["ES6_STRICT"],
- "ecmascript6_strict": ["ECMASCRIPT6_STRICT"],
- "es6_typed": ["ES6_TYPED"],
- "ecmascript6_typed": ["ECMASCRIPT6_TYPED"],
-}
-
-def _impl(ctx):
- externs = set(order="compile")
- srcs = set(order="compile")
- for dep in ctx.attr.deps:
- externs += dep.transitive_js_externs
- srcs += dep.transitive_js_srcs
-
- args = [
- "--entry_point=goog:%s" % ctx.attr.main,
- "--js_output_file=%s" % ctx.outputs.out.path,
- "--dependency_mode=LOOSE",
- "--warning_level=VERBOSE",
- ] + (["--js=%s" % src.path for src in srcs] +
- ["--externs=%s" % extern.path for extern in externs])
-
- # Set the compilation level.
- if ctx.attr.compilation_level in _COMPILATION_LEVELS:
- args += _COMPILATION_LEVELS[ctx.attr.compilation_level]
- else:
- fail("Invalid compilation_level '%s', expected one of %s" %
- (ctx.attr.compilation_level, _COMPILATION_LEVELS.keys()))
-
- # Set the language in.
- if ctx.attr.language_in in _SUPPORTED_LANGUAGES:
- args += "--language_in=" + _SUPPORTED_LANGUAGES[ctx.attr.language_in]
- else:
- fail("Invalid language_in '%s', expected one of %s" %
- (ctx.attr.language_in, _SUPPORTED_LANGUAGES.keys()))
-
- # Set the language out.
- if ctx.attr.language_out in _SUPPORTED_LANGUAGES:
- args += "--language_out=" + _SUPPORTED_LANGUAGES[ctx.attr.language_out]
- else:
- fail("Invalid language_out '%s', expected one of %s" %
- (ctx.attr.language_out, _SUPPORTED_LANGUAGES.keys()))
-
- ctx.action(
- inputs=list(srcs) + list(externs),
- outputs=[ctx.outputs.out],
- arguments=args,
- executable=ctx.executable._closure_compiler)
-
- return struct(files=set([ctx.outputs.out]))
-
-closure_js_binary = rule(
- implementation=_impl,
- attrs={
- "deps": attr.label_list(
- allow_files=False,
- providers=["transitive_js_externs", "transitive_js_srcs"]),
- "main": attr.string(default="%{name}"),
- "compilation_level": attr.string(default="advanced"),
- "language_in": attr.string(default="ecmascript6"),
- "language_out": attr.string(default="ecmascript3"),
- "_closure_compiler": attr.label(
- default=Label("//external:closure_compiler_"),
- executable=True),
- },
- outputs={"out": "%{name}_combined.js"})
diff --git a/tools/build_rules/closure/closure_js_library.bzl b/tools/build_rules/closure/closure_js_library.bzl
deleted file mode 100644
index b759b4989a..0000000000
--- a/tools/build_rules/closure/closure_js_library.bzl
+++ /dev/null
@@ -1,49 +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 definitions for JavaScript libraries. The library targets may be used
-in closure_js_binary rules.
-
-Example:
-
- closure_js_library(
- name = "hello_lib",
- srcs = ["hello.js"],
- deps = ["//third_party/javascript/closure_library"],
- )
-"""
-
-_JS_FILE_TYPE = FileType([".js"])
-
-def _impl(ctx):
- externs = set(order="compile")
- srcs = set(order="compile")
- for dep in ctx.attr.deps:
- externs += dep.transitive_js_externs
- srcs += dep.transitive_js_srcs
-
- externs += _JS_FILE_TYPE.filter(ctx.files.externs)
- srcs += _JS_FILE_TYPE.filter(ctx.files.srcs)
-
- return struct(
- files=set(), transitive_js_externs=externs, transitive_js_srcs=srcs)
-
-closure_js_library = rule(
- implementation=_impl,
- attrs={
- "externs": attr.label_list(allow_files=_JS_FILE_TYPE),
- "srcs": attr.label_list(allow_files=_JS_FILE_TYPE),
- "deps": attr.label_list(
- providers=["transitive_js_externs", "transitive_js_srcs"])
- })
diff --git a/tools/build_rules/closure/closure_repositories.bzl b/tools/build_rules/closure/closure_repositories.bzl
deleted file mode 100644
index f67f76f7d4..0000000000
--- a/tools/build_rules/closure/closure_repositories.bzl
+++ /dev/null
@@ -1,114 +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.
-
-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_content = CLOSURE_COMPILER_BUILD_FILE,
- sha256 = "215ba5df026e5d92bda6634463a9c634d38a1aa4b6dab336da5c52e884cbde95",
- url = "https://dl.google.com/closure-compiler/compiler-20160208.zip",
- )
-
- native.new_http_archive(
- name = "closure_library",
- build_file_content = CLOSURE_LIBRARY_BUILD_FILE,
- sha256 = "8f610300e4930190137505a574a54d12346426f2a7b4f179026e41674e452a86",
- url = "https://github.com/google/closure-library/archive/20160208.zip",
- )
-
- native.http_jar(
- name = "closure_stylesheets",
- sha256 = "5308cb46f7677b9995237ade57770d27592aff69359d29be571220a2bf10e724",
- url = "https://github.com/google/closure-stylesheets/releases/download/v1.1.0/closure-stylesheets.jar",
- )
-
- native.new_http_archive(
- name = "closure_templates",
- build_file_content = CLOSURE_TEMPLATES_BUILD_FILE,
- sha256 = "cdd94123cd0d1c3a183c15e855739c0aa5390297c22dddc731b8d7b23815e8a2",
- url = "http://dl.google.com/closure-templates/closure-templates-for-javascript-latest.zip",
- )
-
- native.bind(
- name = "closure_compiler_",
- actual = "@closure_compiler//:closure_compiler",
- )
-
- native.bind(
- name = "closure_templates_",
- actual = "@closure_templates//:closure_templates",
- )
diff --git a/tools/build_rules/closure/closure_stylesheet_library.bzl b/tools/build_rules/closure/closure_stylesheet_library.bzl
deleted file mode 100644
index c1532c0547..0000000000
--- a/tools/build_rules/closure/closure_stylesheet_library.bzl
+++ /dev/null
@@ -1,82 +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 definitions for Closure stylesheets. Two files are produced: a minified
-and obfuscated CSS file and a JS file defining a map between CSS classes and the
-obfuscated class name. The stylesheet targets may be used in closure_js_binary
-rules.
-
-Both CSS and GSS files may be used with this rule.
-
-Example:
-
- closure_stylesheet_library(
- name = "hello_css",
- srcs = ["hello.gss"].
- )
-
-This rule will produce hello_css_combined.css and hello_css_renaming.js.
-"""
-
-_GSS_FILE_TYPE = FileType([".css", ".gss"])
-
-def _impl(ctx):
- srcs = set(order="compile")
- for dep in ctx.attr.deps:
- srcs += dep.transitive_gss_srcs
-
- srcs += _GSS_FILE_TYPE.filter(ctx.files.srcs)
-
- args = [
- "--output-file",
- ctx.outputs.out.path,
- "--output-renaming-map",
- ctx.outputs.out_renaming.path,
- "--output-renaming-map-format",
- "CLOSURE_COMPILED",
- "--rename",
- "CLOSURE"
- ] + [src.path for src in srcs]
-
- ctx.action(
- inputs=list(srcs),
- outputs=[ctx.outputs.out, ctx.outputs.out_renaming],
- arguments=args,
- executable=ctx.executable._closure_stylesheets)
-
- return struct(
- files=set([ctx.outputs.out]),
- transitive_gss_srcs=srcs,
- transitive_js_externs=set(),
- transitive_js_srcs=[ctx.outputs.out_renaming])
-
-# There are two outputs:
-# - %{name}_combined.css: A minified and obfuscated CSS file.
-# - %{name}_renaming.js: A map from the original CSS class name to the
-# obfuscated name. This file is used by
-# closure_js_binary rules.
-closure_stylesheet_library = rule(
- implementation=_impl,
- attrs={
- "srcs": attr.label_list(allow_files=_GSS_FILE_TYPE),
- "deps": attr.label_list(
- providers=["transitive_gss_srcs", "transitive_js_srcs"]),
- "_closure_stylesheets": attr.label(
- default=Label("//tools/build_rules/closure:closure_stylesheets"),
- executable=True),
- },
- outputs={
- "out": "%{name}_combined.css",
- "out_renaming": "%{name}_renaming.js"
- })
diff --git a/tools/build_rules/closure/closure_template_library.bzl b/tools/build_rules/closure/closure_template_library.bzl
deleted file mode 100644
index 94f246aa2a..0000000000
--- a/tools/build_rules/closure/closure_template_library.bzl
+++ /dev/null
@@ -1,59 +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 definitions for Closure templates. The template targets may be used in
-closure_js_binary rules.
-
-Example:
-
- closure_template_library(
- name = "hello_soy",
- srcs = ["hello.soy"],
- )
-
-This rule will produce hello_soy.js.
-"""
-
-_SOY_FILE_TYPE = FileType([".soy"])
-
-def _impl(ctx):
- srcs = ctx.files.srcs
- args = [
- "--outputPathFormat",
- ctx.outputs.out.path,
- "--shouldGenerateJsdoc",
- "--shouldProvideRequireSoyNamespaces",
- "--srcs",
- ",".join([src.path for src in srcs])
- ]
-
- ctx.action(
- inputs=list(srcs),
- outputs=[ctx.outputs.out],
- arguments=args,
- executable=ctx.executable._closure_templates)
-
- return struct(
- files=set(), transitive_js_externs=set(),
- transitive_js_srcs=set([ctx.outputs.out]))
-
-closure_template_library = rule(
- implementation=_impl,
- attrs={
- "srcs": attr.label_list(allow_files=_SOY_FILE_TYPE),
- "_closure_templates": attr.label(
- default=Label("//external:closure_templates_"),
- executable=True),
- },
- outputs={"out": "%{name}.js"})
diff --git a/tools/build_rules/rust/BUILD b/tools/build_rules/rust/BUILD
deleted file mode 100644
index 3abf631571..0000000000
--- a/tools/build_rules/rust/BUILD
+++ /dev/null
@@ -1,49 +0,0 @@
-package(default_visibility = ["//visibility:public"])
-
-filegroup(
- name = "srcs",
- srcs = glob(["**"]),
- visibility = ["//tools:__pkg__"],
-)
-
-config_setting(
- name = "darwin",
- values = {"host_cpu": "darwin"},
-)
-
-config_setting(
- name = "k8",
- values = {"host_cpu": "k8"},
-)
-
-filegroup(
- name = "rustc",
- srcs = select({
- ":darwin": ["@rust_darwin_x86_64//:rustc"],
- ":k8": ["@rust_linux_x86_64//:rustc"],
- }),
-)
-
-filegroup(
- name = "rustc_lib",
- srcs = select({
- ":darwin": ["@rust_darwin_x86_64//:rustc_lib"],
- ":k8": ["@rust_linux_x86_64//:rustc_lib"],
- }),
-)
-
-filegroup(
- name = "rustdoc",
- srcs = select({
- ":darwin": ["@rust_darwin_x86_64//:rustdoc"],
- ":k8": ["@rust_linux_x86_64//:rustdoc"],
- }),
-)
-
-filegroup(
- name = "rustlib",
- srcs = select({
- ":darwin": ["@rust_darwin_x86_64//:rustlib"],
- ":k8": ["@rust_linux_x86_64//:rustlib"],
- }),
-)
diff --git a/tools/build_rules/rust/README.md b/tools/build_rules/rust/README.md
deleted file mode 100644
index 85b9978ee7..0000000000
--- a/tools/build_rules/rust/README.md
+++ /dev/null
@@ -1,1008 +0,0 @@
-# Rust Rules
-
-<div class="toc">
- <h2>Rules</h2>
- <ul>
- <li><a href="#rust_library">rust_library</a></li>
- <li><a href="#rust_binary">rust_binary</a></li>
- <li><a href="#rust_test">rust_test</a></li>
- <li><a href="#rust_bench_test">rust_bench_test</a></li>
- <li><a href="#rust_doc">rust_doc</a></li>
- <li><a href="#rust_doc_test">rust_doc_test</a></li>
- </ul>
-</div>
-
-## Overview
-
-These build rules are used for building [Rust][rust] projects with Bazel.
-
-[rust]: http://www.rust-lang.org/
-
-<a name="setup"></a>
-## Setup
-
-To use the Rust rules, add the following to your `WORKSPACE` file to add the
-external repositories for the Rust toolchain:
-
-```python
-load("@bazel_tools//tools/build_rules/rust:rust.bzl", "rust_repositories")
-
-rust_repositories()
-```
-
-<a name="roadmap"></a>
-## Roadmap
-
-* Add `rust_toolchain` rule to make it easy to use a custom Rust toolchain.
-* Add tool for taking `Cargo.toml` and generating a `WORKSPACE` file with
- workspace rules for pulling external dependencies.
-* Improve expressiveness of features and support for [Cargo's feature
- groups](http://doc.crates.io/manifest.html#the-[features]-section).
-* Add `cargo_crate` workspace rule for pulling crates from
- [Cargo](https://crates.io/).
-
-<a name="rust_library"></a>
-## rust_library
-
-```python
-rust_library(name, srcs, deps, data, crate_features, rustc_flags)
-```
-
-<table class="table table-condensed table-bordered table-params">
- <colgroup>
- <col class="col-param" />
- <col class="param-description" />
- </colgroup>
- <thead>
- <tr>
- <th colspan="2">Attributes</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><code>name</code></td>
- <td>
- <code>Name, required</code>
- <p>A unique name for this rule.</p>
- <p>
- This name will also be used as the name of the library crate built by
- this rule.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>srcs</code></td>
- <td>
- <code>List of labels, required</code>
- <p>List of Rust <code>.rs</code> source files used to build the
- library.</p>
- <p>
- If <code>srcs</code> contains more than one file, then there must be
- a file either named <code>lib.rs</code>. Otherwise,
- <code>crate_root</code> must be set to the source file that is the
- root of the crate to be passed to <code>rustc</code> to build this
- crate.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>crate_root</code></td>
- <td>
- <code>Label, optional</code>
- <p>
- The file that will be passed to <code>rustc</code> to be used for
- building this crate.
- </p>
- <p>
- If <code>crate_root</code> is not set, then this rule will look for
- a <code>lib.rs</code> file or the single file in <code>srcs</code>
- if <code>srcs</code> contains only one file.
- </p>
- </td>
- </td>
- <tr>
- <td><code>deps</code></td>
- <td>
- <code>List of labels, optional</code>
- <p>List of other libraries to be linked to this library target.</p>
- <p>
- These can be either other <code>rust_library</code> targets or
- <code>cc_library</code> targets if linking a native library.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>data</code></td>
- <td>
- <code>List of labels, optional</code>
- <p>List of files used by this rule at runtime.</p>
- <p>
- This attribute can be used to specify any data files that are embedded
- into the library, such as via the
- <a href="https://doc.rust-lang.org/std/macro.include_str!.html target="_blank"><code>include_str!</code></a>
- macro.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>crate_features</code></td>
- <td>
- <code>List of strings, optional</code>
- <p>List of features to enable for this crate.</p>
- <p>
- Features are defined in the code using the
- <code>#[cfg(feature = "foo")]</code> configuration option. The
- features listed here will be passed to <code>rustc</code> with
- <code>--cfg feature="${feature_name}"</code> flags.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>rustc_flags</code></td>
- <td>
- <code>List of strings, optional</code>
- <p>List of compiler flags passed to <code>rustc</code>.</p>
- </td>
- </tr>
- </tbody>
-</table>
-
-### Example
-
-Suppose you have the following directory structure for a simple Rust library
-crate:
-
-```
-[workspace]/
- WORKSPACE
- hello_lib/
- BUILD
- src/
- greeter.rs
- lib.rs
-```
-
-`hello_lib/src/greeter.rs`:
-
-```rust
-pub struct Greeter {
- greeting: String,
-}
-
-impl Greeter {
- pub fn new(greeting: &str) -> Greeter {
- Greeter { greeting: greeting.to_string(), }
- }
-
- pub fn greet(&self, thing: &str) {
- println!("{} {}", &self.greeting, thing);
- }
-}
-```
-
-`hello_lib/src/lib.rs`:
-
-
-```rust
-pub mod greeter;
-```
-
-`hello_lib/BUILD`:
-
-```python
-package(default_visibility = ["//visibility:public"])
-
-load("@bazel_tools//tools/build_rules/rust:rust.bzl", "rust_library")
-
-rust_library(
- name = "hello_lib",
- srcs = [
- "src/greeter.rs",
- "src/lib.rs",
- ],
-)
-```
-
-Build the library:
-
-```
-$ bazel build //hello_lib
-INFO: Found 1 target...
-Target //examples/rust/hello_lib:hello_lib up-to-date:
- bazel-bin/examples/rust/hello_lib/libhello_lib.rlib
-INFO: Elapsed time: 1.245s, Critical Path: 1.01s
-```
-
-<a name="rust_binary"></a>
-## rust_binary
-
-```
-rust_binary(name, srcs, deps, data, crate_features, rustc_flags)
-```
-
-<table class="table table-condensed table-bordered table-params">
- <colgroup>
- <col class="col-param" />
- <col class="param-description" />
- </colgroup>
- <thead>
- <tr>
- <th colspan="2">Attributes</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><code>name</code></td>
- <td>
- <code>Name, required</code>
- <p>A unique name for this rule.</p>
- <p>
- This name will also be used as the name of the binary crate built by
- this rule.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>srcs</code></td>
- <td>
- <code>List of labels, required</code>
- <p>List of Rust <code>.rs</code> source files used to build the
- binary.</p>
- <p>
- If <code>srcs</code> contains more than one file, then there must be
- a file either named <code>main.rs</code>. Otherwise,
- <code>crate_root</code> must be set to the source file that is the
- root of the crate to be passed to <code>rustc</code> to build this
- crate.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>crate_root</code></td>
- <td>
- <code>Label, optional</code>
- <p>
- The file that will be passed to <code>rustc</code> to be used for
- building this crate.
- </p>
- <p>
- If <code>crate_root</code> is not set, then this rule will look for
- a <code>main.rs</code> file or the single file in <code>srcs</code>
- if <code>srcs</code> contains only one file.
- </p>
- </td>
- </td>
- <tr>
- <td><code>deps</code></td>
- <td>
- <code>List of labels, optional</code>
- <p>List of other libraries to be linked to this library target.</p>
- <p>
- These must be <code>rust_library</code> targets.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>data</code></td>
- <td>
- <code>List of labels, optional</code>
- <p>List of files used by this rule at runtime.</p>
- <p>
- This attribute can be used to specify any data files that are embedded
- into the library, such as via the
- <a href="https://doc.rust-lang.org/std/macro.include_str!.html target="_blank"><code>include_str!</code></a>
- macro.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>crate_features</code></td>
- <td>
- <code>List of strings, optional</code>
- <p>List of features to enable for this crate.</p>
- <p>
- Features are defined in the code using the
- <code>#[cfg(feature = "foo")]</code> configuration option. The
- features listed here will be passed to <code>rustc</code> with
- <code>--cfg feature="${feature_name}"</code> flags.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>rustc_flags</code></td>
- <td>
- <code>List of strings, optional</code>
- <p>List of compiler flags passed to <code>rustc</code>.</p>
- </td>
- </tr>
- </tbody>
-</table>
-
-### Example
-
-Suppose you have the following directory structure for a Rust project with a
-library crate, `hello_lib`, and a binary crate, `hello_world` that uses the
-`hello_lib` library:
-
-```
-[workspace]/
- WORKSPACE
- hello_lib/
- BUILD
- src/
- lib.rs
- hello_world/
- BUILD
- src/
- main.rs
-```
-
-`hello_lib/src/lib.rs`:
-
-```rust
-pub struct Greeter {
- greeting: String,
-}
-
-impl Greeter {
- pub fn new(greeting: &str) -> Greeter {
- Greeter { greeting: greeting.to_string(), }
- }
-
- pub fn greet(&self, thing: &str) {
- println!("{} {}", &self.greeting, thing);
- }
-}
-```
-
-`hello_lib/BUILD`:
-
-```python
-package(default_visibility = ["//visibility:public"])
-
-load("@bazel_tools//tools/build_rules/rust:rust.bzl", "rust_library")
-
-rust_library(
- name = "hello_lib",
- srcs = ["src/lib.rs"],
-)
-```
-
-`hello_world/src/main.rs`:
-
-```rust
-extern crate hello_lib;
-
-fn main() {
- let hello = hello_lib::Greeter::new("Hello");
- hello.greet("world");
-}
-```
-
-`hello_world/BUILD`:
-
-```python
-load("@bazel_tools//tools/build_rules/rust:rust.bzl", "rust_binary")
-
-rust_binary(
- name = "hello_world",
- srcs = ["src/main.rs"],
- deps = ["//hello_lib"],
-)
-```
-
-Build and run `hello_world`:
-
-```
-$ bazel run //hello_world
-INFO: Found 1 target...
-Target //examples/rust/hello_world:hello_world up-to-date:
- bazel-bin/examples/rust/hello_world/hello_world
-INFO: Elapsed time: 1.308s, Critical Path: 1.22s
-
-INFO: Running command line: bazel-bin/examples/rust/hello_world/hello_world
-Hello world
-```
-
-<a name="rust_test"></a>
-## rust_test
-
-```python
-rust_test(name, srcs, deps, data, crate_features, rustc_flags)
-```
-
-<table class="table table-condensed table-bordered table-params">
- <colgroup>
- <col class="col-param" />
- <col class="param-description" />
- </colgroup>
- <thead>
- <tr>
- <th colspan="2">Attributes</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><code>name</code></td>
- <td>
- <code>Name, required</code>
- <p>A unique name for this rule.</p>
- <p>
- This name will also be used as the name of the binary test crate
- built by this rule.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>srcs</code></td>
- <td>
- <code>List of labels, required</code>
- <p>List of Rust <code>.rs</code> source files used to build the
- library.</p>
- <p>
- If <code>srcs</code> contains more than one file, then there must be
- a file either named <code>lib.rs</code>. Otherwise,
- <code>crate_root</code> must be set to the source file that is the
- root of the crate to be passed to <code>rustc</code> to build this
- crate.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>crate_root</code></td>
- <td>
- <code>Label, optional</code>
- <p>
- The file that will be passed to <code>rustc</code> to be used for
- building this crate.
- </p>
- <p>
- If <code>crate_root</code> is not set, then this rule will look for
- a <code>lib.rs</code> file or the single file in <code>srcs</code>
- if <code>srcs</code> contains only one file.
- </p>
- </td>
- </td>
- <tr>
- <td><code>deps</code></td>
- <td>
- <code>List of labels, optional</code>
- <p>List of other libraries to be linked to this test target.</p>
- <p>
- These must be <code>rust_library</code> targets.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>data</code></td>
- <td>
- <code>List of labels, optional</code>
- <p>List of files used by this rule at runtime.</p>
- <p>
- This attribute can be used to specify any data files that are embedded
- into the library, such as via the
- <a href="https://doc.rust-lang.org/std/macro.include_str!.html target="_blank"><code>include_str!</code></a>
- macro.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>crate_features</code></td>
- <td>
- <code>List of strings, optional</code>
- <p>List of features to enable for this crate.</p>
- <p>
- Features are defined in the code using the
- <code>#[cfg(feature = "foo")]</code> configuration option. The
- features listed here will be passed to <code>rustc</code> with
- <code>--cfg feature="${feature_name}"</code> flags.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>rustc_flags</code></td>
- <td>
- <code>List of strings, optional</code>
- <p>List of compiler flags passed to <code>rustc</code>.</p>
- </td>
- </tr>
- </tbody>
-</table>
-
-### Example
-
-Suppose you have the following directory structure for a Rust library crate
-with unit test code in the library sources:
-
-```
-[workspace]/
- WORKSPACE
- hello_lib/
- BUILD
- src/
- lib.rs
-```
-
-`hello_lib/src/lib.rs`:
-
-```rust
-pub struct Greeter {
- greeting: String,
-}
-
-impl Greeter {
- pub fn new(greeting: &str) -> Greeter {
- Greeter { greeting: greeting.to_string(), }
- }
-
- pub fn greet(&self, thing: &str) {
- println!("{} {}", &self.greeting, thing);
- }
-}
-
-#[cfg(test)]
-mod test {
- use super::Greeter;
-
- #[test]
- fn test_greeting() {
- let hello = Greeter::new("Hi");
- assert_eq!("Hi Rust", hello.greeting("Rust"));
- }
-}
-```
-
-To build and run the tests, simply add a `rust_test` rule with no `srcs` and
-only depends on the `hello_lib` `rust_library` target:
-
-`hello_lib/BUILD`:
-
-```python
-package(default_visibility = ["//visibility:public"])
-
-load("@bazel_tools//tools/build_rules/rust:rust.bzl", "rust_library", "rust_test")
-
-rust_library(
- name = "hello_lib",
- srcs = ["src/lib.rs"],
-)
-
-rust_test(
- name = "hello_lib_test",
- deps = [":hello_lib"],
-)
-```
-
-Run the test with `bazel build //hello_lib:hello_lib_test`.
-
-### Example: `test` directory
-
-Integration tests that live in the [`tests` directory][int-tests], they are
-essentially built as separate crates. Suppose you have the following directory
-structure where `greeting.rs` is an integration test for the `hello_lib`
-library crate:
-
-[int-tests]: http://doc.rust-lang.org/book/testing.html#the-tests-directory
-
-```
-[workspace]/
- WORKSPACE
- hello_lib/
- BUILD
- src/
- lib.rs
- tests/
- greeting.rs
-```
-
-`hello_lib/tests/greeting.rs`:
-
-```rust
-extern crate hello_lib;
-
-use hello_lib;
-
-#[test]
-fn test_greeting() {
- let hello = greeter::Greeter::new("Hello");
- assert_eq!("Hello world", hello.greeting("world"));
-}
-```
-
-To build the `greeting.rs` integration test, simply add a `rust_test` target
-with `greeting.rs` in `srcs` and a dependency on the `hello_lib` target:
-
-`hello_lib/BUILD`:
-
-```python
-package(default_visibility = ["//visibility:public"])
-
-load("@bazel_tools//tools/build_rules/rust:rust.bzl", "rust_library", "rust_test")
-
-rust_library(
- name = "hello_lib",
- srcs = ["src/lib.rs"],
-)
-
-rust_test(
- name = "greeting_test",
- srcs = ["tests/greeting.rs"],
- deps = [":hello_lib"],
-)
-```
-
-Run the test with `bazel build //hello_lib:hello_lib_test`.
-
-<a name="rust_bench_test"></a>
-## rust\_bench\_test
-
-```python
-rust_bench_test(name, srcs, deps, data, crate_features, rustc_flags)
-```
-
-**Warning**: This rule is currently experimental. [Rust Benchmark
-tests][rust-bench] require the `Bencher` interface in the unstable `libtest`
-crate, which is behind the `test` unstable feature gate. As a result, using
-this rule would require using a nightly binary release of Rust. A
-`rust_toolchain` rule will be added in the [near future](#roadmap) to make it
-easy to use a custom Rust toolchain, such as a nightly release.
-
-[rust-bench]: https://doc.rust-lang.org/book/benchmark-tests.html
-
-<table class="table table-condensed table-bordered table-params">
- <colgroup>
- <col class="col-param" />
- <col class="param-description" />
- </colgroup>
- <thead>
- <tr>
- <th colspan="2">Attributes</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><code>name</code></td>
- <td>
- <code>Name, required</code>
- <p>A unique name for this rule.</p>
- <p>
- This name will also be used as the name of the binary test crate
- built by this rule.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>srcs</code></td>
- <td>
- <code>List of labels, required</code>
- <p>List of Rust <code>.rs</code> source files used to build the
- library.</p>
- <p>
- If <code>srcs</code> contains more than one file, then there must be
- a file either named <code>lib.rs</code>. Otherwise,
- <code>crate_root</code> must be set to the source file that is the
- root of the crate to be passed to <code>rustc</code> to build this
- crate.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>crate_root</code></td>
- <td>
- <code>Label, optional</code>
- <p>
- The file that will be passed to <code>rustc</code> to be used for
- building this crate.
- </p>
- <p>
- If <code>crate_root</code> is not set, then this rule will look for
- a <code>lib.rs</code> file or the single file in <code>srcs</code>
- if <code>srcs</code> contains only one file.
- </p>
- </td>
- </td>
- <tr>
- <td><code>deps</code></td>
- <td>
- <code>List of labels, optional</code>
- <p>List of other libraries to be linked to this test target.</p>
- <p>
- These must be <code>rust_library</code> targets.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>data</code></td>
- <td>
- <code>List of labels, optional</code>
- <p>List of files used by this rule at runtime.</p>
- <p>
- This attribute can be used to specify any data files that are embedded
- into the library, such as via the
- <a href="https://doc.rust-lang.org/std/macro.include_str!.html target="_blank"><code>include_str!</code></a>
- macro.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>crate_features</code></td>
- <td>
- <code>List of strings, optional</code>
- <p>List of features to enable for this crate.</p>
- <p>
- Features are defined in the code using the
- <code>#[cfg(feature = "foo")]</code> configuration option. The
- features listed here will be passed to <code>rustc</code> with
- <code>--cfg feature="${feature_name}"</code> flags.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>rustc_flags</code></td>
- <td>
- <code>List of strings, optional</code>
- <p>List of compiler flags passed to <code>rustc</code>.</p>
- </td>
- </tr>
- </tbody>
-</table>
-
-### Example
-
-Suppose you have the following directory structure for a Rust project with a
-library crate, `fibonacci` with benchmarks under the `benches/` directory:
-
-```
-[workspace]/
- WORKSPACE
- fibonacci/
- BUILD
- src/
- lib.rs
- benches/
- fibonacci_bench.rs
-```
-
-`fibonacci/src/lib.rs`:
-
-```rust
-pub fn fibonacci(n: u64) -> u64 {
- if n < 2 {
- return n;
- }
- let mut n1: u64 = 0;
- let mut n2: u64 = 1;
- for _ in 1..n {
- let sum = n1 + n2;
- n1 = n2;
- n2 = sum;
- }
- n2
-}
-```
-
-`fibonacci/benches/fibonacci_bench.rs`:
-
-```rust
-#![feature(test)]
-
-extern crate test;
-extern crate fibonacci;
-
-use test::Bencher;
-
-#[bench]
-fn bench_fibonacci(b: &mut Bencher) {
- b.iter(|| fibonacci::fibonacci(40));
-}
-```
-
-To build the benchmark test, simply add a `rust_bench_test` target:
-
-`fibonacci/BUILD`:
-
-```python
-package(default_visibility = ["//visibility:public"])
-
-load("@bazel_tools//tools/build_rules/rust:rust.bzl", "rust_library", "rust_bench_test")
-
-rust_library(
- name = "fibonacci",
- srcs = ["src/lib.rs"],
-)
-
-rust_bench_test(
- name = "fibonacci_bench",
- srcs = ["benches/fibonacci_bench.rs"],
- deps = [":fibonacci"],
-)
-```
-
-Run the benchmark test using: `bazel build //fibonacci:fibonacci_bench`.
-
-<a name="rust_doc"></a>
-## rust_doc
-
-```python
-rust_doc(name, dep, markdown_css, html_in_header, html_before_content, html_after_content)
-```
-
-<table class="table table-condensed table-bordered table-params">
- <colgroup>
- <col class="col-param" />
- <col class="param-description" />
- </colgroup>
- <thead>
- <tr>
- <th>Attribute</th>
- <th>Description</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><code>name</code></td>
- <td>
- <code>Name, required</code>
- <p>A unique name for this rule.</p>
- </td>
- </tr>
- <tr>
- <td><code>dep</code></td>
- <td>
- <code>Label, required</code>
- <p>The label of the target to generate code documentation for.</p>
- <p>
- <code>rust_doc</code> can generate HTML code documentation for the
- source files of <code>rust_library</code> or <code>rust_binary</code>
- targets.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>markdown_css</code></td>
- <td>
- <code>List of Labels, optional</code>
- <p>
- CSS files to include via <code>&lt;link&gt;</code> in a rendered
- Markdown file.
- </p>
- </td>
- </tr>
- <tr>
- <td><code>html_in_header</code></td>
- <td>
- <code>Label, optional</code>
- <p>File to add to <code>&lt;head&gt;</code>.</p>
- </td>
- </tr>
- <tr>
- <td><code>html_before_content</code></td>
- <td>
- <code>Label, optional</code>
- <p>File to add in <code>&lt;body&gt;</code>, before content.</p>
- </td>
- </tr>
- <tr>
- <td><code>html_after_content</code></td>
- <td>
- <code>Label, optional</code>
- <p>File to add in <code>&lt;body&gt;</code>, after content.</p>
- </td>
- </tr>
- </tbody>
-</table>
-
-### Example
-
-Suppose you have the following directory structure for a Rust library crate:
-
-```
-[workspace]/
- WORKSPACE
- hello_lib/
- BUILD
- src/
- lib.rs
-```
-
-To build [`rustdoc`][rustdoc] documentation for the `hello_lib` crate, define
-a `rust_doc` rule that depends on the the `hello_lib` `rust_library` target:
-
-[rustdoc]: https://doc.rust-lang.org/book/documentation.html
-
-```python
-package(default_visibility = ["//visibility:public"])
-
-load("@bazel_tools//tools/build_rules/rust:rust.bzl", "rust_library", "rust_doc")
-
-rust_library(
- name = "hello_lib",
- srcs = ["src/lib.rs"],
-)
-
-rust_doc(
- name = "hello_lib_doc",
- dep = ":hello_lib",
-)
-```
-
-Running `bazel build //hello_lib:hello_lib_doc` will build a zip file containing
-the documentation for the `hello_lib` library crate generated by `rustdoc`.
-
-<a name="rust_doc_test"></a>
-## rust\_doc\_test
-
-```python
-rust_doc_test(name, dep)
-```
-
-<table class="table table-condensed table-bordered table-params">
- <colgroup>
- <col class="col-param" />
- <col class="param-description" />
- </colgroup>
- <thead>
- <tr>
- <th>Attribute</th>
- <th>Description</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><code>name</code></td>
- <td>
- <code>Name, required</code>
- <p>A unique name for this rule.</p>
- </td>
- </tr>
- <tr>
- <td><code>dep</code></td>
- <td>
- <code>Label, required</code>
- <p>The label of the target to run documentation tests for.</p>
- <p>
- <code>rust_doc_test</code> can run documentation tests for the
- source files of <code>rust_library</code> or <code>rust_binary</code>
- targets.
- </p>
- </td>
- </tr>
- </tbody>
-</table>
-
-### Example
-
-Suppose you have the following directory structure for a Rust library crate:
-
-```
-[workspace]/
- WORKSPACE
- hello_lib/
- BUILD
- src/
- lib.rs
-```
-
-To run [documentation tests][doc-test] for the `hello_lib` crate, define a
-`rust_doc_test` target that depends on the `hello_lib` `rust_library` target:
-
-[doc-test]: https://doc.rust-lang.org/book/documentation.html#documentation-as-tests
-
-```python
-package(default_visibility = ["//visibility:public"])
-
-load("@bazel_tools//tools/build_rules/rust:rust.bzl", "rust_library", "rust_doc_test")
-
-rust_library(
- name = "hello_lib",
- srcs = ["src/lib.rs"],
-)
-
-rust_doc_test(
- name = "hello_lib_doc_test",
- dep = ":hello_lib",
-)
-```
-
-Running `bazel test //hello_lib:hello_lib_doc_test` will run all documentation
-tests for the `hello_lib` library crate.
diff --git a/tools/build_rules/rust/rust.bzl b/tools/build_rules/rust/rust.bzl
deleted file mode 100644
index 59ba17eee5..0000000000
--- a/tools/build_rules/rust/rust.bzl
+++ /dev/null
@@ -1,755 +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.
-
-"""Rust rules for Bazel"""
-
-RUST_FILETYPE = FileType([".rs"])
-
-A_FILETYPE = FileType([".a"])
-
-LIBRARY_CRATE_TYPES = [
- "lib",
- "rlib",
- "dylib",
- "staticlib",
-]
-
-# Used by rust_doc
-HTML_MD_FILETYPE = FileType([
- ".html",
- ".md",
-])
-
-CSS_FILETYPE = FileType([".css"])
-
-ZIP_PATH = "/usr/bin/zip"
-
-def _path_parts(path):
- """Takes a path and returns a list of its parts with all "." elements removed.
-
- The main use case of this function is if one of the inputs to _relative()
- is a relative path, such as "./foo".
-
- Args:
- path_parts: A list containing parts of a path.
-
- Returns:
- Returns a list containing the path parts with all "." elements removed.
- """
- path_parts = path.split("/")
- return [part for part in path_parts if part != "."]
-
-def _relative(src_path, dest_path):
- """Returns the relative path from src_path to dest_path."""
- src_parts = _path_parts(src_path)
- dest_parts = _path_parts(dest_path)
- n = 0
- done = False
- for src_part, dest_part in zip(src_parts, dest_parts):
- if src_part != dest_part:
- break
- n += 1
-
- relative_path = ""
- for i in range(n, len(src_parts)):
- relative_path += "../"
- relative_path += "/".join(dest_parts[n:])
-
- return relative_path
-
-def _create_setup_cmd(lib, deps_dir, in_runfiles):
- """
- Helper function to construct a command for symlinking a library into the
- deps directory.
- """
- lib_path = lib.short_path if in_runfiles else lib.path
- return (
- "ln -sf " + _relative(deps_dir, lib_path) + " " +
- deps_dir + "/" + lib.basename + "\n"
- )
-
-def _setup_deps(deps, name, working_dir, is_library=False, in_runfiles=False):
- """
- Walks through dependencies and constructs the necessary commands for linking
- to all the necessary dependencies.
-
- Args:
- deps: List of Labels containing deps from ctx.attr.deps.
- name: Name of the current target.
- working_dir: The output directory for the current target's outputs.
- is_library: True if the current target is a rust_library target, False
- otherwise.
- in_runfiles: True if the setup commands will be run in a .runfiles
- directory. In this case, the working dir should be '.', and the deps
- will be symlinked into the .deps dir from the runfiles tree.
-
- Returns:
- Returns a struct containing the following fields:
- libs:
- transitive_libs:
- setup_cmd:
- search_flags:
- link_flags:
- """
- deps_dir = working_dir + "/" + name + ".deps"
- setup_cmd = ["rm -rf " + deps_dir + "; mkdir " + deps_dir + "\n"]
-
- has_rlib = False
- has_native = False
-
- libs = set()
- transitive_libs = set()
- symlinked_libs = set()
- link_flags = []
- for dep in deps:
- if hasattr(dep, "rust_lib"):
- # This dependency is a rust_library
- libs += [dep.rust_lib]
- transitive_libs += [dep.rust_lib] + dep.transitive_libs
- symlinked_libs += [dep.rust_lib] + dep.transitive_libs
- link_flags += [(
- "--extern " + dep.label.name + "=" +
- deps_dir + "/" + dep.rust_lib.basename
- )]
- has_rlib = True
-
- elif hasattr(dep, "cc"):
- if not is_library:
- fail("Only rust_library targets can depend on cc_library")
-
- # This dependency is a cc_library
- native_libs = A_FILETYPE.filter(dep.cc.libs)
- libs += native_libs
- transitive_libs += native_libs
- symlinked_libs += native_libs
- link_flags += ["-l static=" + dep.label.name]
- has_native = True
-
- else:
- fail(("rust_library" if is_library else "rust_binary and rust_test") +
- " targets can only depend on rust_library " +
- ("or cc_library " if is_library else "") + "targets")
-
- for symlinked_lib in symlinked_libs:
- setup_cmd += [_create_setup_cmd(symlinked_lib, deps_dir, in_runfiles)]
-
- search_flags = []
- if has_rlib:
- search_flags += ["-L dependency=%s" % deps_dir]
- if has_native:
- search_flags += ["-L native=%s" % deps_dir]
-
- return struct(
- libs = list(libs),
- transitive_libs = list(transitive_libs),
- setup_cmd = setup_cmd,
- search_flags = search_flags,
- link_flags = link_flags)
-
-def _get_features_flags(features):
- """
- Constructs a string containing the feature flags from the features specified
- in the features attribute.
- """
- features_flags = []
- for feature in features:
- features_flags += ["--cfg feature=\\\"%s\\\"" % feature]
- return features_flags
-
-def _rust_toolchain(ctx):
- return struct(
- rustc_path = ctx.file.rustc.path,
- rustc_lib_path = ctx.files.rustc_lib[0].dirname,
- rustlib_path = ctx.files.rustlib[0].dirname,
- rustdoc_path = ctx.file.rustdoc.path)
-
-def _build_rustc_command(ctx, crate_name, crate_type, src, output_dir,
- depinfo, rust_flags=[]):
- """Builds the rustc command.
-
- Constructs the rustc command used to build the current target.
-
- Args:
- ctx: The ctx object for the current target.
- crate_type: The type of crate to build ("lib" or "bin")
- src: The File object for crate root source file ("lib.rs" or "main.rs")
- output_dir: The output directory for the target.
- depinfo: Struct containing information about dependencies as returned by
- _setup_deps
-
- Return:
- String containing the rustc command.
- """
-
- # Paths to the Rust compiler and standard libraries.
- toolchain = _rust_toolchain(ctx)
-
- # Paths to cc (for linker) and ar
- cpp_fragment = ctx.fragments.cpp
- cc = cpp_fragment.compiler_executable
- ar = cpp_fragment.ar_executable
- # Currently, the CROSSTOOL config for darwin sets ar to "libtool". Because
- # rust uses ar-specific flags, use /usr/bin/ar in this case.
- # TODO(dzc): This is not ideal. Remove this workaround once ar_executable
- # always points to an ar binary.
- ar_str = "%s" % ar
- if ar_str.find("libtool", 0) != -1:
- ar = "/usr/bin/ar"
-
- # Construct features flags
- features_flags = _get_features_flags(ctx.attr.crate_features)
-
- return " ".join(
- ["set -e;"] +
- depinfo.setup_cmd +
- [
- "LD_LIBRARY_PATH=%s" % toolchain.rustc_lib_path,
- "DYLD_LIBRARY_PATH=%s" % toolchain.rustc_lib_path,
- toolchain.rustc_path,
- src.path,
- "--crate-name %s" % crate_name,
- "--crate-type %s" % crate_type,
- "-C opt-level=3",
- "--codegen ar=%s" % ar,
- "--codegen linker=%s" % cc,
- "--codegen link-args='%s'" % ' '.join(cpp_fragment.link_options),
- "-L all=%s" % toolchain.rustlib_path,
- "--out-dir %s" % output_dir,
- "--emit=dep-info,link",
- ] +
- features_flags +
- rust_flags +
- depinfo.search_flags +
- depinfo.link_flags +
- ctx.attr.rustc_flags)
-
-def _find_crate_root_src(srcs, file_names=["lib.rs"]):
- """Finds the source file for the crate root."""
- if len(srcs) == 1:
- return srcs[0]
- for src in srcs:
- if src.basename in file_names:
- return src
- fail("No %s source file found." % " or ".join(file_names), "srcs")
-
-def _crate_root_src(ctx, file_names=["lib.rs"]):
- if ctx.file.crate_root == None:
- return _find_crate_root_src(ctx.files.srcs, file_names)
- else:
- return ctx.file.crate_root
-
-def _rust_library_impl(ctx):
- """
- Implementation for rust_library Skylark rule.
- """
-
- # Find lib.rs
- lib_rs = _crate_root_src(ctx)
-
- # Validate crate_type
- crate_type = ""
- if ctx.attr.crate_type != "":
- if ctx.attr.crate_type not in LIBRARY_CRATE_TYPES:
- fail("Invalid crate_type for rust_library. Allowed crate types are: %s"
- % " ".join(LIBRARY_CRATE_TYPES), "crate_type")
- crate_type += ctx.attr.crate_type
- else:
- crate_type += "lib"
-
- # Output library
- rust_lib = ctx.outputs.rust_lib
- output_dir = rust_lib.dirname
-
- # Dependencies
- depinfo = _setup_deps(ctx.attr.deps,
- ctx.label.name,
- output_dir,
- is_library=True)
-
- # Build rustc command
- cmd = _build_rustc_command(
- ctx = ctx,
- crate_name = ctx.label.name,
- crate_type = crate_type,
- src = lib_rs,
- output_dir = output_dir,
- depinfo = depinfo)
-
- # Compile action.
- compile_inputs = (
- ctx.files.srcs +
- ctx.files.data +
- depinfo.libs +
- depinfo.transitive_libs +
- [ctx.file.rustc] +
- ctx.files.rustc_lib +
- ctx.files.rustlib)
-
- ctx.action(
- inputs = compile_inputs,
- outputs = [rust_lib],
- mnemonic = 'Rustc',
- command = cmd,
- use_default_shell_env = True,
- progress_message = ("Compiling Rust library %s (%d files)"
- % (ctx.label.name, len(ctx.files.srcs))))
-
- return struct(
- files = set([rust_lib]),
- crate_type = crate_type,
- crate_root = lib_rs,
- rust_srcs = ctx.files.srcs,
- rust_deps = ctx.attr.deps,
- transitive_libs = depinfo.transitive_libs,
- rust_lib = rust_lib)
-
-def _rust_binary_impl(ctx):
- """Implementation for rust_binary Skylark rule."""
-
- # Find main.rs.
- main_rs = _crate_root_src(ctx, ["main.rs"])
-
- # Output binary
- rust_binary = ctx.outputs.executable
- output_dir = rust_binary.dirname
-
- # Dependencies
- depinfo = _setup_deps(ctx.attr.deps,
- ctx.label.name,
- output_dir,
- is_library=False)
-
- # Build rustc command.
- cmd = _build_rustc_command(ctx = ctx,
- crate_name = ctx.label.name,
- crate_type = "bin",
- src = main_rs,
- output_dir = output_dir,
- depinfo = depinfo)
-
- # Compile action.
- compile_inputs = (
- ctx.files.srcs +
- ctx.files.data +
- depinfo.libs +
- depinfo.transitive_libs +
- [ctx.file.rustc] +
- ctx.files.rustc_lib +
- ctx.files.rustlib)
-
- ctx.action(
- inputs = compile_inputs,
- outputs = [rust_binary],
- mnemonic = "Rustc",
- command = cmd,
- use_default_shell_env = True,
- progress_message = ("Compiling Rust binary %s (%d files)"
- % (ctx.label.name, len(ctx.files.srcs))))
-
- return struct(rust_srcs = ctx.files.srcs,
- crate_root = main_rs,
- rust_deps = ctx.attr.deps)
-
-def _rust_test_common(ctx, test_binary):
- """Builds a Rust test binary.
-
- Args:
- ctx: The ctx object for the current target.
- test_binary: The File object for the test binary.
- """
- output_dir = test_binary.dirname
-
- if len(ctx.attr.deps) == 1 and len(ctx.files.srcs) == 0:
- # Target has a single dependency but no srcs. Build the test binary using
- # the dependency's srcs.
- dep = ctx.attr.deps[0]
- crate_type = dep.crate_type if hasattr(dep, "crate_type") else "bin"
- target = struct(name = ctx.label.name,
- srcs = dep.rust_srcs,
- deps = dep.rust_deps,
- crate_root = dep.crate_root,
- crate_type = crate_type)
- else:
- # Target is a standalone crate. Build the test binary as its own crate.
- target = struct(name = ctx.label.name,
- srcs = ctx.files.srcs,
- deps = ctx.attr.deps,
- crate_root = _crate_root_src(ctx),
- crate_type = "lib")
-
- # Get information about dependencies
- depinfo = _setup_deps(target.deps,
- target.name,
- output_dir,
- is_library=False)
-
- cmd = _build_rustc_command(ctx = ctx,
- crate_name = test_binary.basename,
- crate_type = target.crate_type,
- src = target.crate_root,
- output_dir = output_dir,
- depinfo = depinfo,
- rust_flags = ["--test"])
-
- compile_inputs = (target.srcs +
- depinfo.libs +
- depinfo.transitive_libs +
- [ctx.file.rustc] +
- ctx.files.rustc_lib +
- ctx.files.rustlib)
-
- ctx.action(
- inputs = compile_inputs,
- outputs = [test_binary],
- mnemonic = "RustcTest",
- command = cmd,
- use_default_shell_env = True,
- progress_message = ("Compiling Rust test %s (%d files)"
- % (ctx.label.name, len(target.srcs))))
-
-def _rust_test_impl(ctx):
- """
- Implementation for rust_test Skylark rule.
- """
- _rust_test_common(ctx, ctx.outputs.executable)
-
-def _rust_bench_test_impl(ctx):
- """Implementation for the rust_bench_test Skylark rule."""
- rust_bench_test = ctx.outputs.executable
- test_binary = ctx.new_file(ctx.configuration.bin_dir,
- "%s_bin" % rust_bench_test.basename)
- _rust_test_common(ctx, test_binary)
-
- ctx.file_action(
- output = rust_bench_test,
- content = " ".join([
- "#!/bin/bash\n",
- "set -e\n",
- "%s --bench\n" % test_binary.short_path]),
- executable = True)
-
- runfiles = ctx.runfiles(files = [test_binary], collect_data = True)
- return struct(runfiles = runfiles)
-
-def _build_rustdoc_flags(ctx):
- """Collects the rustdoc flags."""
- doc_flags = []
- doc_flags += [
- "--markdown-css %s" % css.path for css in ctx.files.markdown_css]
- if hasattr(ctx.file, "html_in_header"):
- doc_flags += ["--html-in-header %s" % ctx.file.html_in_header.path]
- if hasattr(ctx.file, "html_before_content"):
- doc_flags += ["--html-before-content %s" %
- ctx.file.html_before_content.path]
- if hasattr(ctx.file, "html_after_content"):
- doc_flags += ["--html-after-content %s"]
- return doc_flags
-
-def _rust_doc_impl(ctx):
- """Implementation of the rust_doc rule."""
- rust_doc_zip = ctx.outputs.rust_doc_zip
-
- # Gather attributes about the rust_library target to generated rustdocs for.
- target = struct(name = ctx.label.name,
- srcs = ctx.attr.dep.rust_srcs,
- deps = ctx.attr.dep.rust_deps,
- crate_root = ctx.attr.dep.crate_root)
-
- # Find lib.rs
- lib_rs = (_find_crate_root_src(target.srcs, ["lib.rs", "main.rs"])
- if target.crate_root == None else target.crate_root)
-
- # Get information about dependencies
- output_dir = rust_doc_zip.dirname
- depinfo = _setup_deps(target.deps,
- target.name,
- output_dir,
- is_library=False)
-
- # Rustdoc flags.
- doc_flags = _build_rustdoc_flags(ctx)
-
- # Build rustdoc command.
- toolchain = _rust_toolchain(ctx)
- docs_dir = rust_doc_zip.dirname + "/_rust_docs"
- doc_cmd = " ".join(
- ["set -e;"] +
- depinfo.setup_cmd + [
- "rm -rf %s;" % docs_dir,
- "mkdir %s;" % docs_dir,
- "LD_LIBRARY_PATH=%s" % toolchain.rustc_lib_path,
- "DYLD_LIBRARY_PATH=%s" % toolchain.rustc_lib_path,
- toolchain.rustdoc_path,
- lib_rs.path,
- "--crate-name %s" % target.name,
- "-L all=%s" % toolchain.rustlib_path,
- "-o %s" % docs_dir,
- ] +
- doc_flags +
- depinfo.search_flags +
- depinfo.link_flags + [
- "&&",
- "(cd %s" % docs_dir,
- "&&",
- ZIP_PATH,
- "-qR",
- rust_doc_zip.basename,
- "$(find . -type f) )",
- "&&",
- "mv %s/%s %s" % (docs_dir, rust_doc_zip.basename, rust_doc_zip.path),
- ])
-
- # Rustdoc action
- rustdoc_inputs = (target.srcs +
- depinfo.libs +
- [ctx.file.rustdoc] +
- ctx.files.rustc_lib +
- ctx.files.rustlib)
-
- ctx.action(
- inputs = rustdoc_inputs,
- outputs = [rust_doc_zip],
- mnemonic = "Rustdoc",
- command = doc_cmd,
- use_default_shell_env = True,
- progress_message = ("Generating rustdoc for %s (%d files)"
- % (target.name, len(target.srcs))))
-
-def _rust_doc_test_impl(ctx):
- """Implementation for the rust_doc_test rule."""
- rust_doc_test = ctx.outputs.executable
-
- # Gather attributes about the rust_library target to generated rustdocs for.
- target = struct(name = ctx.label.name,
- srcs = ctx.attr.dep.rust_srcs,
- deps = ctx.attr.dep.rust_deps,
- crate_root = ctx.attr.dep.crate_root)
-
- # Find lib.rs
- lib_rs = (_find_crate_root_src(target.srcs, ["lib.rs", "main.rs"])
- if target.crate_root == None else target.crate_root)
-
- # Get information about dependencies
- output_dir = rust_doc_test.dirname
- depinfo = _setup_deps(target.deps,
- target.name,
- working_dir=".",
- is_library=False,
- in_runfiles=True)
-
- # Construct rustdoc test command, which will be written to a shell script
- # to be executed to run the test.
- toolchain = _rust_toolchain(ctx)
- doc_test_cmd = " ".join(
- ["#!/bin/bash\n"] +
- ["set -e\n"] +
- depinfo.setup_cmd +
- [
- "LD_LIBRARY_PATH=%s" % toolchain.rustc_lib_path,
- "DYLD_LIBRARY_PATH=%s" % toolchain.rustc_lib_path,
- toolchain.rustdoc_path,
- "-L all=%s" % toolchain.rustlib_path,
- lib_rs.path,
- ] +
- depinfo.search_flags +
- depinfo.link_flags)
-
- ctx.file_action(output = rust_doc_test,
- content = doc_test_cmd,
- executable = True)
-
- doc_test_inputs = (target.srcs +
- depinfo.libs +
- depinfo.transitive_libs +
- [ctx.file.rustdoc] +
- ctx.files.rustc_lib +
- ctx.files.rustlib)
-
- runfiles = ctx.runfiles(files = doc_test_inputs, collect_data = True)
- return struct(runfiles = runfiles)
-
-_rust_common_attrs = {
- "srcs": attr.label_list(allow_files = RUST_FILETYPE),
- "crate_root": attr.label(
- allow_files = RUST_FILETYPE,
- single_file = True,
- ),
- "data": attr.label_list(
- allow_files = True,
- cfg = DATA_CFG,
- ),
- "deps": attr.label_list(),
- "crate_features": attr.string_list(),
- "rustc_flags": attr.string_list(),
-}
-
-_rust_toolchain_attrs = {
- "rustc": attr.label(
- default = Label("@bazel_tools//tools/build_rules/rust:rustc"),
- executable = True,
- single_file = True,
- ),
- "rustc_lib": attr.label(
- default = Label("@bazel_tools//tools/build_rules/rust:rustc_lib"),
- ),
- "rustlib": attr.label(
- default = Label("@bazel_tools//tools/build_rules/rust:rustlib"),
- ),
- "rustdoc": attr.label(
- default = Label("@bazel_tools//tools/build_rules/rust:rustdoc"),
- executable = True,
- single_file = True,
- ),
-}
-
-_rust_library_attrs = _rust_common_attrs + {
- "crate_type": attr.string(),
-}
-
-rust_library = rule(
- _rust_library_impl,
- attrs = _rust_library_attrs + _rust_toolchain_attrs,
- fragments = ["cpp"],
- outputs = {
- "rust_lib": "lib%{name}.rlib",
- },
-)
-
-rust_binary = rule(
- _rust_binary_impl,
- attrs = _rust_common_attrs + _rust_toolchain_attrs,
- executable = True,
- fragments = ["cpp"],
-)
-
-rust_test = rule(
- _rust_test_impl,
- attrs = _rust_common_attrs + _rust_toolchain_attrs,
- executable = True,
- fragments = ["cpp"],
- test = True,
-)
-
-rust_bench_test = rule(
- _rust_bench_test_impl,
- attrs = _rust_common_attrs + _rust_toolchain_attrs,
- executable = True,
- fragments = ["cpp"],
- test = True,
-)
-
-_rust_doc_common_attrs = {
- "dep": attr.label(mandatory = True),
-}
-
-_rust_doc_attrs = _rust_doc_common_attrs + {
- "markdown_css": attr.label_list(allow_files = CSS_FILETYPE),
- "html_in_header": attr.label(allow_files = HTML_MD_FILETYPE),
- "html_before_content": attr.label(allow_files = HTML_MD_FILETYPE),
- "html_after_content": attr.label(allow_files = HTML_MD_FILETYPE),
-}
-
-rust_doc = rule(
- _rust_doc_impl,
- attrs = _rust_doc_attrs + _rust_toolchain_attrs,
- outputs = {
- "rust_doc_zip": "%{name}-docs.zip",
- },
-)
-
-rust_doc_test = rule(
- _rust_doc_test_impl,
- attrs = _rust_doc_common_attrs + _rust_toolchain_attrs,
- executable = True,
- 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_content = RUST_BUILD_FILE,
- )
-
- native.new_http_archive(
- name = "rust_darwin_x86_64",
- 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_content = RUST_BUILD_FILE,
- )
diff --git a/tools/build_rules/rust/test/BUILD b/tools/build_rules/rust/test/BUILD
deleted file mode 100644
index dca03f2bdf..0000000000
--- a/tools/build_rules/rust/test/BUILD
+++ /dev/null
@@ -1,3 +0,0 @@
-load(":rust_rule_test.bzl", "rust_rule_test")
-
-rust_rule_test("//examples/rust")
diff --git a/tools/build_rules/rust/test/rust_rule_test.bzl b/tools/build_rules/rust/test/rust_rule_test.bzl
deleted file mode 100644
index c4094bd46a..0000000000
--- a/tools/build_rules/rust/test/rust_rule_test.bzl
+++ /dev/null
@@ -1,58 +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.
-
-"""Tests for rust rules."""
-
-load(
- "//tools/build_rules/rust:rust.bzl",
- "rust_library",
- "rust_binary",
- "rust_test",
-)
-load(
- "//tools/build_rules:test_rules.bzl",
- "rule_test",
-)
-
-def _rust_library_test(package):
- rule_test(
- name ="hello_lib_rule_test",
- generates = ["libhello_lib.rlib"],
- provides = {
- "rust_lib": "/libhello_lib.rlib$",
- "transitive_libs": "^\\[\\]$"
- },
- rule = package + "/hello_lib:hello_lib",
- )
-
-def _rust_binary_test(package):
- rule_test(
- name = "hello_world_rule_test",
- generates = ["hello_world"],
- rule = package + "/hello_world:hello_world",
- )
-
-def _rust_test_test(package):
- """Issue rule tests for rust_test."""
- rule_test(
- name = "greeting_rule_test",
- generates = ["greeting"],
- rule = package + "/hello_lib:greeting",
- )
-
-def rust_rule_test(package):
- """Issue simple tests on rust rules."""
- _rust_library_test(package)
- _rust_binary_test(package)
- _rust_test_test(package)