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
Fix building on Linux #12
base: master
Are you sure you want to change the base?
Conversation
This was originally in here so that we didn't import the entirety of Foundation, but that's a little overkill of an optimization. Plus, this way we avoid conditional compilation, and that is preferable to a slightly smaller macOS executable.
As of this point in the PR, 1 and 2 are fixed, but I'm still not sure about Swifter |
For anyone wondering why I'm not just upgrading to the latest version of Swifter (and why we're pinned at 1.4.5), when I do use the latest version, both the directory browser and web server modes don't work |
Here's the patch file for the change necessary to version 1.4.5 of Swifter: diff --git a/Sources/Socket+File.swift b/Sources/Socket+File.swift
index 81f0c48..ff4b57f 100644
--- a/Sources/Socket+File.swift
+++ b/Sources/Socket+File.swift
@@ -19,15 +19,19 @@ import Foundation
}
var writeCounter = 0
while writeCounter < readResult {
- #if os(Linux)
- let writeResult = send(target, &buffer + writeCounter, readResult - writeCounter, Int32(MSG_NOSIGNAL))
- #else
- let writeResult = write(target, &buffer + writeCounter, readResult - writeCounter)
- #endif
+ let writeResult = buffer.withUnsafeBytes { (ptr) -> Int in
+ let start = ptr.baseAddress! + writeCounter
+ let len = readResult - writeCounter
+#if os(Linux)
+ return send(target, start, len, Int32(MSG_NOSIGNAL))
+#else
+ return write(target, start, len)
+#endif
+ }
guard writeResult > 0 else {
return Int32(writeResult)
}
- writeCounter = writeCounter + writeResult
+ writeCounter += writeResult
}
}
} As I said earlier, this is stolen from the latest version of Swifter. |
To get this building, you can run these commands: git clone https://github.com/Samasaur1/SimpleSwiftServer
cd SimpleSwiftServer
git checkout linux-compatibility
swift package edit Swifter
cd Packages/Swifter
git apply ../../swifter.patch
cd ../..
swift build (the |
ok well that works for some linux builds |
5.3, 5.4, and 5.5 build on both versions of Ubuntu |
Earlier today, I tried to build on a Linux machine (clang reports the target triple as
x86_64-unknown-linux-gnu
), and SimpleSwiftServer failed to build. I was able to track down all the bugs and get it building, and they are as follows:Foundation.NSFileManager
on Linux since there is no NSFileManager. Since we were only limiting this import to try to optimize the macOS build, I've removed it (I doubt it was having much of an impact and the simplicity of not having conditional compilation is a priority over any slight reduction in macOS binary size)Worth noting this build was with the following version of Swift: