Skip to content

Commit

Permalink
Add support for bzlmod (#1502)
Browse files Browse the repository at this point in the history
This PR adds initial support for bzlmod. I still have to test it with an
example project, but the basic infrastructure should be ready.

bzlmod is only really ready to be used starting in Bazel 6.0. For this
reason, the `MODULE.bazel` depends on rules_apple 2.0.0, which is also
the release that requires Bazel 6. I will need to first check the newest
version of rules_apple and rules_swift into the Bazel Central Registry,
and then we can proceed testing the rules_xcodeproj integration.
  • Loading branch information
BalestraPatrick authored Jan 13, 2023
1 parent 7217511 commit 15fb29e
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 31 deletions.
22 changes: 22 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module(
name = "rules_xcodeproj",
version = "0.11.0",
repo_name = "com_github_buildbuddy_io_rules_xcodeproj",
compatibility_level = 1,
)
bazel_dep(name = "bazel_skylib", version = "1.3.0")
bazel_dep(name = "rules_swift", version = "1.5.1", repo_name = "build_bazel_rules_swift")
bazel_dep(name = "rules_apple", version = "2.0.0", repo_name = "build_bazel_rules_apple")

non_module_deps = use_extension("//xcodeproj:extensions.bzl", "non_module_deps")
use_repo(
non_module_deps,
"rules_xcodeproj_index_import",
"com_github_kylef_pathkit",
"com_github_tadija_aexml",
"com_github_michaeleisel_jjliso8601dateformatter",
"com_github_michaeleisel_zippyjsoncfamily",
"com_github_michaeleisel_zippyjson",
"com_github_tuist_xcodeproj",
"com_github_apple_swift_collections",
)
15 changes: 15 additions & 0 deletions examples/cc/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
bazel_dep(name = "rules_apple", repo_name = "build_bazel_rules_apple", version = "2.0.0")
bazel_dep(name = "bazel_skylib", version = "1.3.0")
bazel_dep(name = "rules_xcodeproj", repo_name = "com_github_buildbuddy_io_rules_xcodeproj", version = "0.0.0")
bazel_dep(name = "rules_swift", repo_name = "build_bazel_rules_swift", version = "1.5.1")
bazel_dep(name = "examples_cc_external", version = "0.0.1")

local_path_override(
module_name = "rules_xcodeproj",
path = "../.."
)

local_path_override(
module_name = "examples_cc_external",
path = "external"
)
Empty file added examples/cc/WORKSPACE.bzlmod
Empty file.
7 changes: 7 additions & 0 deletions examples/cc/external/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module(
name = "examples_cc_external",
version = "0.0.1",
compatibility_level = 1,
)

bazel_dep(name = "bazel_skylib", version = "1.3.0")
5 changes: 5 additions & 0 deletions xcodeproj/extensions.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Module extension for loading dependencies not yet compatible with bzlmod."""

load("//xcodeproj:repositories.bzl", "xcodeproj_rules_dependencies")

non_module_deps = module_extension(implementation = lambda _: xcodeproj_rules_dependencies(include_bzlmod_ready_dependencies = False))
66 changes: 35 additions & 31 deletions xcodeproj/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ pass `ignore_version_differences = True` to `xcodeproj_rules_dependencies()`.
# buildifier: disable=unnamed-macro
def xcodeproj_rules_dependencies(
ignore_version_differences = False,
use_dev_patches = False):
use_dev_patches = False,
include_bzlmod_ready_dependencies = True):
"""Fetches repositories that are dependencies of `rules_xcodeproj`.
Users should call this macro in their `WORKSPACE` to ensure that all of the
Expand All @@ -63,22 +64,41 @@ def xcodeproj_rules_dependencies(
incompatible versions of dependency repositories will be silenced.
use_dev_patches: If `True`, use patches that are intended to be
applied to the development version of the repository.
include_bzlmod_ready_dependencies: Whether or not bzlmod-ready
dependencies should be included.
"""
_maybe(
http_archive,
name = "bazel_skylib",
sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
url = "https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
ignore_version_differences = ignore_version_differences,
)
if include_bzlmod_ready_dependencies:
_maybe(
http_archive,
name = "bazel_skylib",
sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
url = "https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
ignore_version_differences = ignore_version_differences,
)

_maybe(
http_archive,
name = "build_bazel_rules_swift",
sha256 = "84e2cc1c9e3593ae2c0aa4c773bceeb63c2d04c02a74a6e30c1961684d235593",
url = "https://github.com/bazelbuild/rules_swift/releases/download/1.5.1/rules_swift.1.5.1.tar.gz",
ignore_version_differences = ignore_version_differences,
)
_maybe(
http_archive,
name = "build_bazel_rules_swift",
sha256 = "84e2cc1c9e3593ae2c0aa4c773bceeb63c2d04c02a74a6e30c1961684d235593",
url = "https://github.com/bazelbuild/rules_swift/releases/download/1.5.1/rules_swift.1.5.1.tar.gz",
ignore_version_differences = ignore_version_differences,
)

is_bazel_6 = hasattr(apple_common, "link_multi_arch_static_library")
if is_bazel_6:
rules_apple_sha256 = "43737f28a578d8d8d7ab7df2fb80225a6b23b9af9655fcdc66ae38eb2abcf2ed"
rules_apple_version = "2.0.0"
else:
rules_apple_sha256 = "f94e6dddf74739ef5cb30f000e13a2a613f6ebfa5e63588305a71fce8a8a9911"
rules_apple_version = "1.1.3"

_maybe(
http_archive,
name = "build_bazel_rules_apple",
sha256 = rules_apple_sha256,
url = "https://github.com/bazelbuild/rules_apple/releases/download/{version}/rules_apple.{version}.tar.gz".format(version = rules_apple_version),
ignore_version_differences = ignore_version_differences,
)

# `rules_swift` depends on `build_bazel_rules_swift_index_import`, and we
# also need to use `index-import`, so we could declare the same dependency
Expand All @@ -103,22 +123,6 @@ native_binary(
ignore_version_differences = ignore_version_differences,
)

is_bazel_6 = hasattr(apple_common, "link_multi_arch_static_library")
if is_bazel_6:
rules_apple_sha256 = "43737f28a578d8d8d7ab7df2fb80225a6b23b9af9655fcdc66ae38eb2abcf2ed"
rules_apple_version = "2.0.0"
else:
rules_apple_sha256 = "f94e6dddf74739ef5cb30f000e13a2a613f6ebfa5e63588305a71fce8a8a9911"
rules_apple_version = "1.1.3"

_maybe(
http_archive,
name = "build_bazel_rules_apple",
sha256 = rules_apple_sha256,
url = "https://github.com/bazelbuild/rules_apple/releases/download/{version}/rules_apple.{version}.tar.gz".format(version = rules_apple_version),
ignore_version_differences = ignore_version_differences,
)

_maybe(
http_archive,
name = "com_github_kylef_pathkit",
Expand Down

0 comments on commit 15fb29e

Please sign in to comment.