-
Notifications
You must be signed in to change notification settings - Fork 991
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
Feature: Enable bazel >= 7.1 #16196
Conversation
@memsharded thanks for adding the milestone and looking into this. Any work that needs to be done here, could be taken over by me. I think there are some smaller differences between the |
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. |
I understand the urgency and importance of updating to Conan 2, especially with the upcoming discontinuation of updates for Conan
As mentioned in the PR description, the files which are generated for the older bazel version are not touched. |
605d489
to
c0d8468
Compare
Hi @Neeeflix Thanks a lot for this PR! 👏 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? |
Hey @franramirez688, Regarding the your issue:
Can you may give some more details about your setup. Which example did you use? Reproduction steps: |
c0d8468
to
11171e9
Compare
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 😁
…/integration tests. Conftest with bazel 6.x and 7.x
90938d4
to
38ce62f
Compare
There was a problem hiding this 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.
UPDATE: CI is complaining about Linux and Bazel 7.x (not installed yet). Working on it 😁 |
Co-authored-by: James <memsharded@gmail.com>
conan/tools/google/bazeldeps.py
Outdated
{% endfor %} | ||
|
||
return mctx.extension_metadata( | ||
root_module_direct_deps = None, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 👍
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😁
There was a problem hiding this comment.
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 😁
There was a problem hiding this 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
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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")
There was a problem hiding this comment.
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 😁
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. That can be fixed like this:
https://github.com/bazelbuild/bazel/blob/fb171884e10787475b2936607e8c92717f7ff474/tools/build_defs/repo/local.bzl#L99
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
39b6538
to
9b28239
Compare
conan/api/subapi/new.py
Outdated
"bazel_lib_7": bazel_lib_files_7, | ||
"bazel_exe_7": bazel_exe_files_7, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about changing these names to bazel_7_lib/bazel_7_exe
or bazel7_lib/bazel7_exe
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest, if we plan to deprecate bazel 6 anytime soon and be only compatible with >=7, to add a a deprecation message at some point when using 6, and also add a message when doing a conan new with a bazel6 template so that users are aware that they also have the bazel7 template that works with bazel >= 7
Again, thanks @Neeeflix for the huge effort coming up with this, and @peakschris @fmeum for your help and reviews 👏 |
Amazing, thanks everyone and @franramirez688 thank you too! Any idea when this might be out in a release? |
Conan 2.4 will be very soon, today or tomorrow. |
@franramirez688 thanks for looking into this and finishing it up 👍 |
Changelog: Feature: Add support for Bazel >= 7.1.
Docs: conan-io/docs#3707
Closes: #15754
Closes: #15363
Example: conan-io/examples2#147
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.
develop
branch, documenting this one.