Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying rust versions #307

Merged
merged 1 commit into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@ 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.

### Specifying Rust version

To build with a particular version of the Rust compiler, pass that version to `rust_repositories`:

```python
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:

```python
rust_repositories(version = "nightly", iso_date = "2020-04-19")
```

Similarly, `rustfmt_version` may also be configured:

```python
rust_repositories(rustfmt_version = "1.4.8")
```


### External Dependencies

Currently the most common approach to managing external dependencies is using
Expand Down
33 changes: 22 additions & 11 deletions rust/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

DEFAULT_TOOLCHAIN_NAME_PREFIX = "toolchain_for"

def rust_repositories():
def rust_repositories(version="1.39.0", iso_date=None, rustfmt_version="1.4.8"):
"""Emits a default set of toolchains for Linux, OSX, and Freebsd

Skip this macro and call the `rust_repository_set` macros directly if you need a compiler for
other hosts or for additional target triples.
"""

RUST_VERSION = "1.39.0"
RUSTFMT_VERSION = "1.4.8"
Args:
version: The version of Rust. Either "nightly", "beta", or an exact version.
rustfmt_version: The version of rustfmt. Either "nightly", "beta", or an exact version.
iso_date: The date of the nightly or beta release (or None, if the version is a specific version).
"""

maybe(
http_archive,
Expand All @@ -28,24 +30,27 @@ def rust_repositories():
name = "rust_linux_x86_64",
exec_triple = "x86_64-unknown-linux-gnu",
extra_target_triples = ["wasm32-unknown-unknown"],
version = RUST_VERSION,
rustfmt_version = RUSTFMT_VERSION,
version = version,
iso_date = iso_date,
rustfmt_version = rustfmt_version,
)

rust_repository_set(
name = "rust_darwin_x86_64",
exec_triple = "x86_64-apple-darwin",
extra_target_triples = ["wasm32-unknown-unknown"],
version = RUST_VERSION,
rustfmt_version = RUSTFMT_VERSION,
version = version,
iso_date = iso_date,
rustfmt_version = rustfmt_version,
)

rust_repository_set(
name = "rust_freebsd_x86_64",
exec_triple = "x86_64-unknown-freebsd",
extra_target_triples = ["wasm32-unknown-unknown"],
version = RUST_VERSION,
rustfmt_version = RUSTFMT_VERSION,
version = version,
iso_date = iso_date,
rustfmt_version = rustfmt_version,
)

def _check_version_valid(version, iso_date, param_prefix = ""):
Expand Down Expand Up @@ -269,9 +274,15 @@ def load_arbitrary_tool(ctx, tool_name, param_prefix, tool_subdirectory, version

def _load_rustfmt(ctx):
target_triple = ctx.attr.exec_triple

if ctx.attr.rustfmt_version in ("beta", "nightly"):
iso_date = ctx.attr.iso_date
else:
iso_date = None

load_arbitrary_tool(
ctx,
iso_date = ctx.attr.iso_date,
iso_date = iso_date,
param_prefix = "rustfmt_",
target_triple = target_triple,
tool_name = "rustfmt",
Expand Down