Linux compilation error for main on `swift:latest` Docker image
Summary
I have a Linux-based project which I'm trying to add Zip support. When I add ZipFoundation as a dependency, the build fails with a compiler error. I'm using the swift:latest docker image on Ubuntu 24.04.
However, if I change to using the swift:5.8.1 docker image, the ZipFoundation library compiles successfully.
swift:latest version information
root@411ecbcc19f9:/src# swift --version
Swift version 6.0.3 (swift-6.0.3-RELEASE)
Target: x86_64-unknown-linux-gnu
root@dc032e84b02f:/src# cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.1 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
When I add the ZIPFoundation package and try to compile, I receive a compiler error message.
root@411ecbcc19f9:/src# swift build
warning: 'zipfoundation': found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target
/src/.build/checkouts/ZIPFoundation/Sources/ZIPFoundation/Resources/PrivacyInfo.xcprivacy
Building for debugging...
/src/.build/checkouts/ZIPFoundation/Sources/ZIPFoundation/Archive+MemoryFile.swift:45:20: error: value of optional type 'UnsafeMutablePointer<FILE>?' (aka 'Optional<UnsafeMutablePointer<_IO_FILE>>') must be unwrapped to a value of type 'UnsafeMutablePointer<FILE>' (aka 'UnsafeMutablePointer<_IO_FILE>')
43 | #endif
44 | if append {
45 | fseeko(result, 0, SEEK_END)
| |- error: value of optional type 'UnsafeMutablePointer<FILE>?' (aka 'Optional<UnsafeMutablePointer<_IO_FILE>>') must be unwrapped to a value of type 'UnsafeMutablePointer<FILE>' (aka 'UnsafeMutablePointer<_IO_FILE>')
| |- note: coalesce using '??' to provide a default when the optional value contains 'nil'
| `- note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
46 | }
47 | return result
[16/20] Compiling ZIPFoundation Entry.swift
root@411ecbcc19f9:/src#
It would appear that the issue has been introduced with newer Swift versions.
Steps to Reproduce
I've attached a basic Swift package which shows the error on Linux.
zipfoundation-linux-compile-error.zip
Expected Results
Library compiles successfully
Actual Results
Library compilation fails with an error.
[d@192-168-1-100:~/Projects/Bug Reports/zipfoundation-linux-compile-error]
% docker run --rm --privileged --interactive --tty --volume "$(pwd):/src" --workdir "/src" swift:latest 1 ↵
root@0d192304debf:/src# rm -rf .build/
root@0d192304debf:/src# swift build
Fetching https://github.com/weichsel/ZIPFoundation
Fetched https://github.com/weichsel/ZIPFoundation from cache (1.40s)
Creating working copy for https://github.com/weichsel/ZIPFoundation
Working copy of https://github.com/weichsel/ZIPFoundation resolved at main (02b6abe)
warning: 'zipfoundation': found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target
/src/.build/checkouts/ZIPFoundation/Sources/ZIPFoundation/Resources/PrivacyInfo.xcprivacy
Building for debugging...
/src/.build/checkouts/ZIPFoundation/Sources/ZIPFoundation/Archive+MemoryFile.swift:45:20: error: value of optional type 'UnsafeMutablePointer<FILE>?' (aka 'Optional<UnsafeMutablePointer<_IO_FILE>>') must be unwrapped to a value of type 'UnsafeMutablePointer<FILE>' (aka 'UnsafeMutablePointer<_IO_FILE>')
43 | #endif
44 | if append {
45 | fseeko(result, 0, SEEK_END)
| |- error: value of optional type 'UnsafeMutablePointer<FILE>?' (aka 'Optional<UnsafeMutablePointer<_IO_FILE>>') must be unwrapped to a value of type 'UnsafeMutablePointer<FILE>' (aka 'UnsafeMutablePointer<_IO_FILE>')
| |- note: coalesce using '??' to provide a default when the optional value contains 'nil'
| `- note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
46 | }
47 | return result
/src/.build/checkouts/ZIPFoundation/Sources/ZIPFoundation/Archive+MemoryFile.swift:45:20: error: value of optional type 'UnsafeMutablePointer<FILE>?' (aka 'Optional<UnsafeMutablePointer<_IO_FILE>>') must be unwrapped to a value of type 'UnsafeMutablePointer<FILE>' (aka 'UnsafeMutablePointer<_IO_FILE>')
43 | #endif
44 | if append {
45 | fseeko(result, 0, SEEK_END)
| |- error: value of optional type 'UnsafeMutablePointer<FILE>?' (aka 'Optional<UnsafeMutablePointer<_IO_FILE>>') must be unwrapped to a value of type 'UnsafeMutablePointer<FILE>' (aka 'UnsafeMutablePointer<_IO_FILE>')
| |- note: coalesce using '??' to provide a default when the optional value contains 'nil'
| `- note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
46 | }
47 | return result
[25/29] Compiling ZIPFoundation Entry+Serialization.swift
root@0d192304debf:/src#
At least with Swift 6.x, I've found that the compilation is successful with Ubuntu 22.04 (jammy) but not with Ubuntu 24.04 (noble).
probably a Glibc update that changes the bindings
This can be fixed for both Jammy and Noble with a change to Archive+MemoryFile.swift as linked in the PR above.
Issue on Fedora as well.
Is the issue resolved in the development branch? I have a downstream library depending on ZIPFoundation and would love to ensure the Linux build is working.
@dagronf Thanks for the report - The issue is fixed on development. I'll tag a release shortly.