Skip to content

Commit b5333f0

Browse files
committed
Merge branch 'master' into das-swift-3.0-branch-backport-134-135-139-138-140
2 parents e2d5eb5 + ae1f7e8 commit b5333f0

File tree

11 files changed

+1244
-107
lines changed

11 files changed

+1244
-107
lines changed

INSTALL renamed to INSTALL.md

Lines changed: 70 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Grand Central Dispatch (GCD)
1+
## Grand Central Dispatch (GCD)
22

33
GCD is a concurrent programming framework first shipped with Mac OS X Snow
44
Leopard. This package is an open source bundling of libdispatch, the core
@@ -8,7 +8,7 @@ Leopard and FreeBSD 9-CURRENT, are required to use libdispatch. Linux is
88
supported, but requires specific packages to be installed (see Linux
99
section at the end of the file). Other systems are currently unsupported.
1010

11-
I. Configuring and installing libdispatch (general comments)
11+
### Configuring and installing libdispatch (general comments)
1212

1313
GCD is built using autoconf, automake, and libtool, and has a number of
1414
compile-time configuration options that should be reviewed before starting.
@@ -41,59 +41,83 @@ Note that once libdispatch is installed into a Swift toolchain, that
4141
toolchain cannot be used to compile libdispatch again (you must 'make uninstall'
4242
libdispatch from the toolchain before using it to rebuild libdispatch).
4343

