Skip to content

Commit

Permalink
Support bzlmod
Browse files Browse the repository at this point in the history
This is the very start of making rules_rust being able to load dependencies via bzlmod. Currently the aim is to replace `rules_rust_dependencies` only.

There is one new module, `examples/bzlmod/hello_world`, that depends on the root `rules_rust` module. This can be built by:

```
cd examples/bzlmod/hello_world
bazel build //:hello_world
```

There is currently some strange stuff going on with visibility because I get the following error:

```
While resolving toolchains for target //:hello_world: com.google.devtools.build.lib.packages.BuildFileNotFoundException: no such package '@rules_rust.override//rust': The repository '@rules_rust.override' could not be resolved: Repository '@rules_rust.override' is not visible from repository '@rules_rust.override'
```

A package is not visible to its self?
  • Loading branch information
cameron-martin committed Aug 25, 2022
1 parent 51c0658 commit 1e4150e
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 0 deletions.
22 changes: 22 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module(
name = "rules_rust",
version = "0.9.0",
)

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 = "0.13.0")

# TODO: Implement the equivalent of this:

# # process_wrapper needs a low-dependency way to process json.
# maybe(
# http_archive,
# name = "rules_rust_tinyjson",
# sha256 = "1a8304da9f9370f6a6f9020b7903b044aa9ce3470f300a1fba5bc77c78145a16",
# url = "https://crates.io/api/v1/crates/tinyjson/2.3.0/download",
# strip_prefix = "tinyjson-2.3.0",
# type = "tar.gz",
# build_file = "@rules_rust//util/process_wrapper:BUILD.tinyjson.bazel",
# )
1 change: 1 addition & 0 deletions examples/bzlmod/hello_world/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build --experimental_enable_bzlmod
14 changes: 14 additions & 0 deletions examples/bzlmod/hello_world/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_doc")

package(default_visibility = ["//visibility:public"])

rust_binary(
name = "hello_world",
srcs = ["src/main.rs"],
deps = ["@examples//hello_lib"],
)

rust_doc(
name = "hello_world_doc",
crate = ":hello_world",
)
8 changes: 8 additions & 0 deletions examples/bzlmod/hello_world/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module(
name = "hello_world",
version = "1.0",
)

bazel_dep(name = "rules_rust", version = "0.9.0")

local_path_override(module_name = "rules_rust", path = "../../..")
Empty file.
22 changes: 22 additions & 0 deletions examples/bzlmod/hello_world/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.

extern crate hello_lib;

use hello_lib::greeter;

fn main() {
let hello = greeter::Greeter::new("Hello");
hello.greet("world");
}

0 comments on commit 1e4150e

Please sign in to comment.