examples icon indicating copy to clipboard operation
examples copied to clipboard

Rust examples

Open marvin-hansen opened this issue 1 year ago • 4 comments

As discussed with Alex Eagle on Slack recently,

this PR contributes multiple Rust examples that cover roughly the top ten use cases. All examples use the new Bazelmod format. The format follows loosely the great C++ tutorial.

If there is anything that needs adjustment, please let me know.

Formalities:

  • I've signed the Google CLA
  • I've signed all commits

marvin-hansen avatar Jun 25 '24 08:06 marvin-hansen

Ok, I pushed a bunch of commits resolving you suggestions.

It's possible for me to write some text to go along the tutorial.

However, would you please point me at the source of the C++ and Go tutorial text, as I couldn't find it in this repo? I

I take a look at this at the upcoming weekend.

marvin-hansen avatar Jun 26 '24 00:06 marvin-hansen

I've found the source of the C++ and Go tutorial text in the Bazel main repo.

Just to clarify your question, do you ask for a tutorial similar to the C++ and fill a PR with the main repo to get a Rust getting started tutorial on the Bazel website?

In principal, I am okay with that, I just want to make sure I get this right?

marvin-hansen avatar Jun 26 '24 01:06 marvin-hansen

The Go tutorial isn't on the Bazel site: https://bazel-contrib.github.io/SIG-rules-authors/go-tutorial.html In the past we have not figured out where this content belongs. Google doesn't staff the project with a tech writer currently so it may be better for tutorials to live in bazel-contrib or in the ruleset repo.

I'm asking about your future plans because you named these folders "tutorial", but without accompanying text they are not part of a tutorial. If they are just examples with a README that's fine too. Writing a real tutorial is a lot of work and also easily goes out-of-date so it's a future commitment as well.

alexeagle avatar Jun 26 '24 15:06 alexeagle

@alexeagle

I see. Perfectly valid point. And you are right, this is not a tutorial similar to the Go one you shared; not even close. Sorry for the confusion, first time contribution to this project...

However, there is no way I can allocate the time to put something like the Go tutorial together let alone maintain it over time. This is a job for a professional tech writer, not a random contributor. Also, I am really unsure if that kind of overkill tutorial is actually needed because, in my observation, the Rust Bazel community tends to be filled with rather senior engineers and they may not even want a comprehensive first principle tutorial since they already know Bazel and only need to file some Rust specific gaps such as generating proto bindings, cross compiling, patching MUSL together etc. And that's basically the gap I'm filling.

I read so often comments in the rules_rust issue tracker that refer to, well, missing Rust Bazelmod examples. I actually filled another PR over at the rules_rust repo to address at least half a dozen open Bazelmod issues that can be closed with a simple code example or a brief Readme.

What I suggest to resolve this matter is to rename the folder to "rust-examples" and leave it there.

marvin-hansen avatar Jun 27 '24 05:06 marvin-hansen

@Wyverald Thank you for your valuable review. I've addressed the bulk of your suggestion. Still need to rework the llvm example, but please continue your review.

marvin-hansen avatar Jul 03 '24 06:07 marvin-hansen

Update:

  1. Removed the LLVM example.
  2. Added all Rust examples to CI
  3. Updated Rust example Readme with a notice of supported platforms (Linux and Mac)

I've bumped into the max 80 tasks per config limit on the CI. Initially, I thought the the tutorial file was too big, so I've split that one into three (C++, Java, Rust) as suggested by the Ci error message, but as it turned out, it was the pre-submit file that imports everything and therefore exceeded the 80 task limit. In response, I've removed most Mac targets for the Rust examples except for cross compilation to stay within the limit and to give some more space to add more targets later. That's probably good since the mac targets tend to build slower.

Build is green.

Please let me know if you want any further changes to any of the examples.

marvin-hansen avatar Jul 04 '24 08:07 marvin-hansen

While contributing to the rules_rust repo recently, I've reported a fairly hairy bug that causes the MUSL example to produce an incorrect linked binary due to an incorrect toolchain resolution. I only discovered this bug after the examples were written during some routine structural integrity testing and that way I know that the MUSL example in this PR is also affected. The other examples were fine and especially the cross compilation examples were passing all tests.

Point is, a fix is under way, but may take longer as it's not even merged so the bigger question is how to proceed?

I can think of two options:

  1. Remove the MUSL example, review, merge, and wait for the fix to re-add the MUSL example later. That's what we decided over at rules_rust as it's unclear when the fix lands.

  2. Convert the PR into a draft, put it on hold until the MUSL fix arrives, apply the fix, and take it from there.

Thoughts?

marvin-hansen avatar Jul 13 '24 01:07 marvin-hansen

FYI @illicitonion

alexeagle avatar Jul 15 '24 17:07 alexeagle

I can think of two options:

I'm okay with either option.

Also, please let me know when you've made all necessary changes to the PR and are ready to submit. I can override the CLA check from my end. (Alternatively, feel free to remove the "Co-authored-by" lines referring to me.)

Wyverald avatar Jul 15 '24 17:07 Wyverald

Update:

  1. Removed the WORKSPACE file with rules cc from example nr 4, FFI, and use the default rules. Also, updated the Readme.
  2. Updated all rust examples to the latest rules_rust (0.47.1)
  3. Renamed the rust-tutorial folder to rust-examples to better reflect the intention
  4. Removed the MUSL example for the time being.

I have to renovate the MUSL example anyways once a patch becomes available as the configuration changed, but more importantly I have to wait for the next rules_rust release that includes the patch and I believe that’s going to take some time, therefore it’s sensible to remove the MUSL example for the time being. I add it back later once the rules_rust have been patched and the example has been updated.

CI seems to fail only on Android and MacOS stuff, whereas the Rust examples all build.

Would be great if someone with more knowledge on Android / MacOS could take a look.

Please let me know if you want any further changes.

Otherwise, feel free to merge anytime when the CI issues are resolved.

marvin-hansen avatar Jul 16 '24 03:07 marvin-hansen

CI failures are unrelated (and already failing before this PR).

CLA check failure is a false positive -- somehow my personal email address is used there.

So I went ahead and merged this. Thank you again for your contribution!

Wyverald avatar Jul 23 '24 22:07 Wyverald