44-
II. Building and installing on OS X
44+
You can also use the build-toolchain script to create a toolchain
45+
that includes libdispatch on Linux:
46+
47+
1. Add libdispatch and install-libdispatch lines to ./swift/utils/build-presets.ini under `[preset: buildbot_linux]` section, as following:
48+
49+
```
50+
[preset: buildbot_linux]
51+
mixin-preset=mixin_linux_installation
52+
build-subdir=buildbot_linux
53+
lldb
54+
release
55+
test
56+
validation-test
57+
long-test
58+
libdispatch
59+
foundation
60+
lit-args=-v
61+
dash-dash
62+
63+
install-libdispatch
64+
install-foundation
65+
reconfigure
66+
```
67+
68+
2. Run:
69+
70+
```
71+
./swift/utils/build-toolchain local.swift
72+
```
73+
74+
Note that adding libdispatch in build-presets.ini is for Linux only as Swift on macOS platforms uses the system installed libdispatch, so its not required.
75+
76+
### Building and installing on OS X
4577
4678
The following configure options may be of general interest:
4779
48-
--with-apple-libpthread-source
80+
`--with-apple-libpthread-source`
4981
50-
Specify the path to Apple's libpthread package, so that appropriate headers
82+
Specify the path to Apple's libpthread package, so that appropriate headers
5183
can be found and used.
5284
53-
--with-apple-libplatform-source
85+
`--with-apple-libplatform-source`
5486
55-
Specify the path to Apple's libplatform package, so that appropriate headers
87+
Specify the path to Apple's libplatform package, so that appropriate headers
5688
can be found and used.
5789
58-
--with-apple-libclosure-source
90+
`--with-apple-libclosure-source`
5991
60-
Specify the path to Apple's Libclosure package, so that appropriate headers
92+
Specify the path to Apple's Libclosure package, so that appropriate headers
6193
can be found and used.
6294
63-
--with-apple-xnu-source
95+
`--with-apple-xnu-source`
6496
65-
Specify the path to Apple's XNU package, so that appropriate headers can be
97+
Specify the path to Apple's XNU package, so that appropriate headers can be
6698
found and used.
6799
68-
--with-blocks-runtime
100+
`--with-blocks-runtime`
69101
70-
On systems where -fblocks is supported, specify an additional library path
71-
in which libBlocksRuntime can be found. This is not required on OS X,
72-
where the Blocks runtime is included in libSystem, but is required on
73-
FreeBSD.
102+
On systems where -fblocks is supported, specify an additional library path in which libBlocksRuntime can be found. This is not required on OS X, where the Blocks runtime is included in libSystem, but is required on FreeBSD.
74103
75104
The following options are likely to only be useful when building libdispatch on
76105
OS X as a replacement for /usr/lib/system/libdispatch.dylib:
77106
78-
--with-apple-objc4-source
107+
`--with-apple-objc4-source`
79108
80-
Specify the path to Apple's objc4 package, so that appropriate headers can
109+
Specify the path to Apple's objc4 package, so that appropriate headers can
81110
be found and used.
82111
83-
--disable-libdispatch-init-constructor
112+
`--disable-libdispatch-init-constructor`
84113
85-
Do not tag libdispatch's init routine as __constructor, in which case it
86-
must be run manually before libdispatch routines can be called. This is the
87-
default when building on OS X. For /usr/lib/system/libdispatch.dylib
88-
the init routine is called automatically during process start.
114+
Do not tag libdispatch's init routine as __constructor, in which case it must be run manually before libdispatch routines can be called. This is the default when building on OS X. For /usr/lib/system/libdispatch.dylib the init routine is called automatically during process start.
89115
90-
--enable-apple-tsd-optimizations
116+
`--enable-apple-tsd-optimizations`
91117
92-
Use a non-portable allocation scheme for pthread per-thread data (TSD) keys
93-
when building libdispatch for /usr/lib/system on OS X. This should not
94-
be used on other OS's, or on OS X when building a stand-alone library.
118+
Use a non-portable allocation scheme for pthread per-thread data (TSD) keys when building libdispatch for /usr/lib/system on OS X. This should not be used on other OS's, or on OS X when building a stand-alone library.
95119
96-
Typical configuration commands
120+
#### Typical configuration commands
97121
98122
The following command lines create the configuration required to build
99123
libdispatch for /usr/lib/system on OS X El Capitan:
@@ -112,7 +136,7 @@ libdispatch for /usr/lib/system on OS X El Capitan:
112136
--with-apple-objc4-source=/path/to/10.11.0/objc4-680
113137
make check
114138
115-
III. Building and installing for FreeBSD
139+
### Building and installing for FreeBSD
116140
117141
Typical configuration line for FreeBSD 8.x and 9.x to build libdispatch with
118142
clang and blocks support:
@@ -121,33 +145,35 @@ clang and blocks support:
121145
./configure CC=clang --with-blocks-runtime=/usr/local/lib
122146
make check
123147
124-
IV. Building and installing for Linux
148+
### Building and installing for Linux
125149
126150
Note that libdispatch development and testing is done only
127151
on Ubuntu; currently supported versions are 14.04, 15.10 and 16.04.
128152
129-
(1) The first thing to do is install required packages:
130-
1a. Install build tools and clang compiler.
131-
sudo apt-get install autoconf libtool pkg-config clang
132-
1b. Install dtrace (to generate provider.h)
133-
sudo apt-get install systemtap-sdt-dev
134-
1c. Install additional libdispatch dependencies
135-
sudo apt-get install libblocksruntime-dev libkqueue-dev libbsd-dev
136-
137-
Note: compiling libdispatch requires clang 3.8 or better and
153+
1. The first thing to do is install required packages:
154+
155+
`sudo apt-get install autoconf libtool pkg-config clang systemtap-sdt-dev libbsd-dev`
156+
157+
Note: compiling libdispatch requires clang 3.8 or better and
138158
the gold linker. If the default clang on your Ubuntu version is
139159
too old, see http://apt.llvm.org/ to install a newer version.
140160
On older Ubuntu releases, you may need to install binutils-gold
141161
to get the gold linker.
142162
143-
(2) Initialize git submodules.
163+
2. Initialize git submodules.
144164
We are using git submodules to incorporate specific revisions of the
145165
upstream pthread_workqueue and libkqueue projects into the build.
166+
167+
```
146168
git submodule init
147169
git submodule update
170+
```
171+
172+
3. Build (as in the general instructions above)
148173
149-
(3) Build (as in the general instructions above)
150-
sh autogen.sh
151-
./configure
152-
make
174+
```
175+
sh autogen.sh
176+
./configure
177+
make
153178
make install
179+
```

README.md

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,16 @@ Grand Central Dispatch (GCD or libdispatch) provides comprehensive support for c
44

55
libdispatch is currently available on all Darwin platforms. This project aims to make a modern version of libdispatch available on all other Swift platforms. To do this, we will implement as much of the portable subset of the API as possible, using the existing open source C implementation.
66

7-
## Project Goals
8-
9-
We are currently very early in the development of this project. Our starting point is simply a mirror of the open source drop that corresponds with OS X El Capitan (10.11). Therefore, our earliest goals are:
10-
11-
0. Build and test the C source code as a dynamic library on the current Swift Linux targets (Ubuntu 14.04 and Ubuntu 15.10).
12-
0. Add a `module.modulemap` and make the libdispatch API importable into Swift.
13-
0. After the previous two steps are done, consider possible improvements to the interface of the libdispatch API in Swift.
7+
libdispatch on Darwin is a combination of logic in the `xnu` kernel alongside the user-space Library. The kernel has the most information available to balance workload across the entire system. As a first step, however, we believe it is useful to bring up the basic functionality of the library using user-space pthread primitives on Linux. Eventually, a Linux kernel module could be developed to support more informed thread scheduling.
148

