Skip to content

Use the (versioned) triple from swiftc instead. #229

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 2 commits into from
Oct 18, 2021

Conversation

3405691582
Copy link
Member

Here, swiftc is invoked to get the textual unversioned triple from the
compiler. However, TSC wants to use this unversioned triple for the
target flag, which causes breakage on the compiler side on platforms
with versioned triples, because the compiler can't find the stdlib with
the unversioned triple.

Instead, default to getting versioned triples. When clients of TSC want
to do funky things with unversioned triples, we lop the version numbers
off versioned triples to get an unversioned triple. This is somewhat
crude, but the alternative is to get both versioned and unversioned
triples from swiftc, which is similarly awkward.

@neonichu
Copy link
Contributor

@swift-ci please test

@tomerd
Copy link
Contributor

tomerd commented Jun 22, 2021

Thanks for the PR, this may have been discussed elsewhere but I'd love to understand what potential impact this has on downstream code, such as SwiftPM.

Also, should we a dd a couple of tests for the new functionality?

Here, swiftc is invoked to get the textual unversioned triple from the
compiler. However, TSC wants to use this unversioned triple for the
target flag, which causes breakage on the compiler side on platforms
with versioned triples, because the compiler can't find the stdlib with
the unversioned triple.

Instead, default to getting versioned triples. When clients of TSC want
to do funky things with unversioned triples, we lop the version numbers
off versioned triples to get an unversioned triple. This is somewhat
crude, but the alternative is to get both versioned _and_ unversioned
triples from swiftc, which is similarly awkward.
@3405691582
Copy link
Member Author

SPM should be getting platform information through tripleString or tripleString(forPlatform:_), so these changes to SPM should be transparent.

We don't seem to be doing unit testing on Triple in TSC at the moment? I've added some brief tests instead.

@tomerd
Copy link
Contributor

tomerd commented Jun 24, 2021

@swift-ci please test

@tomerd
Copy link
Contributor

tomerd commented Jun 24, 2021

@abertelrud wdyt?

@tomerd
Copy link
Contributor

tomerd commented Jun 25, 2021

@swift-ci please test

@neonichu
Copy link
Contributor

@swift-ci please test

@3405691582
Copy link
Member Author

Not 100% sure yet while the mac OS test is failing. Looking into it. I don't have a mac OS system to poke at this, so happy to receive some advice here...

Also of note is swiftpm pr 3576 but I don't think that change would be of relevance to the test failure here...

@finagolfin
Copy link
Member

Yeah, you probably need to update the triples used in the SPM bootstrap script along with this pull, because it is failing because it cannot find the second build of swift-test:
/Users/buildnode/jenkins/workspace/pr-swift-tools-support-core-macos/branch-main/build/buildbot_incremental/swiftpm-macosx-x86_64/x86_64-apple-macosx/release/swift-test: No such file or directory

See earlier discussion about macOS triple requirements, one of the Apple devs will need to guide you through this.

@3405691582
Copy link
Member Author

This is why I'm confused, because the SPM bootstrap already uses the unversioned triple (and probably should always use the unversioned triple on mac OS). Maybe I'm missing something...

@finagolfin
Copy link
Member

finagolfin commented Jun 29, 2021

So here's the way it works:

  • The bootstrap script uses the unversioned triple from the compiler to create a directory where it places the CMake-built SPM.
  • The CMake-built SPM is used to build bootstrap SPM, which is placed in a directory that SPM decides based on some triple it figures out. This SPM triple has to match the triple from the first step, or downstream steps will fail.
  • The SPM-built swift-test is used to run the tests.

Note that that last step failed for both of us: I suspect you're having the inverse problem now. You could try sticking a debug line in the bootstrap script to dump the directory layout of the SPM build directory before the tests are run: that will tell you what's going wrong.

Stick the debug line in your bootstrap pull if you don't see that build path info already in the CI log, and have these two pulls tested together to figure this out.

@3405691582
Copy link
Member Author

Okay, I believe I've updated the right parts of swiftpm to ensure the subdirectory gets created with the correct name. This means swiftlang/swift-package-manager#3576 is required for a correct build on mac OS.

Can someone please rerun the tests picking that above PR?

@neonichu
Copy link
Contributor

@neonichu
Copy link
Contributor

Looks like there's a test that needs an update?

