Skip to content

Commit f7b5064

Browse files
Add rules_swift 1.2.0 (#247)
* Add rules_swift 1.2.0 * Add repository name to metadata * Add prefix to build targets * Remove strip_prefix since this is a release archive * Add patch adding module extension * Use clang on non-macOS platforms * Download Swift for Ubuntu20.04 * Filter out broken grpc example on Linux We do the same in the `rules_swift` repo: https://github.com/bazelbuild/rules_swift/blob/b6a111ea475da15793dfa5dda7e3e3646658f407/.bazelci/presubmit.yml#L24-L27
1 parent 2a344e4 commit f7b5064

File tree

5 files changed

+256
-0
lines changed

5 files changed

+256
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module(
2+
name = "rules_swift",
3+
compatibility_level = 1,
4+
repo_name = "build_bazel_rules_swift",
5+
version = "1.2.0",
6+
)
7+
8+
bazel_dep(name = "bazel_skylib", version = "1.1.1")
9+
bazel_dep(name = "apple_support", repo_name = "build_bazel_apple_support", version = "1.3.1")
10+
bazel_dep(name = "rules_cc", version = "0.0.2")
11+
bazel_dep(name = "protobuf", repo_name = "com_google_protobuf", version = "3.19.2") # To be removed once rules_proto is bzlmod-ready.
12+
13+
non_module_deps = use_extension("//swift:extensions.bzl", "non_module_deps")
14+
15+
use_repo(
16+
non_module_deps,
17+
"build_bazel_rules_swift_local_config",
18+
"com_github_apple_swift_protobuf",
19+
"com_github_grpc_grpc_swift",
20+
"com_github_apple_swift_nio",
21+
"com_github_apple_swift_nio_http2",
22+
"com_github_apple_swift_nio_transport_services",
23+
"com_github_apple_swift_nio_extras",
24+
"com_github_apple_swift_log",
25+
"com_github_nlohmann_json",
26+
"rules_proto",
27+
"build_bazel_rules_swift_index_import",
28+
)
29+
30+
# Dev dependencies
31+
bazel_dep(name = "stardoc", dev_dependency = True, repo_name = "io_bazel_skydoc", version = "0.5.3")
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
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+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
shell_commands: &shell_commands
2+
- "echo --- Downloading and extracting Swift $SWIFT_VERSION to $SWIFT_HOME"
3+
- "mkdir $SWIFT_HOME"
4+
- "curl https://download.swift.org/swift-${SWIFT_VERSION}-release/ubuntu2004/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-ubuntu20.04.tar.gz | tar xvz --strip-components=1 -C $SWIFT_HOME"
5+
6+
matrix:
7+
platform:
8+
- ubuntu2004
9+
tasks:
10+
verify_targets:
11+
name: Verify build targets
12+
platform: ${{ platform }}
13+
environment:
14+
CC: "clang"
15+
SWIFT_VERSION: "5.5.3"
16+
SWIFT_HOME: "$HOME/swift-$SWIFT_VERSION"
17+
PATH: "$PATH:$SWIFT_HOME/usr/bin"
18+
shell_commands: *shell_commands
19+
build_flags:
20+
- "--action_env=PATH"
21+
build_targets:
22+
- "@rules_swift//examples/xplatform/..."
23+
- "-@rules_swift//examples/xplatform/grpc/..." # TODO: Fix grpc on Linux
24+
verify_targets_macos:
25+
name: Verify build targets
26+
platform: macos
27+
build_targets:
28+
- "@rules_swift//examples/apple/..."

modules/rules_swift/1.2.0/source.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"integrity": "sha256-Ue/a+F4E5RF03nbvVj8lVFHVpc0kxhrZAv7q2vxwRtk=",
3+
"patch_strip": 1,
4+
"patches": {
5+
"add-initial-bzlmod-support.patch": "sha256-vvJmXqGJVvASBe1l6/cm/Hv4RF2u/cchcbs7mF3f+tU="
6+
},
7+
"url": "https://github.com/bazelbuild/rules_swift/releases/download/1.2.0/rules_swift.1.2.0.tar.gz"
8+
}

modules/rules_swift/metadata.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"homepage": "https://github.com/bazelbuild/rules_swift",
3+
"maintainers": [
4+
{
5+
"email": "me@patrickbalestra.com",
6+
"github": "BalestraPatrick",
7+
"name": "Patrick Balestra"
8+
},
9+
{
10+
"email": "keithbsmiley@gmail.com",
11+
"github": "keith",
12+
"name": "Keith Smiley"
13+
}
14+
],
15+
"repository": [
16+
"github:bazelbuild/rules_swift"
17+
],
18+
"versions": [
19+
"1.2.0"
20+
],
21+
"yanked_versions": {}
22+
}

0 commit comments

Comments
 (0)