vapor / toolbox

Simplifies common command line tasks when using Vapor
MIT License
283 stars 85 forks source link

[18.7.4] Code does not compile using make. #430

Closed aravasio closed 7 months ago

aravasio commented 7 months ago

Describe the bug

When cloning toolbox, and running make install, I get the following error:

Building for production...
~/src/toolbox/.build/checkouts/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)
                                                               ^
~/src/toolbox/.build/checkouts/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#> }
~/src/toolbox/.build/checkouts/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#>
~/src/toolbox/.build/checkouts/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)
                        ^
                                             !
~/src/toolbox/.build/checkouts/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#>
~/src/toolbox/.build/checkouts/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
[12/22] Compiling c-atomics.c
Swift/ErrorType.swift:200: Fatal error: Error raised at top level: build.ShellError(terminationStatus: 1)
Current stack trace:
0    libswiftCore.so                    0x00007fa53dc986d0 _swift_stdlib_reportFatalErrorInFile + 109
1    libswiftCore.so                    0x00007fa53d964d85 <unavailable> + 1461637
2    libswiftCore.so                    0x00007fa53d964ba7 <unavailable> + 1461159
3    libswiftCore.so                    0x00007fa53d963b10 _assertionFailure(_:_:file:line:flags:) + 342
4    libswiftCore.so                    0x00007fa53d9cac5c <unavailable> + 1879132
5    build                              0x00005611330b8177 <unavailable> + 8567
6    libc.so.6                          0x00007fa53c827cd0 <unavailable> + 163024
7    libc.so.6                          0x00007fa53c827d00 __libc_start_main + 138
8    build                              0x00005611330b7e65 <unavailable> + 7781

💣 Program crashed: Illegal instruction at 0x00007fa53d963c72

Thread 0 "build" crashed:

0 0x00007fa53d963c72 _assertionFailure(_:_:file:line:flags:) + 354 in libswiftCore.so
1 0x00007fa53d9cac5c swift_errorInMain + 619 in libswiftCore.so
2 0x00005611330b8177 main + 54 in build

As one would expect from the reported error, if you go to the Logging.swift file, line 1392 (timestamp() function), and add an if let clause, you can build normally.

if let localTime {
    strftime(&buffer, buffer.count, "%Y-%m-%dT%H:%M:%S%z", localTime)
}

To Reproduce

Simply follow the steps from the Vapor guide on linux. The last part is cloning toolbox and running make install. There. That's where it fails.

Expected behavior

Toolbox builds and one is able to use cli commands such as vapor -h.

Environment

Note; I wasn't too specific in my computer specs since I consider this issue to be very straight forward in itself.

However, if needed, I can still provide them. just let me know.

gwynne commented 7 months ago

At this time, the recommended way to build the toolbox is the same way the CI does, by just executing swift build -c release.

That being said, the problem is that Arch Linux is not currently supported as a host platform by Swift itself. This is not an issue with Vapor. As far as Linux goes, Swift currently officially supports Ubuntu (18.04 Bionic, 20.04 Focal, and 22.04 Jammy), CentOS 7, Amazon Linux 2, and RedHat UBI 9 (see https://www.swift.org/platform-support/ and https://www.swift.org/download/ for more details). Arch Linux, being a BSD-based distribution, is nominally supported by the compiler itself, but there are clearly issues in various packages, in this case swift-log. (This being said, I'll see if I can't get that particular failure fixed upstream, since there's no reason not to.)

gwynne commented 7 months ago

For the record, the following patch fixes the swift-log build on Arch Linux (tested on Arch Linux 20231112.0.191179 (Docker tag archlinux:latest) using the swift-bin AUR package version 5.9.1-2):

diff --git a/Sources/Logging/Logging.swift b/Sources/Logging/Logging.swift
index 5910e73..23ef1ab 100644
--- a/Sources/Logging/Logging.swift
+++ b/Sources/Logging/Logging.swift
@@ -1388,7 +1388,9 @@ public struct StreamLogHandler: LogHandler {
         _ = strftime(&buffer, buffer.count, "%Y-%m-%dT%H:%M:%S%z", &localTime)
         #else
         var timestamp = time(nil)
-        let localTime = localtime(&timestamp)
+        guard let localTime = localtime(&timestamp) else {
+            return "<unknown>"
+        }
         strftime(&buffer, buffer.count, "%Y-%m-%dT%H:%M:%S%z", localTime)
         #endif
         return buffer.withUnsafeBufferPointer {

I have opened a PR against the upstream swift-log repository with this fix, since it also fixes a potential NULL pointer dereference.