<commit_before>[![Build status](https://badge.buildkite.com/76523cc666caab9ca91c2a08d9ac8f84af28cb25a92f387293.svg?branch=master)](https://buildkite.com/bazel/rustlang-rules-rust-postsubmit?branch=master)

# 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:

#### Bazel <= 0.6.1
```python
http_archive(
    name = "io_bazel_rules_rust",
    sha256 = "aa7ad550e2960143835c6a7d3bbc29e313aedf89ea879e5465e97f5d6a19e7f5",
    strip_prefix = "rules_rust-0.0.5",
    urls = [
        "http://bazel-mirror.storage.googleapis.com/github.com/bazelbuild/rules_rust/archive/0.0.5.tar.gz",
        "https://github.com/bazelbuild/rules_rust/archive/0.0.5.tar.gz",
    ],
)
load("@io_bazel_rules_rust//rust:repositories.bzl", "rust_repositories")

rust_repositories()
```
#### Bazel Latest

The master branch should always be current with the latest bazel, as such you can pin to a recent commit on master.

<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, crate_root, crate_type, deps, data, crate_features, rustc_flags, out_dir_tar)
```

<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><commit_msg>Update readme for 0.0.6 (#81)<commit_after>[![Build status](https://badge.buildkite.com/76523cc666caab9ca91c2a08d9ac8f84af28cb25a92f387293.svg?branch=master)](https://buildkite.com/bazel/rustlang-rules-rust-postsubmit?branch=master)

# 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:

#### Bazel <= 0.6.1
```python
http_archive(
    name = "io_bazel_rules_rust",
    sha256 = "615639cfd5459fec4b8a5751112be808ab25ba647c4c1953d29bb554ef865da7",
    strip_prefix = "rules_rust-0.0.6",
    urls = [
        "http://bazel-mirror.storage.googleapis.com/github.com/bazelbuild/rules_rust/archive/0.0.6.tar.gz",
        "https://github.com/bazelbuild/rules_rust/archive/0.0.6.tar.gz",
    ],
)

load("@io_bazel_rules_rust//rust:repositories.bzl", "rust_repositories")

rust_repositories()

```
#### Bazel Latest

The master branch should always be current with the latest bazel, as such you can pin to a recent commit on master.

<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, crate_root, crate_type, deps, data, crate_features, rustc_flags, out_dir_tar)
```

<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>
{'fraction_non_alphanumeric': 0.15839293226756415, 'fraction_numerical': 0.03807320151451409, 'mean_word_length': 4.681003584229391, 'pattern_counts': {'":': 0, '<': 95, '<?xml version=': 0, '>': 93, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4241925', 'n_tokens_mistral': 1861, 'n_tokens_neox': 1725, 'n_words': 363}