Reputation: 145
I would like to use bzlmod as I am in the process of splitting a project into different modules and thought it would be a great way to solve the transitive dependencies.
However, not all project have yet a MODULE.bazel file (e.g. grpc), so the question is: is it possible to add an external dependency that doesn't have a MODULE.bazel to the module system so that everything works fine if I reuse the new module?
Upvotes: 5
Views: 974
Reputation: 324
If I undetand questions correctly you can try to use module extension:
https://github.com/Alamofire/Alamofire
just as example, as it does not contain anything related to bazel.
In some file, like //custom_deps.bzl
you can createload("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive",)
def custom_deps_repos():
http_archive(
name = "Alamofire",
build_file = "//:Alamofire.BUILD",
...
url = "https://github.com/....",
)
Alamofire.BUILD
, so we need to create one:...
swift_library(
name = "Alamofire",
scrs = glob(["Source/**/*.swift"]),
...
)
//extensions.bzl
you can create module extension:load("//:custom_deps.bzl", "custom_deps_repos")
def _non_module_custom_deps_repos_impl(_ctx):
custom_deps_repos()
non_module_custom_deps_repos = module_extension(
implementation = _non_module_custom_deps_repos_impl,
)
MODULE.bazel
filecustom_deps_repos = use_extension("//:extensions.bzl", "non_module_custom_deps_repos")
use_repo(
custom_deps_repos,
"Alamofire",
)
after, we can use @Alamofire
anywhere in the project.
Some example here:
PS: instead of http_archive
or any remote files it possible to use some local paths as well https://bazel.build/rules/lib/repo/local
Upvotes: 0