calsign / gazelle_rust Goto Github PK
View Code? Open in Web Editor NEWGazelle language plugin for Rust.
License: Apache License 2.0
Gazelle language plugin for Rust.
License: Apache License 2.0
error[E0603]: module `context` is private
--> external/gazelle_rust/rust_parser/lockfile_crates.rs:23:31
|
23 | let context: cargo_bazel::context::Context = match serde_json::from_str(&lockfile_str) {
| ^^^^^^^ private module
|
note: the module `context` is defined here
--> external/rules_rust/crate_universe/src/lib.rs:6:1
error[E0603]: module `utils` is private
--> external/gazelle_rust/rust_parser/lockfile_crates.rs:135:43
|
135 | package.crate_name = cargo_bazel::utils::sanitize_module_name(&package.name);
| ^^^^^ private module
|
note: the module `utils` is defined here
--> external/rules_rust/crate_universe/src/lib.rs:11:1
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0603`.
Aspect @rules_rust//rust/private:clippy.bzl%rust_clippy_aspect of //:gazelle-rust up-to-date (nothing to build)
INFO: Elapsed time: 1.777s, Critical Path: 0.09s
INFO: 2 processes: 2 internal.
We are wanting to switch to gazelle to generate our rust files for us since we have had great success with go's gazelle. Currently we are seeing these errors while using this version of rules rust in our WORKSPACe file
http_archive(
name = "rules_rust",
sha256 = "6357de5982dd32526e02278221bb8d6aa45717ba9bbacf43686b130aa2c72e1e",
urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.30.0/rules_rust-v0.30.0.tar.gz"],
)
Here's what I have: zemn-me/monorepo@674bff4
When I run bazel run //:gazelle
, I get:
gazelle: /Users/tshadwell/code/monorepo-sl/BUILD.bazel: unknown directive: gazelle:prefix
Could not parse lockfile /Users/tshadwell/code/monorepo-sl/cargo.bazel.lock: expected value at line 1 column 1
gazelle: /Users/tshadwell/code/monorepo-sl/cargo.bazel.lock: failed to parse lockfile crates: invalid size
I'm working on the new monorepo project based on the existing Cargo project, we decided to use Blzmod instead of the old Workspace.
We have applied the hybrid mode but IMO should support Bzlmod by default:
gazelle
instead of bazel_gazelle
, rules_go
instead of io_bazel_rules_go
I propose a PR that I have use as local module: #9
I'm having some troubles with a Cargo workspace that uses Cargo.toml
files as the source of truth. Gazelle will generate third-party dependencies fine. But, I can't seem to get Gazelle to automatically generate the deps
attributes properly for other workspace members.
Let's say I have a some Cargo.toml
s like this:
# Cargo.toml
[workspace]
members = ["foo", "bar"]
resolver = "2"
# foo/Cargo.toml
[package]
name = "foo"
version = "0.1.0"
edition = "2021"
[dependencies]
bar = { version = "0.1.0", path = "../bar" }
# bar/Cargo.toml
[package]
name = "bar"
version = "0.1.0"
edition = "2021"
[dependencies]
And I import bar
in foo
:
// foo/src/lib.rs
use bar::*;
Whenever I run Gazelle, it does not find the dependency for bar
:
$ bazel run //:gazelle
<snip>
gazelle: @test_workspace//foo/src:lib: no match for bar
I'm not 100% sure I've got the workspace setup properly. As mentioned, Gazelle can find third-party dependencies alright (I use things like clap
and tracing
in the actual workspace). But, that might be handled differently from first-party dependencies.
Looking at the examples/tests, nothing seems to use Cargo.toml
files as the source of truth with gazelle_rust
. Is it that this use case hasn't been fleshed out yet? If not, any thoughts on what the issue could be?
no-panic
crate is not recognizedI have the following Rust file that uses the no-panic
crate. However, the gazelle plugin does not recognize the dependency in the following Rust code:
// apps/main.rs
use no_panic::no_panic;
#[no_panic]
fn main() {
println!("Hello, world!");
}
When I run Gazelle, it does not recognize the no-panic
crate:
$ bazel run //:gazelle
INFO: Analyzed target //:gazelle (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //:gazelle up-to-date:
bazel-bin/gazelle-runner.bash
bazel-bin/gazelle
INFO: Elapsed time: 0.198s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/gazelle
gazelle: @workspace//apps:main: no match for no_panic
And here's the resulting BUILD.bazel
file.
# apps/BUILD.bazel
load("@rules_rust//rust:defs.bzl", "rust_binary")
rust_binary(
name = "main",
srcs = ["main.rs"],
)
-
in crate names become _
in Rust codeI tried renaming the crate in the crate in the WORKSPACE
file.
"no_panic": crate.spec(
package = "no-panic",
version = "0.1.26",
),
Here's the applicable sections of my Bazel configuration to help debug things.
# WORKSPACE
# version info
RULES_RUST_VERSION = "0.28.0"
RUST_EDITION = "2021"
RUST_VERSION = "1.73.0"
GAZELLE_RUST_COMMIT = "92761c83eaa076d01c10ca6215c13094f68c35bc"
GAZELLE_VERSION = "0.33.0"
crates_repository(
name = "crates",
cargo_lockfile = "//:Cargo.Bazel.lock",
lockfile = "//:cargo-bazel-lock.json",
packages = {
"no-panic": crate.spec(
package = "no-panic",
version = "0.1.26",
),
},
render_config = render_config(
default_package_name = "",
),
)
# BUILD.bazel
load("@bazel_gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary")
gazelle(
name = "gazelle",
gazelle = ":gazelle_bin",
)
gazelle_binary(
name = "gazelle_bin",
languages = DEFAULT_LANGUAGES + ["@gazelle_rust//rust_language"],
)
Thank you for your hard work on this project. I'm really excited to use these rules.
I think the current code is a little out of sync with upstream rules_rust:
ERROR: Error computing the main repository mapping: at /private/var/tmp/_bazel_tshadwell/15310e5df52295849af33b570a7d9e6c/external/gazelle_rust/deps2.bzl:7:6: cannot load '@rules_rust//proto:repositories.bzl': no such file
I think the file you're looking for is now in https://github.com/bazelbuild/rules_rust/blob/main/proto/protobuf/repositories.bzl
I heard about this plugin only in the Slack Bazel chat:
Daniel Wagner-Hall
2023-08-25
There is https://github.com/Calsign/gazelle_rust but IIRC it just works from .rs files not Cargo.toml
It is also weirdly ungoogleable for me with "gazelle rust bazel".
It would be awesome if you create a PR to include it here:
https://github.com/bazelbuild/bazel-gazelle#supported-languages
(I am also happy to do it for you)
Hey, really like the project and would like to contribute if you are open to it. With that in mind would it be possible to add a license to the repo to make that easier?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.