|
| 1 | +From 218a8babe872169174be860db14c321fc6eb8379 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Patrick Balestra <me@patrickbalestra.com> |
| 3 | +Date: Wed, 12 Oct 2022 15:29:12 +0200 |
| 4 | +Subject: [PATCH] Add initial bzlmod support |
| 5 | + |
| 6 | +--- |
| 7 | + MODULE.bazel | 31 ++++++++++++++++++++++++++++++ |
| 8 | + doc/setup.md | 9 ++++++++- |
| 9 | + swift/extensions.bzl | 22 +++++++++++++++++++++ |
| 10 | + swift/repositories.bzl | 43 +++++++++++++++++++++++------------------- |
| 11 | + 4 files changed, 85 insertions(+), 20 deletions(-) |
| 12 | + create mode 100644 MODULE.bazel |
| 13 | + create mode 100644 swift/extensions.bzl |
| 14 | + |
| 15 | +diff --git a/MODULE.bazel b/MODULE.bazel |
| 16 | +new file mode 100644 |
| 17 | +index 0000000..e394f48 |
| 18 | +--- /dev/null |
| 19 | ++++ b/MODULE.bazel |
| 20 | +@@ -0,0 +1,31 @@ |
| 21 | ++module( |
| 22 | ++ name = "rules_swift", |
| 23 | ++ compatibility_level = 1, |
| 24 | ++ repo_name = "build_bazel_rules_swift", |
| 25 | ++ version = "1.2.0", |
| 26 | ++) |
| 27 | ++ |
| 28 | ++bazel_dep(name = "bazel_skylib", version = "1.1.1") |
| 29 | ++bazel_dep(name = "apple_support", repo_name = "build_bazel_apple_support", version = "1.3.1") |
| 30 | ++bazel_dep(name = "rules_cc", version = "0.0.2") |
| 31 | ++bazel_dep(name = "protobuf", repo_name = "com_google_protobuf", version = "3.19.2") # To be removed once rules_proto is bzlmod-ready. |
| 32 | ++ |
| 33 | ++non_module_deps = use_extension("//swift:extensions.bzl", "non_module_deps") |
| 34 | ++ |
| 35 | ++use_repo( |
| 36 | ++ non_module_deps, |
| 37 | ++ "build_bazel_rules_swift_local_config", |
| 38 | ++ "com_github_apple_swift_protobuf", |
| 39 | ++ "com_github_grpc_grpc_swift", |
| 40 | ++ "com_github_apple_swift_nio", |
| 41 | ++ "com_github_apple_swift_nio_http2", |
| 42 | ++ "com_github_apple_swift_nio_transport_services", |
| 43 | ++ "com_github_apple_swift_nio_extras", |
| 44 | ++ "com_github_apple_swift_log", |
| 45 | ++ "com_github_nlohmann_json", |
| 46 | ++ "rules_proto", |
| 47 | ++ "build_bazel_rules_swift_index_import", |
| 48 | ++) |
| 49 | ++ |
| 50 | ++# Dev dependencies |
| 51 | ++bazel_dep(name = "stardoc", dev_dependency = True, repo_name = "io_bazel_skydoc", version = "0.5.3") |
| 52 | +diff --git a/doc/setup.md b/doc/setup.md |
| 53 | +index 38e3e0f..5a52217 100644 |
| 54 | +--- a/doc/setup.md |
| 55 | ++++ b/doc/setup.md |
| 56 | +@@ -5,7 +5,7 @@ |
| 57 | + ## swift_rules_dependencies |
| 58 | + |
| 59 | + <pre> |
| 60 | +-swift_rules_dependencies() |
| 61 | ++swift_rules_dependencies(<a href="#swift_rules_dependencies-include_bzlmod_ready_dependencies">include_bzlmod_ready_dependencies</a>) |
| 62 | + </pre> |
| 63 | + |
| 64 | + Fetches repositories that are dependencies of `rules_swift`. |
| 65 | +@@ -15,4 +15,11 @@ dependencies of the Swift rules are downloaded and that they are isolated |
| 66 | + from changes to those dependencies. |
| 67 | + |
| 68 | + |
| 69 | ++**PARAMETERS** |
| 70 | ++ |
| 71 | ++ |
| 72 | ++| Name | Description | Default Value | |
| 73 | ++| :------------- | :------------- | :------------- | |
| 74 | ++| <a id="swift_rules_dependencies-include_bzlmod_ready_dependencies"></a>include_bzlmod_ready_dependencies | Whether or not bzlmod-ready dependencies should be included. | <code>True</code> | |
| 75 | ++ |
| 76 | + |
| 77 | +diff --git a/swift/extensions.bzl b/swift/extensions.bzl |
| 78 | +new file mode 100644 |
| 79 | +index 0000000..dc2a7ff |
| 80 | +--- /dev/null |
| 81 | ++++ b/swift/extensions.bzl |
| 82 | +@@ -0,0 +1,22 @@ |
| 83 | ++# Copyright 2022 The Bazel Authors. All rights reserved. |
| 84 | ++# |
| 85 | ++# Licensed under the Apache License, Version 2.0 (the "License"); |
| 86 | ++# you may not use this file except in compliance with the License. |
| 87 | ++# You may obtain a copy of the License at |
| 88 | ++# |
| 89 | ++# http://www.apache.org/licenses/LICENSE-2.0 |
| 90 | ++# |
| 91 | ++# Unless required by applicable law or agreed to in writing, software |
| 92 | ++# distributed under the License is distributed on an "AS IS" BASIS, |
| 93 | ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 94 | ++# See the License for the specific language governing permissions and |
| 95 | ++# limitations under the License. |
| 96 | ++ |
| 97 | ++"""Definitions for bzlmod module extensions.""" |
| 98 | ++ |
| 99 | ++load("//swift:repositories.bzl", "swift_rules_dependencies") |
| 100 | ++ |
| 101 | ++def _non_module_deps_impl(_): |
| 102 | ++ swift_rules_dependencies(include_bzlmod_ready_dependencies = False) |
| 103 | ++ |
| 104 | ++non_module_deps = module_extension(implementation = _non_module_deps_impl) |
| 105 | +diff --git a/swift/repositories.bzl b/swift/repositories.bzl |
| 106 | +index 2b85185..60d662a 100644 |
| 107 | +--- a/swift/repositories.bzl |
| 108 | ++++ b/swift/repositories.bzl |
| 109 | +@@ -31,31 +31,36 @@ def _maybe(repo_rule, name, **kwargs): |
| 110 | + if not native.existing_rule(name): |
| 111 | + repo_rule(name = name, **kwargs) |
| 112 | + |
| 113 | +-def swift_rules_dependencies(): |
| 114 | ++def swift_rules_dependencies(include_bzlmod_ready_dependencies = True): |
| 115 | + """Fetches repositories that are dependencies of `rules_swift`. |
| 116 | + |
| 117 | + Users should call this macro in their `WORKSPACE` to ensure that all of the |
| 118 | + dependencies of the Swift rules are downloaded and that they are isolated |
| 119 | + from changes to those dependencies. |
| 120 | +- """ |
| 121 | +- _maybe( |
| 122 | +- http_archive, |
| 123 | +- name = "bazel_skylib", |
| 124 | +- urls = [ |
| 125 | +- "https://github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz", |
| 126 | +- "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz", |
| 127 | +- ], |
| 128 | +- sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d", |
| 129 | +- ) |
| 130 | + |
| 131 | +- _maybe( |
| 132 | +- http_archive, |
| 133 | +- name = "build_bazel_apple_support", |
| 134 | +- urls = [ |
| 135 | +- "https://github.com/bazelbuild/apple_support/releases/download/1.3.1/apple_support.1.3.1.tar.gz", |
| 136 | +- ], |
| 137 | +- sha256 = "f4fdf5c9b42b92ea12f229b265d74bb8cedb8208ca7a445b383c9f866cf53392", |
| 138 | +- ) |
| 139 | ++ Args: |
| 140 | ++ include_bzlmod_ready_dependencies: Whether or not bzlmod-ready |
| 141 | ++ dependencies should be included. |
| 142 | ++ """ |
| 143 | ++ if include_bzlmod_ready_dependencies: |
| 144 | ++ _maybe( |
| 145 | ++ http_archive, |
| 146 | ++ name = "bazel_skylib", |
| 147 | ++ urls = [ |
| 148 | ++ "https://github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz", |
| 149 | ++ "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz", |
| 150 | ++ ], |
| 151 | ++ sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d", |
| 152 | ++ ) |
| 153 | ++ |
| 154 | ++ _maybe( |
| 155 | ++ http_archive, |
| 156 | ++ name = "build_bazel_apple_support", |
| 157 | ++ urls = [ |
| 158 | ++ "https://github.com/bazelbuild/apple_support/releases/download/1.3.1/apple_support.1.3.1.tar.gz", |
| 159 | ++ ], |
| 160 | ++ sha256 = "f4fdf5c9b42b92ea12f229b265d74bb8cedb8208ca7a445b383c9f866cf53392", |
| 161 | ++ ) |
| 162 | + |
| 163 | + _maybe( |
| 164 | + http_archive, |
| 165 | +-- |
| 166 | +2.37.0 (Apple Git-136) |
| 167 | + |
0 commit comments