Skip to content

Commit c04488a

Browse files
committed
Merge pull request swiftlang#43 from dgrove-oss/swift-overlay-cp1
Initial integration of Swift overlay into libdispatch build
2 parents 1a9c57f + 67450cb commit c04488a

File tree

6 files changed

+277
-3
lines changed

6 files changed

+277
-3
lines changed

configure.ac

+14
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ AS_IF([test "x$enable_apple_tsd_optimizations" = "xyes"],
101101
[Define to use non-portable pthread TSD optimizations for Mac OS X)])]
102102
)
103103

104+
#
105+
# Enable building Swift overlay support into libdispatch
106+
#
107+
AC_ARG_WITH([swift-toolchain],
108+
[AS_HELP_STRING([--with-swift-toolchain], [Specify path to Swift toolchain])],
109+
[swift_toolchain_path=${withval}
110+
AC_DEFINE(HAVE_SWIFT, 1, [Define if building for Swift])
111+
SWIFTC="$swift_toolchain_path/bin/swiftc"
112+
have_swift=true],
113+
[have_swift=false]
114+
)
115+
AM_CONDITIONAL(HAVE_SWIFT, $have_swift)
116+
AC_SUBST([SWIFTC])
117+
104118
AC_USE_SYSTEM_EXTENSIONS
105119
AM_INIT_AUTOMAKE([foreign no-dependencies subdir-objects])
106120
LT_INIT([disable-static])

src/.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
provider.h
2+
module.map
3+
module.build.map
24
.libs
35
*.lo
46
*.la
5-
7+
*.o
8+
*.swiftmodule
9+
*.swiftdoc

src/Makefile.am

+36-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ libdispatch_la_SOURCES= \
4646
shims/tsd.h \
4747
shims/yield.h
4848

49+
EXTRA_libdispatch_la_SOURCES=
50+
EXTRA_libdispatch_la_DEPENDENCIES=
51+
4952
AM_CPPFLAGS=-I$(top_builddir) -I$(top_srcdir) \
5053
-I$(top_srcdir)/private -I$(top_srcdir)/os
5154

@@ -103,8 +106,39 @@ DTRACE_SOURCES=provider.h
103106
$(DTRACE) -h -s $< -o $@
104107
endif
105108

106-
BUILT_SOURCES=$(MIG_SOURCES) $(DTRACE_SOURCES)
109+
if HAVE_SWIFT
110+
libdispatch_la_SOURCES+=swift/swift_wrappers.c
111+
EXTRA_libdispatch_la_SOURCES+=swift/Dispatch.swift
112+
EXTRA_libdispatch_la_DEPENDENCIES+=$(abs_builddir)/Dispatch.o $(abs_builddir)/Dispatch.swiftmodule
113+
libdispatch_la_LIBADD+=$(abs_builddir)/Dispatch.o
114+
115+
SWIFT_MODULEMAPS=$(abs_builddir)/module.map $(abs_builddir)/module.build.map
116+
SWIFTMODULE_OBJECTS= \
117+
$(abs_builddir)/Dispatch.swiftmodule \
118+
$(abs_builddir)/Dispatch.swiftdoc \
119+
$(abs_builddir)/Dispatch.o
120+
121+
SWIFTC_FLAGS = -I$(abs_top_srcdir) -parse-as-library -Xcc -fblocks -Xcc -fmodule-map-file=module.build.map
122+
123+
$(abs_builddir)/module.build.map: $(abs_srcdir)/swift/module.map.in
124+
m4 -DPREFIX=$(abs_top_srcdir) $< > $@
125+
126+
$(abs_builddir)/module.map: $(abs_srcdir)/swift/module.map.in
127+
m4 -DPREFIX=$(includedir) $< > $@
128+
129+
$(abs_builddir)/Dispatch.o: $(abs_srcdir)/swift/Dispatch.swift $(abs_builddir)/module.build.map
130+
$(SWIFTC) $(SWIFTC_FLAGS) -c -o $@ $<
131+
132+
$(abs_builddir)/Dispatch.swiftmodule: $(abs_srcdir)/swift/Dispatch.swift $(abs_builddir)/module.build.map
133+
$(SWIFTC) $(SWIFTC_FLAGS) -emit-module -emit-module-path $@ $<
134+
135+
swiftdir=$(includedir)/Dispatch
136+
swift_HEADERS=$(abs_builddir)/module.map $(abs_builddir)/Dispatch.swiftmodule $(abs_builddir)/Dispatch.swiftdoc
137+
138+
endif
139+
140+
BUILT_SOURCES=$(MIG_SOURCES) $(DTRACE_SOURCES) $(SWIFT_MODULEMAPS)
107141
nodist_libdispatch_la_SOURCES=$(BUILT_SOURCES)
108-
CLEANFILES=$(BUILT_SOURCES)
142+
CLEANFILES=$(BUILT_SOURCES) $(SWIFTMODULE_OBJECTS)
109143
DISTCLEANFILES=pthread_machdep.h pthread System mach objc
110144

