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

Add extra_rustc_flags_for_crate_types. #2431

Merged
merged 4 commits into from
Mar 29, 2024

Conversation

granaghan
Copy link
Contributor

This allows extra rustc flags that will only apply to library targets to be set by the toolchain. Cross language LTO needs '-C linker-plugin-lto' on libraries, how passing this flag to rust_binary generated bloat. Adding this attribute resolves this issue.

Change-Id: Iba725fab1b1941e9586ff97cd71ec3bc1dfc1523

Copy link
Contributor

@daivinhtran daivinhtran left a comment

Choose a reason for hiding this comment

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

I left a comment. I think macros would be the solution for your use cases. Let me know if macros won't work.

rust/private/rustc.bzl Outdated Show resolved Hide resolved
Copy link
Contributor

@daivinhtran daivinhtran left a comment

Choose a reason for hiding this comment

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

This LGTM. Do you mind adding some tests?

@granaghan granaghan changed the title Add extra_rustlib_rustc_flags. Add extra_rustc_flags_for_crate_types. Mar 15, 2024
@granaghan
Copy link
Contributor Author

I added a simple test. Is there a way to get the CrateInfo provider in the test so I can test with multiple crate types? I poked around a bit and didn't manage to, but I'm pretty new to working with rule implementations.

@matts1
Copy link
Contributor

matts1 commented Mar 15, 2024

To get any provider, you just need to do target[Provider] on a target that defines a CrateInfo (cc_binary and cc_library). However, looking at the test, it seems quite confusing, but it only seems to do assertions on the toolchain itself, so doesn't have access to cc_binary and cc_library targets, so there's no CrateInfo to get.

@granaghan granaghan force-pushed the rlib_rustc_flags branch 6 times, most recently from d17f136 to 1c87ac6 Compare March 20, 2024 19:41
@granaghan
Copy link
Contributor Author

From the CI:

bazel-out/darwin_x86_64-opt-exec-ST-a84ee23024d0/bin/util/process_wrapper/process_wrapper.sh: line 18: /private/var/tmp/_bazel_buildkite/e4140ff87fa9a41eb6ddd3bb20d07fdc/sandbox/darwin-sandbox/22/execroot/rules_rust/bazel-out/darwin_x86_64-opt-exec-ST-a84ee23024d0/bin/test/toolchain/rust_extra_flags_toolchain/bin/mock_rustc.exe: Undefined error: 0

Did I do something to make it try and run the fake binaries? Is it the rust_binary I added?

@daivinhtran
Copy link
Contributor

@granaghan I merged the main branch into your branch to rerun CI. Now it's failing with different error.

Can you pull the updated branch, run ./docs/update_docs.sh locally, and then git push again?

@granaghan
Copy link
Contributor Author

It looks like the coverage check is still tying to use the mock compiler. For some reason it's building for OS none on both Ubuntu and Mac. It passes for me locally though.

    CARGO_CFG_TARGET_OS=none \

@granaghan
Copy link
Contributor Author

Okay, I managed to repro it after gathering all the additions flags. It seems that //rust/settings:experimental_use_coverage_metadata_files is causing this, but I'm not sure why yet.

@granaghan granaghan force-pushed the rlib_rustc_flags branch 2 times, most recently from 6222d3f to 5e2943d Compare March 23, 2024 01:11
@granaghan
Copy link
Contributor Author

It seems this only happens if I declare a rust_binary in the tests. I switched rust_shared_library and it passes.

granaghan and others added 3 commits March 23, 2024 01:14
This allows extra rustc flags that will only apply to specific library types to
be set by the toolchain. Cross language LTO needs '-C linker-plugin-lto'
on libraries, how passing this flag to rust_binary generated bloat.
Adding this attribute resolves this issue.

Change-Id: Iba725fab1b1941e9586ff97cd71ec3bc1dfc1523
Change-Id: I75472b1f9bb67d7348ad31a495d59344c4a6edf1
@granaghan
Copy link
Contributor Author

Any other changes here or is this good to go?

Copy link
Contributor

@daivinhtran daivinhtran left a comment

Choose a reason for hiding this comment

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

LGTM. Can you also file an issue about the failure with rust_binary? Thanks!

@granaghan
Copy link
Contributor Author

Added #2583. I don't have write access, so you'll need to merge. Thanks!

@daivinhtran daivinhtran added this pull request to the merge queue Mar 29, 2024
@daivinhtran daivinhtran requested a review from matts1 March 29, 2024 15:56
Merged via the queue into bazelbuild:main with commit 63fbedb Mar 29, 2024
3 checks passed
fmeum pushed a commit to bazel-contrib/toolchains_llvm that referenced this pull request Apr 2, 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 | patch | `0.41.0` -> `0.41.1` |

---

### Release Notes

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

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

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

### 0.41.1

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

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

#### What's Changed

- Add extra_rustc_flags_for_crate_types. by
[@&#8203;granaghan](https://togithub.com/granaghan) in
[bazelbuild/rules_rust#2431
- Android jobs should be using LTS Bazel releases by
[@&#8203;UebelAndre](https://togithub.com/UebelAndre) in
[bazelbuild/rules_rust#2589
- BUG-FIX: host-triple str for bzl mod by
[@&#8203;ericmcbride](https://togithub.com/ericmcbride) in
[bazelbuild/rules_rust#2587
- fix(cargo-bazel): ignore example crates when checking if proc-macro by
[@&#8203;qtica](https://togithub.com/qtica) in
[bazelbuild/rules_rust#2596
- Deprecated `rust_bindgen.leak_symbols` by
[@&#8203;UebelAndre](https://togithub.com/UebelAndre) in
[bazelbuild/rules_rust#2590
- Update test metadata for crate_universe by
[@&#8203;UebelAndre](https://togithub.com/UebelAndre) in
[bazelbuild/rules_rust#2599
- Fixed bug where crate_universe could match aliases to bench/example
deps by [@&#8203;UebelAndre](https://togithub.com/UebelAndre) in
[bazelbuild/rules_rust#2600
- Cleanup splicing utils by
[@&#8203;dzbarsky](https://togithub.com/dzbarsky) in
[bazelbuild/rules_rust#2564
- Updated repository rules to notify users about non-reproducible repos.
by [@&#8203;UebelAndre](https://togithub.com/UebelAndre) in
[bazelbuild/rules_rust#2593
- feat: Strip debug info from opt builds by
[@&#8203;matte1](https://togithub.com/matte1) in
[bazelbuild/rules_rust#2513
- Release 0.41.1 by
[@&#8203;UebelAndre](https://togithub.com/UebelAndre) in
[bazelbuild/rules_rust#2592

#### New Contributors

- [@&#8203;qtica](https://togithub.com/qtica) made their first
contribution in
[bazelbuild/rules_rust#2596
- [@&#8203;matte1](https://togithub.com/matte1) made their first
contribution in
[bazelbuild/rules_rust#2513

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

</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

4 participants