-
Notifications
You must be signed in to change notification settings - Fork 990
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
Merged
franramirez688
merged 22 commits into
conan-io:develop2
from
Neeeflix:feature/enable-bazel-7.1
Jun 4, 2024
Merged
Feature: Enable bazel >= 7.1 #16196
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d0aea5c
feat: Rename template to repository template
Neeeflix 3396189
feat: Make rule_cc a cannonical repository
Neeeflix 093217d
feat: Add conan_deps_repo_rules to generate repos
Neeeflix 25f21c8
feat: Generate module file to be used by consumers
Neeeflix 802848f
feat: Add appropriate documentation for consumers
Neeeflix bc164f4
feat: Add content based test for conan_deps_module_extension
Neeeflix cbefeaf
Added Bazel 7.x templates. Minor BazelDeps changes. Adding functional…
franramirez688 38ce62f
Added both versions to CI+
franramirez688 27d9896
Not version as kwarg
franramirez688 5163c77
Added Linux CI bazel folders
franramirez688 42fdd12
docstrings
franramirez688 9d65a40
Update conan/tools/google/bazeldeps.py
franramirez688 b911371
Typos
franramirez688 6248415
Merge branch 'develop2' into feature/enable-bazel-7.1
czoido 9b28239
Removed rules loading
franramirez688 4e9e396
Using less common word
franramirez688 e53e2bf
Using root_module_direct_deps = 'all'
franramirez688 61ebf7e
Renamed and deprecated warning
franramirez688 8025db2
Useless starting msg
franramirez688 a654d36
Renamed modules
franramirez688 1b50bb1
Better within the build() method
franramirez688 c5d94f0
Fixed docstrings
franramirez688 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from conan.internal.api.new.cmake_lib import source_cpp, source_h, test_main | ||
|
||
|
||
conanfile_exe = """ | ||
import os | ||
from conan import ConanFile | ||
from conan.tools.google import Bazel, bazel_layout | ||
from conan.tools.files import copy | ||
|
||
|
||
class {{package_name}}Recipe(ConanFile): | ||
name = "{{name}}" | ||
version = "{{version}}" | ||
package_type = "application" | ||
|
||
# Binary configuration | ||
settings = "os", "compiler", "build_type", "arch" | ||
|
||
# Sources are located in the same place as this recipe, copy them to the recipe | ||
exports_sources = "main/*", "MODULE.bazel" | ||
|
||
generators = "BazelToolchain" | ||
|
||
def layout(self): | ||
bazel_layout(self) | ||
|
||
def build(self): | ||
bazel = Bazel(self) | ||
bazel.build(target="//main:{{name}}") | ||
|
||
def package(self): | ||
dest_bin = os.path.join(self.package_folder, "bin") | ||
build = os.path.join(self.build_folder, "bazel-bin", "main") | ||
copy(self, "{{name}}", build, dest_bin, keep_path=False) | ||
copy(self, "{{name}}.exe", build, dest_bin, keep_path=False) | ||
""" | ||
|
||
test_conanfile_exe_v2 = """from conan import ConanFile | ||
from conan.tools.build import can_run | ||
|
||
|
||
class {{package_name}}Test(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
|
||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
|
||
def test(self): | ||
if can_run(self): | ||
self.run("{{name}}", env="conanrun") | ||
""" | ||
|
||
_bazel_build_exe = """\ | ||
cc_binary( | ||
name = "{{name}}", | ||
srcs = ["main.cpp", "{{name}}.cpp", "{{name}}.h"] | ||
) | ||
""" | ||
|
||
_bazel_workspace = " " # Important not empty, so template doesn't discard it | ||
|
||
|
||
bazel_exe_files_7 = {"conanfile.py": conanfile_exe, | ||
"main/{{name}}.cpp": source_cpp, | ||
"main/{{name}}.h": source_h, | ||
"main/main.cpp": test_main, | ||
"main/BUILD": _bazel_build_exe, | ||
"MODULE.bazel": _bazel_workspace, | ||
"test_package/conanfile.py": test_conanfile_exe_v2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
from conan.internal.api.new.cmake_lib import source_cpp, source_h, test_main | ||
|
||
conanfile_sources_v2 = """ | ||
import os | ||
from conan import ConanFile | ||
from conan.tools.google import Bazel, bazel_layout | ||
from conan.tools.files import copy | ||
|
||
class {{package_name}}Recipe(ConanFile): | ||
name = "{{name}}" | ||
version = "{{version}}" | ||
package_type = "library" | ||
|
||
# Binary configuration | ||
settings = "os", "compiler", "build_type", "arch" | ||
options = {"shared": [True, False], "fPIC": [True, False]} | ||
default_options = {"shared": False, "fPIC": True} | ||
|
||
# Sources are located in the same place as this recipe, copy them to the recipe | ||
exports_sources = "main/*", "MODULE.bazel" | ||
generators = "BazelToolchain" | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
self.options.rm_safe("fPIC") | ||
|
||
def configure(self): | ||
if self.options.shared: | ||
self.options.rm_safe("fPIC") | ||
|
||
def layout(self): | ||
bazel_layout(self) | ||
|
||
def build(self): | ||
bazel = Bazel(self) | ||
# On Linux platforms, Bazel creates both shared and static libraries by default, and | ||
# it is getting naming conflicts if we use the cc_shared_library rule | ||
if self.options.shared and self.settings.os != "Linux": | ||
# We need to add '--experimental_cc_shared_library' because the project uses | ||
# cc_shared_library to create shared libraries | ||
bazel.build(args=["--experimental_cc_shared_library"], target="//main:{{name}}_shared") | ||
else: | ||
bazel.build(target="//main:{{name}}") | ||
|
||
def package(self): | ||
dest_lib = os.path.join(self.package_folder, "lib") | ||
dest_bin = os.path.join(self.package_folder, "bin") | ||
build = os.path.join(self.build_folder, "bazel-bin", "main") | ||
copy(self, "*.so", build, dest_lib, keep_path=False) | ||
copy(self, "*.dll", build, dest_bin, keep_path=False) | ||
copy(self, "*.dylib", build, dest_lib, keep_path=False) | ||
copy(self, "*.a", build, dest_lib, keep_path=False) | ||
copy(self, "*.lib", build, dest_lib, keep_path=False) | ||
copy(self, "{{name}}.h", os.path.join(self.source_folder, "main"), | ||
os.path.join(self.package_folder, "include"), keep_path=False) | ||
|
||
def package_info(self): | ||
if self.options.shared and self.settings.os != "Linux": | ||
self.cpp_info.libs = ["{{name}}_shared"] | ||
else: | ||
self.cpp_info.libs = ["{{name}}"] | ||
""" | ||
|
||
|
||
test_conanfile_v2 = """import os | ||
from conan import ConanFile | ||
from conan.tools.google import Bazel, bazel_layout | ||
from conan.tools.build import can_run | ||
|
||
|
||
class {{package_name}}TestConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "BazelToolchain", "BazelDeps" | ||
|
||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
|
||
def build(self): | ||
bazel = Bazel(self) | ||
bazel.build(target="//main:example") | ||
|
||
def layout(self): | ||
bazel_layout(self) | ||
|
||
def test(self): | ||
if can_run(self): | ||
cmd = os.path.join(self.cpp.build.bindir, "main", "example") | ||
self.run(cmd, env="conanrun") | ||
""" | ||
|
||
|
||
_bazel_build_test = """\ | ||
cc_binary( | ||
name = "example", | ||
srcs = ["example.cpp"], | ||
deps = [ | ||
"@{{name}}//:{{name}}", | ||
], | ||
) | ||
""" | ||
|
||
_bazel_build = """\ | ||
cc_library( | ||
name = "{{name}}", | ||
srcs = ["{{name}}.cpp"], | ||
hdrs = ["{{name}}.h"], | ||
) | ||
""" | ||
|
||
_bazel_build_shared = """ | ||
cc_shared_library( | ||
name = "{{name}}_shared", | ||
shared_lib_name = "lib{{name}}_shared.%s", | ||
deps = [":{{name}}"], | ||
) | ||
""" | ||
|
||
_bazel_workspace = " " # Important not empty, so template doesn't discard it | ||
_test_bazel_module_bazel = """\ | ||
load_conan_dependencies = use_extension("//conan:conan_deps_module_extension.bzl", "conan_extension") | ||
use_repo(load_conan_dependencies, "{{name}}") | ||
""" | ||
|
||
|
||
def _get_bazel_build(): | ||
import platform | ||
os_ = platform.system() | ||
ret = _bazel_build | ||
if os_ != "Linux": | ||
ret += _bazel_build_shared % ("dylib" if os_ == "Darwin" else "dll") | ||
return ret | ||
|
||
|
||
bazel_lib_files_7 = {"conanfile.py": conanfile_sources_v2, | ||
"main/{{name}}.cpp": source_cpp, | ||
"main/{{name}}.h": source_h, | ||
"main/BUILD": _get_bazel_build(), | ||
"MODULE.bazel": _bazel_workspace, | ||
"test_package/conanfile.py": test_conanfile_v2, | ||
"test_package/main/example.cpp": test_main, | ||
"test_package/main/BUILD": _bazel_build_test, | ||
"test_package/MODULE.bazel": _test_bazel_module_bazel} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
orbazel7_lib/bazel7_exe
?