src/swift/Dispatch.swift

+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
@_exported import Dispatch
14+
15+
/// The type of blocks submitted to dispatch queues, which take no arguments
16+
/// and have no return value.
17+
///
18+
/// The dispatch_block_t typealias is different from usual closures in that it
19+
/// uses @convention(block). This is to avoid unnecessary bridging between
20+
/// C blocks and Swift closures, which interferes with Grand Central Dispatch
21+
/// APIs that depend on the referential identity of a block.
22+
public typealias dispatch_block_t = @convention(block) () -> Void
23+
24+
//===----------------------------------------------------------------------===//
25+
// Macros
26+
// FIXME: rdar://16851050 update API so these import better
27+
//===----------------------------------------------------------------------===//
28+
29+
// dispatch/io.h
30+
public var DISPATCH_IO_STREAM: dispatch_io_type_t {
31+
return 0
32+
}
33+
public var DISPATCH_IO_RANDOM: dispatch_io_type_t {
34+
return 1
35+
}
36+
37+
public var DISPATCH_IO_STOP: dispatch_io_close_flags_t {
38+
return 1
39+
}
40+
public var DISPATCH_IO_STRICT_INTERVAL: dispatch_io_interval_flags_t {
41+
return 1
42+
}
43+
44+
public var DISPATCH_QUEUE_SERIAL: dispatch_queue_attr_t {
45+
return nil
46+
}
47+
public var DISPATCH_CURRENT_QUEUE_LABEL: dispatch_queue_t {
48+
return nil
49+
}
50+
public var DISPATCH_TARGET_QUEUE_DEFAULT: dispatch_queue_t {
51+
return nil
52+
}
53+
public var DISPATCH_QUEUE_PRIORITY_HIGH: dispatch_queue_priority_t {
54+
return 2
55+
}
56+
public var DISPATCH_QUEUE_PRIORITY_DEFAULT: dispatch_queue_priority_t {
57+
return 0
58+
}
59+
public var DISPATCH_QUEUE_PRIORITY_LOW: dispatch_queue_priority_t {
60+
return -2
61+
}
62+
public var DISPATCH_QUEUE_PRIORITY_BACKGROUND: dispatch_queue_priority_t {
63+
return -32768
64+
}
65+
66+
/*
67+
FIXME: LINUX_PORT: qos_class_t not being imported
68+
@warn_unused_result
69+
public func dispatch_get_global_queue(identifier: qos_class_t,
70+
_ flags: UInt) -> dispatch_queue_t {
71+
return dispatch_get_global_queue(Int(identifier.rawValue), flags)
72+
}
73+
*/
74+
75+
public var DISPATCH_QUEUE_CONCURRENT: dispatch_queue_attr_t {
76+
return _swift_dispatch_queue_concurrent()
77+
}
78+
79+
@warn_unused_result
80+
@_silgen_name("_swift_dispatch_queue_concurrent")
81+
internal func _swift_dispatch_queue_concurrent() -> dispatch_queue_attr_t
82+
83+
// dispatch/data.h
84+
public var dispatch_data_empty: dispatch_data_t {
85+
return _swift_dispatch_data_empty()
86+
}
87+
88+
@warn_unused_result
89+
@_silgen_name("_swift_dispatch_data_empty")
90+
internal func _swift_dispatch_data_empty() -> dispatch_data_t
91+
92+
// dispatch/source.h
93+
// FIXME: DISPATCH_SOURCE_TYPE_*
94+
public var DISPATCH_PROC_EXIT: dispatch_source_proc_flags_t {
95+
return 0x80000000
96+
}
97+
public var DISPATCH_PROC_FORK: dispatch_source_proc_flags_t { return 0x40000000 }
98+
public var DISPATCH_PROC_EXEC: dispatch_source_proc_flags_t { return 0x20000000 }
99+
public var DISPATCH_PROC_SIGNAL: dispatch_source_proc_flags_t { return 0x08000000 }
100+
public var DISPATCH_VNODE_DELETE: dispatch_source_vnode_flags_t { return 0x1 }
101+
public var DISPATCH_VNODE_WRITE: dispatch_source_vnode_flags_t { return 0x2 }
102+
public var DISPATCH_VNODE_EXTEND: dispatch_source_vnode_flags_t { return 0x4 }
103+
public var DISPATCH_VNODE_ATTRIB: dispatch_source_vnode_flags_t { return 0x8 }
104+
public var DISPATCH_VNODE_LINK: dispatch_source_vnode_flags_t { return 0x10 }
105+
public var DISPATCH_VNODE_RENAME: dispatch_source_vnode_flags_t { return 0x20 }
106+
public var DISPATCH_VNODE_REVOKE: dispatch_source_vnode_flags_t { return 0x40 }
107+
public var DISPATCH_TIMER_STRICT: dispatch_source_timer_flags_t { return 1 }
108+
109+
public var DISPATCH_SOURCE_TYPE_DATA_ADD: dispatch_source_type_t {
110+
return _swift_dispatch_source_type_data_add()
111+
}
112+
public var DISPATCH_SOURCE_TYPE_DATA_OR: dispatch_source_type_t {
113+
return _swift_dispatch_source_type_data_or()
114+
}
115+
public var DISPATCH_SOURCE_TYPE_READ: dispatch_source_type_t {
116+
return _swift_dispatch_source_type_read()
117+
}
118+
public var DISPATCH_SOURCE_TYPE_PROC: dispatch_source_type_t {
119+
return _swift_dispatch_source_type_proc()
120+
}
121+
public var DISPATCH_SOURCE_TYPE_SIGNAL: dispatch_source_type_t {
122+
return _swift_dispatch_source_type_signal()
123+
}
124+
public var DISPATCH_SOURCE_TYPE_TIMER: dispatch_source_type_t {
125+
return _swift_dispatch_source_type_timer()
126+
}
127+
public var DISPATCH_SOURCE_TYPE_VNODE: dispatch_source_type_t {
128+
return _swift_dispatch_source_type_vnode()
129+
}
130+
public var DISPATCH_SOURCE_TYPE_WRITE: dispatch_source_type_t {
131+
return _swift_dispatch_source_type_write()
132+
}
133+
134+
@warn_unused_result
135+
@_silgen_name("_swift_dispatch_source_type_DATA_ADD")
136+
internal func _swift_dispatch_source_type_data_add() -> dispatch_source_type_t
137+
138+
@warn_unused_result
139+
@_silgen_name("_swift_dispatch_source_type_DATA_OR")
140+
internal func _swift_dispatch_source_type_data_or() -> dispatch_source_type_t
141+
142+
@warn_unused_result
143+
@_silgen_name("_swift_dispatch_source_type_PROC")
144+
internal func _swift_dispatch_source_type_proc() -> dispatch_source_type_t
145+
146+
@warn_unused_result
147+
@_silgen_name("_swift_dispatch_source_type_READ")
148+
internal func _swift_dispatch_source_type_read() -> dispatch_source_type_t
149+
150+
@warn_unused_result
151+
@_silgen_name("_swift_dispatch_source_type_SIGNAL")
152+
internal func _swift_dispatch_source_type_signal() -> dispatch_source_type_t
153+
154+
@warn_unused_result
155+
@_silgen_name("_swift_dispatch_source_type_TIMER")
156+
internal func _swift_dispatch_source_type_timer() -> dispatch_source_type_t
157+
158+
@warn_unused_result
159+
@_silgen_name("_swift_dispatch_source_type_VNODE")
160+
internal func _swift_dispatch_source_type_vnode() -> dispatch_source_type_t
161+
162+
@warn_unused_result
163+
@_silgen_name("_swift_dispatch_source_type_WRITE")
164+
internal func _swift_dispatch_source_type_write() -> dispatch_source_type_t
165+
166+
// dispatch/time.h
167+
// DISPATCH_TIME_NOW: ok
168+
// DISPATCH_TIME_FOREVER: ok