15-
## Building a C Library
16-
17-
libdispatch on Darwin is a combination of logic in the `xnu` kernel alongside the user-space Library. The kernel has the most information available to balance workload across the entire system. As a first step, however, we believe it is useful to bring up the basic functionality of the library using user-space pthread primitives on Linux.
9+
## Project Goals
1810

19-
Our first tasks for this project are:
11+
We are currently early in the development of this project. We began with a mirror of the open source drop that corresponds with OS X El Capitan (10.11) and have ported it to x86_64 Ubuntu 14.04 and 15.10. The next steps are:
12+
1. Complete the work to adopt libdispatch in other Core Libraries projects, especially Foundation. This will validate our work and get immediate test coverage on basic functionality of the Swift API.
13+
2. Include libdispatch and libdispatch-enabled Core Libraries in the Swift CI environment and the pre-built Swift toolchains at Swift.org.
14+
4. Develop a test suite for the Swift APIs of libdispatch.
15+
4. Enhance libdispatch as needed to support Swift language evolution and the needs of the other Core Libraries projects.
2016

21-
0. Adapt the current autotools build system to work on Linux, or develop a new makefile or other build script for the project on Linux. The current version of the build system has only been tested on Darwin, though previous versions have been made to work on FreeBSD and Linux (see INSTALL).
22-
0. Omit as much of the extra functionality of the library as possible, to get a core version of the project building. Much of the OS X-specific functionality can be elided completely on Linux.
23-
0. Adopt libdispatch in other Core Libraries projects, especially Foundation. This will validate our work and get immediate coverage on basic functionality.
24-
0. Incrementally add functionality back in.
17+
## Build and Install
2518

