Skip to content

Linux compilation error for main on swift:latest Docker image #356

@dagronf

Description

@dagronf

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# 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions