-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This makes rules_rust load dependencies via bzlmod. Currently only basic functionality is completed, such as registering rustc toolchains and compiling crates. Note that it cannot interact with cargo, wasm or load any other rust toolchains such as rustfmt. There is one new module, `examples/bzlmod/hello_world`, that depends on the root `rules_rust` module. This example can be built and run using: ``` cd examples/bzlmod/hello_world bazel run //:hello_world ``` To register toolchains in an ergonomic way, it defines a new "hub" repository that contains all the toolchain proxies, so they can all be registered like so: ``` register_toolchains("@rust_toolchains//:all") ``` closes #1493
- Loading branch information
1 parent
1074ecb
commit eaf5138
Showing
12 changed files
with
303 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module( | ||
name = "rules_rust", | ||
version = "0.20.0", | ||
) | ||
|
||
print("WARNING: The rules_rust Bazel module is still highly experimental and subject to change at any time. Only use it to try out bzlmod for now.") # buildifier: disable=print | ||
|
||
bazel_dep(name = "platforms", version = "0.0.5") | ||
bazel_dep(name = "rules_cc", version = "0.0.1") | ||
bazel_dep(name = "bazel_skylib", version = "1.2.0") | ||
bazel_dep(name = "apple_support", version = "1.3.1") | ||
|
||
internal_deps = use_extension("//rust/private:extensions.bzl", "internal_deps") | ||
use_repo( | ||
internal_deps, | ||
"rules_rust_tinyjson", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build --experimental_enable_bzlmod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/bazel-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_doc") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
rust_binary( | ||
name = "hello_world", | ||
srcs = ["src/main.rs"], | ||
) | ||
|
||
rust_doc( | ||
name = "hello_world_doc", | ||
crate = ":hello_world", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module( | ||
name = "hello_world", | ||
version = "1.0", | ||
) | ||
|
||
bazel_dep(name = "rules_rust", version = "0.9.0") | ||
local_path_override( | ||
module_name = "rules_rust", | ||
path = "../../..", | ||
) | ||
|
||
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") | ||
rust.toolchain(edition = "2021") | ||
use_repo( | ||
rust, | ||
"rust_toolchains", | ||
) | ||
|
||
register_toolchains("@rust_toolchains//:all") |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2015 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
fn main() { | ||
println!("Hello, world!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"Module extensions for using rules_rust with bzlmod" | ||
|
||
load( | ||
"//rust/private:repository_utils.bzl", | ||
"DEFAULT_EXTRA_TARGET_TRIPLES", | ||
"DEFAULT_NIGHTLY_VERSION", | ||
"DEFAULT_STATIC_RUST_URL_TEMPLATES", | ||
) | ||
load(":repositories.bzl", "rust_register_toolchains") | ||
|
||
def _rust_impl(ctx): | ||
mod = ctx.modules[0] | ||
for toolchain in mod.tags.toolchain: | ||
rust_register_toolchains( | ||
dev_components = toolchain.dev_components, | ||
edition = toolchain.edition, | ||
allocator_library = toolchain.allocator_library, | ||
rustfmt_version = toolchain.rustfmt_version, | ||
rust_analyzer_version = toolchain.rust_analyzer_version, | ||
sha256s = toolchain.sha256s, | ||
extra_target_triples = toolchain.extra_target_triples, | ||
urls = toolchain.urls, | ||
versions = toolchain.versions, | ||
register_toolchains = False, | ||
) | ||
|
||
rust_toolchain = tag_class(attrs = { | ||
"allocator_library": attr.string(), | ||
"dev_components": attr.bool(default = False), | ||
"edition": attr.string(), | ||
"extra_target_triples": attr.string_list(default = DEFAULT_EXTRA_TARGET_TRIPLES), | ||
"rust_analyzer_version": attr.string(), | ||
"rustfmt_version": attr.string(default = DEFAULT_NIGHTLY_VERSION), | ||
"sha256s": attr.string_dict(), | ||
"urls": attr.string_list(default = DEFAULT_STATIC_RUST_URL_TEMPLATES), | ||
"versions": attr.string_list(default = []), | ||
}) | ||
|
||
rust = module_extension( | ||
implementation = _rust_impl, | ||
tag_classes = {"toolchain": rust_toolchain}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"""Bzlmod module extensions that are only used internally""" | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
load("//rust/private:repository_utils.bzl", "TINYJSON_KWARGS") | ||
|
||
def _internal_deps_impl(_module_ctx): | ||
http_archive(**TINYJSON_KWARGS) | ||
|
||
internal_deps = module_extension( | ||
doc = "Dependencies for rules_rust", | ||
implementation = _internal_deps_impl, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.