/Users/buildnode/jenkins/workspace/pr-swift-tools-support-core-macos/branch-main/swiftpm/Tests/CommandsTests/BuildToolTests.swift:79: error: -[CommandsTests.BuildToolTests testBinPathAndSymlink] : XCTAssertEqual failed: ("/private/var/folders/_8/79jmzf2142z2xydc_01btlx00000gn/T/ValidLayouts_SingleModule_ExecutableNew.Oni2JT/ValidLayouts_SingleModule_ExecutableNew/.build/x86_64-apple-macosx/debug
12:30:31 ") is not equal to ("/private/var/folders/_8/79jmzf2142z2xydc_01btlx00000gn/T/ValidLayouts_SingleModule_ExecutableNew.Oni2JT/ValidLayouts_SingleModule_ExecutableNew/.build/x86_64-apple-macosx11.0/debug

@finagolfin
Copy link
Member

Heh, you just wanted to add the version to the triple for OpenBSD and now you're stuck making a bunch of macOS changes, since it uses versioned triples too. 😃

@3405691582
Copy link
Member Author

Associated SPM pr is updated to address the failing tests. I think that should take care of everything in the failed mac OS build log; sorry for the multiple cycles here.

@neonichu
Copy link
Contributor

@finagolfin
Copy link
Member

More failing tests on macOS because of the versioned triple used in the SPM build directory.

@neonichu, wouldn't it make more sense to just start using versioned triples in SPM on macOS, what is the downside there?

@3405691582
Copy link
Member Author

3405691582 commented Jun 30, 2021

Oof, I should have just changed all instances of Resources.default.toolchain.triple.tripleString to Resources.default.toolchain.triple.platformBuildPathComponent(). I'll do that now.

The question as to mac OS is still worthwhile and I can't answer. I am specialcasing Darwin because I'm being cautious and from a cursory reading of the SPM code, I don't know for real whether that cautiousness is warranted or not.

@neonichu
Copy link
Contributor

Since you've always allowed setting the Darwin OS version in SPM, the only question is what is the advantage of using an unversioned triple for the name of the build directory, ie was that just an easy way to set it up or is there any utility to doing that?

IIRC, platform versions were added around Swift 4.2 or 5.0, so they didn't always exist.

I think we want to retain a shared build directory for all artifacts of a build operation, but since each package carries its own platform version with it, this would no longer be given if we added the version to the name of the build directory.

@finagolfin
Copy link
Member

I think we want to retain a shared build directory for all artifacts of a build operation, but since each package carries its own platform version with it, this would no longer be given if we added the version to the name of the build directory.

I don't know anything about the intricacies of how this already worked on macOS, but I would think having multiple versioned build directories would enable versioning more. For example, on Android, I could build the same Swift package with the aarch64-linux-android24 triple then with the aarch64-linux-android28 triple and it would place them in separate build directories after this pull, whereas right now they're placed in the same unversioned build directory, with the latter presumably overwriting the former.

I assume the situation is similar on macOS, though I haven't looked at that code as I don't use macOS.

@neonichu
Copy link
Contributor

@buttaface Sure, what I am saying is that if you have a package that targets e.g. macOS 11.0 which depends on another that targets macOS 10.0, today both end up in the same build directory (e.g. x86_64-apple-macosx), so a simple search path into that one directory lets us find Swift modules etc. If we add the version to the directory, we need search paths to both x86_64-apple-macosx11.0 and x86_64-apple-macosx10.0 when building the first package, otherwise it won't find its dependency (which is targeting a different version). This means we would have to keep track of this and also introduces a potential ambiguity because each directory could at least theoretically contain artifacts with the same names. That's why I am thinking it makes sense to retain a single build directory for all artifacts.

@finagolfin
Copy link
Member

OK, I am not familiar with how that works on Darwin, hence my questions so far. I'm fine with whatever you decide regarding the build directory, my main concern is with passing these versioned triples through when compiling.

@finagolfin
Copy link
Member

Ping, just needs a CI run and we can get this in?

@abertelrud
Copy link
Contributor

@swift-ci please test

@finagolfin
Copy link
Member

@abertelrud, I think this needs to be tested with the SPM pull, as seen above.

@neonichu
Copy link
Contributor

neonichu commented Sep 7, 2021

@3405691582
Copy link
Member Author

Squashed another minor error on the spm side. Please retry, thanks.

@neonichu
Copy link
Contributor

neonichu commented Sep 8, 2021

@finagolfin
Copy link
Member

Only a single sourcekit-lsp test failed on macOS on the last CI run, a flake?

@neonichu
Copy link
Contributor

swiftlang/swift-package-manager#3576
@swift-ci please test macOS

@finagolfin
Copy link
Member

The exact same test case failed again, SourceKitLSPTests.SwiftPMIntegrationTests, reporting an empty array rather the file positions it expects. I don't know how these pulls would affect that, so maybe the test is super-flaky?

@3405691582, what do you think?

@3405691582
Copy link
Member Author

3405691582 commented Sep 28, 2021

Yeah, I'll take a closer look and report back.

@3405691582
Copy link
Member Author

I haven't done a full trace through SourceKit, but my guess is that https://github.com/apple/sourcekit-lsp/blob/main/Sources/SKSwiftPMWorkspace/SwiftPMWorkspace.swift#L120 needs to be updated accordingly. I've opened pr swiftlang/sourcekit-lsp#430 on SourceKit-LSP to try and fix this.

I don't normally build SourceKit, so I can't immediately test this properly. I can do an integration test tomorrow on a Linux install, or it'd be nice to have a CI run that picks this PR as well to see if this fixes the broken test case.

@benlangmuir
Copy link
Contributor

@3405691582
Copy link
Member Author

Squashed another failure on the SPM side (probably something changed in the interim on the CI environment that tickled this gap in the change). Please retry, thank you!

@benlangmuir
Copy link
Contributor

@3405691582
Copy link
Member Author

Fixed the SourceKit tests, please retest, thank you!

Apologies for the extra noise on this.

@benlangmuir
Copy link
Contributor

swiftlang/swift-package-manager#3576
swiftlang/sourcekit-lsp#430
@swift-ci please test

@neonichu neonichu merged commit d0bca40 into swiftlang:main Oct 18, 2021
@finagolfin
Copy link
Member

Yay, one less flag I have to pass in when cross-compiling SPM or sourcekit-lsp for Android, specifically that linked line passes in -Xswiftc -Xclang-linker -Xswiftc -target=aarch64-linux-android24 to SPM so the Android linker knows to link against libc and other system libraries at Android API 24, rather than one of the dozen other supported API levels.

Now I can just add it to the target triple passed to SPM and it won't be ignored. 🎆

3405691582 added a commit to 3405691582/swift-driver that referenced this pull request Oct 29, 2022
Some platforms require the normal, versioned triple to be supplied for
the target flag, as Swift modules use this versioned triple as a
subdirectory. If the unversioned triple is used instead, the standard
library won't be found on these platforms.

Instead, use the unversioned triple only on Darwin. This also should be
a noop on Linux. This behavior matches swiftlang/swift-package-manager#3576
and swiftlang/swift-tools-support-core#229 which contain additional context.
3405691582 added a commit to 3405691582/swift-driver that referenced this pull request Oct 29, 2022
Some platforms require the normal, versioned triple to be supplied for
the target flag, as Swift modules use this versioned triple as a
subdirectory. If the unversioned triple is used instead, the standard
library won't be found on these platforms.

Instead, use the unversioned triple only on Darwin. This also should be
a noop on Linux. This behavior matches swiftlang/swift-package-manager#3576
and swiftlang/swift-tools-support-core#229 which contain additional context.
3405691582 added a commit to 3405691582/swift-driver that referenced this pull request Oct 29, 2022
Some platforms require the normal, versioned triple to be supplied for
the target flag, as Swift modules use this versioned triple as a
subdirectory. If the unversioned triple is used instead, the standard
library won't be found on these platforms.

Instead, use the unversioned triple only on Darwin. This also should be
a noop on Linux. This behavior matches swiftlang/swift-package-manager#3576
and swiftlang/swift-tools-support-core#229 which contain additional context.
3405691582 added a commit to 3405691582/swift-driver that referenced this pull request Oct 29, 2022
Some platforms require the normal, versioned triple to be supplied for
the target flag, as Swift modules use this versioned triple as a
subdirectory. If the unversioned triple is used instead, the standard
library won't be found on these platforms.

Instead, use the unversioned triple only on Darwin. This also should be
a noop on Linux. This behavior matches swiftlang/swift-package-manager#3576
and swiftlang/swift-tools-support-core#229 which contain additional context.
MaxDesiatov pushed a commit to swiftlang/swift-driver that referenced this pull request Jan 5, 2023
Some platforms require the normal, versioned triple to be supplied for
the target flag, as Swift modules use this versioned triple as a
subdirectory. If the unversioned triple is used instead, the standard
library won't be found on these platforms.

Instead, use the unversioned triple only on Darwin. This also should be
a noop on Linux. This behavior matches swiftlang/swift-package-manager#3576
and swiftlang/swift-tools-support-core#229 which contain additional context.
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