diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 120d15844..fd663d542 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -10,13 +10,15 @@ x_defaults: test_targets: - "//examples/..." - "//test/..." - linux_common: &linux_common + linux_environment: &linux_environment platform: ubuntu2004 environment: CC: clang SWIFT_VERSION: "5.9.2" SWIFT_HOME: "$HOME/swift-$SWIFT_VERSION" PATH: "$PATH:$SWIFT_HOME/usr/bin" + linux_common: &linux_common + <<: *linux_environment build_flags: &linux_flags # On Linux, we look for Swift toolchain binaries on the path. We may be # able to change this when we start auto-downloading toolchains (see @@ -129,7 +131,11 @@ tasks: doc_tests: name: "Doc tests" bazel: last_green - platform: ubuntu2004 + <<: *linux_environment + shell_commands: + - "echo --- Downloading and extracting Swift $SWIFT_VERSION to $SWIFT_HOME" + - "mkdir $SWIFT_HOME" + - "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" test_targets: - "doc/..." diff --git a/MODULE.bazel b/MODULE.bazel index 2ed9c7e2c..f51ba835b 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -38,6 +38,8 @@ use_repo( apple_cc_configure = use_extension("@build_bazel_apple_support//crosstool:setup.bzl", "apple_cc_configure_extension") use_repo(apple_cc_configure, "local_config_apple_cc") +register_toolchains("@build_bazel_rules_swift_local_config//:all") + # Dev dependencies bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.5.0", dev_dependency = True) bazel_dep(name = "gazelle", version = "0.33.0", dev_dependency = True, repo_name = "bazel_gazelle") diff --git a/swift/internal/toolchain_utils.bzl b/swift/internal/toolchain_utils.bzl index d2d830dbe..31426cf1f 100644 --- a/swift/internal/toolchain_utils.bzl +++ b/swift/internal/toolchain_utils.bzl @@ -68,8 +68,4 @@ def use_swift_toolchain(): A list of toolchain types that should be passed to `rule()`, `aspect()`, or `exec_group`. """ - - # TODO(b/205018581): Intentionally empty for now so that rule definitions - # can reference the function while still being a no-op. A future change will - # add the toolchain type to this list to enable toolchain resolution. - return [] + return [SWIFT_TOOLCHAIN_TYPE] diff --git a/swift/repositories.bzl b/swift/repositories.bzl index 266429dd5..9e02a4d34 100644 --- a/swift/repositories.bzl +++ b/swift/repositories.bzl @@ -31,6 +31,7 @@ def _maybe(repo_rule, name, **kwargs): if not native.existing_rule(name): repo_rule(name = name, **kwargs) +# buildifier: disable=unnamed-macro def swift_rules_dependencies(include_bzlmod_ready_dependencies = True): """Fetches repositories that are dependencies of `rules_swift`. @@ -213,3 +214,9 @@ def swift_rules_dependencies(include_bzlmod_ready_dependencies = True): swift_autoconfiguration, name = "build_bazel_rules_swift_local_config", ) + + if include_bzlmod_ready_dependencies: + native.register_toolchains( + # Use register_toolchain's target pattern expansion to register all toolchains in the package. + "@build_bazel_rules_swift_local_config//:all", + )