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

[Bazel][Part 1]: Bazel/BazelToolchain refactor #14845

Closed

Conversation

franramirez688
Copy link
Contributor

@franramirez688 franramirez688 commented Sep 28, 2023

Changelog: Feature: BazelToolchain creates a conan_bzl.rc file which defines the conan-config configuration. If it exists, Bazel helper will use it automatically.
Changelog: Global refactor in BazelToolchain and Bazel conan.tools.google classes.
Docs: https://github.com/conan-io/docs/pull/XXXX
Closes: #14282 #14519

Summary:

  • bazel_layout is now creating all the Conan-generated files inside another folder, bazel-conan-tools.

    • WORKSPACE file (consumer side) before my change:
    load("@//:dependencies.bzl", "load_conan_dependencies")
    load_conan_dependencies()
    
    • Now:
    load("@//bazel-conan-tools:dependencies.bzl", "load_conan_dependencies")
    load_conan_dependencies()
    
  • BazelToolchain is generating a conan_bzl.rc file with a build:conan-config configuration depending on your settings/options.

  • BazelToolchain is not generating a real Bazel toolchain (https://bazel.build/extending/toolchains) because they require much more knowledge and expertise in Bazel to make a dynamic Bazel toolchain per user configuration.

  • Bazel is moving forward to platforms (https://bazel.build/extending/platforms) for future releases instead of toolchains but it does not imply that BazelToolchain could be incompatible but some changes to inject those platforms constraints in our conan-config configuration.

@franramirez688 franramirez688 marked this pull request as ready for review October 2, 2023 10:05
@franramirez688 franramirez688 changed the title [Bazel][Part 1]: BazelToolchain refactor [Bazel][Part 1]: Bazel/BazelToolchain refactor Oct 4, 2023
@@ -9,12 +9,12 @@
class {{package_name}}Recipe(ConanFile):
name = "{{name}}"
version = "{{version}}"
package_type = "library"
package_type = "static-library"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

static one as Bazel, AFAIK, has no dynamic way to build a shared/static library. It has options as --dynamic_mode=fully but it's not working as expected. The only way that I got it was to add linkshared=True to the BUILD file in the test_package but it made useless the use of shared=True dynamically

Comment on lines +85 to +86
self.strip = 'sometimes' # 'always', 'sometimes', 'never'
self.compilation_mode = "fastbuild" # 'fastbuild', 'dbg', 'opt'
Copy link
Contributor

@czoido czoido Oct 4, 2023

Choose a reason for hiding this comment

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

Checking the docs I think we don't need to define strip because it has a default of sometimes in Bazel, that will only strip the debug information for fastbuild mode and fastbuild mode I think that should only be defined by the user because it does not directly correspond to neither Debug or Release of our settings. So I would propose setting something like:

self.strip = None
self.compilation_mode = {'Release': 'opt', 
                         'Debug': 'dbg'}.get(self.settings.build_type)

The user will be able to change this in case they have another custom build type defined.

self.force_pic = fpic if (not shared and fpic is not None) else None
# FIXME: Keeping this option but it's not working as expected. It's not creating the shared
# libraries at all.
self.dynamic_mode = "fully" if shared else "off"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I commented above, it's not working as expected because it depends on the user's BUILD file. I've asked in the official Bazel Slack channel to know more about this.

subproject = conanfile.folders.subproject
conanfile.folders.source = src_folder if not subproject else os.path.join(subproject, src_folder)
conanfile.folders.build = "." # Bazel always build the whole project in the root folder
conanfile.folders.generators = "bazel-conan-tools" # one
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor thing, but what about changing the name of the folder to conan or generators like in other generators layouts?

Suggested change
conanfile.folders.generators = "bazel-conan-tools" # one
conanfile.folders.generators = "conan" # one

@franramirez688
Copy link
Contributor Author

Superseded by #14958

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.

[feature] (Possibility to) change output path for generated Bazel BUILD files by BazelDeps
2 participants