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

Allow a no-cargo setup for bzlmod #2565

Merged
merged 1 commit into from
Mar 26, 2024

Conversation

dzbarsky
Copy link
Contributor

Usage looks like so:

crate = use_extension("@rules_rust//crate_universe:extension.bzl", "crate")
crate.spec(package = "anyhow", version = "1.0.77")
....
crate.from_specs(name = "crates")

It might make sense to merge the annotation attributes into the spec so we don't have to duplicate things, but we can probably iterate on this in the future, this API is still experimental, yeah?

@dzbarsky
Copy link
Contributor Author

@matts1 You're probably best-equipped to review this if you have the cycles

Copy link
Contributor

@matts1 matts1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nitpicks, but generally looks good to me

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I've recently been made aware of a much better way to do this.

Can you add bazel_dep(name = "aspect_bazel_lib", version = "1.36.0") to MODULE.bazel, then add the following to the build file:

load("@aspect_bazel_lib//lib:run_binary.bzl", "run_binary)
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")

run_binary(
  name = "run_hello_world",
  tool = ":hello_world",
)

diff_test(
    name = "hello_world_diff_test",
    file1 = ":run_hello_world",
    file2 = "testdata/hello_world.out",
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would need more changes to the binary to direct the output to a file, or another wrapper. But really I don't even need to run it, I'll just switch this to a build_test. As long as it compiles we're ok :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, sounds good to me. Don't know if we even need a build_test. bazel test :all actually builds all non-test targets as well IIRC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's true, I'll just leave the rust_binary

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Can we make most of the files in the directory a symlink to examples/bzlmod/hello_world/*? That should help us keep them in sync - the only file that should actually be different is MODULE.bazel, but the rest should be the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added --noenable_workspace to the .bazelrc, so now we only have BUILD.bazel, MODULE.bazel, .bazelrc and src/main.rs. The last one is the only one that is the same. I tried symlinking it but Bazel rust_binary seems to not pick up the symlinked source file. Given the source is pretty trivial, it didn't seem worth poking at it more, but let me know if you feel strongly!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's very curious, but yeah, don't think it's worth digging into.

all_repos.append(cfg.name)
local_repos.append(cfg.name)

for cfg in mod.tags.from_specs:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Looks like a lot of duplicated code between this and the above section. Could we pull the common stuff into a function?

Copy link
Contributor Author

@dzbarsky dzbarsky Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call, I rearranged this a bit to share the repo validation. So the duplication now is the 3 lines for annotations. I'm hesitating a bit because sharing this either requires using a lambda or a function that takes module_annotations, repo_specific_annotations, and cfg.name. Alternately, it can look like this_repo_annotations = update_annotations(module_annotations, repo_specific_annotations.get(cfg.name, {})) or something.

Do you still think it's worth pulling out or keep it as-is?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I quite like the repo_specific_annotations idea. I think that'd probably be the cleanest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I factored that out, PTAL

@@ -290,10 +325,39 @@ _annotation = tag_class(
),
)

_from_specs = tag_class(
doc = "Generates a repo @crates from a Cargo.toml / Cargo.lock pair",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This looks like it needs to be updated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep good catch, ty!

@dzbarsky
Copy link
Contributor Author

@UebelAndre @illicitonion can we merge this?

@dzbarsky dzbarsky mentioned this pull request Mar 21, 2024
Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! A couple of nits and can you add a build in CI that runs on this workspace? Or some kind of regression test somewhere else?

I'd also love to know if @matts1 approves too. (They do!)

crate_universe/extension.bzl Outdated Show resolved Hide resolved
crate_universe/extension.bzl Show resolved Hide resolved
examples/bzlmod/hello_world_no_cargo/.bazelrc Outdated Show resolved Hide resolved
crate_universe/extension.bzl Show resolved Hide resolved
@dzbarsky
Copy link
Contributor Author

Thanks! A couple of nits and can you add a build in CI that runs on this workspace? Or some kind of regression test somewhere else?

Oh I had assumed we were already testing the examples in CI. Should we fix that instead?

@UebelAndre
Copy link
Collaborator

Oh I had assumed we were already testing the examples in CI. Should we fix that instead?

A new workspace requires a new job. Had this been an expansion of an existing case the it would have been picked up

@dzbarsky
Copy link
Contributor Author

Oh I had assumed we were already testing the examples in CI. Should we fix that instead?

A new workspace requires a new job. Had this been an expansion of an existing case the it would have been picked up

Ah I see, the CI framework makes it hard to iterate over all the example workspaces, fair enough. Updated with all your comments, PTAL!

Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I had just one more request to fix the .bazelignore file and then I think it's good to go!

examples/bzlmod/hello_world_no_cargo/MODULE.bazel Outdated Show resolved Hide resolved
crate_universe/extension.bzl Show resolved Hide resolved
Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@UebelAndre UebelAndre added this pull request to the merge queue Mar 26, 2024
@UebelAndre UebelAndre removed this pull request from the merge queue due to a manual request Mar 26, 2024
@UebelAndre UebelAndre added this pull request to the merge queue Mar 26, 2024
Merged via the queue into bazelbuild:main with commit 00a4bfb Mar 26, 2024
3 checks passed
fmeum pushed a commit to bazel-contrib/toolchains_llvm that referenced this pull request Mar 28, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [rules_rust](https://togithub.com/bazelbuild/rules_rust) |
http_archive | minor | `0.40.0` -> `0.41.0` |

---

### Release Notes

<details>
<summary>bazelbuild/rules_rust (rules_rust)</summary>

###
[`v0.41.0`](https://togithub.com/bazelbuild/rules_rust/releases/tag/0.41.0)

[Compare
Source](https://togithub.com/bazelbuild/rules_rust/compare/0.40.0...0.41.0)

### 0.41.0

```python
load("@&#8203;bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "rules_rust",
    integrity = "sha256-Y4v6kjQQfXxh5tU6FQB6YXux/ODFGUq3IlpgBV4Bwj8=",
    urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.41.0/rules_rust-v0.41.0.tar.gz"],
)
```

Additional documentation can be found at:
https://bazelbuild.github.io/rules_rust/#setup

#### What's Changed

- Add example of cross-compiling with musl by
[@&#8203;illicitonion](https://togithub.com/illicitonion) in
[bazelbuild/rules_rust#2535
- Temporarily disable "Examples Clang with LLD" CI job by
[@&#8203;UebelAndre](https://togithub.com/UebelAndre) in
[bazelbuild/rules_rust#2560
- Update cargo_toml to `0.19.2` by
[@&#8203;jun-sheaf](https://togithub.com/jun-sheaf) in
[bazelbuild/rules_rust#2551
- Stop rustfmt versioning from overriding rust-analyzer versioning. by
[@&#8203;ReticentIris](https://togithub.com/ReticentIris) in
[bazelbuild/rules_rust#2553
- Rust Analyzer added NixOS supported platforms by
[@&#8203;rickvanprim](https://togithub.com/rickvanprim) in
[bazelbuild/rules_rust#2547
- Removed unused 'select_with_or' by
[@&#8203;dzbarsky](https://togithub.com/dzbarsky) in
[bazelbuild/rules_rust#2562
- Added Rust 1.77.0 by
[@&#8203;UebelAndre](https://togithub.com/UebelAndre) in
[bazelbuild/rules_rust#2568
- bzlmod: fix issue with nightly versions by
[@&#8203;QuentinPerez](https://togithub.com/QuentinPerez) in
[bazelbuild/rules_rust#2545
- Allow a no-cargo setup for bzlmod by
[@&#8203;dzbarsky](https://togithub.com/dzbarsky) in
[bazelbuild/rules_rust#2565
- Fixed genquery for rust targets by
[@&#8203;UebelAndre](https://togithub.com/UebelAndre) in
[bazelbuild/rules_rust#2559
- Fix cargo-bazel recompile for MODULE.bazel by
[@&#8203;ericmcbride](https://togithub.com/ericmcbride) in
[bazelbuild/rules_rust#2570
- Minor cleanup of bzl files by
[@&#8203;UebelAndre](https://togithub.com/UebelAndre) in
[bazelbuild/rules_rust#2573
- Added starlark unit tests for `rust_toolchain.opt_level` by
[@&#8203;UebelAndre](https://togithub.com/UebelAndre) in
[bazelbuild/rules_rust#2578
- Mark the bzlmod extension reproducible as appropriate by
[@&#8203;dzbarsky](https://togithub.com/dzbarsky) in
[bazelbuild/rules_rust#2575
- Release 0.41.0 by
[@&#8203;UebelAndre](https://togithub.com/UebelAndre) in
[bazelbuild/rules_rust#2569

#### New Contributors

- [@&#8203;jun-sheaf](https://togithub.com/jun-sheaf) made their first
contribution in
[bazelbuild/rules_rust#2551
- [@&#8203;ReticentIris](https://togithub.com/ReticentIris) made their
first contribution in
[bazelbuild/rules_rust#2553
- [@&#8203;QuentinPerez](https://togithub.com/QuentinPerez) made their
first contribution in
[bazelbuild/rules_rust#2545
- [@&#8203;ericmcbride](https://togithub.com/ericmcbride) made their
first contribution in
[bazelbuild/rules_rust#2570

**Full Changelog**:
bazelbuild/rules_rust@0.40.0...0.41.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/bazel-contrib/toolchains_llvm).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yNjkuMiIsInVwZGF0ZWRJblZlciI6IjM3LjI2OS4yIiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIn0=-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants