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

Feature: Enable bazel >= 7.1 #16196

Open
wants to merge 17 commits into
base: develop2
Choose a base branch
from

Conversation

Neeeflix
Copy link
Contributor

@Neeeflix Neeeflix commented May 3, 2024

Feature: Add support for Bazel >= 7.1. This is also requested in #15754.

This will not break older bazel versions, as just some additional files are generated.

I added some of those file based test-cases, and did some "real" integration tests locally. If you know any better better way to put this into the conan test-environment, please let me know.

It's "only" supporting versions from 7.1 on, as there is a feature being used which is not available in 7.0. This is also documented in the code.

Docs: conan-io/docs#3707
Example: conan-io/examples2#147

  • Refer to the issue that supports this Pull Request.
  • If the issue has missing info, explain the purpose/use case/pain/need that covers this Pull Request.
  • I've read the Contributing guide.
  • I've followed the PEP8 style guides for Python code.
  • I've opened another PR in the Conan docs repo to the develop branch, documenting this one.

@Neeeflix
Copy link
Contributor Author

Neeeflix commented May 3, 2024

@memsharded thanks for adding the milestone and looking into this.
Would it also be possible to add a milestone for 1.X, as for us it will not be easy to go with 2.X in the near future.

Any work that needs to be done here, could be taken over by me. I think there are some smaller differences between the 1.X generator and the 2.X one

@memsharded
Copy link
Member

Would it also be possible to add a milestone for 1.X, as for us it will not be easy to go with 2.X in the near future.

This is not something that we can keep doing much longer, for new features like this one we'd strongly favor Conan 2 only. It was released more than 14 months ago, ConanCenter will soon stop updating packages for Conan 1.X too. We strongly recommend to prioritize as much as possible the update to Conan 2.

In this case, if you'd like to get this in Conan 1, and you are willing to do the effort, then we might want to wait until we get @franramirez688 feedback about this.
One of the aspects is that we should be 100% sure that it is not breaking Conan 1.X users, if there is any minimal risk (and I am a bit concerned about the proposed changes could no work for users using older versions of Bazel). @franramirez688 is more aware of the possible issues and efforts related to this.

@Neeeflix
Copy link
Contributor Author

Neeeflix commented May 3, 2024

This is not something that we can keep doing much longer, for new features like this one we'd strongly favor Conan 2 only. It was released more than 14 months ago, ConanCenter will soon stop updating packages for Conan 1.X too. We strongly recommend to prioritize as much as possible the update to Conan 2.

I understand the urgency and importance of updating to Conan 2, especially with the upcoming discontinuation of updates for Conan 1.X. However, the process presents significant challenges, especially when depending on teams in different organizations, etc.

One of the aspects is that we should be 100% sure that it is not breaking Conan 1.X users,

As mentioned in the PR description, the files which are generated for the older bazel version are not touched.
There are only two additional files being generated, there is no interference between those files at all.

@Neeeflix Neeeflix force-pushed the feature/enable-bazel-7.1 branch 2 times, most recently from 605d489 to c0d8468 Compare May 7, 2024 10:47
@franramirez688
Copy link
Contributor

Hi @Neeeflix

Thanks a lot for this PR! 👏
I was trying to test it locally but I got stuck with this error:

INFO: Starting clean (this may take a while). Consider using --async if the clean takes more than several minutes.

hello/0.1: RUN: bazel --bazelrc=/Users/franchuti/.conan2/p/b/hellodfdcbdac82faa/b/conan/conan_bzl.rc build --config=conan-config //main:hello
WARNING: --enable_bzlmod is set, but no MODULE.bazel file was found at the workspace root. Bazel will create an empty MODULE.bazel file. Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel. For more details, please refer to https://github.com/bazelbuild/bazel/issues/18958.
ERROR: Error computing the main repository mapping: in module dependency chain <root> -> bazel_tools@_ -> rules_python@0.22.1: Error accessing registry https://bcr.bazel.build/: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Computing main repo mapping:

hello/0.1: ERROR:
Package '015c501fa3ba2da21e4c2e71becb7b76fa605a36' build failed
hello/0.1: WARN: Build folder /Users/franchuti/.conan2/p/b/hellodfdcbdac82faa/b

I do not know how to solve this. I just tried a couple of things that I found here:

Nothing worked 😭 Do you know how I can get it running OK locally?

@Neeeflix
Copy link
Contributor Author

Neeeflix commented May 8, 2024

Hey @franramirez688,
Thanks for looking into this

Regarding the your issue:

