diff --git a/.bazelrc b/.bazelrc index 680734883..a8cb51b2a 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,7 +1,7 @@ # To update these lines, execute # `bazel run @rules_bazel_integration_test//tools:update_deleted_packages` -build --deleted_packages=bzlmod/workspace,bzlmod/workspace/Sources/MyExecutable,bzlmod/workspace/Sources/MyLibrary,bzlmod/workspace/Tests/MyLibraryTests,examples/firebase_example,examples/firebase_example/abtesting,examples/firebase_example/abtesting/SharedApp,examples/firebase_example/analytics/AnalyticsExample,examples/firebase_example/appdistribution,examples/firebase_example/appdistribution/AppDistributionExample,examples/firebase_example/appdistribution/AppDistributionTests,examples/firebase_example/crashlytics,examples/google_maps_example,examples/google_maps_example/GoogleMapsExample,examples/google_maps_example/third-party/google-maps-ios-sdk,examples/grpc_example,examples/grpc_example/compilers,examples/grpc_example/protos/echo_service,examples/grpc_example/protos/echo_service/requests,examples/grpc_example/protos/echo_service/responses,examples/grpc_example/sources/client,examples/grpc_example/sources/server,examples/injectionnext_example,examples/injectionnext_example/Tests,examples/interesting_deps,examples/interesting_deps/ios,examples/ios_sim,examples/ios_sim/Sources/Foo,examples/ios_sim/Tests/FooTests,examples/kscrash_example,examples/kscrash_example/Sources/MyApp,examples/kscrash_example/Tests/MyAppUITests,examples/kscrash_example/swift,examples/language_modes_example,examples/lottie_ios_example,examples/lottie_ios_example/LottieExample,examples/lottie_ios_example/LottieExampleUITest,examples/messagekit_example,examples/messagekit_example/Sources/Models,examples/messagekit_example/Tests/ModelTests,examples/nimble_example,examples/nimble_example/Sources/NimbleExample,examples/objc_code,examples/objc_code/Tests/TrustKitTests,examples/phone_number_kit,examples/phone_number_kit/Tests/PhoneNumberKitTests,examples/pkg_manifest_minimal,examples/pkg_manifest_minimal/Sources/MyExecutable,examples/pkg_manifest_minimal/Sources/MyLibrary,examples/pkg_manifest_minimal/Tests/MyLibraryTests,examples/pkg_manifest_minimal/third_party,examples/resources_example,examples/resources_example/Sources/MyApp,examples/resources_example/Tests/MyAppTests,examples/resources_example/Tests/MyAppUITests,examples/resources_example/swift,examples/resources_example/third_party,examples/shake_ios_example,examples/shake_ios_example/ShakeIOSExample,examples/shake_ios_example/ShakeIOSExampleUITests,examples/skip_local_transitive_dependencies_example,examples/snapkit_example,examples/soto_example,examples/soto_example/Tests/SotoTests,examples/sqlite_data_example,examples/stripe_example,examples/stripe_example/PaymentSheet/PaymentSheetExample,examples/stripe_example/PaymentSheet/PaymentSheetUITest,examples/swift_package_registry_example,examples/symlink_example,examples/symlink_example/Sources/ImportFramework,examples/symlink_example/Tests/ImportFrameworkTests,examples/tca_example,examples/tca_example/Sources,examples/tca_example/Tests,examples/vapor_example,examples/vapor_example/Sources/App,examples/vapor_example/Sources/Run,examples/vapor_example/Tests/AppTests,examples/vapor_example/swift,examples/xcmetrics_example -query --deleted_packages=bzlmod/workspace,bzlmod/workspace/Sources/MyExecutable,bzlmod/workspace/Sources/MyLibrary,bzlmod/workspace/Tests/MyLibraryTests,examples/firebase_example,examples/firebase_example/abtesting,examples/firebase_example/abtesting/SharedApp,examples/firebase_example/analytics/AnalyticsExample,examples/firebase_example/appdistribution,examples/firebase_example/appdistribution/AppDistributionExample,examples/firebase_example/appdistribution/AppDistributionTests,examples/firebase_example/crashlytics,examples/google_maps_example,examples/google_maps_example/GoogleMapsExample,examples/google_maps_example/third-party/google-maps-ios-sdk,examples/grpc_example,examples/grpc_example/compilers,examples/grpc_example/protos/echo_service,examples/grpc_example/protos/echo_service/requests,examples/grpc_example/protos/echo_service/responses,examples/grpc_example/sources/client,examples/grpc_example/sources/server,examples/injectionnext_example,examples/injectionnext_example/Tests,examples/interesting_deps,examples/interesting_deps/ios,examples/ios_sim,examples/ios_sim/Sources/Foo,examples/ios_sim/Tests/FooTests,examples/kscrash_example,examples/kscrash_example/Sources/MyApp,examples/kscrash_example/Tests/MyAppUITests,examples/kscrash_example/swift,examples/language_modes_example,examples/lottie_ios_example,examples/lottie_ios_example/LottieExample,examples/lottie_ios_example/LottieExampleUITest,examples/messagekit_example,examples/messagekit_example/Sources/Models,examples/messagekit_example/Tests/ModelTests,examples/nimble_example,examples/nimble_example/Sources/NimbleExample,examples/objc_code,examples/objc_code/Tests/TrustKitTests,examples/phone_number_kit,examples/phone_number_kit/Tests/PhoneNumberKitTests,examples/pkg_manifest_minimal,examples/pkg_manifest_minimal/Sources/MyExecutable,examples/pkg_manifest_minimal/Sources/MyLibrary,examples/pkg_manifest_minimal/Tests/MyLibraryTests,examples/pkg_manifest_minimal/third_party,examples/resources_example,examples/resources_example/Sources/MyApp,examples/resources_example/Tests/MyAppTests,examples/resources_example/Tests/MyAppUITests,examples/resources_example/swift,examples/resources_example/third_party,examples/shake_ios_example,examples/shake_ios_example/ShakeIOSExample,examples/shake_ios_example/ShakeIOSExampleUITests,examples/skip_local_transitive_dependencies_example,examples/snapkit_example,examples/soto_example,examples/soto_example/Tests/SotoTests,examples/sqlite_data_example,examples/stripe_example,examples/stripe_example/PaymentSheet/PaymentSheetExample,examples/stripe_example/PaymentSheet/PaymentSheetUITest,examples/swift_package_registry_example,examples/symlink_example,examples/symlink_example/Sources/ImportFramework,examples/symlink_example/Tests/ImportFrameworkTests,examples/tca_example,examples/tca_example/Sources,examples/tca_example/Tests,examples/vapor_example,examples/vapor_example/Sources/App,examples/vapor_example/Sources/Run,examples/vapor_example/Tests/AppTests,examples/vapor_example/swift,examples/xcmetrics_example +build --deleted_packages=bzlmod/workspace,bzlmod/workspace/Sources/MyExecutable,bzlmod/workspace/Sources/MyLibrary,bzlmod/workspace/Tests/MyLibraryTests,examples/firebase_example,examples/firebase_example/abtesting,examples/firebase_example/abtesting/SharedApp,examples/firebase_example/analytics/AnalyticsExample,examples/firebase_example/appdistribution,examples/firebase_example/appdistribution/AppDistributionExample,examples/firebase_example/appdistribution/AppDistributionTests,examples/firebase_example/crashlytics,examples/google_maps_example,examples/google_maps_example/GoogleMapsExample,examples/google_maps_example/third-party/google-maps-ios-sdk,examples/grpc_example,examples/grpc_example/compilers,examples/grpc_example/protos/echo_service,examples/grpc_example/protos/echo_service/requests,examples/grpc_example/protos/echo_service/responses,examples/grpc_example/sources/client,examples/grpc_example/sources/server,examples/injectionnext_example,examples/injectionnext_example/Tests,examples/interesting_deps,examples/interesting_deps/ios,examples/ios_sim,examples/ios_sim/Sources/Foo,examples/ios_sim/Tests/FooTests,examples/kscrash_example,examples/kscrash_example/Sources/MyApp,examples/kscrash_example/Tests/MyAppUITests,examples/kscrash_example/swift,examples/language_modes_example,examples/lottie_ios_example,examples/lottie_ios_example/LottieExample,examples/lottie_ios_example/LottieExampleUITest,examples/messagekit_example,examples/messagekit_example/Sources/Models,examples/messagekit_example/Tests/ModelTests,examples/nimble_example,examples/nimble_example/Sources/NimbleExample,examples/objc_code,examples/objc_code/Tests/TrustKitTests,examples/phone_number_kit,examples/phone_number_kit/Tests/PhoneNumberKitTests,examples/pkg_manifest_minimal,examples/pkg_manifest_minimal/Sources/MyExecutable,examples/pkg_manifest_minimal/Sources/MyLibrary,examples/pkg_manifest_minimal/Tests/MyLibraryTests,examples/pkg_manifest_minimal/third_party,examples/resources_example,examples/resources_example/Sources/MyApp,examples/resources_example/Tests/MyAppTests,examples/resources_example/Tests/MyAppUITests,examples/resources_example/swift,examples/resources_example/swift/.build/checkouts/promises,examples/resources_example/third_party,examples/shake_ios_example,examples/shake_ios_example/ShakeIOSExample,examples/shake_ios_example/ShakeIOSExampleUITests,examples/skip_local_transitive_dependencies_example,examples/snapkit_example,examples/soto_example,examples/soto_example/Tests/SotoTests,examples/sqlite_data_example,examples/stripe_example,examples/stripe_example/PaymentSheet/PaymentSheetExample,examples/stripe_example/PaymentSheet/PaymentSheetUITest,examples/swift_package_registry_example,examples/symlink_example,examples/symlink_example/Sources/ImportFramework,examples/symlink_example/Tests/ImportFrameworkTests,examples/tca_example,examples/tca_example/Sources,examples/tca_example/Tests,examples/vapor_example,examples/vapor_example/Sources/App,examples/vapor_example/Sources/Run,examples/vapor_example/Tests/AppTests,examples/vapor_example/swift,examples/xcmetrics_example +query --deleted_packages=bzlmod/workspace,bzlmod/workspace/Sources/MyExecutable,bzlmod/workspace/Sources/MyLibrary,bzlmod/workspace/Tests/MyLibraryTests,examples/firebase_example,examples/firebase_example/abtesting,examples/firebase_example/abtesting/SharedApp,examples/firebase_example/analytics/AnalyticsExample,examples/firebase_example/appdistribution,examples/firebase_example/appdistribution/AppDistributionExample,examples/firebase_example/appdistribution/AppDistributionTests,examples/firebase_example/crashlytics,examples/google_maps_example,examples/google_maps_example/GoogleMapsExample,examples/google_maps_example/third-party/google-maps-ios-sdk,examples/grpc_example,examples/grpc_example/compilers,examples/grpc_example/protos/echo_service,examples/grpc_example/protos/echo_service/requests,examples/grpc_example/protos/echo_service/responses,examples/grpc_example/sources/client,examples/grpc_example/sources/server,examples/injectionnext_example,examples/injectionnext_example/Tests,examples/interesting_deps,examples/interesting_deps/ios,examples/ios_sim,examples/ios_sim/Sources/Foo,examples/ios_sim/Tests/FooTests,examples/kscrash_example,examples/kscrash_example/Sources/MyApp,examples/kscrash_example/Tests/MyAppUITests,examples/kscrash_example/swift,examples/language_modes_example,examples/lottie_ios_example,examples/lottie_ios_example/LottieExample,examples/lottie_ios_example/LottieExampleUITest,examples/messagekit_example,examples/messagekit_example/Sources/Models,examples/messagekit_example/Tests/ModelTests,examples/nimble_example,examples/nimble_example/Sources/NimbleExample,examples/objc_code,examples/objc_code/Tests/TrustKitTests,examples/phone_number_kit,examples/phone_number_kit/Tests/PhoneNumberKitTests,examples/pkg_manifest_minimal,examples/pkg_manifest_minimal/Sources/MyExecutable,examples/pkg_manifest_minimal/Sources/MyLibrary,examples/pkg_manifest_minimal/Tests/MyLibraryTests,examples/pkg_manifest_minimal/third_party,examples/resources_example,examples/resources_example/Sources/MyApp,examples/resources_example/Tests/MyAppTests,examples/resources_example/Tests/MyAppUITests,examples/resources_example/swift,examples/resources_example/swift/.build/checkouts/promises,examples/resources_example/third_party,examples/shake_ios_example,examples/shake_ios_example/ShakeIOSExample,examples/shake_ios_example/ShakeIOSExampleUITests,examples/skip_local_transitive_dependencies_example,examples/snapkit_example,examples/soto_example,examples/soto_example/Tests/SotoTests,examples/sqlite_data_example,examples/stripe_example,examples/stripe_example/PaymentSheet/PaymentSheetExample,examples/stripe_example/PaymentSheet/PaymentSheetUITest,examples/swift_package_registry_example,examples/symlink_example,examples/symlink_example/Sources/ImportFramework,examples/symlink_example/Tests/ImportFrameworkTests,examples/tca_example,examples/tca_example/Sources,examples/tca_example/Tests,examples/vapor_example,examples/vapor_example/Sources/App,examples/vapor_example/Sources/Run,examples/vapor_example/Tests/AppTests,examples/vapor_example/swift,examples/xcmetrics_example # Import Shared settings import %workspace%/shared.bazelrc diff --git a/swiftpkg/bzlmod/swift_deps.bzl b/swiftpkg/bzlmod/swift_deps.bzl index b7913e104..d221e912a 100644 --- a/swiftpkg/bzlmod/swift_deps.bzl +++ b/swiftpkg/bzlmod/swift_deps.bzl @@ -238,6 +238,7 @@ def _declare_pkg_from_dependency(dep, config_pkg, from_package, config_swift_pac env_inherit = from_package.env_inherit, init_submodules = init_submodules, recursive_init_submodules = recursive_init_submodules, + netrc = from_package.netrc, patch_args = patch_args, patch_cmds = patch_cmds, patch_cmds_win = patch_cmds_win, @@ -289,6 +290,7 @@ def _declare_swift_package_repo(name, from_package, config_swift_package): package = from_package.swift.package, name = from_package.swift.name, ), + netrc = from_package.netrc, registries = from_package.registries, **config_swift_package_kwargs ) diff --git a/swiftpkg/internal/swift_package.bzl b/swiftpkg/internal/swift_package.bzl index af90915e1..ee4ccc1f8 100644 --- a/swiftpkg/internal/swift_package.bzl +++ b/swiftpkg/internal/swift_package.bzl @@ -220,7 +220,13 @@ _ALL_ATTRS = dicts.add( _GIT_ATTRS, repo_rules.env_attrs, repo_rules.swift_attrs, - {"version": attr.string(doc = "The resolved version of the package.")}, + { + "netrc": attr.label( + default = None, + doc = "A `.netrc` file for authentication when downloading binary artifacts.", + ), + "version": attr.string(doc = "The resolved version of the package."), + }, ) swift_package = repository_rule( diff --git a/swiftpkg/internal/swift_package_tool.bzl b/swiftpkg/internal/swift_package_tool.bzl index 5d80a7fa5..1a38506d8 100644 --- a/swiftpkg/internal/swift_package_tool.bzl +++ b/swiftpkg/internal/swift_package_tool.bzl @@ -16,6 +16,7 @@ def _swift_package_tool_impl(ctx): cmd = ctx.attr.cmd package = ctx.attr.package package_path = paths.dirname(package) + netrc = ctx.file.netrc registries = ctx.file.registries runfiles = [] @@ -23,6 +24,9 @@ def _swift_package_tool_impl(ctx): swift = toolchain.swift_worker runfiles.append(swift.executable) + if netrc: + runfiles.append(netrc) + if registries: runfiles.append(registries) @@ -43,6 +47,10 @@ def _swift_package_tool_impl(ctx): "true" if ctx.attr.dependency_caching else "false", ) template_dict.add("%(manifest_cache)s", ctx.attr.manifest_cache) + template_dict.add( + "%(netrc_file)s", + netrc.short_path if netrc else "", + ) template_dict.add( "%(registries_json)s", registries.short_path if registries else "", diff --git a/swiftpkg/internal/swift_package_tool_attrs.bzl b/swiftpkg/internal/swift_package_tool_attrs.bzl index abe958446..13a64b180 100644 --- a/swiftpkg/internal/swift_package_tool_attrs.bzl +++ b/swiftpkg/internal/swift_package_tool_attrs.bzl @@ -1,9 +1,17 @@ """Attributes shared between rules that interact with the Swift package tool.""" _swift_package_registry_attrs = { + "netrc": attr.label( + allow_single_file = True, + doc = """ +A `.netrc` file that contains authentication credentials used for fetching Swift packages and or binary artifacts. + +When provided, this file will be passed to Swift Package Manager commands using \ +the `--netrc-file` flag during package resolution and updates. +""", + ), "registries": attr.label( allow_single_file = [".json"], - cfg = "exec", doc = """ A `registries.json` file that defines the configured Swift package registries. diff --git a/swiftpkg/internal/swift_package_tool_repo.bzl b/swiftpkg/internal/swift_package_tool_repo.bzl index f5a6522c1..a5f8f39a4 100644 --- a/swiftpkg/internal/swift_package_tool_repo.bzl +++ b/swiftpkg/internal/swift_package_tool_repo.bzl @@ -35,6 +35,21 @@ def _swift_package_tool_repo_impl(repository_ctx): attrs_content = _package_config_attrs_to_content(repository_ctx.attr) package_path = repository_ctx.attr.package + # We copy .netrc file contents to avoid requiring users to use `exports_files(...)` + netrc_attr = None + if repository_ctx.attr.netrc: + netrc_content = repository_ctx.read(repository_ctx.attr.netrc) + repository_ctx.file(".netrc", netrc_content) + netrc_attr = ' netrc = ":.netrc",' + + attrs_lines = [line for line in attrs_content.split("\n") if "netrc =" not in line] + filtered_attrs = "\n".join(attrs_lines) + + final_attrs_parts = [filtered_attrs] + if netrc_attr: + final_attrs_parts.append(netrc_attr) + final_attrs_content = "\n".join([p for p in final_attrs_parts if p]) + repository_ctx.file( "BUILD.bazel", content = """ @@ -55,7 +70,7 @@ swift_package_tool( ) """.format( package = package_path, - attrs_content = attrs_content, + attrs_content = final_attrs_content, ), ) diff --git a/swiftpkg/internal/swift_package_tool_runner_template.sh b/swiftpkg/internal/swift_package_tool_runner_template.sh index 17c3b0b44..2cdb7af2a 100644 --- a/swiftpkg/internal/swift_package_tool_runner_template.sh +++ b/swiftpkg/internal/swift_package_tool_runner_template.sh @@ -27,6 +27,7 @@ config_path="%(config_path)s" enable_build_manifest_caching="%(enable_build_manifest_caching)s" enable_dependency_cache="%(enable_dependency_cache)s" manifest_cache="%(manifest_cache)s" +netrc_file="%(netrc_file)s" registries_json="%(registries_json)s" replace_scm_with_registry="%(replace_scm_with_registry)s" security_path="%(security_path)s" @@ -57,6 +58,11 @@ fi args+=("--manifest-cache=$manifest_cache") +# If netrc_file is set, add the --netrc-file flag. +if [ -n "$netrc_file" ]; then + args+=("--netrc-file" "$(readlink -f "$netrc_file")") +fi + # If registries_json is set, symlink the `.json` file to the `config_path/configuration` directory. if [ -n "$registries_json" ]; then mkdir -p "$config_path"