Great to read that! I also hope for FreeBSD to be on the list if supported OS.
The OpenBSD port has been done!
What’s the best things to do to port Swift to FreeBSD 13.1 ? And how much!?
What’s the best things to do to port Swift to FreeBSD 13.1 ? And how much!?
I would encourage you or anyone else interested to look at the pulls making up @3405691582's OpenBSD port over the last couple years, which give you an idea of the work involved, as I noted on another FreeBSD thread late last year. FreeBSD may be less work, as I already see some support merged.
Anything new here?
This is a good sign.
Maybe not. They list lots of other platforms, but not FreeBSD.
Has anybody gotten swift on FreeBSD to work ? I've tried the excellent instructions on swift/FreeBSD.md at freebsd-docs · mhjacobson/swift · GitHub inside a FreeBSD 13.2 jail (applying the module patch on the basejail) and gotten to the point during the build where ninja starts to compile swift code.
Now I get a segmentation fault in
4. While evaluating request ASTLoweringRequest(Lowering AST to SIL for module Swift)
5. While silgen emitFunction SIL function "@$ss3minyxx_xxxdtSLRzlF".
for 'min(_:_:_:_:)' (at /root/swift/swift/stdlib/public/core/Algorithm.swift:38:8)
But I have no idea how to debug ninja. I've loaded the core in lldb but there is not really anything there
[root@swift ~/swift/build]# lldb -c ./tools/swift/stdlib/public/core/swift-frontend.core
(lldb) target create --core "./tools/swift/stdlib/public/core/swift-frontend.core"
Core file '/root/swift/build/tools/swift/stdlib/public/core/swift-frontend.core' (x86_64) was loaded.
(lldb) bt all
* thread #1, name = 'swift-frontend', stop reason = signal SIGSEGV
* frame #0: 0x0000000001a64933
frame #1: 0x000000087cc8e300
(lldb)
Any idea how to get it running ? I've tried contacting the author of the FreeBSD build instructions, but got no answer. That's why I'm shouting out here for help.
I think once the Swift 5.9 and new swift based Foundation library become stable, we can re investigate this problem.
What version of Swift are you building? What is the failing command? I assume this is FreeBSD amd64.
I've seen a similar error when bootstrapping on linux x86_64: try turning the bootstrap off, -DBOOTSTRAPPING_MODE:STRING=OFF
.
Thanx for the hint - as said I'm using the configure script from mhjacobson/swift , which has
-DBOOTSTRAPPING_MODE=BOOTSTRAPPING
enabled.
I did disable it and ..... it compiled fine!!!
I just ran my first 'hello world' on freebsd:
[root@swift ~/swift/build/bin]# ./swift helloworld.swift
hello world
[root@swift ~/swift/build/bin]#
swiftc to compile it also worked and I only had to set the correct library path to get it working!
So in essence:
To get swift compile on FreeBSD follow the instructions on:
change bootstrapping mode in configure.sh to off:
-DBOOTSTRAPPING_MODE=OFF \
and everything compiles
What version of Swift did you build?
I tried to build with release/5.8
branches following the instructions, but I got the following errors:
$ ninja
...
[4304/4413] Compiling /home/kebo/swift/build/tools/swift/stdlib/public/Platform//FREEBSD/x86_64/Glibc.o
FAILED: tools/swift/stdlib/public/Platform/FREEBSD/x86_64/Glibc.o /home/kebo/swift/build/tools/swift/stdlib/public/Platform/FREEBSD/x86_64/Glibc.o
cd /home/kebo/swift/build/tools/swift/stdlib/public/Platform && /usr/local/bin/python3 /usr/home/kebo/swift/swift/utils/line-directive @/home/kebo/swift/build/tools/swift/stdlib/public/Platform/8d867dd6b1ec09232628ee2ec417609030768a85.txt -- /home/kebo/swift/build/./bin/swiftc -c -sdk / -target x86_64-unknown-freebsd13.2 -resource-dir /home/kebo/swift/build/./lib/swift -O -D SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING -D SWIFT_RUNTIME_OS_VERSIONING -D SWIFT_STDLIB_ENABLE_UNICODE_DATA -D SWIFT_STDLIB_ENABLE_VECTOR_TYPES -D SWIFT_STDLIB_HAS_COMMANDLINE -D SWIFT_STDLIB_HAS_STDIN -D SWIFT_STDLIB_HAS_ENVIRON -Xcc -DSWIFT_STDLIB_HAS_ENVIRON -D SWIFT_THREADING_PTHREADS -tools-directory /home/kebo/swift/build/bin -module-cache-path /home/kebo/swift/build/./module-cache -no-link-objc-runtime -enable-library-evolution -library-level api -Xfrontend -require-explicit-availability=ignore -Xfrontend -enforce-exclusivity=unchecked -D SWIFT_ENABLE_REFLECTION -module-name Glibc -swift-version 5 -swift-version 5 -autolink-force-load -runtime-compatibility-version none -disable-autolinking-runtime-compatibility-dynamic-replacements -Xfrontend -disable-autolinking-runtime-compatibility-concurrency -warn-swift3-objc-inference-complete -Xfrontend -disable-objc-interop -DSWIFT_ENABLE_REFLECTION -warn-implicit-overrides -Xfrontend -enable-ossa-modules -Xfrontend -enable-lexical-lifetimes=false -Xfrontend -disable-implicit-concurrency-module-import -Xfrontend -disable-implicit-string-processing-module-import -Xfrontend -disable-implicit-string-processing-module-import -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 9999:macOS\ 9999,\ iOS\ 9999,\ watchOS\ 9999,\ tvOS\ 9999 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.0:macOS\ 10.14.4,\ iOS\ 12.2,\ watchOS\ 5.2,\ tvOS\ 12.2 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.1:macOS\ 10.15,\ iOS\ 13.0,\ watchOS\ 6.0,\ tvOS\ 13.0 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.2:macOS\ 10.15.4,\ iOS\ 13.4,\ watchOS\ 6.2,\ tvOS\ 13.4 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.3:macOS\ 11.0,\ iOS\ 14.0,\ watchOS\ 7.0,\ tvOS\ 14.0 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.4:macOS\ 11.3,\ iOS\ 14.5,\ watchOS\ 7.4,\ tvOS\ 14.5 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.5:macOS\ 12.0,\ iOS\ 15.0,\ watchOS\ 8.0,\ tvOS\ 15.0 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.6:macOS\ 12.3,\ iOS\ 15.4,\ watchOS\ 8.5,\ tvOS\ 15.4 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.7:macOS\ 13.0,\ iOS\ 16.0,\ watchOS\ 9.0,\ tvOS\ 16.0 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.8:macOS\ 13.3,\ iOS\ 16.4,\ watchOS\ 9.4,\ tvOS\ 16.4 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.9:macOS\ 9999,\ iOS\ 9999,\ watchOS\ 9999,\ tvOS\ 9999 -Xfrontend -target-min-inlining-version -Xfrontend min -module-link-name swiftGlibc -whole-module-optimization -parse-as-library -resource-dir /home/kebo/swift/build/./lib/swift -I /home/kebo/swift/build/./lib/swift/freebsd -o /home/kebo/swift/build/tools/swift/stdlib/public/Platform//FREEBSD/x86_64/Glibc.o @/home/kebo/swift/build/tools/swift/stdlib/public/Platform/8d867dd6b1ec09232628ee2ec417609030768a85.txt
<unknown>:0: warning: glibc not found for 'x86_64-unknown-freebsd13.2'; C stdlib may be unavailable
/usr/home/kebo/swift/swift/stdlib/public/Platform/Glibc.swift.gyb:13:19: error: no such module 'SwiftGlibc'
@_exported import SwiftGlibc // Clang module
^
[4305/4413] Generating /home/kebo/swift/build/./lib/swift/freebsd/Glibc.swiftmodule/x86_64-unknown-freebsd13.2.swiftmodule
FAILED: lib/swift/freebsd/Glibc.swiftmodule/x86_64-unknown-freebsd13.2.swiftmodule lib/swift/freebsd/Glibc.swiftmodule/x86_64-unknown-freebsd13.2.swiftdoc lib/swift/freebsd/Glibc.swiftmodule/x86_64-unknown-freebsd13.2.swiftinterface /home/kebo/swift/build/lib/swift/freebsd/Glibc.swiftmodule/x86_64-unknown-freebsd13.2.swiftmodule /home/kebo/swift/build/lib/swift/freebsd/Glibc.swiftmodule/x86_64-unknown-freebsd13.2.swiftdoc /home/kebo/swift/build/lib/swift/freebsd/Glibc.swiftmodule/x86_64-unknown-freebsd13.2.swiftinterface
cd /home/kebo/swift/build/tools/swift/stdlib/public/Platform && /usr/local/bin/cmake -E remove -f /home/kebo/swift/build/./lib/swift/freebsd/Glibc.swiftmodule/x86_64-unknown-freebsd13.2.swiftmodule /home/kebo/swift/build/./lib/swift/freebsd/Glibc.swiftmodule/x86_64-unknown-freebsd13.2.swiftdoc /home/kebo/swift/build/./lib/swift/freebsd/Glibc.swiftmodule/x86_64-unknown-freebsd13.2.swiftinterface && /usr/local/bin/cmake -E make_directory /home/kebo/swift/build/./lib/swift/freebsd /home/kebo/swift/build/./lib/swift/freebsd/Glibc.swiftmodule && /usr/local/bin/python3 /usr/home/kebo/swift/swift/utils/line-directive @/home/kebo/swift/build/tools/swift/stdlib/public/Platform/8d867dd6b1ec09232628ee2ec417609030768a85.txt -- /home/kebo/swift/build/./bin/swiftc -emit-module -o /home/kebo/swift/build/./lib/swift/freebsd/Glibc.swiftmodule/x86_64-unknown-freebsd13.2.swiftmodule -avoid-emit-module-source-info -sdk / -target x86_64-unknown-freebsd13.2 -resource-dir /home/kebo/swift/build/./lib/swift -O -D SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING -D SWIFT_RUNTIME_OS_VERSIONING -D SWIFT_STDLIB_ENABLE_UNICODE_DATA -D SWIFT_STDLIB_ENABLE_VECTOR_TYPES -D SWIFT_STDLIB_HAS_COMMANDLINE -D SWIFT_STDLIB_HAS_STDIN -D SWIFT_STDLIB_HAS_ENVIRON -Xcc -DSWIFT_STDLIB_HAS_ENVIRON -D SWIFT_THREADING_PTHREADS -tools-directory /home/kebo/swift/build/bin -module-cache-path /home/kebo/swift/build/./module-cache -no-link-objc-runtime -enable-library-evolution -library-level api -Xfrontend -require-explicit-availability=ignore -Xfrontend -enforce-exclusivity=unchecked -D SWIFT_ENABLE_REFLECTION -module-name Glibc -swift-version 5 -swift-version 5 -autolink-force-load -runtime-compatibility-version none -disable-autolinking-runtime-compatibility-dynamic-replacements -Xfrontend -disable-autolinking-runtime-compatibility-concurrency -warn-swift3-objc-inference-complete -Xfrontend -disable-objc-interop -DSWIFT_ENABLE_REFLECTION -warn-implicit-overrides -Xfrontend -enable-ossa-modules -Xfrontend -enable-lexical-lifetimes=false -Xfrontend -disable-implicit-concurrency-module-import -Xfrontend -disable-implicit-string-processing-module-import -Xfrontend -disable-implicit-string-processing-module-import -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 9999:macOS\ 9999,\ iOS\ 9999,\ watchOS\ 9999,\ tvOS\ 9999 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.0:macOS\ 10.14.4,\ iOS\ 12.2,\ watchOS\ 5.2,\ tvOS\ 12.2 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.1:macOS\ 10.15,\ iOS\ 13.0,\ watchOS\ 6.0,\ tvOS\ 13.0 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.2:macOS\ 10.15.4,\ iOS\ 13.4,\ watchOS\ 6.2,\ tvOS\ 13.4 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.3:macOS\ 11.0,\ iOS\ 14.0,\ watchOS\ 7.0,\ tvOS\ 14.0 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.4:macOS\ 11.3,\ iOS\ 14.5,\ watchOS\ 7.4,\ tvOS\ 14.5 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.5:macOS\ 12.0,\ iOS\ 15.0,\ watchOS\ 8.0,\ tvOS\ 15.0 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.6:macOS\ 12.3,\ iOS\ 15.4,\ watchOS\ 8.5,\ tvOS\ 15.4 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.7:macOS\ 13.0,\ iOS\ 16.0,\ watchOS\ 9.0,\ tvOS\ 16.0 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.8:macOS\ 13.3,\ iOS\ 16.4,\ watchOS\ 9.4,\ tvOS\ 16.4 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.9:macOS\ 9999,\ iOS\ 9999,\ watchOS\ 9999,\ tvOS\ 9999 -Xfrontend -target-min-inlining-version -Xfrontend min -module-link-name swiftGlibc -whole-module-optimization -parse-as-library -resource-dir /home/kebo/swift/build/./lib/swift -I /home/kebo/swift/build/./lib/swift/freebsd -emit-module-interface-path /home/kebo/swift/build/./lib/swift/freebsd/Glibc.swiftmodule/x86_64-unknown-freebsd13.2.swiftinterface -Xfrontend -experimental-skip-non-inlinable-function-bodies @/home/kebo/swift/build/tools/swift/stdlib/public/Platform/8d867dd6b1ec09232628ee2ec417609030768a85.txt
<unknown>:0: warning: glibc not found for 'x86_64-unknown-freebsd13.2'; C stdlib may be unavailable
/usr/home/kebo/swift/swift/stdlib/public/Platform/Glibc.swift.gyb:13:19: error: no such module 'SwiftGlibc'
@_exported import SwiftGlibc // Clang module
^
[4306/4413] Compiling /home/kebo/swift/build/tools/swift/stdlib/public/Cxx//FREEBSD/x86_64/Cxx.o
<unknown>:0: warning: glibc not found for 'x86_64-unknown-freebsd13.2'; C stdlib may be unavailable
[4307/4413] Compiling /home/kebo/swift/build/tools/swift/stdlib/public/SwiftOnoneSupport//FREEBSD/x86_64/SwiftOnoneSupport.o
<unknown>:0: warning: glibc not found for 'x86_64-unknown-freebsd13.2'; C stdlib may be unavailable
[4308/4413] Compiling /home/kebo/swift/build/tools/swift/stdlib/public/core//FREEBSD/x86_64/Swift.o
<unknown>:0: warning: glibc not found for 'x86_64-unknown-freebsd13.2'; C stdlib may be unavailable
/home/kebo/swift/swift/stdlib/public/core/SIMDVector.swift:63:17: warning: protocol 'SIMDScalar' should be declared to refine 'Decodable' due to a same-type constraint on 'Self'
public protocol SIMDScalar {
^
/home/kebo/swift/swift/stdlib/public/core/SIMDVector.swift:63:17: warning: protocol 'SIMDScalar' should be declared to refine 'Encodable' due to a same-type constraint on 'Self'
public protocol SIMDScalar {
^
/home/kebo/swift/swift/stdlib/public/core/SIMDVector.swift:63:17: warning: protocol 'SIMDScalar' should be declared to refine 'Hashable' due to a same-type constraint on 'Self'
public protocol SIMDScalar {
^
ninja: build stopped: subcommand failed.
I used head of the current branch.
Thank you. I think my errors may be resolved by this PR so I'll try with head or release/5.9 branches.
Updated: I also succeeded to build Swift on FreeBSD. I used release/5.9
branches.
With a freshly created jail on 13.2 I do the following
mkdir swift && cd swift
git clone -b main --depth=1 https://github.com/apple/swift
git clone -b stable/20221013 --depth=1 https://github.com/apple/llvm-project
git clone -b gfm --depth=1 https://github.com/apple/swift-cmark cmark
git clone -b main --depth=1 https://github.com/apple/swift-syntax
git clone -b main --depth=1 https://github.com/apple/swift-experimental-string-processing.git
mkdir build
cd build
../../configure.sh
with the configure.sh script containing:
#!/bin/sh
SRCROOT="`pwd`/.."
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DLLVM_ENABLE_PROJECTS=clang \
-DLLVM_TARGETS_TO_BUILD=X86 \
-DLLVM_EXTERNAL_PROJECTS="cmark;swift" \
-DLLVM_EXTERNAL_CMARK_SOURCE_DIR="${SRCROOT}/cmark" \
-DLLVM_EXTERNAL_SWIFT_SOURCE_DIR="${SRCROOT}/swift" \
-DSWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE="${SRCROOT}/swift-syntax" \
-DSWIFT_ENABLE_DISPATCH=OFF \
-DSWIFT_IMPLICIT_CONCURRENCY_IMPORT=OFF \
-DSWIFT_USE_LINKER=ld \
-DSWIFT_BUILD_STATIC_STDLIB=ON \
-DBOOTSTRAPPING_MODE=OFF \
-DSWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING=ON \
-DSWIFT_PATH_TO_STRING_PROCESSING_SOURCE="${SRCROOT}/swift-experimental-string-processing" \
-G Ninja \
../llvm-project/llvm
then
cd swift/build
ninja
I got swift to build.
For build-script
options and arguments that you find work successfully, would you mind submitting a PR to build-presets.ini
with a FreeBSD-specific preset so that it's easily reproducible?
I would not mind and looked at it , but I'm not proficient in how that ini file is used. I will have a look if I can figure out on how to change it, even though I only used the patch from @mhjacobson . He did all the work.
I see that you use separate cmake
and ninja
invocations for building. Is there anything in build-script
that prevents you from using it when building for FreeBSD? If not, you can just paste its arguments to a new section build-presets.ini
, a preset is basically a sequence of newline-separate arguments to build-script
with leading --
prefixes stripped off.
@Max_Desiatov I just did follow these instructions and wanted to tell the others in this thread how one can now get it started building on current 13.2 FreeBSD.
I have no idea how those build systems work but I'll give it a try to find out how to add it to the 'normal' build system. Right now it's not really usable anyways as swift package manager is not included.
Ok, I've tried out the utils/build-script as described in documentation and it started ok, but failed at one stage with _Float16 not being defined - even though the compiler switch explicitly seems to have use it:
[4252/4802][ 88%][6776.302s] Performing build step for 'compiler-rt'
[395/1097][ 36%][25.977s] Building C object lib/builtins/CMakeFiles/clang_rt.builtins-i386.dir/extendhfsf2.c.o
FAILED: lib/builtins/CMakeFiles/clang_rt.builtins-i386.dir/extendhfsf2.c.o
/root/swift-project/build/Ninja-RelWithDebInfoAssert/llvm-freebsd-x86_64/./bin/clang -DVISIBILITY_HIDDEN -Wall -Wno-unused-parameter -O2 -g -DNDEBUG -m32 -fno-lto -DCOMPILER_RT_HAS_FLOAT16 -std=c11 -fPIC -fno-builtin -fvisibility=hidden -fomit-frame-pointer -MD -MT lib/builtins/CMakeFiles/clang_rt.builtins-i386.dir/extendhfsf2.c.o -MF lib/builtins/CMakeFiles/clang_rt.builtins-i386.dir/extendhfsf2.c.o.d -o lib/builtins/CMakeFiles/clang_rt.builtins-i386.dir/extendhfsf2.c.o -c /root/swift-project/llvm-project/compiler-rt/lib/builtins/extendhfsf2.c
In file included from /root/swift-project/llvm-project/compiler-rt/lib/builtins/extendhfsf2.c:11:
In file included from /root/swift-project/llvm-project/compiler-rt/lib/builtins/fp_extend_impl.inc:38:
/root/swift-project/llvm-project/compiler-rt/lib/builtins/fp_extend.h:44:9: error: _Float16 is not supported on this target
typedef _Float16 src_t;
^
1 error generated.
question would now be why -DCOMPILER_RT_HAS_FLOAT16 is used if though it has not ?
I'm not proficient in these things (I have stopped using manual build systems in the early 90's for a reason).
And it seems to takes ages before anything gets built ( 2 hours before that error happend) and just using /utils/update and building again this morning takes more than 20 minutes before it gets to that error again. Seems my freebsd server is too slow to for fixing this issue, neither have I any idea on how to proceed and where to look for - should one define float16 or fix the compiler define ?
I really hope that @mhjacobson gets to fixing these issues.