|
| 1 | +diff --git a/swift/internal/extensions/toolchains.bzl b/swift/internal/extensions/toolchains.bzl |
| 2 | +--- a/swift/internal/extensions/toolchains.bzl |
| 3 | ++++ b/swift/internal/extensions/toolchains.bzl |
| 4 | +@@ -132,12 +132,11 @@ def toolchains_for_platform(platform, toolchain_repository): |
| 5 | + toolchain_repository = toolchain_repository, |
| 6 | + ) |
| 7 | + |
| 8 | +- if platform != "xcode": |
| 9 | +- content += _EXEC_TOOLCHAIN_PLATFORM.format( |
| 10 | +- exec_compatible_with = _exec_compatible_with_for_platform(platform), |
| 11 | +- platform = platform, |
| 12 | +- toolchain_repository = toolchain_repository, |
| 13 | +- ) |
| 14 | ++ content += _EXEC_TOOLCHAIN_PLATFORM.format( |
| 15 | ++ exec_compatible_with = _exec_compatible_with_for_platform(platform), |
| 16 | ++ platform = platform, |
| 17 | ++ toolchain_repository = toolchain_repository, |
| 18 | ++ ) |
| 19 | + |
| 20 | + if platform in ( |
| 21 | + "ubuntu22.04", |
| 22 | +diff --git a/swift/toolchains/swift_toolchain.bzl b/swift/toolchains/swift_toolchain.bzl |
| 23 | +--- a/swift/toolchains/swift_toolchain.bzl |
| 24 | ++++ b/swift/toolchains/swift_toolchain.bzl |
| 25 | +@@ -605,10 +605,14 @@ def _parse_target_system_name(*, arch, os, target_system_name): |
| 26 | + """Returns the target system name set by the CC toolchain or attempts to create one based on the OS and arch.""" |
| 27 | + |
| 28 | + if target_system_name and target_system_name != "local": |
| 29 | ++ if os == "macos" and target_system_name.endswith(("-macos", "-macosx")): |
| 30 | ++ return target_system_name + "10.15" |
| 31 | + return target_system_name |
| 32 | + |
| 33 | + if os == "linux": |
| 34 | + return "%s-unknown-linux-gnu" % arch |
| 35 | ++ elif os == "macos": |
| 36 | ++ return "%s-apple-macos10.15" % arch |
| 37 | + elif os == "windows": |
| 38 | + # The MSVC cc toolchain reports a `target_gnu_system_name` of "local", |
| 39 | + # so synthesize the triple. |
| 40 | +@@ -706,5 +710,16 @@ def _swift_toolchain_impl(ctx): |
| 41 | + elif ctx.attr.os == "none": |
| 42 | + swift_linkopts_cc_info = CcInfo() |
| 43 | ++ elif ctx.attr.os == "macos": |
| 44 | ++ macos_linkopts = ["-L{}".format(paths.join(toolchain_root, "lib/swift/macosx"))] |
| 45 | ++ if sdkroot: |
| 46 | ++ macos_linkopts.append("-L{}".format(paths.join(sdkroot, "usr/lib/swift"))) |
| 47 | ++ swift_linkopts_cc_info = _swift_sdk_linkopts_cc_info( |
| 48 | ++ ctx.label, |
| 49 | ++ macos_linkopts, |
| 50 | ++ ctx.attr.swift_tools[SwiftToolsInfo].additional_inputs if ctx.attr.swift_tools else [], |
| 51 | ++ ) |
| 52 | ++ dynamic_runtime_cc_info = None |
| 53 | ++ static_runtime_cc_info = None |
| 54 | + elif ctx.attr.os == "android": |
| 55 | + if not sdkroot: |
| 56 | + fail("Android toolchain requires a sysroot to be set, either via the `sdkroot` attribute or by using a CC toolchain that provides one.") |
| 57 | +diff --git a/swift/internal/extensions/toolchain.BUILD b/swift/internal/extensions/toolchain.BUILD |
| 58 | +--- a/swift/internal/extensions/toolchain.BUILD |
| 59 | ++++ b/swift/internal/extensions/toolchain.BUILD |
| 60 | +@@ -333,17 +333,22 @@ swift_toolchain( |
| 61 | + features = [ |
| 62 | + "swift._supports_upcoming_features", |
| 63 | + "swift.no_embed_debug_module", |
| 64 | +- "swift.use_autolink_extract", |
| 65 | +- "swift.lld_gc_workaround", |
| 66 | +- "swift.use_module_wrap", |
| 67 | + # TODO: This should be removed so that private headers can be used with |
| 68 | + # explicit modules, but the build targets for CgRPC need to be cleaned up |
| 69 | + # first because they contain C++ code. |
| 70 | + "swift.module_map_no_private_headers", |
| 71 | +- ], |
| 72 | ++ ] + select({ |
| 73 | ++ "@platforms//os:linux": [ |
| 74 | ++ "swift.lld_gc_workaround", |
| 75 | ++ "swift.use_autolink_extract", |
| 76 | ++ "swift.use_module_wrap", |
| 77 | ++ ], |
| 78 | ++ "//conditions:default": [], |
| 79 | ++ }), |
| 80 | + os = select({ |
| 81 | + "@platforms//os:linux": "linux", |
| 82 | + "@platforms//os:macos": "macos", |
| 83 | + }), |
| 84 | + parsed_version = "{swift_version}", |
| 85 | ++ sdkroot = "{macos_sdkroot}", |
| 86 | + static_runtime = select({ |
| 87 | +diff --git a/swift/internal/extensions/standalone_toolchain.bzl b/swift/internal/extensions/standalone_toolchain.bzl |
| 88 | +--- a/swift/internal/extensions/standalone_toolchain.bzl |
| 89 | ++++ b/swift/internal/extensions/standalone_toolchain.bzl |
| 90 | +@@ -91,11 +91,17 @@ def _standalone_toolchain_impl(repository_ctx): |
| 91 | + strip_prefix = filename.removesuffix(".tar.gz"), |
| 92 | + ) |
| 93 | + |
| 94 | ++ macos_sdkroot = "" |
| 95 | ++ if repository_ctx.attr.platform == "xcode": |
| 96 | ++ macos_sdkroot = _run(repository_ctx, ["xcrun", "--sdk", "macosx", "--show-sdk-path"]) |
| 97 | ++ repository_ctx.watch(macos_sdkroot) |
| 98 | ++ |
| 99 | + repository_ctx.file(".swift-version", repository_ctx.attr.swift_version) |
| 100 | + repository_ctx.template( |
| 101 | + "BUILD.bazel", |
| 102 | + repository_ctx.attr._build_template, |
| 103 | + substitutions = { |
| 104 | ++ "{macos_sdkroot}": macos_sdkroot, |
| 105 | + "{swift_version}": repository_ctx.attr.swift_version, |
| 106 | + }, |
| 107 | + ) |
| 108 | +@@ -107,19 +109,29 @@ def _standalone_toolchain_impl(repository_ctx): |
| 109 | +-standalone_toolchain = repository_rule( |
| 110 | +- implementation = _standalone_toolchain_impl, |
| 111 | +- attrs = { |
| 112 | +- "_build_template": attr.label( |
| 113 | +- default = "//swift/internal/extensions:toolchain.BUILD", |
| 114 | +- ), |
| 115 | +- "platform": attr.string( |
| 116 | +- doc = "The host platform name in the swift package download URL", |
| 117 | +- mandatory = True, |
| 118 | +- ), |
| 119 | +- "sha256": attr.string( |
| 120 | +- doc = "The expected SHA-256 of the file downloaded. This must match the SHA-256 of the file downloaded.", |
| 121 | +- ), |
| 122 | +- "swift_version": attr.string( |
| 123 | +- doc = "Version of the swift toolchain to be installed.", |
| 124 | +- mandatory = True, |
| 125 | +- ), |
| 126 | +- }, |
| 127 | ++_STANDALONE_TOOLCHAIN_ATTRS = { |
| 128 | ++ "_build_template": attr.label( |
| 129 | ++ default = "//swift/internal/extensions:toolchain.BUILD", |
| 130 | ++ ), |
| 131 | ++ "platform": attr.string( |
| 132 | ++ doc = "The host platform name in the swift package download URL", |
| 133 | ++ mandatory = True, |
| 134 | ++ ), |
| 135 | ++ "sha256": attr.string( |
| 136 | ++ doc = "The expected SHA-256 of the file downloaded. This must match the SHA-256 of the file downloaded.", |
| 137 | ++ ), |
| 138 | ++ "swift_version": attr.string( |
| 139 | ++ doc = "Version of the swift toolchain to be installed.", |
| 140 | ++ mandatory = True, |
| 141 | ++ ), |
| 142 | ++} |
| 143 | ++ |
| 144 | ++standalone_toolchain = repository_rule( |
| 145 | ++ implementation = _standalone_toolchain_impl, |
| 146 | ++ attrs = _STANDALONE_TOOLCHAIN_ATTRS, |
| 147 | ++) |
| 148 | ++ |
| 149 | ++standalone_macos_toolchain = repository_rule( |
| 150 | ++ implementation = _standalone_toolchain_impl, |
| 151 | ++ attrs = _STANDALONE_TOOLCHAIN_ATTRS, |
| 152 | ++ configure = True, |
| 153 | ++ environ = ["DEVELOPER_DIR"], |
| 154 | ++ local = True, |
| 155 | + ) |
| 156 | +diff --git a/swift/extensions.bzl b/swift/extensions.bzl |
| 157 | +--- a/swift/extensions.bzl |
| 158 | ++++ b/swift/extensions.bzl |
| 159 | +@@ -17 +17,5 @@ |
| 160 | +-load("//swift/internal/extensions:standalone_toolchain.bzl", "standalone_toolchain") |
| 161 | ++load( |
| 162 | ++ "//swift/internal/extensions:standalone_toolchain.bzl", |
| 163 | ++ "standalone_macos_toolchain", |
| 164 | ++ "standalone_toolchain", |
| 165 | ++) |
| 166 | +@@ -182,7 +186,8 @@ def _standalone_toolchain_impl(module_ctx): |
| 167 | + toolchain_releases = toolchain.platform_sha256.items() or swift_releases[swift_version].items() |
| 168 | + for platform, sha256 in toolchain_releases: |
| 169 | + repository_name = toolchain.name + "_{}".format(platform) |
| 170 | +- standalone_toolchain( |
| 171 | ++ toolchain_repository = standalone_macos_toolchain if platform == "xcode" else standalone_toolchain |
| 172 | ++ toolchain_repository( |
| 173 | + name = repository_name, |
| 174 | + sha256 = sha256, |
| 175 | + platform = platform, |
0 commit comments