26-
Some C headers and sources (e.g. `Availability.h`, `Block.h`, and the libclosure `runtime.c`) are similar to ones embedded into the CoreFoundation part of [swift-corelibs-foundation](http://github.com/apple/swift-corelibs-foundation). We should figure out a mechanism to share these instead of duplicating them across projects.
19+
For detailed instructions on building and installing libdispatch, see [INSTALL.md](INSTALL.md)

dispatch/module.modulemap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module Dispatch {
22
requires blocks
33
export *
44
link "dispatch"
5-
link "BlocksRuntime"
65
}
76

87
module DispatchIntrospection [system] [extern_c] {
@@ -16,5 +15,4 @@ module CDispatch [system] [extern_c] {
1615
export *
1716
requires blocks
1817
link "dispatch"
19-
link "BlocksRuntime"
2018
}

libpwq

m4/blocks.m4

Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@ AC_ARG_WITH([blocks-runtime],
1010
LIBS="$LIBS -L$blocks_runtime"]
1111
)
1212
13+
#
14+
# Configure argument to enable/disable using an embedded blocks runtime
15+
#
16+
AC_ARG_ENABLE([embedded_blocks_runtime],
17+
[AS_HELP_STRING([--enable_embedded_blocks_runtime],
18+
[Enable usage of blocks runtime embedded in libdispatch])],,
19+
[case $target_os in
20+
linux*)
21+
enable_embedded_blocks_runtime=yes
22+
;;
23+
*)
24+
enable_embedded_blocks_runtime=no
25+
esac]
26+
)
27+
1328
#
1429
# Detect compiler support for Blocks; perhaps someday -fblocks won't be
1530
# required, in which case we'll need to change this.
@@ -29,30 +44,32 @@ AC_CACHE_CHECK([for C Blocks support], [dispatch_cv_cblocks], [
2944
AS_IF([test "x$dispatch_cv_cblocks" != "xno"], [
3045
CBLOCKS_FLAGS="$dispatch_cv_cblocks"
3146
32-
#
33-
# It may be necessary to directly link the Blocks runtime on some
34-
# systems, so give it a try if we can't link a C program that uses
35-
# Blocks. We will want to remove this at somepoint, as really -fblocks
36-
# should force that linkage already.
37-
#
38-
saveCFLAGS="$CFLAGS"
39-
CFLAGS="$CFLAGS -fblocks -O0"
40-
AC_MSG_CHECKING([whether additional libraries are required for the Blocks runtime])
41-
AC_TRY_LINK([], [
42-
^{ int j; j=0; }();
43-
], [
44-
AC_MSG_RESULT([no]);
45-
], [
46-
saveLIBS="$LIBS"
47-
LIBS="$LIBS -lBlocksRuntime"
48-
AC_TRY_LINK([], [
49-
^{ int k; k=0; }();
50-
], [
51-
AC_MSG_RESULT([-lBlocksRuntime])
52-
], [
53-
AC_MSG_ERROR([can't find Blocks runtime])
54-
])
55-
])
47+
AS_IF([test "x$enable_embedded_blocks_runtime" != "xyes"], [
48+
#
49+
# It may be necessary to directly link the Blocks runtime on some
50+
# systems, so give it a try if we can't link a C program that uses
51+
# Blocks. We will want to remove this at somepoint, as really -fblocks
52+
# should force that linkage already.
53+
#
54+
saveCFLAGS="$CFLAGS"
55+
CFLAGS="$CFLAGS -fblocks -O0"
56+
AC_MSG_CHECKING([whether additional libraries are required for the Blocks runtime])
57+
AC_TRY_LINK([], [
58+
^{ int j; j=0; }();
59+
], [
60+
AC_MSG_RESULT([no]);
61+
], [
62+
saveLIBS="$LIBS"
63+
LIBS="$LIBS -lBlocksRuntime"
64+
AC_TRY_LINK([], [
65+
^{ int k; k=0; }();
66+
], [
67+
AC_MSG_RESULT([-lBlocksRuntime])
68+
], [
69+
AC_MSG_ERROR([can't find Blocks runtime])
70+
])
71+
])
72+
])
5673
CFLAGS="$saveCFLAGS"
5774
have_cblocks=true
5875
], [
@@ -61,6 +78,7 @@ AS_IF([test "x$dispatch_cv_cblocks" != "xno"], [
6178
])
6279
AM_CONDITIONAL(HAVE_CBLOCKS, $have_cblocks)
6380
AC_SUBST([CBLOCKS_FLAGS])
81+
AM_CONDITIONAL([BUILD_OWN_BLOCKS_RUNTIME], [test "x$enable_embedded_blocks_runtime" = "xyes"])
6482
6583
#
6684
# Because a different C++ compiler may be specified than C compiler, we have
@@ -82,24 +100,26 @@ AC_CACHE_CHECK([for C++ Blocks support], [dispatch_cv_cxxblocks], [
82100
AS_IF([test "x$dispatch_cv_cxxblocks" != "xno"], [
83101
CXXBLOCKS_FLAGS="$dispatch_cv_cxxblocks"
84102
85-
saveCXXFLAGS="$CXXFLAGS"
86-
CXXFLAGS="$CXXFLAGS -fblocks -O0"
87-
AC_MSG_CHECKING([whether additional libraries are required for the Blocks runtime])
88-
AC_TRY_LINK([], [
89-
^{ int j; j=0; }();
90-
], [
91-
AC_MSG_RESULT([no]);
92-
], [
93-
saveLIBS="$LIBS"
94-
LIBS="$LIBS -lBlocksRuntime"
95-
AC_TRY_LINK([], [
96-
^{ int k; k=0; }();
97-
], [
98-
AC_MSG_RESULT([-lBlocksRuntime])
99-
], [
100-
AC_MSG_ERROR([can't find Blocks runtime])
101-
])
102-
])
103+
AS_IF([test "x$enable_embedded_blocks_runtime" != "xyes"], [
104+
saveCXXFLAGS="$CXXFLAGS"
105+
CXXFLAGS="$CXXFLAGS -fblocks -O0"
106+
AC_MSG_CHECKING([whether additional libraries are required for the Blocks runtime])
107+
AC_TRY_LINK([], [
108+
^{ int j; j=0; }();
109+
], [
110+
AC_MSG_RESULT([no]);
111+
], [
112+
saveLIBS="$LIBS"
113+
LIBS="$LIBS -lBlocksRuntime"
114+
AC_TRY_LINK([], [
115+
^{ int k; k=0; }();
116+
], [
117+
AC_MSG_RESULT([-lBlocksRuntime])
118+
], [
119+
AC_MSG_ERROR([can't find Blocks runtime])
120+
])
121+
])
122+
])
103123
CXXFLAGS="$saveCXXFLAGS"
104124
have_cxxblocks=true
105125
], [

0 commit comments

Comments
 (0)