Skip to content

Use swift-driver triple #6627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 21, 2023
Merged

Use swift-driver triple #6627

merged 7 commits into from
Jun 21, 2023

Conversation

rauhul
Copy link
Member

@rauhul rauhul commented May 30, 2023

Removes and replaces the custom LLVM Triple type from the Basics module with the implementation from SwiftDriver. This change allows SwiftPM to understand all triples that swift-driver already does and resolves some issues surrounding incorrect triple parsing. For example the Basics.Triple was not able to parse 'armv7em-apple-none-eabihf-macho' where as SwiftDriver.Triple can.

@rauhul
Copy link
Member Author

rauhul commented May 30, 2023

@swift-ci please smoke test

@rauhul
Copy link
Member Author

rauhul commented May 30, 2023

@swift-ci please smoke test windows

@rauhul rauhul requested a review from compnerd May 30, 2023 17:47
@@ -382,11 +382,11 @@ public final class UserToolchain: Toolchain {
// the merged swiftmodules. XCTest followed suit.
"-I",
AbsolutePath(
validating: "usr/lib/swift/windows/\(triple.arch)",
validating: "usr/lib/swift/windows/\(triple.arch?.rawValue ?? "unknown")",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm somewhat uncomfortable with this. The unknown here is confusing. Would we be able to replace this with something like <<NULL>> or something that is explicitly bad and obviously so?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this throw in case it is null?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that having it throw would be a much safer option. We need to know the architecture to be able to build.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this by using archName which is non-optional

@@ -716,32 +716,32 @@ public final class UserToolchain: Toolchain {
// (~5.7), we always had a singular installed SDK. Prefer the
// new variant which has an architecture subdirectory in `bin`
// if available.
switch triple.arch {
case .x86_64, .x86_64h:
switch triple.archName {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we ensure that this is in lower case? I'm worried about the stringly matching here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switching on the string feels like a regression from a type safety pov. is it necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this back to switch on arch, the coverage of the included cases is increased as a result though.

@MaxDesiatov
Copy link
Contributor

MaxDesiatov commented May 30, 2023

Is there a reason we're not using Driver's Triple type directly instead of copying it here?

@rauhul
Copy link
Member Author

rauhul commented May 30, 2023

Is there a reason we're not using Driver's Triple type directly instead of copying it here?

That's a @neonichu question

@rauhul
Copy link
Member Author

rauhul commented May 30, 2023

@swift-ci please smoke test

@MaxDesiatov
Copy link
Contributor

MaxDesiatov commented May 30, 2023

I've previously copied this Triple implementation from TSC since we wanted to deprecate the TSC version, but it seems like the duplication in both TSC and Driver is historic. As SwiftPM already uses Driver as a dependency, I don't see why we can't use Driver's Triple type directly and just remove one in SwiftPM if one from Driver does everything we need.

@neonichu
Copy link
Contributor

We don't want to introduce a dependency on Driver in the "data model" portion of SwiftPM since that will cause issues for the Xcode integration.

@MaxDesiatov
Copy link
Contributor

@swift-ci test windows

@rauhul
Copy link
Member Author

rauhul commented May 30, 2023

@swift-ci please smoke test

@rauhul
Copy link
Member Author

rauhul commented May 30, 2023

@swift-ci please smoke test windows

$0.platform == triple.os.asXCFrameworkPlatformString &&
$0.architectures.contains(triple.arch.rawValue)
$0.platform == triple.os?.asXCFrameworkPlatformString &&
$0.architectures.contains(triple.archName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can architectures be made more type safe instead of string array?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have absolutely no idea how this XCFramework code works and I'd like to avoid touching it if possible in this PR.

struct XCFrameworkMetadata.Library {
    let libraryIdentifier: String
    let libraryPath: String
    let headersPath: String?
    let platform: String
    let architectures: [String]
}

return nil
}
extension Triple {
public static let macOS = try! Self("x86_64-apple-macosx")
Copy link
Contributor

@tomerd tomerd Jun 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does Triple need a non-throwing constructer that takes a static string / ExpressibleByStringLiteral?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, but I want to avoid additional changes API changes in this PR. (The existing triple uses the above API shape)

candidates.append((name: "macos", value: .macOS))
return candidates.first(where: { string.hasPrefix($0.name) })?.value
extension Triple {
public init(_ description: String) throws {
Copy link
Contributor

@tomerd tomerd Jun 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where/how is this used? worried about the public extension

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this to match the current Basics.Triple API

import enum TSCBasic.JSON
import class TSCBasic.Process
import struct SwiftDriver.Triple
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should probably be renamed to Triple+Extension to match style of repo

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

Package.swift Outdated
@@ -152,6 +152,7 @@ let package = Package(
.product(name: "DequeModule", package: "swift-collections"),
.product(name: "OrderedCollections", package: "swift-collections"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
.product(name: "SwiftDriver", package: "swift-driver"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I dont love adding this to Basics. I think we are going that only for the extension which are a bit questionable imho. Maybe we can limit the dependency to the modules that actually use it and find a better home (closer to call site) for the extensions

@tomerd
Copy link
Contributor

tomerd commented Jun 12, 2023

@swift-ci test Windows

@tomerd tomerd enabled auto-merge (squash) June 12, 2023 21:51
@WowbaggersLiquidLunch
Copy link
Contributor

WowbaggersLiquidLunch commented Jun 13, 2023

Is there a reason we're not using Driver's Triple type directly instead of copying it here?

We don't want to introduce a dependency on Driver in the "data model" portion of SwiftPM since that will cause issues for the Xcode integration.

What if Triple is extracted into its own module?

@tomerd
Copy link
Contributor

tomerd commented Jun 13, 2023

I think creating a new library that has some of these very basic models (eg semantic version, triple) is called for. TSC was suppose to be that but became a grab bag of "stuff" that is impossible to version properly and as such lost utility, and will be deprecated. while we are working to deprecate TSC, this specific solution seems like an okay compromise

@neonichu
Copy link
Contributor

Yah, I would see this as a temporary compromise, but in the future we should have a library with shared types like this one between driver and SwiftPM.

Removes and replaces the custom LLVM Triple type from the Basics module
with the implementation from SwiftDrvier. This change allows spm to
understand all triples that swift-driver already does and resolves some
issues surrounding incorrect triple parsing. For example the
Basics.Triple was not able to parse 'armv7em-apple-none-eabihf-macho'
where as SwiftDriver.Triple can.
@tomerd
Copy link
Contributor

tomerd commented Jun 20, 2023

@rauhul is this ready to be merged?

@rauhul rauhul force-pushed the one-triple-to-rule-them-all branch from eb3a1f9 to 459d652 Compare June 20, 2023 19:57
@rauhul
Copy link
Member Author

rauhul commented Jun 20, 2023

@tomerd I just pushed fixes to address the review feedback, do you mind taking another look?

@rauhul rauhul disabled auto-merge June 20, 2023 20:00
@rauhul
Copy link
Member Author

rauhul commented Jun 20, 2023

Likely in a follow on PR Sources/Basics/Triple+Basics.swift should be slimmed down as much as possible, upstreaming necessary content to swift-driver

@rauhul
Copy link
Member Author

rauhul commented Jun 20, 2023

@swift-ci please smoke test

@rauhul
Copy link
Member Author

rauhul commented Jun 20, 2023

@swift-ci please test windows

@tomerd tomerd enabled auto-merge (squash) June 20, 2023 21:44
@rauhul
Copy link
Member Author

rauhul commented Jun 20, 2023

@swift-ci test Windows

@rauhul
Copy link
Member Author

rauhul commented Jun 21, 2023

@swift-ci test windows

@tomerd tomerd merged commit 4e6501b into main Jun 21, 2023
@tomerd tomerd deleted the one-triple-to-rule-them-all branch June 21, 2023 17:56
MaxDesiatov pushed a commit that referenced this pull request Jul 21, 2023
Cherry-pick of #6627

Removes and replaces the custom LLVM Triple type from the Basics module with the implementation from the Swift Driver. This change allows SwiftPM to understand all triples that the Swift Driver already does and resolves some issues surrounding incorrect triple parsing. For example the
Basics.Triple was not able to parse 'armv7em-apple-none-eabihf-macho' where as SwiftDriver.Triple can.

(cherry picked from commit 4e6501b)
```
# Conflicts:
#	Sources/Basics/CMakeLists.txt
#	Sources/Basics/Triple.swift
```
MaxDesiatov added a commit that referenced this pull request Jul 21, 2023
Cherry-pick of #6627

Removes and replaces the custom LLVM Triple type from the Basics module with the implementation from the Swift Driver. This change allows SwiftPM to understand all triples that the Swift Driver already does and resolves some issues surrounding incorrect triple parsing. For example the
Basics.Triple was not able to parse 'armv7em-apple-none-eabihf-macho' where as SwiftDriver.Triple can.

(cherry picked from commit 4e6501b)
```
# Conflicts:
#	Sources/Basics/CMakeLists.txt
#	Sources/Basics/Triple.swift
```

* Fix missing `import struct TSCBasic.AbsolutePath`

---------

Co-authored-by: Rauhul Varma <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants