Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 2 additions & 36 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,14 @@ x_defaults:
- "//..."
test_targets:
- "//..."
linux_environment: &linux_environment
platform: ubuntu2204
environment:
SWIFT_VERSION: "6.3.3"
SWIFT_HOME: "$HOME/swift-$SWIFT_VERSION"
PATH: "$SWIFT_HOME/usr/bin:$PATH"
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
# https://github.com/bazelbuild/rules_swift/issues/4).
- "--action_env=PATH"
platform: ubuntu2204
build_targets:
- "//..."
- "-//examples/apple/..."
test_flags: *linux_flags
test_targets:
- "//..."
- "-//examples/apple/..."
# The following tests require Swift >5.8.
- "-//test:const_values_empty_const_values_multiple_files"
- "-//test:const_values_empty_const_values_single_file"
- "-//test:const_values_expected_argv"
- "-//test:const_values_wmo_single_values_file"
- "-//test:output_file_map_default"
windows_common: &windows_common
platform: windows
build_targets:
Expand Down Expand Up @@ -75,28 +57,16 @@ tasks:
ubuntu2204_latest:
name: "Current LTS"
bazel: latest
shell_commands:
- "echo --- Downloading and extracting Swift $SWIFT_VERSION to $SWIFT_HOME"
- "mkdir $SWIFT_HOME"
- "curl https://download.swift.org/swift-${SWIFT_VERSION}-release/ubuntu2204/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-ubuntu22.04.tar.gz | tar xvz --strip-components=1 -C $SWIFT_HOME"
<<: *linux_common

ubuntu2204_rolling:
name: "Latest rolling"
bazel: rolling
shell_commands:
- "echo --- Downloading and extracting Swift $SWIFT_VERSION to $SWIFT_HOME"
- "mkdir $SWIFT_HOME"
- "curl https://download.swift.org/swift-${SWIFT_VERSION}-release/ubuntu2204/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-ubuntu22.04.tar.gz | tar xvz --strip-components=1 -C $SWIFT_HOME"
<<: *linux_common

ubuntu2204_last_green:
name: "Last Green Bazel"
bazel: last_green
shell_commands:
- "echo --- Downloading and extracting Swift $SWIFT_VERSION to $SWIFT_HOME"
- "mkdir $SWIFT_HOME"
- "curl https://download.swift.org/swift-${SWIFT_VERSION}-release/ubuntu2204/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-ubuntu22.04.tar.gz | tar xvz --strip-components=1 -C $SWIFT_HOME"
<<: *linux_common

windows:
Expand Down Expand Up @@ -128,11 +98,7 @@ tasks:
doc_tests:
name: "Doc tests"
bazel: latest
<<: *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/ubuntu2204/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-ubuntu22.04.tar.gz | tar xvz --strip-components=1 -C $SWIFT_HOME"
platform: ubuntu2204
test_targets:
- "doc/..."

Expand Down
40 changes: 38 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module(

bazel_dep(name = "abseil-cpp", version = "20250814.1")
bazel_dep(name = "apple_support", version = "2.6.1")
bazel_dep(name = "bazel_linux_packages", version = "0.3.1")
bazel_dep(name = "bazel_features", version = "1.51.0")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "nlohmann_json", version = "3.12.0.bcr.1")
Expand All @@ -18,6 +19,21 @@ bazel_dep(name = "rules_cc", version = "0.2.14")
bazel_dep(name = "rules_shell", version = "0.3.0")
bazel_dep(name = "swift_argument_parser", version = "1.7.0")

# Regenerate lockfile: bazel run @swift_ubuntu22.04_sysroot//:lock
apt = use_extension("@bazel_linux_packages//apt:extensions.bzl", "apt")
apt.ubuntu(
name = "swift_ubuntu22.04_sysroot",
lockfile = "//swift/internal/extensions:ubuntu22.04_sysroot.lock.json",
packages = [
"libc6-dev",
"libstdc++-11-dev",
"linux-libc-dev",
"zlib1g-dev",
],
suites = ["jammy"],
)
use_repo(apt, "swift_ubuntu22.04_sysroot")

swift_autoconfiguration = use_repo_rule("//swift/internal:swift_autoconfiguration.bzl", "swift_autoconfiguration")

swift_autoconfiguration(name = "rules_swift_local_config")
Expand Down Expand Up @@ -145,8 +161,6 @@ http_archive(
urls = ["https://github.com/MobileNativeFoundation/index-import/releases/download/6.1.0.1/index-import.tar.gz"],
)

