|
| 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,13 @@ def _standalone_toolchain_impl(repository_ctx): |
| 91 | + strip_prefix = filename.removesuffix(".tar.gz"), |
| 92 | + ) |
| 93 | + |
| 94 | ++ macos_sdkroot = _run(repository_ctx, ["xcrun", "--sdk", "macosx", "--show-sdk-path"]) if repository_ctx.attr.platform == "xcode" else "" |
| 95 | + repository_ctx.file(".swift-version", repository_ctx.attr.swift_version) |
| 96 | + repository_ctx.template( |
| 97 | + "BUILD.bazel", |
| 98 | + repository_ctx.attr._build_template, |
| 99 | + substitutions = { |
| 100 | ++ "{macos_sdkroot}": macos_sdkroot, |
| 101 | + "{swift_version}": repository_ctx.attr.swift_version, |
| 102 | + }, |
| 103 | + ) |
0 commit comments