Pull/expose rustfmt binaries (#291)

* Fetch and expose the rustfmt binary

Pulls in the version of rustfmt that is shipped with Rust 1.39.0.
Distribution path/version found in official release channel TOML. See
http://static.rust-lang.org/dist/channel-rust-1.39.0.toml, and
rust-lang/rust-forge#215 for more information on this.

Relates to #87.

* Set LC_ALL in fetch_shas.sh

The order of `sort`'s output depends on this variable, and different
users may have it set differently.

* Add rustfmt hashes to known_shas

rustfmt is versioned independently of the other Rust tools, which
necessitates keeping track of its version separately. Binaries are also
not provided for FreeBSD, and so a separate targets list is also used.

* Expose rustfmt binary via the Rust toolchain

* Add test that rustfmt binary works
11 files changed
tree: c1e4a650d85a3f0723f0206111a22e552e4de2b4
  1. .bazelci/
  2. bindgen/
  3. docs/
  4. examples/
  5. proto/
  6. rust/
  7. test/
  8. tools/
  9. util/
  10. wasm_bindgen/
  11. .gitignore
  12. AUTHORS
  13. BUILD
  14. CODEOWNERS
  15. CONTRIBUTING.md
  16. CONTRIBUTORS
  17. libc.BUILD
  18. LICENSE.txt
  19. package-lock.json
  20. package.json
  21. README.md
  22. renovate.json
  23. WORKSPACE
  24. workspace.bzl
README.md

Rust Rules

  • Postsubmit Build status
  • Postsubmit + Current Bazel Incompatible Flags Build status

Overview

This repository provides rules for building Rust projects with Bazel.

Basics

WebAssembly

To build a rust_binary for wasm32-unknown-unknown add the --platforms=//rust/platform:wasm flag.

bazel build @examples//hello_world_wasm --platforms=//rust/platform:wasm

rust_wasm_bindgen will automatically transition to the wasm platform and can be used when building wasm code for the host target.

Protobuf

with an overview here.

Setup

To use the Rust rules, add the following to your WORKSPACE file to add the external repositories for the Rust toolchain:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "io_bazel_rules_rust",
    sha256 = "b6da34e057a31b8a85e343c732de4af92a762f804fc36b0baa6c001423a70ebc",
    strip_prefix = "rules_rust-55f77017a7f5b08e525ebeab6e11d8896a4499d2",
    urls = [
        # Master branch as of 2019-10-07
        "https://github.com/bazelbuild/rules_rust/archive/55f77017a7f5b08e525ebeab6e11d8896a4499d2.tar.gz",
    ],
)

http_archive(
    name = "bazel_skylib",
    sha256 = "9a737999532daca978a158f94e77e9af6a6a169709c0cee274f0a4c3359519bd",
    strip_prefix = "bazel-skylib-1.0.0",
    url = "https://github.com/bazelbuild/bazel-skylib/archive/1.0.0.tar.gz",
)

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

load("@io_bazel_rules_rust//:workspace.bzl", "bazel_version")
bazel_version(name = "bazel_version")

The rules are under active development, as such the lastest commit on the master branch should be used. master currently requires Bazel >= 0.26.0.

External Dependencies

Currently the most common approach to managing external dependencies is using cargo-raze to generate BUILD files for Cargo crates.

Roadmap

  • Improve expressiveness of features and support for Cargo's feature groups.
  • Add cargo_crate workspace rule for pulling crates from Cargo.