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

fix: rustc_compile_action emits CcInfo for wasm32 targets #1979

Merged
merged 2 commits into from
Dec 8, 2023

Conversation

rickvanprim
Copy link
Contributor

@rickvanprim rickvanprim commented May 24, 2023

This change allows cc_binary(), cc_library(), etc. targets to depend on rust_libary(), rust_static_library(), etc. targets when targeting wasm32.

@rickvanprim rickvanprim marked this pull request as ready for review May 24, 2023 18:50
@rickvanprim
Copy link
Contributor Author

@titanous your initial addition gated CcInfo on not being wasm32, so I'm hoping you can weigh in here on whether this is a bad idea/I'm overlooking something 😅

@titanous
Copy link
Contributor

titanous commented May 24, 2023

I don't actually have any code using the patch from #715 right now, so I'm not certain... I don't remember why I added that condition 😰

@titanous
Copy link
Contributor

#627 said this:

For the rule to succeed it is also necessary to skip the output of the CcInfo, since it won't be generated. This issue also shows up and is resolved when trying to build a rust_library with crate_type=cdylib and --platforms=@rules_rust//rust/platform:wasm.

@rickvanprim
Copy link
Contributor Author

Hmm that surprises me. I'd expect rust_wasm_bindgen to emit its own set of providers and whatever rust_library emitted to be ignored (beyond the purposes of bindgen running and producing the .wasm). I'll try to dig in further.

@rickvanprim
Copy link
Contributor Author

It seems like that case should be covered by the targets in examples/wasm/BUILD.bazel which build just fine with this change. I'm thinking the original scenario where rust_library() accepted a crate_type may have been the culprit and it's no longer an issue with rust_shared_library(). Any thoughts on other stuff to test?

@rickvanprim
Copy link
Contributor Author

@titanous any further thoughts on this or what I should do to move this forward?

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.

@rickvanprim @titanous I think this change is fine but could you add a unit test of sorts with some comments on the rationale for needing this? None of the maintainers really use WASM so we need to rely on the community and heavy documentation to make sure we don't break things.

@rickvanprim rickvanprim force-pushed the wasm32_cc_info branch 9 times, most recently from 27e716e to bb59ea0 Compare November 16, 2023 20:00
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.

Awesome work! Sorry it took me so long to look at this 😅

Just a couple of requests

examples/nix_cross_compiling/BUILD.bazel Outdated Show resolved Hide resolved
examples/nix_cross_compiling/bazel/cargo/platforms/BUILD Outdated Show resolved Hide resolved
@rickvanprim rickvanprim force-pushed the wasm32_cc_info branch 3 times, most recently from 6e6b169 to 2a19f00 Compare November 17, 2023 16:49
.bazelci/presubmit.yml Outdated Show resolved Hide resolved
.bazelci/presubmit.yml Show resolved Hide resolved
@rickvanprim rickvanprim force-pushed the wasm32_cc_info branch 3 times, most recently from e51f42c to 155cfaf Compare November 21, 2023 05:33
@rickvanprim
Copy link
Contributor Author

Regarding the example and cargo-bazel, it looks like the other examples build cargo-bazel from source (cargo_bazel_bootstrap()) and that's what I have set up here (Nix builds it with Cargo via buildRustPackage), but this is fairly slow. Is there some trick that's speeding it up in the other examples?

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.

I think this is looking good! I just had one last question 😄

.bazelci/presubmit.yml Show resolved Hide resolved
nix/flake.nix Show resolved Hide resolved
@rickvanprim rickvanprim force-pushed the wasm32_cc_info branch 6 times, most recently from b9f6d5f to 76a4c9d Compare November 29, 2023 16:40
@rickvanprim rickvanprim force-pushed the wasm32_cc_info branch 4 times, most recently from 7768002 to 8e19e11 Compare December 1, 2023 18:09
@UebelAndre
Copy link
Collaborator

Looks like you have some nix errors? I can take another pass when CI is green.

@rickvanprim
Copy link
Contributor Author

I think I've come up with an approach that just installs Nix as part of the setup step, which would mean no new container needed (yay). I'm not sure why I'm hitting the current error, which is presumably due to how bazelci.py invokes things, so unfortunately my iteration right now is "test in CI" 😞 Apologies for the email spam.

@rickvanprim rickvanprim force-pushed the wasm32_cc_info branch 4 times, most recently from 6150ef2 to 07e5bed Compare December 1, 2023 20:46
@rickvanprim
Copy link
Contributor Author

It went green! 😱 That said, for whatever reason until I forced my local Nix to rebuild cargo-bazel, it was producing a different hash for the lockfile. I'm a little concerned that might manifest again, although I'm also wondering if the examples should be running with CARGO_BAZEL_REPIN=true anyways to test that portion of things, though at the expense of not testing that it works with the existing lockfile?

.bazelci/presubmit.yml 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.

Oh sorry! I didn't realize CI had been passing. I just had a few more requests and then this otherwise looks good to me!

.bazelci/presubmit.yml Show resolved Hide resolved
@@ -0,0 +1,3 @@
# Use `path:` syntax to avoid copying the entire repo to the Nix Store.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a comment to what the .envrc file is and link to some docs? For those who don't know anything about nix like me 😅

@@ -0,0 +1,25 @@
{
Copy link
Collaborator

@UebelAndre UebelAndre Dec 8, 2023

Choose a reason for hiding this comment

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

Can you add a BUILD.bazel file to this package and a README explaining what the package is for?

(relates to #1979 (comment))

@rickvanprim
Copy link
Contributor Author

@UebelAndre I have hopefully addressed your feedback and CI passed 🙂

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.

Awesome! Thank you for all your patience and hard work!

@UebelAndre UebelAndre merged commit 0a4c4df into bazelbuild:main Dec 8, 2023
3 checks passed
@rickvanprim rickvanprim deleted the wasm32_cc_info branch December 8, 2023 21:44
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.

3 participants