src/swift/module.map.in

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Dispatch [system] {
2+
umbrella header "PREFIX/dispatch/dispatch.h"
3+
requires blocks
4+
export *
5+
link "dispatch"
6+
link "BlocksRuntime"
7+
}

src/swift/swift_wrappers.c

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include <dispatch/dispatch.h>
14+
15+
DISPATCH_EXPORT
16+
dispatch_queue_attr_t
17+
_swift_dispatch_queue_serial(void) {
18+
return DISPATCH_QUEUE_SERIAL;
19+
}
20+
21+
DISPATCH_EXPORT
22+
dispatch_queue_attr_t
23+
_swift_dispatch_queue_concurrent(void) {
24+
return DISPATCH_QUEUE_CONCURRENT;
25+
}
26+
27+
DISPATCH_EXPORT
28+
dispatch_data_t
29+
_swift_dispatch_data_empty(void) {
30+
return dispatch_data_empty;
31+
}
32+
33+
#define SOURCE(t) \
34+
DISPATCH_EXPORT \
35+
dispatch_source_type_t \
36+
_swift_dispatch_source_type_##t(void) { \
37+
return DISPATCH_SOURCE_TYPE_##t; \
38+
}
39+
40+
SOURCE(DATA_ADD)
41+
SOURCE(DATA_OR)
42+
SOURCE(PROC)
43+
SOURCE(READ)
44+
SOURCE(SIGNAL)
45+
SOURCE(TIMER)
46+
SOURCE(VNODE)
47+
SOURCE(WRITE)

0 commit comments

Comments
 (0)