From e1c5fc1b0557f8ffacc3bec471f465ce52ec4ffd Mon Sep 17 00:00:00 2001 From: Erik Kerber Date: Mon, 8 Apr 2024 15:35:38 -0500 Subject: [PATCH] Support consuming sign-here via bzlmod --- MODULE.bazel | 13 +++++-- extensions.bzl | 2 +- repositories.bzl | 90 +++++++++++++++++++++++++----------------------- 3 files changed, 59 insertions(+), 46 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index ac5324c..a3b77e5 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,4 +1,13 @@ -bazel_dep(name = "rules_apple", version = "3.2.1", repo_name = "build_bazel_rules_apple") +module(name = "sign-here") + +bazel_dep(name = "rules_apple", version = "3.5.0", repo_name = "build_bazel_rules_apple") +bazel_dep(name = "rules_swift", version = "1.18.0", repo_name = "build_bazel_rules_swift") +bazel_dep(name = "swift-syntax", version = "509.0.2", repo_name = "SwiftSyntax") +bazel_dep(name = "swift_argument_parser", version = "1.3.0", repo_name = "com_github_apple_swift_argument_parser") non_module_dependencies = use_extension("//:extensions.bzl", "non_module_dependencies") -use_repo(non_module_dependencies, "data_file") +use_repo( + non_module_dependencies, + "com_github_kitura_blueecc", + "com_github_kylef_pathkit", +) diff --git a/extensions.bzl b/extensions.bzl index b5227a2..d246ee2 100644 --- a/extensions.bzl +++ b/extensions.bzl @@ -1,7 +1,7 @@ load("//:repositories.bzl", "sign_here_dependencies") def _non_module_dependencies_impl(_ctx): - sign_here_dependencies() + sign_here_dependencies(bzlmod = True) non_module_dependencies = module_extension( implementation = _non_module_dependencies_impl, diff --git a/repositories.bzl b/repositories.bzl index 3cc373f..bdec7a8 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -13,51 +13,9 @@ def _maybe(repo_rule, name, **kwargs): if not native.existing_rule(name): repo_rule(name = name, **kwargs) -def sign_here_dependencies(): +def sign_here_dependencies(bzlmod = False): """Sets up all necessary transitive dependencies.""" - _maybe( - http_archive, - name = "com_github_apple_swift_argument_parser", - url = "https://github.com/apple/swift-argument-parser/archive/refs/tags/1.2.2.tar.gz", - strip_prefix = "swift-argument-parser-1.2.2", - sha256 = "44782ba7180f924f72661b8f457c268929ccd20441eac17301f18eff3b91ce0c", - build_file_content = """ -load( - "@build_bazel_rules_swift//swift:swift.bzl", - "swift_library", -) - -load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") - -swift_library( - name = "ArgumentParserToolInfo", - module_name = "ArgumentParserToolInfo", - srcs = glob([ - "Sources/ArgumentParserToolInfo/**/*.swift" - ], allow_empty = False), -) - -swift_library( - name = "ArgumentParser", - module_name = "ArgumentParser", - srcs = glob([ - "Sources/ArgumentParser/**/*.swift" - ], allow_empty = False), - copts = [ - "-suppress-warnings", - ], - features = [ - "-swift.treat_warnings_as_errors", - ], - visibility = ["//visibility:public"], - deps = [ - ":ArgumentParserToolInfo" - ] -) - """, - ) - PATHKIT_GIT_SHA = "2fcd4618d52869b342e208324d455131a48f9e9b" _maybe( http_archive, @@ -340,3 +298,49 @@ swift_library( strip_prefix = "swift-syntax-%s" % SWIFT_SYNTAX_VERSION, url = "https://github.com/apple/swift-syntax/archive/refs/tags/%s.tar.gz" % SWIFT_SYNTAX_VERSION, ) + + # End non-bzlmod deps + if bzlmod: + return + + _maybe( + http_archive, + name = "com_github_apple_swift_argument_parser", + url = "https://github.com/apple/swift-argument-parser/archive/refs/tags/1.2.2.tar.gz", + strip_prefix = "swift-argument-parser-1.2.2", + sha256 = "44782ba7180f924f72661b8f457c268929ccd20441eac17301f18eff3b91ce0c", + build_file_content = """ +load( + "@build_bazel_rules_swift//swift:swift.bzl", + "swift_library", +) + +load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") + +swift_library( + name = "ArgumentParserToolInfo", + module_name = "ArgumentParserToolInfo", + srcs = glob([ + "Sources/ArgumentParserToolInfo/**/*.swift" + ], allow_empty = False), +) + +swift_library( + name = "ArgumentParser", + module_name = "ArgumentParser", + srcs = glob([ + "Sources/ArgumentParser/**/*.swift" + ], allow_empty = False), + copts = [ + "-suppress-warnings", + ], + features = [ + "-swift.treat_warnings_as_errors", + ], + visibility = ["//visibility:public"], + deps = [ + ":ArgumentParserToolInfo" + ] +) + """, + )