-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[FreeBSD] Adding FreeBSD support #77836
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2562,6 +2562,10 @@ PlatformAvailability::PlatformAvailability(const LangOptions &langOpts) | |
case PlatformKind::visionOSApplicationExtension: | ||
break; | ||
|
||
case PlatformKind::FreeBSD: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we coalesce the non-Apple cases? |
||
deprecatedAsUnavailableMessage = ""; | ||
break; | ||
|
||
case PlatformKind::OpenBSD: | ||
deprecatedAsUnavailableMessage = ""; | ||
break; | ||
|
@@ -2609,6 +2613,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"; | ||
|
||
|
@@ -2680,6 +2687,10 @@ bool PlatformAvailability::treatDeprecatedAsUnavailable( | |
// No deprecation filter on xrOS | ||
return false; | ||
|
||
case PlatformKind::FreeBSD: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we coalesce? |
||
// No deprecation filter on FreeBSD | ||
return false; | ||
|
||
case PlatformKind::OpenBSD: | ||
// No deprecation filter on OpenBSD | ||
return false; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -244,6 +244,8 @@ getLinkerPlatformId(OriginallyDefinedInAttr::ActiveVersion Ver, | |
llvm_unreachable("cannot find platform kind"); | ||
case swift::PlatformKind::OpenBSD: | ||
llvm_unreachable("not used for this platform"); | ||
case swift::PlatformKind::FreeBSD: | ||
llvm_unreachable("not used for this platform"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we coalesce? (Also, nitpick, the order of FreeBSD relative to OpenBSD is inconsistent. It's not important in any practical sense, but consistency is a good thing.) |
||
case swift::PlatformKind::Windows: | ||
llvm_unreachable("not used for this platform"); | ||
case swift::PlatformKind::iOS: | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: platform order |
||||||||||
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,7 @@ public var environ: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?> { | |||||||||
} | ||||||||||
#endif | ||||||||||
#endif // SWIFT_STDLIB_HAS_ENVIRON | ||||||||||
|
||||||||||
#if os(FreeBSD) | ||||||||||
public let inet_pton = __inet_pton | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this header available universally? I think that this might need to be under a FreeBSD condition. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The gyb expands '${header}' to an include guarded by
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, any headers added to this file are just ignored if they don't exist, as there are already some OpenBSD-specific headers. Have you considered adding a FreeBSD overlay instead? You could take a look at the recent Musl, WASI, and Android overlays for examples. I know that's more work, but the WASI one isn't so bad, and FreeBSD may not be either. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's definitely on my radar! I'm not sure yet if I have to bandwidth to include that change in this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shoulda just called them all There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And yeah, the implementation is actually very difficult, especially when C++ gets involved. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for all the feedback! Sorry for the late reply I was extremely sick for the past 2 weeks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My plan is to put the overlay changes into a separate PR, due to size of diff is quite big and this is already a rather large PR (as you can imagine all instance of where I have a working implementation ready to go, either committing to this PR, or as a separate PR, depending on what will be more comfortable for you to review. Wdyt @al45tair @ian-twilightcoder @grynspan @finagolfin This also helps keep my head sane as I've been to maintaining quite a few separate trees of all the swift sub-projects locally to implement various feature for FreeBSD and it's getting quite messy. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no opinion either way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. overlay PR created. #79261 |
||
'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', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", "OPENBSD", "FREEBSD"]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: platform order |
||
link "m" | ||
% end | ||
% if CMAKE_SDK in ["LINUX", "FREEBSD", "OPENBSD", "CYGWIN"]: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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__) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: platf—okay you get the idea |
||
#include <stdint.h> | ||
typedef int64_t __swift_int64_t; | ||
typedef uint64_t __swift_uint64_t; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this actually need to be public? |
||
@usableFromInline | ||
let value: _Cell<umutex> | ||
|
||
@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) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you just change the call sites that are using the constructor? That would simplify the diff.