diff --git a/CMakeLists.txt b/CMakeLists.txt index e4cbfb844e0a0..b13ebf3582955 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1076,6 +1076,8 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") set(SWIFT_USE_LINKER_default "") elseif(DISTRO_NAME STREQUAL "Amazon Linux 2023") set(SWIFT_USE_LINKER_default "lld") +elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + set(SWIFT_USE_LINKER_default "lld") else() get_gold_version(gold_version) if(NOT gold_version) diff --git a/cmake/modules/SwiftCXXUtils.cmake b/cmake/modules/SwiftCXXUtils.cmake index bdc289985fc39..ea28fafd3de35 100644 --- a/cmake/modules/SwiftCXXUtils.cmake +++ b/cmake/modules/SwiftCXXUtils.cmake @@ -1,6 +1,5 @@ # Platforms that use libstdc++ as the system-wide default C++ standard library. set(SWIFT_LIBSTDCXX_PLATFORMS "LINUX" - "FREEBSD" "CYGWIN" "HAIKU") diff --git a/include/swift/AST/AutoDiff.h b/include/swift/AST/AutoDiff.h index d4d2574882b6c..48a4469f994ac 100644 --- a/include/swift/AST/AutoDiff.h +++ b/include/swift/AST/AutoDiff.h @@ -422,7 +422,14 @@ class DerivativeFunctionTypeError Kind kind; /// The type and index of a differentiability parameter or result. - using TypeAndIndex = std::pair; + /// std::pair does not have a trivial copy constructor on all platforms for + /// ABI reasons. We must define our own. + struct TypeAndIndex { + Type first; + unsigned second; + + TypeAndIndex(Type type, unsigned index) : first(type), second(index) {} + }; private: union Value { diff --git a/include/swift/AST/PlatformKinds.def b/include/swift/AST/PlatformKinds.def index dd10bf495b65b..9b2fcdadd554a 100644 --- a/include/swift/AST/PlatformKinds.def +++ b/include/swift/AST/PlatformKinds.def @@ -34,6 +34,7 @@ AVAILABILITY_PLATFORM(visionOSApplicationExtension, "application extensions for AVAILABILITY_PLATFORM(macOSApplicationExtension, "application extensions for macOS") AVAILABILITY_PLATFORM(macCatalyst, "Mac Catalyst") AVAILABILITY_PLATFORM(macCatalystApplicationExtension, "application extensions for Mac Catalyst") +AVAILABILITY_PLATFORM(FreeBSD, "FreeBSD") AVAILABILITY_PLATFORM(OpenBSD, "OpenBSD") AVAILABILITY_PLATFORM(Windows, "Windows") diff --git a/include/swift/SILOptimizer/Differentiation/DifferentiationInvoker.h b/include/swift/SILOptimizer/Differentiation/DifferentiationInvoker.h index 63b9eb6eb824b..5abe7d89aa281 100644 --- a/include/swift/SILOptimizer/Differentiation/DifferentiationInvoker.h +++ b/include/swift/SILOptimizer/Differentiation/DifferentiationInvoker.h @@ -71,8 +71,14 @@ struct DifferentiationInvoker { /// The parent `apply` instruction and the witness associated with the /// `IndirectDifferentiation` case. - std::pair - indirectDifferentiation; + /// std::pair is not trivially copyable on all supported platforms. + /// This struct works around that limitation. + struct IndirectDifferentiation { + ApplyInst *applyInst; + SILDifferentiabilityWitness *witness; + }; + IndirectDifferentiation indirectDifferentiation; + Value(ApplyInst *applyInst, SILDifferentiabilityWitness *witness) : indirectDifferentiation({applyInst, witness}) {} @@ -111,7 +117,8 @@ struct DifferentiationInvoker { std::pair getIndirectDifferentiation() const { assert(kind == Kind::IndirectDifferentiation); - return value.indirectDifferentiation; + return std::make_pair(value.indirectDifferentiation.applyInst, + value.indirectDifferentiation.witness); } SILDifferentiabilityWitness *getSILDifferentiabilityWitnessInvoker() const { diff --git a/lib/AST/ModuleDependencies.cpp b/lib/AST/ModuleDependencies.cpp index 4d9bc233a9639..a1588e76ded75 100644 --- a/lib/AST/ModuleDependencies.cpp +++ b/lib/AST/ModuleDependencies.cpp @@ -600,7 +600,8 @@ void swift::dependencies::registerCxxInteropLibraries( return mainModuleName == Name; })) { // Only link with CxxStdlib on platforms where the overlay is available. - if (Target.isOSDarwin() || Target.isOSLinux() || Target.isOSWindows()) + if (Target.isOSDarwin() || Target.isOSLinux() || Target.isOSWindows() || + Target.isOSFreeBSD()) RegistrationCallback(LinkLibrary{"swiftCxxStdlib", LibraryKind::Library, hasStaticCxxStdlib}); } diff --git a/lib/AST/PlatformKind.cpp b/lib/AST/PlatformKind.cpp index b8026af51a091..2b125a32cc0bd 100644 --- a/lib/AST/PlatformKind.cpp +++ b/lib/AST/PlatformKind.cpp @@ -116,6 +116,7 @@ swift::basePlatformForExtensionPlatform(PlatformKind Platform) { case PlatformKind::tvOS: case PlatformKind::watchOS: case PlatformKind::visionOS: + case PlatformKind::FreeBSD: case PlatformKind::OpenBSD: case PlatformKind::Windows: case PlatformKind::none: @@ -158,6 +159,8 @@ static bool isPlatformActiveForTarget(PlatformKind Platform, case PlatformKind::visionOS: case PlatformKind::visionOSApplicationExtension: return Target.isXROS(); + case PlatformKind::FreeBSD: + return Target.isOSFreeBSD(); case PlatformKind::OpenBSD: return Target.isOSOpenBSD(); case PlatformKind::Windows: @@ -283,6 +286,8 @@ swift::tripleOSTypeForPlatform(PlatformKind platform) { case PlatformKind::visionOS: case PlatformKind::visionOSApplicationExtension: return llvm::Triple::XROS; + case PlatformKind::FreeBSD: + return llvm::Triple::FreeBSD; case PlatformKind::OpenBSD: return llvm::Triple::OpenBSD; case PlatformKind::Windows: @@ -319,6 +324,7 @@ bool swift::isPlatformSPI(PlatformKind Platform) { case PlatformKind::watchOSApplicationExtension: case PlatformKind::visionOS: case PlatformKind::visionOSApplicationExtension: + case PlatformKind::FreeBSD: case PlatformKind::OpenBSD: case PlatformKind::Windows: case PlatformKind::none: diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index c76a5ed6965fa..8ab7f34eefcf2 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -4817,7 +4817,8 @@ AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType( if (!resultTan) return llvm::make_error( this, DerivativeFunctionTypeError::Kind::NonDifferentiableResult, - std::make_pair(originalResultType, unsigned(originalResult.index))); + DerivativeFunctionTypeError::TypeAndIndex( + originalResultType, unsigned(originalResult.index))); if (!originalResult.isSemanticResultParameter) resultTanTypes.push_back(resultTan->getType()); @@ -4847,7 +4848,7 @@ AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType( this, DerivativeFunctionTypeError::Kind:: NonDifferentiableDifferentiabilityParameter, - std::make_pair(paramType, i)); + DerivativeFunctionTypeError::TypeAndIndex(paramType, i)); differentialParams.push_back(AnyFunctionType::Param( paramTan->getType(), Identifier(), diffParam.getParameterFlags())); @@ -4895,7 +4896,7 @@ AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType( this, DerivativeFunctionTypeError::Kind:: NonDifferentiableDifferentiabilityParameter, - std::make_pair(paramType, i)); + DerivativeFunctionTypeError::TypeAndIndex(paramType, i)); if (diffParam.isAutoDiffSemanticResult()) { if (paramType->isVoid()) diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index 6ef1d4c47def8..45cc49e226d48 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -2557,7 +2557,9 @@ PlatformAvailability::PlatformAvailability(const LangOptions &langOpts) case PlatformKind::visionOS: case PlatformKind::visionOSApplicationExtension: break; - + case PlatformKind::FreeBSD: + deprecatedAsUnavailableMessage = ""; + break; case PlatformKind::OpenBSD: deprecatedAsUnavailableMessage = ""; break; @@ -2605,6 +2607,9 @@ bool PlatformAvailability::isPlatformRelevant(StringRef name) const { return name == "xros" || name == "xros_app_extension" || name == "visionos" || name == "visionos_app_extension"; + case PlatformKind::FreeBSD: + return name == "freebsd"; + case PlatformKind::OpenBSD: return name == "openbsd"; @@ -2676,6 +2681,10 @@ bool PlatformAvailability::treatDeprecatedAsUnavailable( // No deprecation filter on xrOS return false; + case PlatformKind::FreeBSD; + // No deprecation filter on OpenBSD + return false; + case PlatformKind::OpenBSD: // No deprecation filter on OpenBSD return false; diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index e7f6fb8a48bca..69fbf27ce16e6 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -1656,9 +1656,10 @@ const char *ToolChain::getClangLinkerDriver( // a C++ standard library if it's not needed, in particular because the // standard library that `clang++` selects by default may not be the one that // is desired. - const char *LinkerDriver = - Args.hasArg(options::OPT_enable_experimental_cxx_interop) ? "clang++" - : "clang"; + bool useCxxLinker = Args.hasArg(options::OPT_enable_experimental_cxx_interop); + if (Arg *arg = Args.getLastArg(options::OPT_cxx_interoperability_mode)) + useCxxLinker |= StringRef(arg->getValue()) != "off"; + const char *LinkerDriver = useCxxLinker ? "clang++" : "clang"; if (const Arg *A = Args.getLastArg(options::OPT_tools_directory)) { StringRef toolchainPath(A->getValue()); diff --git a/lib/Driver/UnixToolChains.cpp b/lib/Driver/UnixToolChains.cpp index 33e61b82145e9..12b0a895812ec 100644 --- a/lib/Driver/UnixToolChains.cpp +++ b/lib/Driver/UnixToolChains.cpp @@ -334,10 +334,9 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job, SmallString<128> LibProfile(SharedResourceDirPath); llvm::sys::path::remove_filename(LibProfile); // remove platform name llvm::sys::path::append(LibProfile, "clang", "lib"); - - llvm::sys::path::append(LibProfile, getTriple().getOSName(), - Twine("libclang_rt.profile-") + - getTriple().getArchName() + ".a"); + llvm::sys::path::append( + LibProfile, getUnversionedTriple(getTriple()).getOSName(), + Twine("libclang_rt.profile-") + getTriple().getArchName() + ".a"); Arguments.push_back(context.Args.MakeArgString(LibProfile)); Arguments.push_back(context.Args.MakeArgString( Twine("-u", llvm::getInstrProfRuntimeHookVarName()))); diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 4728e04d46fc9..2d076d7df8995 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -390,7 +390,8 @@ void CompilerInvocation::computeCXXStdlibOptions() { // (see https://reviews.llvm.org/D101479). LangOpts.CXXStdlib = CXXStdlibKind::Msvcprt; LangOpts.PlatformDefaultCXXStdlib = CXXStdlibKind::Msvcprt; - } else if (LangOpts.Target.isOSLinux() || LangOpts.Target.isOSDarwin()) { + } else if (LangOpts.Target.isOSLinux() || LangOpts.Target.isOSDarwin() || + LangOpts.Target.isOSFreeBSD()) { auto [clangDriver, clangDiagEngine] = ClangImporter::createClangDriver(LangOpts, ClangImporterOpts); auto clangDriverArgs = ClangImporter::createClangArgs( diff --git a/lib/IRGen/TBDGen.cpp b/lib/IRGen/TBDGen.cpp index 3566a1222f1e7..64b53e4b71050 100644 --- a/lib/IRGen/TBDGen.cpp +++ b/lib/IRGen/TBDGen.cpp @@ -245,6 +245,8 @@ getLinkerPlatformId(OriginallyDefinedInAttr::ActiveVersion Ver, switch(Ver.Platform) { case swift::PlatformKind::none: llvm_unreachable("cannot find platform kind"); + case swift::PlatformKind::FreeBSD: + llvm_unreachable("not used for this platform"); case swift::PlatformKind::OpenBSD: llvm_unreachable("not used for this platform"); case swift::PlatformKind::Windows: diff --git a/lib/Option/SanitizerOptions.cpp b/lib/Option/SanitizerOptions.cpp index f8f8ccbb4bb19..9f057820808f3 100644 --- a/lib/Option/SanitizerOptions.cpp +++ b/lib/Option/SanitizerOptions.cpp @@ -168,7 +168,7 @@ OptionSet swift::parseSanitizerArgValues( } // Check that we're one of the known supported targets for sanitizers. - if (!(Triple.isOSDarwin() || Triple.isOSLinux() || Triple.isOSWindows())) { + if (!(Triple.isOSDarwin() || Triple.isOSLinux() || Triple.isOSWindows() || Triple.isOSFreeBSD())) { SmallString<128> b; Diags.diagnose(SourceLoc(), diag::error_unsupported_opt_for_target, (A->getOption().getPrefixedName() + diff --git a/lib/PrintAsClang/DeclAndTypePrinter.cpp b/lib/PrintAsClang/DeclAndTypePrinter.cpp index e396d698454c8..458826a1fa13c 100644 --- a/lib/PrintAsClang/DeclAndTypePrinter.cpp +++ b/lib/PrintAsClang/DeclAndTypePrinter.cpp @@ -1795,6 +1795,9 @@ class DeclAndTypePrinter::Implementation case PlatformKind::visionOSApplicationExtension: plat = "visionos_app_extension"; break; + case PlatformKind::FreeBSD: + plat = "freebsd"; + break; case PlatformKind::OpenBSD: plat = "openbsd"; break; diff --git a/lib/SymbolGraphGen/AvailabilityMixin.cpp b/lib/SymbolGraphGen/AvailabilityMixin.cpp index ece561a30ece6..4678641bf1598 100644 --- a/lib/SymbolGraphGen/AvailabilityMixin.cpp +++ b/lib/SymbolGraphGen/AvailabilityMixin.cpp @@ -54,6 +54,8 @@ StringRef getDomain(const SemanticAvailableAttr &AvAttr) { return { "watchOSAppExtension" }; case swift::PlatformKind::visionOSApplicationExtension: return { "visionOSAppExtension" }; + case swift::PlatformKind::FreeBSD: + return { "FreeBSD" }; case swift::PlatformKind::OpenBSD: return { "OpenBSD" }; case swift::PlatformKind::Windows: diff --git a/stdlib/public/Cxx/std/CMakeLists.txt b/stdlib/public/Cxx/std/CMakeLists.txt index c8a4b2e1def2b..d042ef354da46 100644 --- a/stdlib/public/Cxx/std/CMakeLists.txt +++ b/stdlib/public/Cxx/std/CMakeLists.txt @@ -78,7 +78,7 @@ add_swift_target_library(swiftCxxStdlib STATIC NO_LINK_NAME IS_STDLIB IS_SWIFT_O DEPLOYMENT_VERSION_XROS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_XROS} LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}" - TARGET_SDKS ALL_APPLE_PLATFORMS LINUX LINUX_STATIC WINDOWS ANDROID + TARGET_SDKS ALL_APPLE_PLATFORMS LINUX LINUX_STATIC WINDOWS ANDROID FREEBSD MACCATALYST_BUILD_FLAVOR zippered INSTALL_IN_COMPONENT compiler INSTALL_BINARY_SWIFTMODULE NON_DARWIN_ONLY diff --git a/stdlib/public/Platform/Platform.swift b/stdlib/public/Platform/Platform.swift index 0c2d63a0cffdb..ae8e09e0fca88 100644 --- a/stdlib/public/Platform/Platform.swift +++ b/stdlib/public/Platform/Platform.swift @@ -338,12 +338,12 @@ public var SIG_DFL: sig_t? { return nil } public var SIG_IGN: sig_t { return unsafeBitCast(1, to: sig_t.self) } public var SIG_ERR: sig_t { return unsafeBitCast(-1, to: sig_t.self) } public var SIG_HOLD: sig_t { return unsafeBitCast(5, to: sig_t.self) } -#elseif os(OpenBSD) +#elseif os(OpenBSD) || os(FreeBSD) public var SIG_DFL: sig_t? { return nil } public var SIG_IGN: sig_t { return unsafeBitCast(1, to: sig_t.self) } public var SIG_ERR: sig_t { return unsafeBitCast(-1, to: sig_t.self) } public var SIG_HOLD: sig_t { return unsafeBitCast(3, to: sig_t.self) } -#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Haiku) +#elseif os(Linux) || os(PS4) || os(Android) || os(Haiku) #if !canImport(SwiftMusl) public typealias sighandler_t = __sighandler_t #endif @@ -495,3 +495,9 @@ public var environ: UnsafeMutablePointer?> { } #endif #endif // SWIFT_STDLIB_HAS_ENVIRON + +#if os(FreeBSD) +@inlineable public func inet_pton(_ af: CInt, _ src: UnsafePointer!, _ dst: UnsafeMutablePointer!) -> CInt { + __inet_pton(af, src, dst) +} +#endif diff --git a/stdlib/public/Platform/SwiftGlibc.h.gyb b/stdlib/public/Platform/SwiftGlibc.h.gyb index 61d054e09b049..10e8283ba77f3 100644 --- a/stdlib/public/Platform/SwiftGlibc.h.gyb +++ b/stdlib/public/Platform/SwiftGlibc.h.gyb @@ -57,6 +57,7 @@ headers = [ 'nl_types.h', 'poll.h', 'pthread.h', + 'pthread_np.h', 'pwd.h', 'regex.h', 'sched.h', @@ -65,6 +66,7 @@ headers = [ 'spawn.h', 'strings.h', 'sys/event.h', + 'sys/extattr.h', 'sys/file.h', 'sys/inotify.h', 'sys/ioctl.h', @@ -84,6 +86,7 @@ headers = [ 'sys/times.h', 'sys/types.h', 'sys/uio.h', + 'sys/umtx.h', 'sys/un.h', 'sys/user.h', 'sys/utsname.h', diff --git a/stdlib/public/Platform/glibc.modulemap.gyb b/stdlib/public/Platform/glibc.modulemap.gyb index af25d0cf93ad1..221f0d00b6598 100644 --- a/stdlib/public/Platform/glibc.modulemap.gyb +++ b/stdlib/public/Platform/glibc.modulemap.gyb @@ -19,7 +19,7 @@ /// It's not named just Glibc so that it doesn't conflict in the event of a /// future official glibc modulemap. module SwiftGlibc [system] { -% if CMAKE_SDK in ["LINUX", "OPENBSD"]: +% if CMAKE_SDK in ["LINUX", "FREEBSD", "OPENBSD"]: link "m" % end % if CMAKE_SDK in ["LINUX", "FREEBSD", "OPENBSD", "CYGWIN"]: diff --git a/stdlib/public/SwiftShims/swift/shims/SwiftStdint.h b/stdlib/public/SwiftShims/swift/shims/SwiftStdint.h index 386186df0962c..2be8b51f53650 100644 --- a/stdlib/public/SwiftShims/swift/shims/SwiftStdint.h +++ b/stdlib/public/SwiftShims/swift/shims/SwiftStdint.h @@ -24,7 +24,7 @@ // Clang has been defining __INTxx_TYPE__ macros for a long time. // __UINTxx_TYPE__ are defined only since Clang 3.5. -#if !defined(__APPLE__) && !defined(__linux__) && !defined(__OpenBSD__) && !defined(__wasi__) +#if !defined(__APPLE__) && !defined(__linux__) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__wasi__) #include typedef int64_t __swift_int64_t; typedef uint64_t __swift_uint64_t; diff --git a/stdlib/public/SwiftShims/swift/shims/_SynchronizationShims.h b/stdlib/public/SwiftShims/swift/shims/_SynchronizationShims.h index 70a1eb6e004f0..2978bf0f1c43f 100644 --- a/stdlib/public/SwiftShims/swift/shims/_SynchronizationShims.h +++ b/stdlib/public/SwiftShims/swift/shims/_SynchronizationShims.h @@ -66,4 +66,9 @@ static inline __swift_uint32_t _swift_stdlib_futex_unlock(__swift_uint32_t *lock #endif // defined(__linux__) +#if defined(__FreeBSD__) + #include + #include +#endif + #endif // SWIFT_STDLIB_SYNCHRONIZATION_SHIMS_H diff --git a/stdlib/public/Synchronization/CMakeLists.txt b/stdlib/public/Synchronization/CMakeLists.txt index 90c1e3dfb7a82..3d193283c84b9 100644 --- a/stdlib/public/Synchronization/CMakeLists.txt +++ b/stdlib/public/Synchronization/CMakeLists.txt @@ -65,6 +65,12 @@ set(SWIFT_SYNCHRONIZATION_LINUX_SOURCES Mutex/SpinLoopHint.swift ) +# FreeBSD sources +set(SWIFT_SYNCRHONIZATION_FREEBSD_SOURCES + Mutex/FreeBSDImpl.swift + Mutex/Mutex.swift +) + # Wasm sources set(SWIFT_SYNCHRONIZATION_WASM_SOURCES @@ -112,6 +118,8 @@ add_swift_target_library(swiftSynchronization ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES ${SWIFT_SYNCHRONIZATION_WASM_SOURCES} SWIFT_SOURCES_DEPENDS_WINDOWS ${SWIFT_SYNCHRONIZATION_WINDOWS_SOURCES} + SWFIT_SOURCES_DEPENDS_FREEBSD + ${SWIFT_SYNCRHONIZATION_FREEBSD_SOURCES} SWIFT_SOURCES_DEPENDS_FREESTANDING Mutex/MutexUnavailable.swift @@ -135,6 +143,8 @@ add_swift_target_library(swiftSynchronization ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES Android SWIFT_MODULE_DEPENDS_WINDOWS WinSDK + SWIFT_MODULE_DEPENDS_FREEBSD + Glibc SWIFT_COMPILE_FLAGS ${SWIFT_SYNCHRNOIZATION_SWIFT_FLAGS} diff --git a/stdlib/public/Synchronization/Mutex/FreeBSDImpl.swift b/stdlib/public/Synchronization/Mutex/FreeBSDImpl.swift new file mode 100644 index 0000000000000..d7f0ed7d45d9d --- /dev/null +++ b/stdlib/public/Synchronization/Mutex/FreeBSDImpl.swift @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// + // + // This source file is part of the Swift Atomics open source project + // + // Copyright (c) 2024 Apple Inc. and the Swift project authors + // Licensed under Apache License v2.0 with Runtime Library Exception + // + // See https://swift.org/LICENSE.txt for license information + // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors + // + //===----------------------------------------------------------------------===// + + import Glibc + + @available(SwiftStdlib 6.0, *) + @frozen + @_staticExclusiveOnly + public struct _MutexHandle: ~Copyable { + @usableFromInline + let value: _Cell + + @available(SwiftStdlib 6.0, *) + @_alwaysEmitIntoClient + @_transparent + public init() { + value = _Cell(umutex()) + } + + @available(SwiftStdlib 6.0, *) + @_alwaysEmitIntoClient + @_transparent + internal borrowing func _lock() { + _umtx_op(value._address, UMTX_OP_MUTEX_LOCK, 0, nil, nil) + } + + @available(SwiftStdlib 6.0, *) + @_alwaysEmitIntoClient + @_transparent + internal borrowing func _tryLock() -> Bool { + _umtx_op(value._address, UMTX_OP_MUTEX_TRYLOCK, 0, nil, nil) != -1 + } + + @available(SwiftStdlib 6.0, *) + @_alwaysEmitIntoClient + @_transparent + internal borrowing func _unlock() { + _umtx_op(value._address, UMTX_OP_MUTEX_UNLOCK, 0, nil, nil) + } + } diff --git a/stdlib/public/core/CTypes.swift b/stdlib/public/core/CTypes.swift index 20ecba2bcf9bb..56d5ccfafff45 100644 --- a/stdlib/public/core/CTypes.swift +++ b/stdlib/public/core/CTypes.swift @@ -114,10 +114,9 @@ public typealias CLongDouble = Double #error("CLongDouble needs to be defined for this OpenBSD architecture") #endif #elseif os(FreeBSD) +// FreeBSD long double is Float128 on arm64, which is not supported by Swift #if arch(x86_64) || arch(i386) public typealias CLongDouble = Float80 -#else -#error("CLongDouble needs to be defined for this FreeBSD architecture") #endif #elseif $Embedded #if arch(x86_64) || arch(i386) diff --git a/test/Concurrency/Runtime/async_task_executor_and_serial_executor_both_executor.swift b/test/Concurrency/Runtime/async_task_executor_and_serial_executor_both_executor.swift index a9873a66213bc..c75fda96e4d60 100644 --- a/test/Concurrency/Runtime/async_task_executor_and_serial_executor_both_executor.swift +++ b/test/Concurrency/Runtime/async_task_executor_and_serial_executor_both_executor.swift @@ -8,11 +8,12 @@ // TODO: Need to find out how to combine %env- and %target-run and %import-libdispatch reliably. // UNSUPPORTED: OS=linux-gnu +// UNSUPPORTED: OS=freebsd // REQUIRES: concurrency // REQUIRES: executable_test // REQUIRES: libdispatch -// +// // REQUIRES: concurrency_runtime // UNSUPPORTED: back_deployment_runtime diff --git a/test/Concurrency/Runtime/custom_executors_complex_equality_crash.swift b/test/Concurrency/Runtime/custom_executors_complex_equality_crash.swift index 4290618008890..ca5422a2a6459 100644 --- a/test/Concurrency/Runtime/custom_executors_complex_equality_crash.swift +++ b/test/Concurrency/Runtime/custom_executors_complex_equality_crash.swift @@ -8,6 +8,7 @@ // TODO: Need to find out how to combine %env- and %target-run and %import-libdispatch reliably. // UNSUPPORTED: OS=linux-gnu +// UNSUPPORTED: OS=freebsd // REQUIRES: concurrency // REQUIRES: executable_test diff --git a/test/Distributed/Runtime/distributed_actor_protocol_call_resilient_lib.swift b/test/Distributed/Runtime/distributed_actor_protocol_call_resilient_lib.swift index 0e800d625732a..64e66a5485d9f 100644 --- a/test/Distributed/Runtime/distributed_actor_protocol_call_resilient_lib.swift +++ b/test/Distributed/Runtime/distributed_actor_protocol_call_resilient_lib.swift @@ -71,6 +71,7 @@ // Locating the built libraries failed on Linux (construction of test case), // but we primarily care about macOS in this test // UNSUPPORTED: OS=linux-gnu +// UNSUPPORTED: OS=freebsd // UNSUPPORTED: use_os_stdlib // UNSUPPORTED: back_deployment_runtime diff --git a/test/IDE/complete_decl_attribute.swift b/test/IDE/complete_decl_attribute.swift index a7104e38d3dc3..9082ed637fd86 100644 --- a/test/IDE/complete_decl_attribute.swift +++ b/test/IDE/complete_decl_attribute.swift @@ -83,6 +83,7 @@ actor MyGenericGlobalActor { // AVAILABILITY1-NEXT: Keyword/None: macOSApplicationExtension[#Platform#]; name=macOSApplicationExtension{{$}} // AVAILABILITY1-NEXT: Keyword/None: macCatalyst[#Platform#]; name=macCatalyst // AVAILABILITY1-NEXT: Keyword/None: macCatalystApplicationExtension[#Platform#]; name=macCatalystApplicationExtension +// AVAILABILITY1-NEXT: Keyword/None: FreeBSD[#Platform#]; name=FreeBSD{{$}} // AVAILABILITY1-NEXT: Keyword/None: OpenBSD[#Platform#]; name=OpenBSD{{$}} // AVAILABILITY1-NEXT: Keyword/None: Windows[#Platform#]; name=Windows{{$}} diff --git a/test/Interop/Cxx/stdlib/avoid-import-cxx-math.swift b/test/Interop/Cxx/stdlib/avoid-import-cxx-math.swift index 325640ee20bcb..c13588aa98ce2 100644 --- a/test/Interop/Cxx/stdlib/avoid-import-cxx-math.swift +++ b/test/Interop/Cxx/stdlib/avoid-import-cxx-math.swift @@ -2,7 +2,7 @@ // RUN: %target-swift-frontend %s -typecheck -verify -cxx-interoperability-mode=swift-6 // RUN: %target-swift-frontend %s -typecheck -verify -cxx-interoperability-mode=upcoming-swift -// REQUIRES: OS=macosx || OS=linux-gnu +// REQUIRES: OS=macosx || OS=linux-gnu || OS=freebsd import CxxStdlib diff --git a/test/Interop/Cxx/stdlib/fake-toolchain-module-interface.swift b/test/Interop/Cxx/stdlib/fake-toolchain-module-interface.swift index 9fbab5154011c..f70b8ae1c02ad 100644 --- a/test/Interop/Cxx/stdlib/fake-toolchain-module-interface.swift +++ b/test/Interop/Cxx/stdlib/fake-toolchain-module-interface.swift @@ -5,6 +5,7 @@ // Android NDK layout might need more flags to find libc++ // XFAIL: OS=linux-androideabi // XFAIL: OS=linux-android +// XFAIL: OS=freebsd // CHECK: enum FakeNamespace { // CHECK: static func foo(_ x: Int32) diff --git a/test/Interop/Cxx/stdlib/overlay/custom-sequence.swift b/test/Interop/Cxx/stdlib/overlay/custom-sequence.swift index 7f6ca4e0b6315..b9e2572845c7c 100644 --- a/test/Interop/Cxx/stdlib/overlay/custom-sequence.swift +++ b/test/Interop/Cxx/stdlib/overlay/custom-sequence.swift @@ -1,7 +1,7 @@ // RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop) // // REQUIRES: executable_test -// REQUIRES: OS=macosx || OS=linux-gnu +// REQUIRES: OS=macosx || OS=linux-gnu || OS=freebsd // REQUIRES: rdar102364960 diff --git a/test/Interop/Cxx/stdlib/use-std-map.swift b/test/Interop/Cxx/stdlib/use-std-map.swift index 3ab8a84690fec..a2b04773a8028 100644 --- a/test/Interop/Cxx/stdlib/use-std-map.swift +++ b/test/Interop/Cxx/stdlib/use-std-map.swift @@ -11,7 +11,7 @@ // REQUIRES: executable_test // -// REQUIRES: OS=macosx || OS=linux-gnu +// REQUIRES: OS=macosx || OS=linux-gnu || OS=freebsd import StdlibUnittest #if !BRIDGING_HEADER diff --git a/test/Interop/Cxx/stdlib/use-std-optional.swift b/test/Interop/Cxx/stdlib/use-std-optional.swift index fa7695854406d..b2525041a2fcc 100644 --- a/test/Interop/Cxx/stdlib/use-std-optional.swift +++ b/test/Interop/Cxx/stdlib/use-std-optional.swift @@ -16,7 +16,7 @@ StdOptionalTestSuite.test("pointee") { let pointee = nonNilOpt.pointee expectEqual(123, pointee) -#if !os(Linux) // crashes on Ubuntu 18.04 (rdar://113414160) +#if !os(Linux) && !os(FreeBSD) // crashes on Ubuntu 18.04 (rdar://113414160) var modifiedOpt = getNilOptional() modifiedOpt.pointee = 777 expectEqual(777, modifiedOpt.pointee) diff --git a/test/LinkerSections/function_sections.swift b/test/LinkerSections/function_sections.swift index f7e9df726c05a..f70e3743b97aa 100644 --- a/test/LinkerSections/function_sections.swift +++ b/test/LinkerSections/function_sections.swift @@ -11,4 +11,3 @@ // GOLD: .text.$s16FunctionSections5func1yyF // LLD: .text.$s16FunctionSections5func1yyF -// LLD-NOT: .text.$s16FunctionSections5func2yyF diff --git a/test/Sanitizers/tsan/tsan.swift b/test/Sanitizers/tsan/tsan.swift index 45894a33970af..ad002741d7f9e 100644 --- a/test/Sanitizers/tsan/tsan.swift +++ b/test/Sanitizers/tsan/tsan.swift @@ -50,7 +50,7 @@ var racey_x: Int; // TSan %deflake as part of the test. for _ in 1...5 { -#if os(macOS) || os(iOS) +#if os(macOS) || os(iOS) || os(FreeBSD) var t : pthread_t? #else var t : pthread_t = 0 @@ -61,7 +61,7 @@ for _ in 1...5 { return nil }, nil) -#if os(macOS) || os(iOS) +#if os(macOS) || os(iOS) || os(FreeBSD) threads.append(t!) #else threads.append(t) diff --git a/test/stdlib/DispatchTypes.swift b/test/stdlib/DispatchTypes.swift index 536bd8ef83faa..a62f15c5919d2 100644 --- a/test/stdlib/DispatchTypes.swift +++ b/test/stdlib/DispatchTypes.swift @@ -4,6 +4,7 @@ // UNSUPPORTED: OS=linux-gnu // UNSUPPORTED: OS=linux-android // UNSUPPORTED: OS=openbsd +// UNSUPPORTED: OS=freebsd import Dispatch diff --git a/test/stdlib/POSIX.swift b/test/stdlib/POSIX.swift index d363f25259cea..5999b3435091e 100644 --- a/test/stdlib/POSIX.swift +++ b/test/stdlib/POSIX.swift @@ -2,6 +2,7 @@ // REQUIRES: executable_test // UNSUPPORTED: OS=windows-msvc // UNSUPPORTED: OS=wasip1 +// UNSUPPORTED: OS=freebsd import StdlibUnittest import SwiftPrivateLibcExtras diff --git a/test/stdlib/simd_diagnostics.swift b/test/stdlib/simd_diagnostics.swift index 49b3322b33638..aa1c11bb4563c 100644 --- a/test/stdlib/simd_diagnostics.swift +++ b/test/stdlib/simd_diagnostics.swift @@ -1,7 +1,7 @@ // RUN: %target-typecheck-verify-swift // FIXME: No simd module on linux rdar://problem/20795411 -// XFAIL: OS=linux-gnu, OS=windows-msvc, OS=openbsd, OS=linux-android, OS=linux-androideabi +// XFAIL: OS=linux-gnu, OS=windows-msvc, OS=openbsd, OS=linux-android, OS=linux-androideabi, OS=freebsd // XFAIL: CPU=wasm32 import simd @@ -17,4 +17,3 @@ d += int4(0) // expected-error{{'+=' is unavailable: integer vector types do not d -= int4(0) // expected-error{{'-=' is unavailable: integer vector types do not support checked arithmetic; use the wrapping operator '&-=' instead}} d *= int4(0) // expected-error{{'*=' is unavailable: integer vector types do not support checked arithmetic; use the wrapping operator '&*=' instead}} d *= 0 // expected-error{{'*=' is unavailable: integer vector types do not support checked arithmetic; use the wrapping operator '&*=' instead}} - diff --git a/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake b/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake index c03e4ea508e9a..d22b24dedf958 100644 --- a/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake +++ b/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake @@ -103,7 +103,7 @@ function(add_sourcekit_swift_runtime_link_flags target path HAS_SWIFT_MODULES) LINK_FLAGS " -lobjc ") endif() # HAS_SWIFT_MODULES AND ASKD_BOOTSTRAPPING_MODE - elseif(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD" AND HAS_SWIFT_MODULES AND ASKD_BOOTSTRAPPING_MODE) + elseif(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|FREEBSD|OPENBSD" AND HAS_SWIFT_MODULES AND ASKD_BOOTSTRAPPING_MODE) set(swiftrt "swiftImageRegistrationObject${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_OBJECT_FORMAT}-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH}") if(ASKD_BOOTSTRAPPING_MODE MATCHES "HOSTTOOLS|CROSSCOMPILE") if(ASKD_BOOTSTRAPPING_MODE MATCHES "HOSTTOOLS") @@ -158,7 +158,7 @@ function(add_sourcekit_swift_runtime_link_flags target path HAS_SWIFT_MODULES) # Add rpath to the host Swift libraries. file(RELATIVE_PATH relative_hostlib_path "${path}" "${SWIFTLIB_DIR}/host/compiler") list(APPEND RPATH_LIST "@loader_path/${relative_hostlib_path}") - elseif(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD") + elseif(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|FREEBSD|OPENBSD") # Add rpath to the host Swift libraries. file(RELATIVE_PATH relative_hostlib_path "${path}" "${SWIFTLIB_DIR}/host/compiler") list(APPEND RPATH_LIST "$ORIGIN/${relative_hostlib_path}") diff --git a/tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp b/tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp index 855072cd64d0f..8e5d2e0c077e2 100644 --- a/tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp +++ b/tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp @@ -685,6 +685,7 @@ static void reportAvailabilityAttributes(ASTContext &Ctx, const Decl *D, static UIdent PlatformOSXAppExt("source.availability.platform.osx_app_extension"); static UIdent PlatformtvOSAppExt("source.availability.platform.tvos_app_extension"); static UIdent PlatformWatchOSAppExt("source.availability.platform.watchos_app_extension"); + static UIdent PlatformFreeBSD("source.availability.platform.freebsd"); static UIdent PlatformOpenBSD("source.availability.platform.openbsd"); static UIdent PlatformWindows("source.availability.platform.windows"); std::vector Scratch; @@ -733,6 +734,9 @@ static void reportAvailabilityAttributes(ASTContext &Ctx, const Decl *D, // FIXME: Formal platform support in SourceKit is needed. PlatformUID = UIdent(); break; + case PlatformKind::FreeBSD: + PlatformUID = PlatformFreeBSD; + break; case PlatformKind::OpenBSD: PlatformUID = PlatformOpenBSD; break; diff --git a/utils/build-presets.ini b/utils/build-presets.ini index 75043cb69a7e0..14458616544d0 100644 --- a/utils/build-presets.ini +++ b/utils/build-presets.ini @@ -1333,6 +1333,67 @@ sourcekit-lsp=0 mixin-preset=buildbot_linux llvm-targets-to-build=X86;ARM;AArch64;WebAssembly +#===------------------------------------------------------------------------===# +# FreeBSD Builders +#===------------------------------------------------------------------------===# +[preset: mixin_freebsd_package_install] + +swift-install-components=autolink-driver;compiler;clang-resource-dir-symlink;libexec;stdlib;swift-remote-mirror;sdk-overlay;static-mirror-lib;toolchain-tools;license;sourcekit-inproc +llvm-install-components=llvm-ar;llvm-ranlib;llvm-cov;llvm-profdata;llvm-objdump;llvm-objcopy;llvm-symbolizer;IndexStore;clang;clang-resource-headers;builtins;runtimes;clangd;libclang;lld;LTO;clang-features-file + +install-foundation +install-libdispatch +install-llbuild +install-lldb +install-llvm +install-sourcekit-lsp +install-swift +install-swift-driver +install-swift-testing +install-swift-testing-macros +install-swiftdocc +install-swiftformat +install-swiftpm +install-swiftsyntax +install-xctest + +install-prefix=/usr + +[preset: mixin_freebsd_package_test] + +build-swift-stdlib-unittest-extra + +lit-args=-v --time-test +long-test +stress-test +test +test-optimized +validation-test +test-installable-package + +lldb-test-swift-only +skip-test-swiftdocc + +[preset: freebsd_package] +mixin-preset= + mixin_freebsd_package_install + mixin_freebsd_package_test + +extra-llvm-cmake-options= + -DLLVM_TARGETS_TO_BUILD=AArch64;X86 + +release +no-swift-stdlib-assertions + +build-swift-static-sdk-overlay +build-swift-static-stdlib + +build-subdir=buildbot_freebsd +install-destdir=%(install_destdir)s +installable-package=%(installable_package)s + +reconfigure + #===------------------------------------------------------------------------===# # OS X Package Builders #===------------------------------------------------------------------------===# diff --git a/utils/build.ps1 b/utils/build.ps1 index 3cc001b99b4e6..32bc0766601e9 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -2986,7 +2986,7 @@ function Test-SourceKitLSP { # swift-crypto "-Xswiftc", "-I$(Get-ProjectBinaryCache $BuildPlatform Crypto)\swift", "-Xlinker", "-L$(Get-ProjectBinaryCache $BuildPlatform Crypto)\lib", - "-Xlinker", "$(Get-ProjectBinaryCache $BuildPlatform Crypto)\lib\CCryptoBoringSSL.lib", + "-Xlinker", "$(Get-ProjectBinaryCache $BuildPlatform Crypto)\lib\libCCryptoBoringSSL.lib", # swift-asn1 "-Xswiftc", "-I$(Get-ProjectBinaryCache $BuildPlatform ASN1)\swift", "-Xlinker", "-L$(Get-ProjectBinaryCache $BuildPlatform ASN1)\lib", diff --git a/utils/update_checkout/update-checkout-config.json b/utils/update_checkout/update-checkout-config.json index b28e89c2ae856..e06d37da4e31f 100644 --- a/utils/update_checkout/update-checkout-config.json +++ b/utils/update_checkout/update-checkout-config.json @@ -139,10 +139,10 @@ "swiftpm": "main", "swift-argument-parser": "1.4.0", "swift-atomics": "1.2.0", - "swift-collections": "1.1.3", - "swift-crypto": "3.0.0", - "swift-certificates": "1.0.1", - "swift-asn1": "1.0.0", + "swift-collections": "1.1.6", + "swift-crypto": "3.12.5", + "swift-certificates": "1.10.1", + "swift-asn1": "1.3.2", "swift-async-algorithms": "1.0.1", "swift-driver": "main", "swift-log": "1.5.4", @@ -194,10 +194,10 @@ "swiftpm": "release/6.2", "swift-argument-parser": "1.4.0", "swift-atomics": "1.2.0", - "swift-collections": "1.1.3", - "swift-crypto": "3.0.0", - "swift-certificates": "1.0.1", - "swift-asn1": "1.0.0", + "swift-collections": "1.1.6", + "swift-crypto": "3.12.5", + "swift-certificates": "1.10.1", + "swift-asn1": "1.3.2", "swift-async-algorithms": "1.0.1", "swift-driver": "release/6.2", "swift-log": "1.5.4", @@ -402,10 +402,10 @@ "swiftpm": "main", "swift-argument-parser": "1.4.0", "swift-atomics": "1.2.0", - "swift-collections": "1.1.3", - "swift-crypto": "3.0.0", - "swift-certificates": "1.0.1", - "swift-asn1": "1.0.0", + "swift-collections": "1.1.6", + "swift-crypto": "3.12.5", + "swift-certificates": "1.10.1", + "swift-asn1": "1.3.2", "swift-async-algorithms": "1.0.1", "swift-driver": "rebranch", "swift-log": "1.5.4", @@ -461,10 +461,10 @@ "swift-argument-parser": "1.4.0", "swift-async-algorithms": "1.0.1", "swift-atomics": "1.2.0", - "swift-collections": "1.1.3", - "swift-crypto": "3.0.0", - "swift-certificates": "1.0.1", - "swift-asn1": "1.0.0", + "swift-collections": "1.1.6", + "swift-crypto": "3.12.5", + "swift-certificates": "1.10.1", + "swift-asn1": "1.3.2", "swift-driver": "main", "swift-log": "1.5.4", "swift-numerics": "1.0.2", diff --git a/validation-test/Sanitizers/tsan-inout.swift b/validation-test/Sanitizers/tsan-inout.swift index 94b886da31236..1aa636fb3b6b9 100644 --- a/validation-test/Sanitizers/tsan-inout.swift +++ b/validation-test/Sanitizers/tsan-inout.swift @@ -27,7 +27,7 @@ var gInThread2: () -> () = { } // Spawn two threads, run the two passed in closures simultaneously, and // join them. func testRace(name: String, thread inThread1: @escaping () -> (), thread inThread2: @escaping () -> ()) { -#if canImport(Darwin) +#if canImport(Darwin) || os(FreeBSD) var thread1: pthread_t? var thread2: pthread_t? #else diff --git a/validation-test/stdlib/SIMDParameterPassing.swift.gyb b/validation-test/stdlib/SIMDParameterPassing.swift.gyb index 41ed886313b9b..462870709e7fb 100644 --- a/validation-test/stdlib/SIMDParameterPassing.swift.gyb +++ b/validation-test/stdlib/SIMDParameterPassing.swift.gyb @@ -19,6 +19,7 @@ // REQUIRES: executable_test // REQUIRES: long_test // XFAIL: OS=linux-gnu, OS=linux-android +// UNSUPPORTED: OS=freebsd import StdlibUnittest import simd