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

SwiftPM requires librarian to be installed before it can build anything #5761

Closed
finagolfin opened this issue Sep 8, 2022 · 5 comments · Fixed by #6829
Closed

SwiftPM requires librarian to be installed before it can build anything #5761

finagolfin opened this issue Sep 8, 2022 · 5 comments · Fixed by #6829
Labels

Comments

@finagolfin
Copy link
Contributor

finagolfin commented Sep 8, 2022

Description

This was introduced by #5720, which moved detecting the archiver executable from inside of llbuild to SPM. This has always been kind of a mess with SPM, with llbuild always grabbing whatever archiver was in the path. This didn't crop up much unless you were building the rare Swift package that had a static library and happened not to have a binutils package installed in your system.

However, trunk SPM now won't build anything without an archiver included in the Swift toolchain or system path, which is too strict. This is particularly an issue because the Swift toolchain doesn't ship with an archiver: I just checked when debugging this issue and was surprised to find that the official builds don't include llvm-ar.

The Swift compiler itself is much better on this issue, as you can supply an alternate -tools-directory flag where it should look for an archiver, as done for Android. I just ran a variant of that compiler command and confirmed it uses the NDK llvm-ar:

> ./swift-5.6.3-RELEASE-ubuntu20.04/usr/bin/swiftc -tools-directory /home/butta/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin
-target aarch64-unknown-linux-android24 -sdk android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/sysroot
-resource-dir swift-5.6.3-android-aarch64-24-sdk/usr/lib/swift swift/test/Interpreter/Inputs/lto/module1.swift
-emit-library -static -v
...
/home/butta/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar crs libmodule1.a /tmp/TemporaryDirectory.yREHfG/module1-1.o

However, I see no flag to do the same with SPM, whereas I could always pass the -tools-directory I want to SPM with the extra swiftc flags before. With SPM itself checking for an archiver now, it errors before that compiler flag is ever used. I worked around this issue on my Android CI by adding the NDK llvm-ar to my system path.

There are various ways to fix this: my preference would be to start shipping llvm-ar with the Swift toolchain and make that the default archiver we use.

Expected behavior

Don't require ar or llvm-ar to be installed before building any Swift package, particularly since most won't use it.

Actual behavior

error: toolchain is invalid: could not find llvm-ar

Steps to reproduce

  1. Make sure binutils is not installed.
  2. Try to build any Swift package.

I realize that binutils is listed as a dependency of the Swift toolchain on linux, but when cross-compiling for other platforms and supplying your own archiver, as I'm doing for Android, it shouldn't be required that a system archiver be installed.

Swift Package Manager version/commit hash

Tested with the September 5 trunk snapshot

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

September 5 trunk snapshot running on Ubuntu 20.04 x86_64

@finagolfin finagolfin added the bug label Sep 8, 2022
@tomerd
Copy link
Contributor

tomerd commented Sep 8, 2022

cc @compnerd @abertelrud

@tomerd
Copy link
Contributor

tomerd commented Sep 8, 2022

we can roll back #5720 if necessary, but I'd like to see what @compnerd thinks as he wanted this change to fix things on Windows.

@finagolfin
Copy link
Contributor Author

This is a bit of a corner case, so no need to revert #5720. We should put some thought into how we handle this though, and do something to at least soften this new requirement before the 5.8 branch.

@compnerd
Copy link
Member

compnerd commented Sep 8, 2022

We already have the dependency on ar for things like swift-syntax which is now being built as part of the toolchain itself. I think that adjusting the path is reasonable, though an alternative approach would be to set the AR environment variable. Packaging llvm-ar is completely reasonable and something that we should do though.

