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

Fails to compile on Fedora 39 with Swift 5.8.1 (From repos) or official 5.9 binaries #278

Open
JCWasmx86 opened this issue Sep 22, 2023 · 8 comments

Comments

@JCWasmx86
Copy link

JCWasmx86 commented Sep 22, 2023

Expected behavior

It compiles on Arch Linux and Fedora 39 (Works on Fedora 38)

Actual behavior

Does not compile on Arch Linux/Fedora 39 (The following part of the issue assumes Fedora 39)

Steps to reproduce

  1. Create fedora 39 VM/container
  2. Install swift using dnf or use the official binaries from swift.org
  3. Try to compile swift-log (From master or the latest release)

If possible, minimal yet complete reproducer code (or URL to code)

git clone https://github.com/apple/swift-log
cd swift-log
swift build
# Or
wget https://download.swift.org/swift-5.9-release/ubuntu2204/swift-5.9-RELEASE/swift-5.9-RELEASE-ubuntu22.04.tar.gz
tar xvf swift-5.9-RELEASE-ubuntu22.04.tar.gz
./swift-5.9-RELEASE-ubuntu22.04/usr/bin/swift build
/swift-log/Sources/Logging/Logging.swift:1392:64: error: value of optional type 'UnsafeMutablePointer<tm>?' must be unwrapped to a value of type 'UnsafeMutablePointer<tm>'
        strftime(&buffer, buffer.count, "%Y-%m-%dT%H:%M:%S%z", localTime)
                                                               ^
/swift-log/Sources/Logging/Logging.swift:1391:13: note: short-circuit using 'guard' to exit this function early if the optional value contains 'nil'
        let localTime = localtime(&timestamp)
            ^
        guard                                 else { return <#default value#> }
/swift-log/Sources/Logging/Logging.swift:1391:25: note: coalesce using '??' to provide a default when the optional value contains 'nil'
        let localTime = localtime(&timestamp)
                        ^
                                              ?? <#default value#>
/swift-log/Sources/Logging/Logging.swift:1391:25: note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
        let localTime = localtime(&timestamp)
                        ^
                                             !
/swift-log/Sources/Logging/Logging.swift:1392:64: note: coalesce using '??' to provide a default when the optional value contains 'nil'
        strftime(&buffer, buffer.count, "%Y-%m-%dT%H:%M:%S%z", localTime)
                                                               ^
                                                                         ?? <#default value#>
/swift-log/Sources/Logging/Logging.swift:1392:64: note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
        strftime(&buffer, buffer.count, "%Y-%m-%dT%H:%M:%S%z", localTime)
                                                               ^
                                                                        !
error: fatalError

SwiftLog version/commit hash

cb28750 and 1.5.3

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

Swift version 5.8.1 (swift-5.8.1-RELEASE)
Target: x86_64-unknown-linux-gnu
Linux 6d64617a9d4e 6.4.15-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Sep  7 00:25:01 UTC 2023 x86_64 GNU/Linux

and

Swift version 5.9 (swift-5.9-RELEASE)
Target: x86_64-unknown-linux-gnu
Linux 6d64617a9d4e 6.4.15-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Sep  7 00:25:01 UTC 2023 x86_64 GNU/Linux

I was able to fix this with the help of helje5 by doing this hack: JCWasmx86@332ed31

@1Jo1
Copy link

1Jo1 commented Oct 2, 2023

I have the exact same issue on Arch Linux, maybe its a glibc related issue
@JCWasmx86 thanks for this nice simple hack :)

glibc 2.38-5
Swift version 5.9 (swift-5.9-RELEASE)
Target: x86_64-unknown-linux-gnu`Swift version 5.9 (swift-5.9-RELEASE)
Target: x86_64-unknown-linux-gnu
6.5.5

@a40yostudent
Copy link

Looking at the same function called in the line 1392:

  • on macOS Sonoma:
    `strftime(::::)

func strftime(
_: UnsafeMutablePointer!,
_: Int,
_: UnsafePointer!,
_: UnsafePointer!
) -> Int`

  • on Ubuntu 23.10, using swift 5.9:
    `strftime(::::)

func strftime(_ __s: UnsafeMutablePointer, _ __maxsize: Int, _ __format: UnsafePointer, _ __tp: UnsafePointer) -> Int`

Looks like it is safe to just force unwrap localtime like this on line failing:
strftime(&buffer, buffer.count, "%Y-%m-%dT%H:%M:%S%z", localTime!)

It worked on my computer™

@JCWasmx86
Copy link
Author

JCWasmx86 commented Oct 13, 2023

But that would break code on Fedora 38 for example. Not sure what the best approach would be, as dropping somewhat recent OS versions like Fedora 38 is probably a bit too fast.

@a40yostudent
Copy link

Of course, I meant it's safe if you're on the OS experiencing this issue. I also wonder if the hack has been already tested on older versions.

@consuelita
Copy link

Also seeing this behavior on Ubuntu 23.10, Swift 5.9.1

@trufanov-nok
Copy link

Same problem Kubuntu 23.10, Swift 5.8.1/5.9.1

@lhoward
Copy link

lhoward commented Jan 16, 2024

Looks like this was fixed in f447991, but a new release would be handy.

@BradEwing
Copy link

Still a problem.

OS: Ubuntu 24.04
Swift: 6.0.1

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

No branches or pull requests

7 participants