INFO: Starting clean (this may take a while). Consider using --async if the clean takes more than several minutes.

hello/0.1: RUN: bazel --bazelrc=/Users/franchuti/.conan2/p/b/hellodfdcbdac82faa/b/conan/conan_bzl.rc build --config=conan-config //main:hello
WARNING: --enable_bzlmod is set, but no MODULE.bazel file was found at the workspace root. Bazel will create an empty MODULE.bazel file. Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel. For more details, please refer to https://github.com/bazelbuild/bazel/issues/18958.
ERROR: Error computing the main repository mapping: in module dependency chain <root> -> bazel_tools@_ -> rules_python@0.22.1: Error accessing registry https://bcr.bazel.build/: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Computing main repo mapping:

hello/0.1: ERROR:
Package '015c501fa3ba2da21e4c2e71becb7b76fa605a36' build failed
hello/0.1: WARN: Build folder /Users/franchuti/.conan2/p/b/hellodfdcbdac82faa/b

Can you may give some more details about your setup. Which example did you use?
I also updated the example in: conan-io/examples2#147, can you try that?
Also noticed that I only tested there for conan 1.X. Updated it, now also conan 2.X works for me.

Reproduction steps:

  1. Install conan from this branch
  2. CD to the example repo and checkout my branch.
  3. In examples/tools/google/bazel_7.1/testsuite I run conan build . -of conan
  4. image

@franramirez688
Copy link
Contributor

Hi @Neeeflix

Thanks a lot for asking and for your help. Finally, after several hours of trying crazy things, I found the solution to my problem. I'm using Zscaler, so the solution came up with importing through keytool the Zscaler root certificate 👏
Now, I can start reviewing everything 🥳 Sorry for the long delay in keeping my environment up-to-date.

Copy link
Contributor

@franramirez688 franramirez688 left a comment

Choose a reason for hiding this comment

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

@Neeeflix

Finally, I was able to try this. Thanks again for the PR to support Bazel >= 7.1 versions and the huge work behind this. It looks promising!

It's working locally in macOS and Win 👏 , but I'm having some problems with the certificates & Java again in Linux (I hope I get it ready ASAP).

Meanwhile, let me know more about this approach. Sorry for my dummy questions but I want to understand everything 😁

conan/tools/google/bazeldeps.py Show resolved Hide resolved
conan/tools/google/bazeldeps.py Outdated Show resolved Hide resolved
Copy link
Contributor

@franramirez688 franramirez688 left a comment

Choose a reason for hiding this comment

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

Hi @Neeeflix

Sorry for the long delay and for forcing the push (I just messed up with the latest commits in dev)! 😭

Thanks again for the contribution! We are almost there 😁

I just added some lines to test it with Bazel 7.1.2, so let's see if it passes with both versions.

@franramirez688
Copy link
Contributor

UPDATE: CI is complaining about Linux and Bazel 7.x (not installed yet). Working on it 😁

@franramirez688 franramirez688 removed their assignment May 30, 2024
conan/tools/google/bazeldeps.py Outdated Show resolved Hide resolved
test/functional/toolchains/google/test_bazel.py Outdated Show resolved Hide resolved
franramirez688 and others added 2 commits May 30, 2024 18:02
Co-authored-by: James <memsharded@gmail.com>
{% endfor %}

return mctx.extension_metadata(
root_module_direct_deps = None,
Copy link

Choose a reason for hiding this comment

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

If you set this to "all", Bazel will show a warning if the user doesn't use_repo all repos defined by this extension and bazel mod tidy updates use_repo automatically. If I understood the logic correctly, that's exactly what you want here.

Copy link
Contributor

Choose a reason for hiding this comment

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

@fmeum thanks for the explanation! Then, it makes total sense 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure, if it really makes sense. Some of the dependencies listed in the conanfile, you might not want to use in the bazel-build, or?

Copy link

Choose a reason for hiding this comment

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

If there is a way to detect which direct dependencies should be used, those could also be returned as a list here. Could also be a follow-up though.

Choose a reason for hiding this comment

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

For me, the suggestion of "all" would be a great usability improvement. I am sure when developers add something to conanfile they will forget to add it to the MODULE.bazel. The warning and possible automation would help a lot.

For us, we will only have things in conanfile that we want in the build; I'm not sure why you would list something there and then not use it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, agree.
I was just thinking about generator packages or compiler-packages, for me it is still not really clear how this will work.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I got what you meant @Neeeflix Let me check it locally and see how it behaves 😁

Copy link
Contributor

Choose a reason for hiding this comment

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

I was running some tests, and it's indeed useful to see something like this:

WARNING: /Users/franchuti/develop/conan/bazel/test_package/MODULE.bazel:1:40: The module extension conan_extension defined in @//conan:conan_deps_module_extension.bzl reported incorrect imports of repositories via use_repo():

Not imported, but reported as direct dependencies by the extension (may cause the build to fail):
    build-cmake, zlib

Fix the use_repo calls by running 'bazel mod tidy'.

I did not find any side effects. IMO, let's give it a try. Thanks to everyone 😁

Copy link

@peakschris peakschris left a comment

Choose a reason for hiding this comment

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

Thanks for a great PR, this is a big help. Only one of my comments is a blocker, the @@rules_cc one.

The other issue I am facing is that zlib conan module has some missing items in its build file, but I suspect this is an issue with zlib recipe:

Missing:

cc_import(
    name = "zlib_precompiled",
    shared_library = "bin/zlib1.dll",
    interface_library = "lib/zdll.lib",
)
deps statement in cc_library(name = "zlib"... referencing this

conan/tools/google/bazeldeps.py Outdated Show resolved Hide resolved
conan/tools/google/bazeldeps.py Outdated Show resolved Hide resolved
In case of bazel >= 7.1, the conan_deps_module_extension.bzl file should be loaded by your
Module.bazel file, e.g. like this:

.. code-block:: python
Copy link

Choose a reason for hiding this comment

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

It would also be nice to show an example using an include MODULE.bazel file

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 an example in the documentation repository

Copy link
Contributor

Choose a reason for hiding this comment

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

Besides that, you can run conan new bazel_lib_7 -d name=hello -d version=1.0 to see how it works (using Conan from source and this git branch for sure).

Choose a reason for hiding this comment

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

I mean, there is an alternative using the include directive, that helps to separate concerns and contention on the MODULE.bazel file, and it would be nice to see this option in docs:

MODULE.bazel:

include("//deps/conan:conan.MODULE.bazel")

deps/conan/conan.MODULE.bazel:

    load_conan_dependencies = use_extension("//:conan_deps_module_extension.bzl", "load_dependencies")
    use_repo(load_conan_dependencies, "zlib")

Copy link
Contributor

Choose a reason for hiding this comment

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

@peakschris could you please add the URL to the documentation? I think it could be quite interesting what you're proposing 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The link can be found here: https://bazel.build/rules/lib/globals/module#include

But somehow I can't get it running…

ERROR: /home/[…]MODULE.bazel:1:1: name 'include' is not defined
ERROR: Error computing the main repository mapping: error executing MODULE.bazel file for <root>

Copy link

Choose a reason for hiding this comment

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

It's only in 7.2.0rc1 and higher.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then, it is better to wait for a more stable version.

# Important for remote build. Actually it's not reproducible, as local paths will
# be different on different machines. But we assume that conan works correctly here.
# IMPORTANT: Not compatible with bazel < 7.1
reproducible = True,

Choose a reason for hiding this comment

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

One oddity I noticed is that if I manually edit one of Conan's BUILD.bazel files after an initial build, the edited version does not get picked up, unless I delete MODULE.bazel.lock. If this isn't fixable without impacting performance, then maybe some documentation could be added to explain what to do.

Copy link

Choose a reason for hiding this comment

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

That's surprising because the repo rule below symlinks in the build file, so changes should be picked up no matter what Bazel does. Can you reproduce this with --nosystem_rc --nohome_rc?

Choose a reason for hiding this comment

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

--nosystem_rc --nohome_rc don't make a difference. The issue is that by default, symlinks are disabled for windows, and I was using the defaults in my hello world workspace. I think in this case bazel's symlinks function reverts to a copy. If I add --windows_enable_symlinks then build file changes are picked up. This could be addressed with documentation.

Copy link

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

Could the watch be done only if symlinks are not enabled?

Copy link

Choose a reason for hiding this comment

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

That's difficult to detect (would require checking the file type after the operation), but unnecessarily watching a few build files shouldn't matter that much.

Copy link

Choose a reason for hiding this comment

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

@Wyverald What do you think, should we watch automatically if the symlink is a copy?

Choose a reason for hiding this comment

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

The automatic watch sounds like a great idea to me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can this be done in a follow up?

Copy link

Choose a reason for hiding this comment

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

Sure!

@franramirez688 franramirez688 self-requested a review May 31, 2024 12:03
@franramirez688 franramirez688 self-assigned this May 31, 2024
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

6 participants