commit | 60b89d09b384f17faa78bb90f4f2034f8d1a1e96 | [log] [tgz] |
---|---|---|
author | Tom Milligan <tommilligan@users.noreply.github.com> | Tue May 12 09:33:10 2020 +0100 |
committer | GitHub <noreply@github.com> | Tue May 12 10:33:10 2020 +0200 |
tree | d31363a8d424f7ea288259e4752ecc42dab211ba | |
parent | 6835a3c8ed1dcd67040cccd603ff3daf611ce41c [diff] |
rustc: add arbitrary environment variables (#314) Rules that call `rustc` setup environment variables in line with `cargo`'s behaviour (see the [documentation here](https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates)). However they don't allow passing in additional environment variables that may be required at compile time, such as the [`PROTOC` variable in `prost-build`](https://github.com/danburkert/prost/blob/2de785aca480779ab0d4442d4bc91a696e3e6c89/prost-build/src/lib.rs#L689). This PR adds the `rustc_env` attribute to the common attribute set, allowing it to be set in the following rules: - `rust_benchmark` - `rust_binary` - `rust_library` - `rust_test` Variables are provided in a string dictionary, and will be merged into the generated environment overriding existing values.
This repository provides rules for building Rust projects with Bazel.
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.
with an overview here.
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.
To build with a particular version of the Rust compiler, pass that version to rust_repositories
:
rust_repositories(version = "1.42.0")
As well as an exact version, version
can be set to "nightly"
or "beta"
. If set to these values, iso_date
must also be set:
rust_repositories(version = "nightly", iso_date = "2020-04-19")
Similarly, rustfmt_version
may also be configured:
rust_repositories(rustfmt_version = "1.4.8")
Currently the most common approach to managing external dependencies is using cargo-raze to generate BUILD
files for Cargo crates.
cargo_crate
workspace rule for pulling crates from Cargo.