Skip to content

Commit

Permalink
Remove OpenFoundation dependency (OpenSwiftUIProject#36)
Browse files Browse the repository at this point in the history
* Remove OpenFoundation dependency

* Update TargetConditionals
  • Loading branch information
Kyle-Ye authored Feb 16, 2024
1 parent ea17b0a commit ce294c1
Show file tree
Hide file tree
Showing 10 changed files with 369 additions and 35 deletions.
11 changes: 1 addition & 10 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
{
"pins" : [
{
"identity" : "openfoundation",
"kind" : "remoteSourceControl",
"location" : "https://github.com/OpenSwiftUIProject/OpenFoundation",
"state" : {
"revision" : "cd2cdb300d53e3e68fda8b690a703a7c5096d9d0",
"version" : "0.0.2"
}
},
{
"identity" : "opengraph",
"kind" : "remoteSourceControl",
"location" : "https://github.com/OpenSwiftUIProject/OpenGraph",
"state" : {
"branch" : "main",
"revision" : "d4f467d9780fcca4c268a1242a8ae90f61377c3d"
"revision" : "8f0376278186b6e24e8d7a07a560f3efaa2fef1d"
}
},
{
Expand Down
5 changes: 1 addition & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ let package = Package(
),
// C Shims for OpenSwiftUI
.target(
name: "OpenSwiftUIShims",
dependencies: [.product(name: "OpenFoundation", package: "OpenFoundation")]
name: "OpenSwiftUIShims"
),
.binaryTarget(name: "CoreServices", path: "PrivateFrameworks/CoreServices.xcframework"),
openSwiftUITarget,
Expand Down Expand Up @@ -164,12 +163,10 @@ if compatibilityTestCondition {
let useLocalDeps = envEnable("OPENSWIFTUI_USE_LOCAL_DEPS")
if useLocalDeps {
package.dependencies += [
.package(path: "../OpenFoundation"),
.package(path: "../OpenGraph"),
]
} else {
package.dependencies += [
.package(url: "https://github.com/OpenSwiftUIProject/OpenFoundation", from: "0.0.1"),
// FIXME: on Linux platform: OG contains unsafe build flags which prevents us using version dependency
.package(url: "https://github.com/OpenSwiftUIProject/OpenGraph", branch: "main"),
]
Expand Down
8 changes: 4 additions & 4 deletions Sources/OpenSwiftUIShims/ProtocolDescriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

#include "ProtocolDescriptor.h"

OF_EXPORT
OPENSWIFTUI_EXPORT
const void *$s11OpenSwiftUI4ViewMp;

OF_EXPORT
OPENSWIFTUI_EXPORT
const void *_viewProtocolDescriptor(void) {
return &$s11OpenSwiftUI4ViewMp;
}

OF_EXPORT
OPENSWIFTUI_EXPORT
const void *$s11OpenSwiftUI12ViewModifierMp;

OF_EXPORT
OPENSWIFTUI_EXPORT
const void *_viewModifierProtocolDescriptor(void) {
return &$s11OpenSwiftUI12ViewModifierMp;
}
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUIShims/dyld_Private.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "dyld_Private.h"

#if !TARGET_OS_DARWIN
#if !OPENSWIFTUI_TARGET_OS_DARWIN
bool dyld_program_sdk_at_least(dyld_build_version_t version) {
return true;
}
Expand Down
10 changes: 6 additions & 4 deletions Sources/OpenSwiftUIShims/include/LockedPointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,27 @@
#ifndef LockedPointer_h
#define LockedPointer_h

#include <OpenFoundation/OpenFoundation.h>
#include "OpenSwiftUIBase.h"

#if __has_include(<os/lock.h>)
#include <os/lock.h>
#define OPENSWIFTUI_LOCK_T os_unfair_lock
#define OPENSWIFTUI_LOCK_INIT OS_UNFAIR_LOCK_INIT
#define OPENSWIFTUI_LOCK_LOCK(lock) os_unfair_lock_lock(lock)
#define OPENSWIFTUI_LOCK_UNLOCK(lock) os_unfair_lock_unlock(lock)
#elif TARGET_OS_LINUX
#elif OPENSWIFTUI_TARGET_OS_LINUX
#define OPENSWIFTUI_LOCK_T int32_t
#include <stdint.h>
#include <unistd.h>
OF_INLINE void __OPENSWIFTUI_Lock(volatile OPENSWIFTUI_LOCK_T * _Nonnull lock) {
OPENSWIFTUI_INLINE
void __OPENSWIFTUI_Lock(volatile OPENSWIFTUI_LOCK_T * _Nonnull lock) {
while (__sync_val_compare_and_swap(lock, 0, ~0) != 0) {
sleep(0);
}
}

OF_INLINE void __OPENSWIFTUI_Unlock(volatile OPENSWIFTUI_LOCK_T * _Nonnull lock) {
OPENSWIFTUI_INLINE
void __OPENSWIFTUI_Unlock(volatile OPENSWIFTUI_LOCK_T * _Nonnull lock) {
__sync_synchronize();
*lock = 0;
}
Expand Down
70 changes: 70 additions & 0 deletions Sources/OpenSwiftUIShims/include/OpenSwiftUIBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// OpenSwiftUIBase.h
//
//
// Created by Kyle on 2024/2/16.
//

#ifndef OpenSwiftUIBase_h
#define OpenSwiftUIBase_h

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include "OpenSwiftUITargetConditionals.h"

#if defined(__cplusplus)
#define OPENSWIFTUI_INLINE inline
#else
#define OPENSWIFTUI_INLINE
#endif

#if defined(__cplusplus)
#define OPENSWIFTUI_EXTERN_C_BEGIN extern "C" {
#define OPENSWIFTUI_EXTERN_C_END }
#else
#define OPENSWIFTUI_EXTERN_C_BEGIN
#define OPENSWIFTUI_EXTERN_C_END
#endif

#if __has_feature(assume_nonnull)
#define OPENSWIFTUI_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin")
#define OPENSWIFTUI_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end")
#else
#define OPENSWIFTUI_ASSUME_NONNULL_BEGIN
#define OPENSWIFTUI_ASSUME_NONNULL_END
#endif

#if OPENSWIFTUI_TARGET_OS_WIN32
#if defined(__cplusplus)
#define _OPENSWIFTUI_EXTERN extern "C"
#else
#define _OPENSWIFTUI_EXTERN extern
#endif

#if defined(_WINDLL)
#if defined(OPENSWIFTUI_EXPORTS)
#define OPENSWIFTUI_EXPORT _OPENSWIFTUI_EXTERN __declspec(dllexport)
#else
#define OPENSWIFTUI_EXPORT _OPENSWIFTUI_EXTERN __declspec(dllimport)
#endif
#else
#define OPENSWIFTUI_EXPORT _OPENSWIFTUI_EXTERN
#endif
#else
#define OPENSWIFTUI_EXPORT extern
#endif

#if __has_attribute(swift_private)
# define OPENSWIFTUI_REFINED_FOR_SWIFT __attribute__((swift_private))
#else
# define OPENSWIFTUI_REFINED_FOR_SWIFT
#endif

#if __has_attribute(swift_name)
# define OPENSWIFTUI_SWIFT_NAME(_name) __attribute__((swift_name(#_name)))
#else
# define OPENSWIFTUI_SWIFT_NAME(_name)
#endif

#endif /* OpenSwiftUIBase_h */
Loading

0 comments on commit ce294c1

Please sign in to comment.