Skip to content

Commit

Permalink
Switch the Swift rules over to toolchains.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 503982850
(cherry picked from commit c42aad2)
Signed-off-by: Brentley Jones <github@brentleyjones.com>
  • Loading branch information
allevato authored and brentleyjones committed Oct 2, 2024
1 parent a186c2c commit c0644db
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
10 changes: 8 additions & 2 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/..."

Expand Down
2 changes: 2 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 1 addition & 5 deletions swift/internal/toolchain_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
7 changes: 7 additions & 0 deletions swift/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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",
)

0 comments on commit c0644db

Please sign in to comment.