|
2 | 2 | // |
3 | 3 | // This source file is part of the Swift open source project |
4 | 4 | // |
5 | | -// Copyright (c) 2025 Apple Inc. and the Swift project authors |
| 5 | +// Copyright (c) 2025-2026 Apple Inc. and the Swift project authors |
6 | 6 | // Licensed under Apache License v2.0 with Runtime Library Exception |
7 | 7 | // |
8 | 8 | // See http://swift.org/LICENSE.txt for license information |
@@ -2528,7 +2528,7 @@ private class SettingsBuilder: ProjectMatchLookup { |
2528 | 2528 | platformTable.push(BuiltinMacros.PLATFORM_DISPLAY_NAME, literal: platform.displayName) |
2529 | 2529 | platformTable.push(BuiltinMacros.PLATFORM_DIR, literal: platform.path.str) |
2530 | 2530 |
|
2531 | | - platformTable.push(BuiltinMacros.EFFECTIVE_PLATFORM_NAME, BuiltinMacros.namespace.parseString(Core.effectivePlatformName(platformName: platform.name, archComponent: "$(CURRENT_ARCH)"))) |
| 2531 | + platformTable.push(BuiltinMacros.EFFECTIVE_PLATFORM_NAME, BuiltinMacros.namespace.parseString(core.effectivePlatformName(platformName: platform.name, archComponent: "$(ONLY_ARCH:default=unknown_arch)"))) |
2532 | 2532 |
|
2533 | 2533 | if platform.name.hasSuffix("simulator") { |
2534 | 2534 | platformTable.push(BuiltinMacros.EFFECTIVE_PLATFORM_SUFFIX, literal: "simulator") |
@@ -4136,6 +4136,37 @@ private class SettingsBuilder: ProjectMatchLookup { |
4136 | 4136 | // This is the method which computes the list of architectures to build for, and so is a funnel point for a bunch of load-bearing logic. |
4137 | 4137 | push(getCommonTargetTaskOverrides(specLookupContext, deploymentTarget, sdk), .exported) |
4138 | 4138 |
|
| 4139 | + // FIXME: There is a more random, but questionable stuff here. To be added in a test case driven fashion. |
| 4140 | + |
| 4141 | + // Resolve some of the key path settings to be absolute. |
| 4142 | + // |
| 4143 | + // This is important, because they can be used to derive paths via xcspecs, and we want those paths to be absolute. |
| 4144 | + // |
| 4145 | + // FIXME: This is a bad way to enforce this, it doesn't have any type safety. What would be much better would be to introduce new macro evaluation features that let us write the specs to clearly demarcate paths. |
| 4146 | + // |
| 4147 | + // FIXME: <rdar://problem/41339901> In Xcode, this also does tilde expansion. We should support that (and test exactly where we want it to work). |
| 4148 | + // Now that these are paths not really required. |
| 4149 | + // These paths must only be normalized after we have bound the architecture settings via getCommonTargetTaskOverrides above, as they may be interpolated into the paths. |
| 4150 | + do { |
| 4151 | + var table = MacroValueAssignmentTable(namespace: userNamespace) |
| 4152 | + let scope = createScope(sdkToUse: sdk) |
| 4153 | + let macrosToNormalize = [ |
| 4154 | + BuiltinMacros.SRCROOT, BuiltinMacros.SYMROOT, BuiltinMacros.OBJROOT, BuiltinMacros.DSTROOT, |
| 4155 | + BuiltinMacros.LOCROOT, BuiltinMacros.LOCSYMROOT, |
| 4156 | + BuiltinMacros.CCHROOT, |
| 4157 | + BuiltinMacros.CONFIGURATION_BUILD_DIR, BuiltinMacros.SHARED_PRECOMPS_DIR, |
| 4158 | + BuiltinMacros.CONFIGURATION_TEMP_DIR, BuiltinMacros.TARGET_TEMP_DIR, BuiltinMacros.TEMP_DIR, |
| 4159 | + BuiltinMacros.PROJECT_DIR, BuiltinMacros.BUILT_PRODUCTS_DIR |
| 4160 | + ] |
| 4161 | + for macro in macrosToNormalize { |
| 4162 | + table.push(macro, literal: (project?.sourceRoot ?? workspaceContext.workspace.path.dirname).join(scope.evaluate(macro), normalize: true).str) |
| 4163 | + } |
| 4164 | + push(table, .exported) |
| 4165 | + } |
| 4166 | + |
| 4167 | + |
| 4168 | + // FIXME: Xcode also normalizes SDKROOT to an absolute path here, although native targets also do this (in a different place). |
| 4169 | + |
4139 | 4170 | do { |
4140 | 4171 | // Also set each a build setting with the name of each architecture to `YES`. |
4141 | 4172 | // This is much more amenable to composable build setting names than using `ARCHS`. |
@@ -4402,13 +4433,14 @@ private class SettingsBuilder: ProjectMatchLookup { |
4402 | 4433 | // Sort the archs for stability. |
4403 | 4434 | let sortedArchs = archs.sorted() |
4404 | 4435 |
|
4405 | | - // Compute the base arch. The purpose of this is to always choose the same base arch from the same list of archs (if we don't have a preferredArch), and picking the first one from a sorted list is a simple way to do that. |
| 4436 | + // Compute the base arch. The purpose of this is to always choose the same base arch from the same list of archs in a stable manner. |
| 4437 | + // If the name of the arch cohort is in the list, then we prefer that one. Otherwise we pick the first one from the sorted list, which is a simple way to ensure stability. |
| 4438 | + // We don't want to use self.preferredArch here, because that can vary depending on context (for example different run destinations may provide different preferredArchs). |
4406 | 4439 | guard let firstArch = sortedArchs.first else { |
4407 | 4440 | // If there are no archs then we don't need to set up a cohort. |
4408 | 4441 | continue |
4409 | 4442 | } |
4410 | | - let preferredBaseArch = self.preferredArch ?? cohortArch |
4411 | | - let baseArch = archs.contains(preferredBaseArch) ? preferredBaseArch : firstArch |
| 4443 | + let baseArch = archs.contains(cohortArch) ? cohortArch : firstArch |
4412 | 4444 | let otherArchs = sortedArchs.filter({ $0 != baseArch }) |
4413 | 4445 |
|
4414 | 4446 | // Set up the build settings for the cohort which CURRENT_ARCH is in. (They will of course be empty if there is no cohort - we won't even have gotten here.) |
@@ -4464,6 +4496,12 @@ private class SettingsBuilder: ProjectMatchLookup { |
4464 | 4496 | // This will omit cohort archs, code for which is generated by the task for the base arch of the cohort. |
4465 | 4497 | table.push(BuiltinMacros.ARCHS_BASE, literal: archsBase) |
4466 | 4498 |
|
| 4499 | + if let onlyArch = archsBase.only { |
| 4500 | + table.push(BuiltinMacros.ONLY_ARCH, literal: onlyArch) |
| 4501 | + } else { |
| 4502 | + table.push(BuiltinMacros.ONLY_ARCH, literal: "multiple_archs") |
| 4503 | + } |
| 4504 | + |
4467 | 4505 | // The set of Swift module-only architectures should be a set of valid architectures that's disjoint from the |
4468 | 4506 | // set of effective architectures. We don't necessarily care about these architectures being deprecated as this |
4469 | 4507 | // setting will primarily be used to support building Swift modules for deprecated (or at least unsupported) |
@@ -4493,31 +4531,6 @@ private class SettingsBuilder: ProjectMatchLookup { |
4493 | 4531 | table.push(BuiltinMacros._LD_ARCH, literal: prefix) |
4494 | 4532 | } |
4495 | 4533 |
|
4496 | | - // FIXME: There is a more random, but questionable stuff here. To be added in a test case driven fashion. |
4497 | | - |
4498 | | - // Resolve some of the key path settings to be absolute. |
4499 | | - // |
4500 | | - // This is important, because they can be used to derive paths via xcspecs, and we want those paths to be absolute. |
4501 | | - // |
4502 | | - // FIXME: This is a bad way to enforce this, it doesn't have any type safety. What would be much better would be to introduce new macro evaluation features that let us write the specs to clearly demarcate paths. |
4503 | | - // |
4504 | | - // FIXME: <rdar://problem/41339901> In Xcode, this also does tilde expansion. We should support that (and test exactly where we want it to work). |
4505 | | - // Now that these are paths not really required. |
4506 | | - let macrosToNormalize = [ |
4507 | | - BuiltinMacros.SRCROOT, BuiltinMacros.SYMROOT, BuiltinMacros.OBJROOT, BuiltinMacros.DSTROOT, |
4508 | | - BuiltinMacros.LOCROOT, BuiltinMacros.LOCSYMROOT, |
4509 | | - BuiltinMacros.CCHROOT, |
4510 | | - BuiltinMacros.CONFIGURATION_BUILD_DIR, BuiltinMacros.SHARED_PRECOMPS_DIR, |
4511 | | - BuiltinMacros.CONFIGURATION_TEMP_DIR, BuiltinMacros.TARGET_TEMP_DIR, BuiltinMacros.TEMP_DIR, |
4512 | | - BuiltinMacros.PROJECT_DIR, BuiltinMacros.BUILT_PRODUCTS_DIR |
4513 | | - ] |
4514 | | - for macro in macrosToNormalize { |
4515 | | - table.push(macro, literal: (project?.sourceRoot ?? workspaceContext.workspace.path.dirname).join(scope.evaluate(macro), normalize: true).str) |
4516 | | - } |
4517 | | - |
4518 | | - |
4519 | | - // FIXME: Xcode also normalizes SDKROOT to an absolute path here, although native targets also do this (in a different place). |
4520 | | - |
4521 | 4534 | // Compute the resolved value for GCC_VERSION, if not otherwise set. |
4522 | 4535 | if scope.evaluate(BuiltinMacros.GCC_VERSION).isEmpty { |
4523 | 4536 | table.push(BuiltinMacros.GCC_VERSION, literal: "com.apple.compilers.llvm.clang.1_0") |
|
0 commit comments