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

[Tracking] Add Bazel support #143

Closed
fmorency opened this issue Jun 29, 2022 · 7 comments · Fixed by #194
Closed

[Tracking] Add Bazel support #143

fmorency opened this issue Jun 29, 2022 · 7 comments · Fixed by #194
Assignees
Labels
enhancement New feature or request

Comments

@fmorency
Copy link
Contributor

We want to be able to build this project and run its tests using Bazel.

@fmorency fmorency added the enhancement New feature or request label Jun 29, 2022
@fmorency fmorency self-assigned this Jun 29, 2022
@fmorency
Copy link
Contributor Author

I've made some PoC in https://github.com/fmorency/bazelpoc and https://github.com/fmorency/bazelpoc_workspace.

I can build a rust project, as well as run tests.

I started porting many-rs but encountered a 'duplicated alias' issue in cargo-raze. The problem comes from the fact that we're using two versions of rand, one aliased.

[dependencies]
rand = "0.8"
rand-07 = { package = "rand", version = "0.7" } # Version compatible with ed25519-dalek

cargo-raze doesn't like it. I wrote an MRE in https://github.com/fmorency/bazelalias and commented in google/cargo-raze#474.

As a last attempt, I tried the PR in google/cargo-raze#512, but it doesn't fix the issue.

@fmorency
Copy link
Contributor Author

fmorency commented Jul 7, 2022

I could build many-rs using crate_universe instead of cargo-raze.

My current PoC parses the Cargo.toml file and creates the necessary boilerplate to build the project with Bazel.

The next step of this project is to get rid of the Cargo.toml files and make Bazel the truth source. Cargo.toml and Cargo.lock should be generated by Bazel and not the other way around.

Lastly, I need to add tests and code coverage support.

@fmorency
Copy link
Contributor Author

Build, tests, code coverage, fmt, and clippy work on https://github.com/fmorency/many-rs/tree/fmorency/enh-143-bazel with rules_rust git commit e83d5f3c77d2b41a0ad2fb9c5a0fb1dfb5e912a7. See the documentation on Coda.

Doc tests are failing because of bazelbuild/rules_rust#1233

@fmorency
Copy link
Contributor Author

TODO:

  • Investigate how to perform a cargo update equivalent.
  • Investigate how to create new command shortcuts, i.e., transform
    bazel build --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect --output_groups=fmt_checks //...:all-targets
    to
    bazel fmt //...:all-targets/

@fmorency fmorency linked a pull request Aug 5, 2022 that will close this issue
@hansl
Copy link
Contributor

hansl commented Aug 22, 2022

PR almost ready to merge, will close this.

@fmorency
Copy link
Contributor Author

About the ability to publish a crate on crates.io from Bazel: bazelbuild/rules_rust#458

@UebelAndre said on Slack

I'm not aware of one, unfortunately. I think this is a complicated problem to solve since the artifacts uploaded to crates.io are bundled source code that will later be built with Cargo.

@fmorency
Copy link
Contributor Author

I am on the fence as to the approach we're taking here.

I don't believe dropping Cargo and using Bazel as the single source of truth is the right approach for an open-source Rust project. Crate publishing, top-tier IDE support, etc., rely on Cargo.

Generating the Cargo manifest from Bazel was worked on in

bazelbuild/rules_rust#71

but it was pointed out in that

I'm of the opinion that generating Cargo.tomls isn't possible in the general case, as Bazel's feature set is basically a superset of Cargo's feature set. That is to say that you don't have to look very far to find situations that can't be expressed via Cargo.tomls. Perhaps a means of siloing these parts of a source tree away (via hacky workarounds) could still prove useful...

We could instead use the Cargo manifest as the single source of truth and generate Bazel files from it. This use-case is supported by crate_universe. One drawback of supporting both Cargo and Bazel is

In cases where Rust targets have heavy interractions with other Bazel targests (Cc, Proto, etc.), maintaining Cargo.toml files may have deminishing returns as things like rust-analyzer begin to be confused about missing targets or environment variables defined only in Bazel. In workspaces like this, it may be desirable to have a “Cargo free” setup. 1

but I don't think it affects us at the moment.

I would be happy to discuss this with you @hansl.

@fmorency fmorency mentioned this issue Aug 25, 2022
@fmorency fmorency linked a pull request Aug 31, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants