Giter Club home page Giter Club logo

gazelle_rust's People

Contributors

calsign avatar illicitonion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gazelle_rust's Issues

Gazelle Rust doesnt work with new rules_rust

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"],
)

unknown directive: gazelle:prefix

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

Support the Bzlmod

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:

  • Use new naming convention: gazelle instead of bazel_gazelle, rules_go instead of io_bazel_rules_go
  • Easy to setup

I propose a PR that I have use as local module: #9

Support for a workspace that uses `Cargo.toml` files as the source of truth

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.tomls 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 recognized

no-panic crate is not recognized

Problem

I 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"],
)

Potential causes

  • gazelle_rust does not recognize procedural macro crates
  • gazelle_rust does not realize - in crate names become _ in Rust code

Debug steps

I tried renaming the crate in the crate in the WORKSPACE file.

"no_panic": crate.spec(
    package = "no-panic",
    version = "0.1.26",
),

Bazel files

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"],
)

cannot load '@rules_rust//proto:repositories.bzl': no such file

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

Add a license?

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.