swiftlang / swift-foundation

The Foundation project
Apache License 2.0
2.36k stars 150 forks source link

Foundation missing when building with the 6.0 release toolchain #924

Closed doozMen closed 2 days ago

doozMen commented 2 days ago

Given you are on macOS 15.0 and installed the toolchain via https://www.swift.org/install/macos/ and installed using the package installer the import of Foundation is causing problems when building. The output I will include at the end but how to reproduce is

export TOOLCHAINS=$(plutil -extract CFBundleIdentifier raw /Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain/Info.plist)
mkdir swift-tool && cd swift-tool
swift package init --type executable
echo `import Foundation` >> Sources/main.swift
swift build

this will output the following error

Building for debugging...
error: emit-module command failed due to signal 6 (use -v to see invocation)
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain/usr/bin/swift-frontend -frontend -emit-module -experimental-skip-non-inlinable-function-bodies-without-types /Users/stijnwillems/Developer/swift-tool/Sources/main.swift -target arm64-apple-macosx10.13 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode-16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk -I /Users/stijnwillems/Developer/swift-tool/.build/arm64-apple-macosx/debug/Modules -I /Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain/usr/lib/swift/macosx/testing -I /Applications/Xcode-16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Applications/Xcode-16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path /Users/stijnwillems/Developer/swift-tool/.build/arm64-apple-macosx/debug/ModuleCache -swift-version 6 -Onone -D SWIFT_PACKAGE -D DEBUG -entry-point-function-name swift_tool_main -empty-abi-descriptor -plugin-path /Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain/usr/lib/swift/host/plugins/testing -resource-dir /Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/stijnwillems/Developer/swift-tool -Xcc -isysroot -Xcc /Applications/Xcode-16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk -Xcc -F -Xcc /Applications/Xcode-16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -Xcc -fPIC -Xcc -g -module-name swift_tool -package-name swift_tool -plugin-path /Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain/usr/local/lib/swift/host/plugins -target-sdk-version 15.0 -target-sdk-name macosx15.0 -external-plugin-path /Applications/Xcode-16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode-16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode-16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -emit-module-doc-path /Users/stijnwillems/Developer/swift-tool/.build/arm64-apple-macosx/debug/Modules/swift_tool.swiftdoc -emit-module-source-info-path /Users/stijnwillems/Developer/swift-tool/.build/arm64-apple-macosx/debug/Modules/swift_tool.swiftsourceinfo -emit-dependencies-path /Users/stijnwillems/Developer/swift-tool/.build/arm64-apple-macosx/debug/swift_tool.build/swift_tool.emit-module.d -o /Users/stijnwillems/Developer/swift-tool/.build/arm64-apple-macosx/debug/Modules/swift_tool.swiftmodule -emit-abi-descriptor-path /Users/stijnwillems/Developer/swift-tool/.build/arm64-apple-macosx/debug/Modules/swift_tool.abi.json
1.  Apple Swift version 6.0 (swift-6.0-RELEASE)
2.  Compiling with the current language version
3.  While evaluating request ExecuteSILPipelineRequest(Run pipelines { Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for Darwin)
4.  While running pass #2548 SILModuleTransform "MandatorySILLinker".
5.  While deserializing SIL function "$s6Darwin14POSIXErrorCodeO8rawValueACSgs5Int32V_tcfC"
6.  *** DESERIALIZATION FAILURE ***
*** If any module named here was modified in the SDK, please delete the ***
*** new swiftmodule files from the SDK and keep only swiftinterfaces.   ***
module '_errno', builder version '6.0(6.0)/Apple Swift version 6.0 (swift-6.0-RELEASE)', built from swiftinterface, resilient, loaded from '/Users/stijnwillems/Developer/swift-tool/.build/arm64-apple-macosx/debug/ModuleCache/_errno-2GQWKKCJV8S7T.swiftmodule'
SILFunction type mismatch for '$s6Darwin14POSIXErrorCodeO8rawValueACSgs5Int32V_tcfC': '$@convention(method) (Int32, @thin POSIXErrorCode.Type) -> Optional<POSIXErrorCode>' != '$@convention(method) (Int32, @thin POSIXErrorCode.Type) -> Optional<POSIXErrorCode>'

Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x0000000109c51e28 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000109c505f4 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000109c52470 SignalHandler(int) + 304
3  libsystem_platform.dylib 0x000000018c638184 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000018c602f70 pthread_kill + 288
5  libsystem_c.dylib        0x000000018c50f908 abort + 128
6  swift-frontend           0x000000010550dadc swift::ModuleFileSharedCore::fatal(llvm::Error) const + 1224
7  swift-frontend           0x00000001054a34dc swift::ModuleFile::getSourceLoc() const + 0
8  swift-frontend           0x00000001054e7a44 swift::SILDeserializer::readSILFunctionChecked(llvm::PointerEmbeddedInt<unsigned int, 31>, swift::SILFunction*, llvm::StringRef, bool, bool) + 1896
9  swift-frontend           0x00000001054f8bbc swift::SILDeserializer::lookupSILFunction(swift::SILFunction*, bool) + 184
10 swift-frontend           0x0000000105597bfc swift::SerializedSILLoader::lookupSILFunction(swift::SILFunction*, bool) + 148
11 swift-frontend           0x00000001055cfd68 swift::SILLinkerVisitor::process() + 484
12 swift-frontend           0x00000001055cfb54 swift::SILLinkerVisitor::processFunction(swift::SILFunction*) + 108
13 swift-frontend           0x000000010564b43c swift::SILModule::linkFunction(swift::SILFunction*, swift::SILModule::LinkingMode) + 108
14 swift-frontend           0x00000001052e71e4 (anonymous namespace)::SILLinker::run() + 128
15 swift-frontend           0x00000001051ad81c swift::SILPassManager::runModulePass(unsigned int) + 856
16 swift-frontend           0x00000001051afbc0 swift::SILPassManager::execute() + 624
17 swift-frontend           0x00000001051aa5ac swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 72
18 swift-frontend           0x00000001051aa52c swift::ExecuteSILPipelineRequest::evaluate(swift::Evaluator&, swift::SILPipelineExecutionDescriptor) const + 68
19 swift-frontend           0x00000001051e5934 swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 28
20 swift-frontend           0x00000001051c5e90 swift::ExecuteSILPipelineRequest::OutputType swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()>(swift::ExecuteSILPipelineRequest const&, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()) + 204
21 swift-frontend           0x00000001051aa788 swift::executePassPipelinePlan(swift::SILModule*, swift::SILPassPipelinePlan const&, bool, swift::irgen::IRGenModule*) + 64
22 swift-frontend           0x00000001051c8358 swift::runSILDiagnosticPasses(swift::SILModule&) + 192
23 swift-frontend           0x00000001049e6ff4 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 80
24 swift-frontend           0x00000001049f2118 swift::ExplicitModuleInterfaceBuilder::buildSwiftModuleFromInterface(llvm::StringRef, llvm::StringRef, bool, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>*, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, llvm::StringRef) + 2372
25 swift-frontend           0x00000001049f374c std::__1::error_code llvm::function_ref<std::__1::error_code (swift::SubCompilerInstanceInfo&)>::callback_fn<swift::ImplicitModuleInterfaceBuilder::buildSwiftModuleInternal(llvm::StringRef, bool, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>*, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>)::$_3::operator()() const::'lambda'(swift::SubCompilerInstanceInfo&)>(long, swift::SubCompilerInstanceInfo&) + 208
26 swift-frontend           0x00000001049fe760 swift::InterfaceSubContextDelegateImpl::runInSubCompilerInstance(llvm::StringRef, llvm::StringRef, llvm::StringRef, llvm::StringRef, swift::SourceLoc, bool, llvm::function_ref<std::__1::error_code (swift::SubCompilerInstanceInfo&)>) + 2372
27 swift-frontend           0x00000001049f34e0 void llvm::function_ref<void ()>::callback_fn<swift::ImplicitModuleInterfaceBuilder::buildSwiftModuleInternal(llvm::StringRef, bool, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>*, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>)::$_3>(long) + 268
28 swift-frontend           0x0000000109bc8438 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) + 164
29 swift-frontend           0x0000000109bc8558 RunSafelyOnThread_Dispatch(void*) + 52
30 swift-frontend           0x0000000109bc8580 void* llvm::thread::ThreadProxy<std::__1::tuple<void (*)(void*), (anonymous namespace)::RunSafelyOnThreadInfo*>>(void*) + 24
31 libsystem_pthread.dylib  0x000000018c6032e4 _pthread_start + 136
32 libsystem_pthread.dylib  0x000000018c5fe0fc thread_start + 8

Trying to mitigate the issue like described swift forum post https://forums.swift.org/t/using-swift-foundation-with-linux-static-sdk/74642 by adding dependency to swift-foundation and using import FoundationEssentials seams to work but has other issues.

This seams to contradict the docs stating that foundation and especially FoundationEssentials is included in the toolchain on any platform?

jmschonfeld commented 2 days ago

This issue is a duplicate of https://github.com/apple/swift-foundation/issues/920

by adding dependency to swift-foundation and using import FoundationEssentials seams to work but has other issues.

This is only intended to be used as a development convenience and it will not work in situations when you are not working on swift-foundation itself. The correct path forward here is to remove the package dependency, and there are folks working on fixing the compiler crash that you reported