register_toolchains("//swift/toolchains:all")

system_sdk = use_extension("//swift:extensions.bzl", "system_sdk")
system_sdk.configure_sdks(
# NOTE: This doesn't apply to downstream repos
Expand Down Expand Up @@ -209,14 +223,18 @@ register_toolchains(
# Anyway, for now we will need to update this every time we update the CI environment. Contributors might also
# have to update this list if they're testing on a different Linux distribution.
"@swift_toolchain//:cc_toolchain_embedded_ubuntu22.04",
"@swift_toolchain//:cc_toolchain_exec_ubuntu22.04",
"@swift_toolchain//:cc_toolchain_embedded_ubuntu22.04-aarch64",
"@swift_toolchain//:cc_toolchain_embedded_xcode",
"@swift_toolchain//:swift_toolchain_embedded_ubuntu22.04",
"@swift_toolchain//:swift_toolchain_exec_ubuntu22.04",
"@swift_toolchain//:swift_toolchain_embedded_ubuntu22.04-aarch64",
"@swift_toolchain//:swift_toolchain_embedded_xcode",
dev_dependency = True,
)

register_toolchains("//swift/toolchains:all")

include("//examples/cross_compilation/android_app:android.MODULE.bazel")
include("//examples/cross_compilation/wasm:wasm.MODULE.bazel")

Expand All @@ -240,3 +258,21 @@ single_version_override(
patch_strip = 1,
patches = ["//third_party/patches:stardoc-revert-load-statements-in-docs.patch"],
)

# FIXME: Delete after testing

archive_override(
module_name = "apple_support",
integrity = "sha256-4YQ7nCqSJ4QcfTF8RLDRQseKtfFS1MTtWKnLlS3bg/U=",
strip_prefix = "apple_support-c268c90e7d1efe0d656081e29b11ab05ada9bdda",
urls = [
"https://github.com/bazelbuild/apple_support/archive/c268c90e7d1efe0d656081e29b11ab05ada9bdda.tar.gz",
],
)

single_version_override(
module_name = "bazel_linux_packages",
patch_strip = 1,
patches = ["//third_party/patches:bazel-linux-packages-bazel-9.patch"],
version = "0.3.1",
)
7 changes: 3 additions & 4 deletions doc/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ SwiftToolchainInfo(<a href="#SwiftToolchainInfo-action_configs">action_configs</
<a href="#SwiftToolchainInfo-const_protocols_to_gather">const_protocols_to_gather</a>, <a href="#SwiftToolchainInfo-cross_import_overlays">cross_import_overlays</a>, <a href="#SwiftToolchainInfo-debug_outputs_provider">debug_outputs_provider</a>,
<a href="#SwiftToolchainInfo-developer_dirs">developer_dirs</a>, <a href="#SwiftToolchainInfo-entry_point_linkopts_provider">entry_point_linkopts_provider</a>, <a href="#SwiftToolchainInfo-feature_allowlists">feature_allowlists</a>,
<a href="#SwiftToolchainInfo-generated_header_module_implicit_deps_providers">generated_header_module_implicit_deps_providers</a>, <a href="#SwiftToolchainInfo-implicit_deps_providers">implicit_deps_providers</a>,
<a href="#SwiftToolchainInfo-module_aliases">module_aliases</a>, <a href="#SwiftToolchainInfo-package_configurations">package_configurations</a>, <a href="#SwiftToolchainInfo-requested_features">requested_features</a>, <a href="#SwiftToolchainInfo-root_dir">root_dir</a>, <a href="#SwiftToolchainInfo-runtime">runtime</a>,
<a href="#SwiftToolchainInfo-swift_worker">swift_worker</a>, <a href="#SwiftToolchainInfo-system_modules">system_modules</a>, <a href="#SwiftToolchainInfo-implicit_system_modules">implicit_system_modules</a>, <a href="#SwiftToolchainInfo-test_configuration">test_configuration</a>,
<a href="#SwiftToolchainInfo-tool_configs">tool_configs</a>, <a href="#SwiftToolchainInfo-unsupported_features">unsupported_features</a>)
<a href="#SwiftToolchainInfo-module_aliases">module_aliases</a>, <a href="#SwiftToolchainInfo-package_configurations">package_configurations</a>, <a href="#SwiftToolchainInfo-requested_features">requested_features</a>, <a href="#SwiftToolchainInfo-root_dir">root_dir</a>, <a href="#SwiftToolchainInfo-swift_worker">swift_worker</a>,
<a href="#SwiftToolchainInfo-system_modules">system_modules</a>, <a href="#SwiftToolchainInfo-implicit_system_modules">implicit_system_modules</a>, <a href="#SwiftToolchainInfo-test_configuration">test_configuration</a>, <a href="#SwiftToolchainInfo-tool_configs">tool_configs</a>,
<a href="#SwiftToolchainInfo-unsupported_features">unsupported_features</a>)
</pre>

