Skip to content

Commit

Permalink
Easy cleanup steps of #117 (#121)
Browse files Browse the repository at this point in the history
* Split rustc.bzl out of toolchain.bzl

* Use .format instead of %, but not in command builders.

* Make rust_bench_test not a test which required renaming it; rename it to rust_benchmark (breaking change..)

* Reuse helper method.
  • Loading branch information
mfarrugi committed Aug 21, 2018
1 parent 41874f9 commit 9aeeda9
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 290 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<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_benchmark">rust_benchmark</a></li>
<li><a href="#rust_doc">rust_doc</a></li>
<li><a href="#rust_doc_test">rust_doc_test</a></li>
</ul>
Expand Down Expand Up @@ -728,11 +728,11 @@ rust_test(

Run the test with `bazel build //hello_lib:hello_lib_test`.

<a name="rust_bench_test"></a>
<a name="rust_benchmark"></a>
## rust\_bench\_test

```python
rust_bench_test(name, srcs, deps, data, crate_features, rustc_flags, out_dir_tar)
rust_benchmark(name, srcs, deps, data, crate_features, rustc_flags, out_dir_tar)
```

**Warning**: This rule is currently experimental. [Rust Benchmark
Expand Down Expand Up @@ -904,21 +904,21 @@ fn bench_fibonacci(b: &mut Bencher) {
}
```

To build the benchmark test, simply add a `rust_bench_test` target:
To build the benchmark test, simply add a `rust_benchmark` target:

`fibonacci/BUILD`:

```python
package(default_visibility = ["//visibility:public"])

load("@io_bazel_rules_rust//rust:rust.bzl", "rust_library", "rust_bench_test")
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_library", "rust_benchmark")

rust_library(
name = "fibonacci",
srcs = ["src/lib.rs"],
)

rust_bench_test(
rust_benchmark(
name = "fibonacci_bench",
srcs = ["benches/fibonacci_bench.rs"],
deps = [":fibonacci"],
Expand Down
8 changes: 4 additions & 4 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
<ul>
<li><a href="https://bazelbuild.github.io/rules_rust/rust/rust.html#overview">Overview</a></li>
<li>
<a href="https://bazelbuild.github.io/rules_rust/rust/rust.html#rust_bench_test">
rust_bench_test
<a href="https://bazelbuild.github.io/rules_rust/rust/rust.html#rust_benchmark">
rust_benchmark
</a>
</li>
<li>
Expand Down Expand Up @@ -96,8 +96,8 @@ <h3>Rules</h3>
<tbody>
<tr>
<td>
<a href="https://bazelbuild.github.io/rules_rust/rust/rust.html#rust_bench_test">
<code>rust_bench_test</code>
<a href="https://bazelbuild.github.io/rules_rust/rust/rust.html#rust_benchmark">
<code>rust_benchmark</code>
</a>
</td>
<td>
Expand Down
34 changes: 17 additions & 17 deletions docs/rust/rust.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
<ul>
<li><a href="https://bazelbuild.github.io/rules_rust/rust/rust.html#overview">Overview</a></li>
<li>
<a href="https://bazelbuild.github.io/rules_rust/rust/rust.html#rust_bench_test">
rust_bench_test
<a href="https://bazelbuild.github.io/rules_rust/rust/rust.html#rust_benchmark">
rust_benchmark
</a>
</li>
<li>
Expand Down Expand Up @@ -81,7 +81,7 @@ <h1>Rust Rules</h1>
<h2><a href="#overview">Overview</a></h2>
<h2>Rules</h2>
<ul>
<li><a href="#rust_bench_test">rust_bench_test</a></li>
<li><a href="#rust_benchmark">rust_benchmark</a></li>
<li><a href="#rust_binary">rust_binary</a></li>
<li><a href="#rust_doc">rust_doc</a></li>
<li><a href="#rust_doc_test">rust_doc_test</a></li>
Expand Down Expand Up @@ -130,9 +130,9 @@ <h2 id="rust_repositories">rust_repositories</h2>

<hr>

<h2 id="rust_bench_test">rust_bench_test</h2>
<h2 id="rust_benchmark">rust_benchmark</h2>

<pre>rust_bench_test(<a href="#rust_bench_test.name">name</a>, <a href="#rust_bench_test.deps">deps</a>, <a href="#rust_bench_test.data">data</a>, <a href="#rust_bench_test.srcs">srcs</a>, <a href="#rust_bench_test.crate_features">crate_features</a>, <a href="#rust_bench_test.crate_root">crate_root</a>, <a href="#rust_bench_test.rustc_flags">rustc_flags</a>)</pre>
<pre>rust_benchmark(<a href="#rust_benchmark.name">name</a>, <a href="#rust_benchmark.deps">deps</a>, <a href="#rust_benchmark.data">data</a>, <a href="#rust_benchmark.srcs">srcs</a>, <a href="#rust_benchmark.crate_features">crate_features</a>, <a href="#rust_benchmark.crate_root">crate_root</a>, <a href="#rust_benchmark.rustc_flags">rustc_flags</a>)</pre>

<p>Builds a Rust benchmark test.</p>
<p><strong>Warning</strong>: This rule is currently experimental. <a href="https://doc.rust-lang.org/book/benchmark-tests.html">Rust Benchmark
Expand All @@ -143,31 +143,31 @@ <h2 id="rust_bench_test">rust_bench_test</h2>
easy to use a custom Rust toolchain, such as a nightly release.</p>


<h3 id="rust_bench_test_args">Attributes</h3>
<h3 id="rust_benchmark_args">Attributes</h3>

<table class="params-table">
<colgroup>
<col class="col-param" />
<col class="col-description" />
</colgroup>
<tbody>
<tr id="rust_bench_test.name">
<tr id="rust_benchmark.name">
<td><code>name</code></td>
<td>
<p><code><a href="https://bazel.build/docs/build-ref.html#name">Name</a>; Required</code></p>
<p>This name will also be used as the name of the binary crate built by
this rule.</p>
</td>
</tr>
<tr id="rust_bench_test.deps">
<tr id="rust_benchmark.deps">
<td><code>deps</code></td>
<td>
<p><code>List of <a href="https://bazel.build/docs/build-ref.html#labels">labels</a>; Optional; Default is []</code></p>
<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 id="rust_bench_test.data">
<tr id="rust_benchmark.data">
<td><code>data</code></td>
<td>
<p><code>List of <a href="https://bazel.build/docs/build-ref.html#labels">labels</a>; Optional; Default is []</code></p>
Expand All @@ -178,7 +178,7 @@ <h3 id="rust_bench_test_args">Attributes</h3>
macro.</p>
</td>
</tr>
<tr id="rust_bench_test.srcs">
<tr id="rust_benchmark.srcs">
<td><code>srcs</code></td>
<td>
<p><code>List of <a href="https://bazel.build/docs/build-ref.html#labels">labels</a>; Optional; Default is []</code></p>
Expand All @@ -188,7 +188,7 @@ <h3 id="rust_bench_test_args">Attributes</h3>
is the root of the crate to be passed to rustc to build this crate.</p>
</td>
</tr>
<tr id="rust_bench_test.crate_features">
<tr id="rust_benchmark.crate_features">
<td><code>crate_features</code></td>
<td>
<p><code>List of strings; Optional; Default is []</code></p>
Expand All @@ -198,7 +198,7 @@ <h3 id="rust_bench_test_args">Attributes</h3>
with <code>--cfg feature="${feature_name}"</code> flags.</p>
</td>
</tr>
<tr id="rust_bench_test.crate_root">
<tr id="rust_benchmark.crate_root">
<td><code>crate_root</code></td>
<td>
<p><code><a href="https://bazel.build/docs/build-ref.html#labels">Label</a>; Optional</code></p>
Expand All @@ -208,7 +208,7 @@ <h3 id="rust_bench_test_args">Attributes</h3>
the single file in <code>srcs</code> if <code>srcs</code> contains only one file.</p>
</td>
</tr>
<tr id="rust_bench_test.rustc_flags">
<tr id="rust_benchmark.rustc_flags">
<td><code>rustc_flags</code></td>
<td>
<p><code>List of strings; Optional; Default is []</code></p>
Expand All @@ -217,7 +217,7 @@ <h3 id="rust_bench_test_args">Attributes</h3>
</tr>
</tbody>
</table>
<h3 id="rust_bench_test_examples">Examples</h3>
<h3 id="rust_benchmark_examples">Examples</h3>
<p>Suppose you have the following directory structure for a Rust project with a
library crate, <code>fibonacci</code> with benchmarks under the <code>benches/</code> directory:</p>
<pre><code>[workspace]/
Expand Down Expand Up @@ -257,18 +257,18 @@ <h3 id="rust_bench_test_examples">Examples</h3>
b.iter(|| fibonacci::fibonacci(40));
}
</code></pre>
<p>To build the benchmark test, simply add a <code>rust_bench_test</code> target:</p>
<p>To build the benchmark test, simply add a <code>rust_benchmark</code> target:</p>
<p><code>fibonacci/BUILD</code>:</p>
<pre><code class="lang-python">package(default_visibility = [&quot;//visibility:public&quot;])

load(&quot;@io_bazel_rules_rust//rust:rust.bzl&quot;, &quot;rust_library&quot;, &quot;rust_bench_test&quot;)
load(&quot;@io_bazel_rules_rust//rust:rust.bzl&quot;, &quot;rust_library&quot;, &quot;rust_benchmark&quot;)

rust_library(
name = &quot;fibonacci&quot;,
srcs = [&quot;src/lib.rs&quot;],
)

rust_bench_test(
rust_benchmark(
name = &quot;fibonacci_bench&quot;,
srcs = [&quot;benches/fibonacci_bench.rs&quot;],
deps = [&quot;:fibonacci&quot;],
Expand Down
4 changes: 2 additions & 2 deletions examples/fibonacci/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load(
"@io_bazel_rules_rust//rust:rust.bzl",
"rust_library",
"rust_test",
"rust_bench_test",
"rust_benchmark",
"rust_doc",
"rust_doc_test",
)
Expand All @@ -19,7 +19,7 @@ rust_test(
deps = [":fibonacci"],
)

rust_bench_test(
rust_benchmark(
name = "fibonacci_bench",
srcs = ["benches/fibonacci_bench.rs"],
tags = [
Expand Down
Loading

0 comments on commit 9aeeda9

Please sign in to comment.