Skip to content
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

Fail to build (link) executable using generated swift-sdk #7222

Open
krzyzanowskim opened this issue Jan 3, 2024 · 11 comments
Open

Fail to build (link) executable using generated swift-sdk #7222

krzyzanowskim opened this issue Jan 3, 2024 · 11 comments

Comments

@krzyzanowskim
Copy link
Contributor

Description

Building executable with sdk generated with https://github.com/apple/swift-sdk-generator fail on unable to find linker error message

Expected behavior

build

Actual behavior

fatal error

Steps to reproduce

git clone https://github.com/apple/swift-sdk-generator.git
cd swift-sdk-generator
swift run swift-sdk-generator
swift experimental-sdk install Bundles/5.9.2-RELEASE_ubuntu_jammy_aarch64.artifactbundle

mkdir hello-world
cd hello-world
swift-package init --type=executable

swift build --experimental-swift-sdk 5.9.2-RELEASE_ubuntu_jammy_aarch64

error unable to find library. the file at the path exists

ld.lld: error: unable to find library -ld-path=/Users/marcinkrzyzanowski/Library/org.swift.swiftpm/swift-sdks/5.9.2-RELEASE_ubuntu_jammy_aarch64.artifactbundle/5.9.2-RELEASE_ubuntu_jammy_aarch64/aarch64-unknown-linux-gnu/swift.xctoolchain/usr/bin/ld.lld
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
error: fatalError

Swift Package Manager version/commit hash

3ce3894

Swift & OS version (output of swift --version ; uname -a)

swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: arm64-apple-macosx14.0

@MaxDesiatov
Copy link
Contributor

-ld-path became available only in Swift 5.10, I wonder if the issue is reproducible with that version?

@krzyzanowskim
Copy link
Contributor Author

do you mind giving me a hint on the swift-sdk-generator that is going to produce usable 5.10 to test it on my side?

@MaxDesiatov
Copy link
Contributor

MaxDesiatov commented Jan 3, 2024

This will generate one with the latest 5.11 snapshot.

swift run swift-sdk-generator --swift-version DEVELOPMENT-SNAPSHOT-2023-12-21-a --swift-branch development

Let me check the right invocation for 5.10 in a moment...

@MaxDesiatov
Copy link
Contributor

Here's one for 5.10:

swift-sdk-generator --swift-version 5.10-DEVELOPMENT-SNAPSHOT-2023-12-21-a --swift-branch swift-5.10-branch

@krzyzanowskim
Copy link
Contributor Author

Thank you. I confirm that it is not an issue with Swift 5.10 and up.

@MaxDesiatov
Copy link
Contributor

MaxDesiatov commented Jan 3, 2024

I'll reopen this for now, since apparently we don't check for -ld-path availability cleanly to provide a nice diagnostic message.

@krzyzanowskim
Copy link
Contributor Author

fair enough. do you think it can be "backported" or just diagnostic and build going to fail?

@MaxDesiatov
Copy link
Contributor

No backporting is possible, since release/5.9 is no longer taking patches IIUC. IMO we should warn that the linker property in toolsets is not supported in 5.9 toolchains and redirect users to pass -use-ld= flag to Swift Driver instead as a workaround.

@krzyzanowskim
Copy link
Contributor Author

I've meant automatic backport that going to use either -ld-path or -use-ld depends which one suppose to work with the toolchain

@MaxDesiatov
Copy link
Contributor

I'm not sure there's a portable way to use -use-ld, that's why -ld-path was introduced in the first place: #6719 (comment)

Maybe @kabiroberai can clarify the context as the original author of that PR.

@kabiroberai
Copy link
Contributor

This comment on the original PR has some relevant context: #6719 (comment)

Passing a path to -use-ld might work in some cases but I don't think it's portable; another solution could be to set -Xclang-linker --ld-path=... in the SDK's linker settings. This isn't recommended long term since Xclang-linker is an impl detail (that's why I made the PR to introduce -ld-path to swiftc), but if it's just for 5.9 it should be okay.

@MaxDesiatov MaxDesiatov removed their assignment Sep 18, 2024
euanh added a commit to euanh/swift-sdk-generator that referenced this issue Nov 18, 2024
Swift Package Manager's linker flag handling changed between
5.9 and 5.10.   The flags which work for 5.9 cause linking failures
5.10 and later, and vice versa:

  swiftlang/swift-package-manager#7222

This commit generates workaround flags for 5.9 and new-style flags
for all other versions.

The EndToEnd tests currently cannot run in CI, so this change was
tested locally. (Issue swiftlang#145)

* The basic 'hello world' example generated by `swift package init`
  built succesfully with 5.9.2, 5.10.1 and 6.0.2 SDKs on x86_64 and aarch64.
* A more complex example using Vapor built succesfully with 5.9.2, 5.10.1.  6.0.2
  failed because of the CShims problem reported in Issue swiftlang#138.
euanh added a commit to euanh/swift-sdk-generator that referenced this issue Nov 18, 2024
Swift Package Manager's linker flag handling changed between
5.9 and 5.10.   The flags which work for 5.9 cause linking failures
5.10 and later, and vice versa:

  swiftlang/swift-package-manager#7222

This commit generates workaround flags for 5.9 and new-style flags
for all other versions.

The EndToEnd tests currently cannot run in CI, so this change was
tested locally. (Issue swiftlang#145)

* The basic 'hello world' example generated by `swift package init`
  built successfully with 5.9.2, 5.10.1 and 6.0.2 SDKs on x86_64 and aarch64.
* A more complex example using Vapor built succesfully with 5.9.2, 5.10.1.  6.0.2
  failed because of the CShims problem reported in Issue swiftlang#138.
euanh added a commit to swiftlang/swift-sdk-generator that referenced this issue Nov 18, 2024
Swift Package Manager's linker flag handling changed between 5.9 and 5.10.   The flags which work for 5.9 cause linking failures 5.10 and later, and vice versa:

  swiftlang/swift-package-manager#7222

This commit generates workaround flags for 5.9 and new-style flags for all other versions.

The EndToEnd tests currently cannot run in CI, so this change was tested locally. (Issue #145)

* The basic 'hello world' example generated by `swift package init` built successfully with 5.9.2, 5.10.1 and 6.0.2 SDKs on x86_64 and aarch64.
* A more complex example using Vapor built succesfully with 5.9.2, 5.10.1.  6.0.2 failed because of the CShims problem reported in Issue #138.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants