Skip to content

Commit f57e544

Browse files
committed
Disuse unversioned triples on non-Darwin platforms.
The target flag should take the versioned triple, otherwise on platforms with versioned triples, the standard library won't be found. On Darwin, the unversioned triple should still be used throughout. This necessitates special-casing in the bootstrap script and when making subdirectories during the build. See TSC pr #229.
1 parent 5e4695d commit f57e544

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

Sources/Commands/SwiftTool.swift

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,8 @@ public class SwiftTool {
656656
// FIXME: At the moment we just pass the built products directory for the host. We will need to extend this
657657
// with a map of the names of tools available to each plugin. In particular this would not work with any
658658
// binary targets.
659-
let builtToolsDir = dataDir.appending(components: try self._hostToolchain.get().triple.tripleString, buildEnvironment.configuration.dirname)
659+
let hostTriple = try self._hostToolchain.get().triple
660+
let builtToolsDir = dataDir.appending(components: hostTriple.platformBuildPathComponent(), buildEnvironment.configuration.dirname)
660661
let diagnostics = DiagnosticsEngine()
661662

662663
// Create the cache directory, if needed.
@@ -768,8 +769,14 @@ public class SwiftTool {
768769
// Use "apple" as the subdirectory because in theory Xcode build system
769770
// can be used to build for any Apple platform and it has it's own
770771
// conventions for build subpaths based on platforms.
771-
let dataPath = buildPath.appending(
772-
component: options.buildSystem == .xcode ? "apple" : triple.tripleString)
772+
let subdir: String
773+
if triple.isDarwin() {
774+
let unversionedTriple = triple.tripleString(forPlatformVersion: "")
775+
subdir = options.buildSystem == .xcode ? "apple" : unversionedTriple
776+
} else {
777+
subdir = triple.tripleString
778+
}
779+
let dataPath = buildPath.appending(component: subdir)
773780
return BuildParameters(
774781
dataPath: dataPath,
775782
configuration: options.configuration,
@@ -945,3 +952,13 @@ extension DispatchTimeInterval {
945952
}
946953
}
947954
}
955+
956+
extension Triple {
957+
public func platformBuildPathComponent() -> String {
958+
if isDarwin() {
959+
return tripleString(forPlatformVersion: "")
960+
}
961+
962+
return tripleString
963+
}
964+
}

Tests/CommandsTests/BuildToolTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ final class BuildToolTests: XCTestCase {
7474
func testBinPathAndSymlink() throws {
7575
fixture(name: "ValidLayouts/SingleModule/ExecutableNew") { path in
7676
let fullPath = resolveSymlinks(path)
77-
let targetPath = fullPath.appending(components: ".build", Resources.default.toolchain.triple.tripleString)
77+
let targetPath = fullPath.appending(components: ".build", Resources.default.toolchain.triple.platformBuildPathComponent())
7878
let xcbuildTargetPath = fullPath.appending(components: ".build", "apple")
7979
XCTAssertEqual(try execute(["--show-bin-path"], packagePath: fullPath).stdout,
8080
"\(targetPath.appending(component: "debug").pathString)\n")

Tests/CommandsTests/PackageToolTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ final class PackageToolTests: XCTestCase {
586586
_ = try SwiftPMProduct.SwiftPackage.execute(["edit", "baz", "--branch", "bugfix"], packagePath: fooPath)
587587

588588
// Path to the executable.
589-
let exec = [fooPath.appending(components: ".build", Resources.default.toolchain.triple.tripleString, "debug", "foo").pathString]
589+
let exec = [fooPath.appending(components: ".build", Resources.default.toolchain.triple.platformBuildPathComponent(), "debug", "foo").pathString]
590590

591591
// We should see it now in packages directory.
592592
let editsPath = fooPath.appending(components: "Packages", "bar")
@@ -660,7 +660,7 @@ final class PackageToolTests: XCTestCase {
660660
// Build it.
661661
XCTAssertBuilds(packageRoot)
662662
let buildPath = packageRoot.appending(component: ".build")
663-
let binFile = buildPath.appending(components: Resources.default.toolchain.triple.tripleString, "debug", "Bar")
663+
let binFile = buildPath.appending(components: Resources.default.toolchain.triple.platformBuildPathComponent(), "debug", "Bar")
664664
XCTAssertFileExists(binFile)
665665
XCTAssert(localFileSystem.isDirectory(buildPath))
666666

@@ -679,7 +679,7 @@ final class PackageToolTests: XCTestCase {
679679
// Build it.
680680
XCTAssertBuilds(packageRoot)
681681
let buildPath = packageRoot.appending(component: ".build")
682-
let binFile = buildPath.appending(components: Resources.default.toolchain.triple.tripleString, "debug", "Bar")
682+
let binFile = buildPath.appending(components: Resources.default.toolchain.triple.platformBuildPathComponent(), "debug", "Bar")
683683
XCTAssertFileExists(binFile)
684684
XCTAssert(localFileSystem.isDirectory(buildPath))
685685
// Clean, and check for removal of the build directory but not Packages.
@@ -749,7 +749,7 @@ final class PackageToolTests: XCTestCase {
749749
func build() throws -> String {
750750
return try SwiftPMProduct.SwiftBuild.execute([], packagePath: fooPath).stdout
751751
}
752-
let exec = [fooPath.appending(components: ".build", Resources.default.toolchain.triple.tripleString, "debug", "foo").pathString]
752+
let exec = [fooPath.appending(components: ".build", Resources.default.toolchain.triple.platformBuildPathComponent(), "debug", "foo").pathString]
753753

754754
// Build and sanity check.
755755
_ = try build()

Tests/FunctionalTests/ToolsVersionTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class ToolsVersionTests: XCTestCase {
9191

9292
// Build the primary package.
9393
_ = try SwiftPMProduct.SwiftBuild.execute([], packagePath: primaryPath)
94-
let exe = primaryPath.appending(components: ".build", Resources.default.toolchain.triple.tripleString, "debug", "Primary").pathString
94+
let exe = primaryPath.appending(components: ".build", Resources.default.toolchain.triple.platformBuildPathComponent(), "debug", "Primary").pathString
9595
// v1 should get selected because v1.0.1 depends on a (way) higher set of tools.
9696
XCTAssertEqual(try Process.checkNonZeroExit(args: exe).spm_chomp(), "[email protected]")
9797

Utilities/bootstrap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@ def get_build_target(args, cross_compile=False):
291291
target_info_json = subprocess.check_output(command,
292292
stderr=subprocess.PIPE, universal_newlines=True).strip()
293293
args.target_info = json.loads(target_info_json)
294-
return args.target_info["target"]["unversionedTriple"]
294+
if platform.system() == 'Darwin':
295+
return args.target_info["target"]["unversionedTriple"]
296+
return args.target_info["target"]["triple"]
295297
except Exception as e:
296298
# Temporary fallback for Darwin.
297299
if platform.system() == 'Darwin':

0 commit comments

Comments
 (0)