Propagates information about a Swift toolchain to compilation and linking rules
Expand All @@ -296,7 +296,6 @@ that use the toolchain.
| <a id="SwiftToolchainInfo-package_configurations"></a>package_configurations | A list of `SwiftPackageConfigurationInfo` providers that specify additional compilation configuration options that are applied to targets on a per-package basis. |
| <a id="SwiftToolchainInfo-requested_features"></a>requested_features | `List` of `string`s. Features that should be implicitly enabled by default for targets built using this toolchain, unless overridden by the user by listing their negation in the `features` attribute of a target/package or in the `--features` command line flag.<br><br>These features determine various compilation and debugging behaviors of the Swift build rules, and they are also passed to the C++ APIs used when linking (so features defined in CROSSTOOL may be used here). |
| <a id="SwiftToolchainInfo-root_dir"></a>root_dir | `String`. The workspace-relative root directory of the toolchain. |
| <a id="SwiftToolchainInfo-runtime"></a>runtime | `List` of `File`s. Files required at runtime by compiled executables. They will be added to the input root at execution time. |
| <a id="SwiftToolchainInfo-swift_worker"></a>swift_worker | `File`. The executable representing the worker executable used to invoke the compiler and other Swift tools (for both incremental and non-incremental compiles). |
| <a id="SwiftToolchainInfo-system_modules"></a>system_modules | A `struct` with the following fields, which represent providers from targets that should be added as implicit dependencies of any compilation or linking target:<br><br>* `cc_infos`: A list of `CcInfo` providers from targets specified as the toolchain's implicit dependencies.<br><br>* `swift_infos`: A list of `SwiftInfo` providers from targets specified as the toolchain's implicit dependencies.<br><br>For ease of use, this field is never `None`; it will always be a valid `struct` containing the fields described above, even if those lists are empty. |
| <a id="SwiftToolchainInfo-implicit_system_modules"></a>implicit_system_modules | A `struct` with in the same shape as `system_modules` for the system modules that every Swift compilation implicitly requires. |
Expand Down
67 changes: 64 additions & 3 deletions swift/internal/extensions/toolchain.BUILD
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
load("@apple_support//toolchain:cc_toolchain.bzl", apple_cc_toolchain = "cc_toolchain")
load("@rules_cc//cc/toolchains:args.bzl", "cc_args")
load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature")
load("@rules_cc//cc/toolchains:make_variable.bzl", "cc_make_variable")
load("@rules_cc//cc/toolchains:tool.bzl", "cc_tool")
load("@rules_cc//cc/toolchains:tool_map.bzl", "cc_tool_map")
load("@rules_cc//cc/toolchains:toolchain.bzl", "cc_toolchain")
load("@rules_cc//cc/toolchains/args:sysroot.bzl", "cc_sysroot")
load("@rules_swift//swift/toolchains:swift_toolchain.bzl", "swift_toolchain")
load("@rules_swift//swift/toolchains:swift_tools.bzl", "swift_tools")

Expand Down Expand Up @@ -76,12 +79,32 @@ cc_tool(
cc_tool(
name = "clang",
src = "usr/bin/clang",
data = [":swift_sdk_linker_inputs"],
tags = ["manual"],
)

cc_tool(
name = "clang++",
src = "usr/bin/clang++",
data = [":swift_sdk_linker_inputs"],
tags = ["manual"],
)

cc_tool(
name = "llvm_cov",
src = "usr/bin/llvm-cov",
tags = ["manual"],
)

cc_tool(
name = "llvm_objcopy",
src = "usr/bin/llvm-objcopy",
tags = ["manual"],
)

cc_tool(
name = "llvm_profdata",
src = "usr/bin/llvm-profdata",
tags = ["manual"],
)

Expand All @@ -93,10 +116,42 @@ cc_tool_map(
"@rules_cc//cc/toolchains/actions:assembly_actions": ":clang",
"@rules_cc//cc/toolchains/actions:c_compile": ":clang",
"@rules_cc//cc/toolchains/actions:cpp_compile_actions": ":clang++",
"@rules_cc//cc/toolchains/actions:link_actions": ":clang",
"@rules_cc//cc/toolchains/actions:link_actions": ":clang++",
"@rules_cc//cc/toolchains/actions:llvm_cov": ":llvm_cov",
"@rules_cc//cc/toolchains/actions:llvm_profdata": ":llvm_profdata",
"@rules_cc//cc/toolchains/actions:objcopy_embed_data": ":llvm_objcopy",
"@rules_cc//cc/toolchains/actions:strip": ":llvm_objcopy",
},
)

cc_sysroot(
name = "linux_sysroot_args",
actions = [
"@rules_cc//cc/toolchains/actions:link_actions",
"@rules_cc//cc/toolchains/actions:compile_actions",
],
data = ["@swift_ubuntu22.04_sysroot//:root"],
sysroot = "@swift_ubuntu22.04_sysroot//:root",
)

cc_feature(
name = "linux_sysroot",
args = [":linux_sysroot_args"],
feature_name = "sysroot",
)

apple_cc_toolchain(
name = "cc_toolchain_exec",
module_map = None,
supports_header_parsing = False,
sysroot_feature = ":linux_sysroot",
target = select({
"@platforms//cpu:aarch64": "aarch64-unknown-linux-gnu",
"@platforms//cpu:x86_64": "x86_64-unknown-linux-gnu",
}),
tool_map = ":all_tools",
)

### Make variables ###
# Used in _swift_toolchain_impl() in swift/toolchain/swift_toolchain.bzl
cc_make_variable(
Expand Down Expand Up @@ -227,6 +282,12 @@ swift_toolchain(
"swift._supports_upcoming_features",
"swift.no_embed_debug_module",
"swift.use_autolink_extract",
"swift.lld_gc_workaround",
"swift.use_module_wrap",
# TODO: This should be removed so that private headers can be used with
# explicit modules, but the build targets for CgRPC need to be cleaned up
# first because they contain C++ code.
"swift.module_map_no_private_headers",
],
os = select({
"@platforms//os:linux": "linux",
Expand All @@ -235,8 +296,8 @@ swift_toolchain(
parsed_version = "{swift_version}",
runtime = glob(
[
"usr/lib/swift/**/*.dylib", # On MacOS
"usr/lib/swift/**/*.so", # On Linux
"usr/lib/swift/linux/*.so",
"usr/lib/swift/macosx/*.dylib",
],
allow_empty = True,
),
Expand Down
28 changes: 27 additions & 1 deletion swift/internal/extensions/toolchains.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ toolchain(

"""

_CC_EXEC_TOOLCHAIN_PLATFORM = """
# C++ exec toolchain from repository: `{toolchain_repository}`
toolchain(
name = "cc_toolchain_exec_{platform}",
exec_compatible_with = {exec_compatible_with},
target_compatible_with = {exec_compatible_with},
toolchain = "@{toolchain_repository}//:cc_toolchain_exec",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
visibility = ["//visibility:public"],
)
"""

_SDK_TOOLCHAIN_PLATFORM = """
# Swift SDK toolchain from repository: `{sdk_repository}`
toolchain(
Expand Down Expand Up @@ -94,12 +106,26 @@ def _exec_compatible_with_for_platform(platform):
]

def toolchains_for_platform(platform, toolchain_repository):
return _TOOLCHAIN_PLATFORM.format(
content = _TOOLCHAIN_PLATFORM.format(
exec_compatible_with = _exec_compatible_with_for_platform(platform),
platform = platform,
toolchain_repository = toolchain_repository,
)

# TODO: Expand based on sysroot compatibility, maybe we should allow users to pass them
if platform in (
"ubuntu22.04",
"ubuntu22.04-aarch64",
"ubuntu24.04",
"ubuntu24.04-aarch64",
):
content += _CC_EXEC_TOOLCHAIN_PLATFORM.format(
exec_compatible_with = _exec_compatible_with_for_platform(platform),
platform = platform,
toolchain_repository = toolchain_repository,
)
return content

def android_sdk_toolchains_for_platform(platform, sdk_repository, archs):
"""Returns Swift `toolchain` declarations for an Android Swift SDK.

Expand Down
Loading
Loading