Skip to content

Commit

Permalink
remove unsafe flags so we can use package as a versioned dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
lhoward committed Nov 23, 2024
1 parent 7b1ec03 commit 8499ae7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 30 deletions.
35 changes: 7 additions & 28 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@ func tryGuessSwiftLibRoot() -> String {
}

let SwiftLibRoot = tryGuessSwiftLibRoot()
let EnableASAN = false
var ASANCFlags: [String] = []
var ASANSwiftFlags: [String] = []
var ASANLinkerSettings: [LinkerSetting] = []

if EnableASAN {
ASANCFlags.append("-fsanitize=address")
ASANSwiftFlags.append("-sanitize=address")
ASANLinkerSettings.append(LinkerSetting.linkedLibrary("asan"))
}

enum CQHandlerType: String {
case dispatch = "DISPATCH_IO_URING"
Expand Down Expand Up @@ -75,14 +65,12 @@ let package = Package(
cSettings: [
.define("_XOPEN_SOURCE=700"),
.define("_DEFAULT_SOURCE"),
.define("\(cqHandlerType.rawValue)=1"),
.unsafeFlags(["-I", SwiftLibRoot] + ASANCFlags),
.define("\(cqHandlerType.rawValue)=1")
],
cxxSettings: [
.define("_XOPEN_SOURCE=700"),
.define("_DEFAULT_SOURCE"),
.define("\(cqHandlerType.rawValue)=1"),
.unsafeFlags(["-I", SwiftLibRoot] + ASANCFlags),
]
),
.target(
Expand All @@ -103,7 +91,6 @@ let package = Package(
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
.unsafeFlags(ASANSwiftFlags),
]
),
.testTarget(
Expand All @@ -118,52 +105,44 @@ let package = Package(
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms")],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
.unsafeFlags(ASANSwiftFlags),
]
),
.target(
name: "IORingFoundation",
dependencies: ["IORingUtils"],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
.unsafeFlags(ASANSwiftFlags),
]
),
.executableTarget(
name: "IORingCat",
dependencies: ["IORing", "IORingUtils"],
path: "Examples/IORingCat",
linkerSettings: [] + ASANLinkerSettings
path: "Examples/IORingCat"
),
.executableTarget(
name: "IORingCopy",
dependencies: ["IORing", "IORingUtils"],
path: "Examples/IORingCopy",
linkerSettings: [] + ASANLinkerSettings
path: "Examples/IORingCopy"
),
.executableTarget(
name: "IORingTCPEcho",
dependencies: ["IORing", "IORingUtils"],
path: "Examples/IORingTCPEcho",
linkerSettings: [] + ASANLinkerSettings
path: "Examples/IORingTCPEcho"
),
.executableTarget(
name: "IORingUDPClient",
dependencies: ["IORing", "IORingUtils"],
path: "Examples/IORingUDPClient",
linkerSettings: [] + ASANLinkerSettings
path: "Examples/IORingUDPClient"
),
.executableTarget(
name: "IORingUDPServer",
dependencies: ["IORing", "IORingUtils"],
path: "Examples/IORingUDPServer",
linkerSettings: [] + ASANLinkerSettings
path: "Examples/IORingUDPServer"
),
.executableTarget(
name: "IORingDeviceSpy",
dependencies: ["IORing", "IORingUtils"],
path: "Examples/IORingDeviceSpy",
linkerSettings: [] + ASANLinkerSettings
path: "Examples/IORingDeviceSpy"
),
],
cLanguageStandard: .c18,
Expand Down
47 changes: 45 additions & 2 deletions Sources/CIORingShims/CQHandlerInternal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,53 @@
#pragma once

#include <liburing.h>
#include <dispatch/dispatch.h>
#include <Block/Block.h>
#include <cassert>

#if __has_include(<Block.h>)
#include <Block.h>
#elif __has_include(<Block/Block.h>)
#include <Block/Block.h>
#else
extern "C" void *_Block_copy(const void *);
extern "C" void _Block_release(const void *);
#endif

#if __has_include(<dispatch/dispatch.h>)
#include <dispatch/dispatch.h>
#else
// on Linux dispatch/dispatch.h is only available with unsafe Swift flags,
// which preclude the use of this package as a versioned dependency
struct dispatch_source_type_s {} __attribute__((aligned(sizeof(uintptr_t))));

typedef struct dispatch_source_s *dispatch_source_t;
typedef struct dispatch_queue_s *dispatch_queue_t;
typedef const struct dispatch_source_type_s *dispatch_source_type_t;

typedef void (^dispatch_block_t)(void);

extern "C" {
extern const struct dispatch_source_type_s _dispatch_source_type_read;

void dispatch_release(void *object);
void dispatch_resume(void *object);

void *dispatch_get_context(void *object);
void dispatch_set_context(void *object, void *context);

void dispatch_source_cancel(void *object);
void dispatch_source_set_event_handler(dispatch_source_t source, dispatch_block_t handler);
void dispatch_source_set_cancel_handler(dispatch_source_t source, dispatch_block_t handler);

dispatch_queue_t dispatch_get_global_queue(intptr_t identifier, uintptr_t flags);
dispatch_source_t dispatch_source_create(dispatch_source_type_t type, uintptr_t handle, uintptr_t mask, dispatch_queue_t queue);
}

#define dispatch_cancel dispatch_source_cancel
#define DISPATCH_QUEUE_PRIORITY_DEFAULT 0
#define DISPATCH_SOURCE_TYPE_READ (&_dispatch_source_type_read)

#endif

#include "CIORingShims.h"

int io_uring_cq_handler(struct io_uring *ring);
Expand Down

0 comments on commit 8499ae7

Please sign in to comment.