Skip to content

Commit

Permalink
Fix build issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Mar 16, 2024
1 parent 263a51b commit 7ecf223
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
17 changes: 16 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ let openSwiftUICompatibilityTestTarget = Target.testTarget(
swiftSettings: sharedSwiftSettings
)

let swiftBinPath = Context.environment["_"] ?? ""
let swiftBinURL = URL(fileURLWithPath: swiftBinPath)
let SDKPath = swiftBinURL.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().path
let includePath = SDKPath.appending("/usr/lib/swift_static")

let package = Package(
name: "OpenSwiftUI",
platforms: [
Expand All @@ -87,7 +92,11 @@ let package = Package(
]
),
.target(
name: "COpenSwiftUI"
name: "COpenSwiftUI",
cSettings: [
.unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)),
.define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)),
]
),
.binaryTarget(name: "CoreServices", path: "PrivateFrameworks/CoreServices.xcframework"),
openSwiftUITarget,
Expand Down Expand Up @@ -196,3 +205,9 @@ if useLocalDeps {
.package(url: "https://github.com/OpenSwiftUIProject/OpenGraph", branch: "main"),
]
}

extension [Platform] {
static var nonDarwinPlatforms: [Platform] {
[.linux, .android, .wasi, .openbsd, .windows]
}
}
18 changes: 17 additions & 1 deletion Sources/COpenSwiftUI/MovableLock.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
extern pthread_t pthread_main_thread_np(void);

void wait_for_lock(MovableLock lock, pthread_t thread);
void sync_main_callback();
void sync_main_callback(MovableLock lock);

MovableLock _MovableLockCreate() {
#if OPENSWIFTUI_TARGET_OS_DARWIN
static_assert(sizeof(MovableLock_t) == 0x100, "MovebleLock size is not 0x100 bytes.");
#endif
MovableLock lock = calloc(1, sizeof(MovableLock_t));
if (!lock) {
abort();
Expand Down Expand Up @@ -49,6 +51,7 @@ bool _MovableLockIsOuterMostOwner(MovableLock lock) {
}

void _MovableLockLock(MovableLock lock) {
#if OPENSWIFTUI_TARGET_OS_DARWIN
pthread_t owner = pthread_self();
if (owner == lock->owner) {
lock->level += 1;
Expand All @@ -60,9 +63,11 @@ void _MovableLockLock(MovableLock lock) {
}
lock->owner = owner;
lock->level = 1;
#endif
}

void _MovableLockUnlock(MovableLock lock) {
#if OPENSWIFTUI_TARGET_OS_DARWIN
lock->level -= 1;
if (lock->level != 0) {
return;
Expand All @@ -72,9 +77,11 @@ void _MovableLockUnlock(MovableLock lock) {
}
lock->owner = NULL;
pthread_mutex_unlock(&lock->mutex);
#endif
}

void _MovableLockSyncMain(MovableLock lock, const void *context, void (*function)(const void *context)) {
#if OPENSWIFTUI_TARGET_OS_DARWIN
if (pthread_self() == lock->main) {
function(context);
} else {
Expand All @@ -93,9 +100,11 @@ void _MovableLockSyncMain(MovableLock lock, const void *context, void (*function
pthread_cond_wait(&lock->cond2, &lock->mutex);
}
}
#endif
}

void _MovableLockWait(MovableLock lock) {
#if OPENSWIFTUI_TARGET_OS_DARWIN
pthread_t owner = pthread_self();
uint32_t level = lock->level;
lock->level = 0;
Expand All @@ -109,13 +118,17 @@ void _MovableLockWait(MovableLock lock) {
}
lock->owner = owner;
lock->level = level;
#endif
}

void _MovableLockBroadcast(MovableLock lock) {
#if OPENSWIFTUI_TARGET_OS_DARWIN
pthread_cond_broadcast(&lock->cond3);
#endif
}

void wait_for_lock(MovableLock lock, pthread_t owner) {
#if OPENSWIFTUI_TARGET_OS_DARWIN
lock->unknown += 1;
if (lock->main == owner) {
lock->unknown5 = 1;
Expand All @@ -137,10 +150,13 @@ void wait_for_lock(MovableLock lock, pthread_t owner) {
lock->unknown5 = 0;
}
lock->unknown -= 1;
#endif
}

void sync_main_callback(MovableLock lock) {
#if OPENSWIFTUI_TARGET_OS_DARWIN
_MovableLockLock(lock);
lock->unknown4 = 0;
_MovableLockUnlock(lock);
#endif
}
2 changes: 2 additions & 0 deletions Sources/OpenSwiftUI/Core/Log/Signpost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
// Status: WIP
// ID: 34756F646CF7AC3DBE2A8E0B344C962F

#if canImport(os)
import os.signpost
#endif

struct Signpost {
private let style: Style
Expand Down
2 changes: 2 additions & 0 deletions Tests/OpenSwiftUITests/COpenSwiftUI/MovableLockTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import COpenSwiftUI
import Testing

#if canImport(Darwin)
final class MovableLockTests {
let lock: MovableLock

Expand All @@ -31,3 +32,4 @@ final class MovableLockTests {
#expect(lock.isOuterMostOwner() == false)
}
}
#endif

0 comments on commit 7ecf223

Please sign in to comment.