finagolfin added a commit to finagolfin/swift that referenced this issue Dec 11, 2022
A recent SPM change made it mandatory for there to be an archiver in the
toolchain/PATH, swiftlang/swift-package-manager#5761, so make sure llvm-ar is
bundled in the toolchain.
finagolfin added a commit to finagolfin/swift that referenced this issue Dec 13, 2022
A recent SPM change made it mandatory for there to be an archiver in the
toolchain/PATH, swiftlang/swift-package-manager#5761, so make sure llvm-ar is
bundled in the toolchain.
finagolfin added a commit to finagolfin/swift that referenced this issue Dec 15, 2022
A recent SPM change made it mandatory for there to be an archiver in the
toolchain/PATH, swiftlang/swift-package-manager#5761, so make sure llvm-ar is
bundled in the toolchain.
@finagolfin
Copy link
Contributor Author

Starting with the latest Dec. 19 trunk snapshot tag, the Swift toolchain now bundles in llvm-ar, which fixes my original Android problem.

However, I'd like to use this bundled llvm-ar for all Unix platforms from now on, not just for Android, by changing the default archiver the Swift compiler looks for, which I tried to do initially in swiftlang/swift#62510 but which will require installing llvm-ar also in the linux CI (the corelibs aren't built with the forked LLVM tools, so it's easier to just install another llvm-ar in the host, which is actually how the current corelibs build works).

I'll get on that next month once the CI opens up again, leaving this issue open till then.

finagolfin added a commit to finagolfin/swift that referenced this issue Jan 1, 2023
…ld directory

Now that llvm-ar is installed by default in the toolchain, swiftlang#62510, and a recent
SPM change requires there to be an archiver in the toolchain/PATH,
swiftlang/swift-package-manager#5761, use that bundled llvm-ar for all Unix
platforms, which requires copying it over into the build directory too before
building the corelibs.
ando-huang pushed a commit to ando-huang/swift that referenced this issue Jan 2, 2023
A recent SPM change made it mandatory for there to be an archiver in the
toolchain/PATH, swiftlang/swift-package-manager#5761, so make sure llvm-ar is
bundled in the toolchain.
finagolfin added a commit to finagolfin/swift that referenced this issue Jan 3, 2023
…ld directory

Now that llvm-ar is installed by default in the toolchain, swiftlang#62510, and a recent
SPM change requires there to be an archiver in the toolchain/PATH,
swiftlang/swift-package-manager#5761, use that bundled llvm-ar for all Unix
platforms, which requires copying it over into the build directory too before
building the corelibs.
tbkka pushed a commit to tbkka/swift that referenced this issue Jan 6, 2023
A recent SPM change made it mandatory for there to be an archiver in the
toolchain/PATH, swiftlang/swift-package-manager#5761, so make sure llvm-ar is
bundled in the toolchain.
@MaxDesiatov MaxDesiatov changed the title SPM now requires a librarian archiver to be installed in the system before it can build anything SwiftPM requires librarian to be installed before it can build anything Mar 26, 2023
finagolfin added a commit to finagolfin/swift-package-manager that referenced this issue Aug 18, 2023
finagolfin added a commit to finagolfin/swift-package-manager that referenced this issue Aug 18, 2023
finagolfin added a commit to finagolfin/swift-package-manager that referenced this issue Aug 18, 2023
finagolfin added a commit to finagolfin/swift-package-manager that referenced this issue Aug 25, 2023
finagolfin added a commit to finagolfin/swift that referenced this issue Jan 9, 2024
…ld directory

Now that llvm-ar is installed by default in the toolchain, swiftlang#62510, and a recent
SPM change requires there to be an archiver in the toolchain/PATH,
swiftlang/swift-package-manager#5761, use that bundled llvm-ar for all Unix
platforms, which requires copying it over into the build directory too before
building the corelibs.
finagolfin added a commit to finagolfin/swift-driver that referenced this issue Jan 9, 2024
Now that llvm-ar is installed by default in the toolchain, swiftlang/swift#62510,
and a recent SPM change requires there to be an archiver in the toolchain/PATH,
swiftlang/swift-package-manager#5761, use that bundled llvm-ar for all Unix
platforms.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants