-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add support for Swift package registries #1318
base: main
Are you sure you want to change the base?
Conversation
a5adfda
to
6739de1
Compare
452f05d
to
ad96158
Compare
671c25d
to
f921aba
Compare
a541b18
to
9838fcd
Compare
3d7452d
to
01abd62
Compare
Im testing in a real registry implementation now and realizing some issues, going to make some updates but the majority of the design is ready for review |
💯 (as a follow-up). |
Can we spin up a local webserver as part of CI instead? |
I like the underscores version. However, it is not a strong preference. |
+1 to @brentleyjones suggestion. Again, I am not too familiar with Swift registry hosting. If it is static, can we use GitHub to host it? I presume the functionality just needs a URL. |
01abd62
to
2a46f9e
Compare
I tried this originally but local host doesn't support https and so the bazel download stuff fails because of insecure connection. |
It is not static, it needs to be a web server which follows the registry spec. |
Done! I fixed my fake registry implementation, the |
@luispadron When you are ready to merge, if you don't want to babysit the merge, you can specify |
I think the answer is here is: no? Thoughts? Doing the replacement would require manipulating the identity in a fair amount of the rules and im not sure it gives us much (plus the label is still different than non registry so we don't gain anything from doing the replacement) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
Yeah, let's not do the replacement. |
24c49a6
to
7ef0ec4
Compare
0aebb42
to
00897e2
Compare
@cgrindel @watt @brentleyjones The PR has been updated, I believe I have addressed all comments here if folks want to give it another review. The biggest change was proper support for I also added a doc on using Swift package registries over here |
00897e2
to
bc773b3
Compare
Firebase failure is unrelated to this change (cc: @cgrindel). |
@brentleyjones That is a weird error. Is this an issue in |
Yes. Seems that rules_xcodeproj doesn't support Bazel 8 yet, in particular it looks like the change from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, LGTM. Most of my comments are related to formatting (e.g., line length).
@@ -196,10 +206,23 @@ def _declare_pkg_from_dependency(dep, config_pkg): | |||
dependencies_index = None, | |||
) | |||
|
|||
elif dep.registry: | |||
resolved = from_package.resolved if from_package else None | |||
replace_scm_with_registry = config_swift_package.replace_scm_with_registry if config_swift_package else False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we format for line length?
config_swift_package = config_swift_package | ||
for config_swift_package_tag in mod.tags.configure_swift_package: | ||
if config_swift_package: | ||
fail("Expected only one `configure_swift_package` tag, but found multiple.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fail("Expected only one `configure_swift_package` tag, but found multiple.") | |
fail("""\ | |
Expected only one `configure_swift_package` tag, but found multiple.\ | |
""") |
@@ -499,7 +519,7 @@ def _new_dependency_identity_to_name_map(dump_deps): | |||
result = {} | |||
for dep in dump_deps: | |||
identity_provider_list = ( | |||
dep.get("sourceControl") or dep.get("fileSystem") | |||
dep.get("sourceControl") or dep.get("fileSystem") or dep.get("registry") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line length.
@@ -703,7 +723,7 @@ def _new_platform(name, version): | |||
|
|||
# MARK: - External Dependency | |||
|
|||
def _new_dependency(identity, name, source_control = None, file_system = None): | |||
def _new_dependency(identity, name, source_control = None, file_system = None, registry = None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line length.
# NOTE: because the Swift Package Registry spec does not define the allowable prefixes within the archive, | ||
# we cannot rely on Bazel's `stripPrefix` feature to strip the parent directory reliably. | ||
# Instead, we'll download and extract to a temporary location and then move the contents to the output. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line length
# Instead, we'll download and extract to a temporary location and then move the contents to the output. | ||
download_output = "{output}/download".format(output = output) | ||
|
||
# NOTE: this requires Bazel 7.1 or later to use `headers` which must be set to reach this endpoint. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check the line length for this entire file.
template_dict.add("%(enable_build_manifest_caching)s", "true" if ctx.attr.manifest_caching else "false") | ||
template_dict.add("%(enable_dependency_cache)s", "true" if ctx.attr.dependency_caching else "false") | ||
template_dict.add("%(manifest_cache)s", ctx.attr.manifest_cache) | ||
template_dict.add("%(registries_json)s", registries.short_path if registries else "") | ||
template_dict.add("%(replace_scm_with_registry)s", "true" if ctx.attr.replace_scm_with_registry else "false") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line length.
|
||
_swift_package_tool_config_attrs = { | ||
"build_path": attr.string( | ||
doc = "The relative path within the runfiles tree for the Swift Package Manager build directory.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check the line length for this file.
Something is wrong. The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I attempted to test this locally with a Package.swift that has a dependency graph requiring the SCM replacement, and it didn't seem to work for me unfortunately. Haven't dug into exactly where it failed yet.
|
||
return source_archive.get("checksum") | ||
|
||
def _get_resolved_pin_for_url(*, registry_url, repository_ctx, resolved_pkg_map, url): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could there be a layer of caching in here somewhere, to avoid hitting the registry multiple times for the same URL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you want to mention the Bazel 7 requirement in this file?
Fixes #1016
This adds initial support for consuming packages using a Swift Package Registry.
The majority of the changes are in the new
registry_swift_package
rule which creates a repository to build the targets from a package downloaded via a registry.Notably, because the identity of the package is used to derive the repository name, packages used via a registry have the following label:
@swiftpkg_[org].[name]
, so for example@swiftpkg_swift_collections
becomes@swiftpkg_apple.swift_collections
if using theswift-collections
package from theapple
organization (as registries support multiple orgs).The
registry_swift_package
rule is mostly just an updated version of #1043 (thanks @watt)Open questions
.
with_
in identity? E.g.@swiftpkg_apple.swift_collections
vs.@swiftpkg_apple_swift_collections
: NOFollow-up
rule_swift_package_manager
already has a bootstrapping issue, if there is noPackage.resolved
defined already then the Bazel repositories fail to generate. The addition of registry support adds another bootstrapping issue with theregistries.json
file (users will need to runswift package-registry
commands to create it currently). We should address both of these by making bootstrapping a new project easier.Caveats
Example
The following shows an example of a
swift_binary
target depending on an SPM dependency downloaded from a registry defined inregistries.json
.Package.swift
Package.resolved
registries.json
MODULE.bazel
BUILD.bazel