Description
Previous ID | SR-397 |
Radar | None |
Original Reporter | tomsheffler (JIRA User) |
Type | Bug |
Status | Resolved |
Resolution | Done |
Attachment: Download
Environment
Ubuntu 14.04
Additional Detail from JIRA
Votes | 3 |
Component/s | Compiler, Package Manager |
Labels | Bug, Dispatch, Linux |
Assignee | @aciidb0mb3r |
Priority | Medium |
md5: 3ce10e8ea99c16ef2da7e8631d663144
is duplicated by:
- SR-415 blocks support in external c libraries disabled
- SR-577 Compiler should pass -Xcc -fblocks when processing .h files
Issue Description:
While libdispatch is well-supported on Linux, using "Swift Build" for a module wrapping <dispatch/dispatch.h> does not compile cleanly. The problem is that to get all of the features of dispatch, "-fblocks" needs to be specified to Clang, and currently, "swift build" does not enable "-fblocks" for modules that wrap C libraries.
-
using "swift build" does not include the -fblocks directive
-
compiling directly with swiftc and including the -fblocks directive works fine
-
creating a module map that specifies "requires blocks" causes a complaint that Objective-C is not supported
Here is my original report, and a Github repo that illustrates the problem.
I made a module called "CDispatch" with a module.modulemap like this
=======
module CDispatch [system] {
header "/usr/include/dispatch/dispatch.h"
export *
link "dispatch"
}
Then I created a little demo project called gcd4 whose Source/main.swift prints some things and then uses a dispatch queue and a block to print a message after 2 seconds delay.
=========
CDispatch.dispatch_after(time, queue, {
print("Delayed!")
})
The entire project is checked in at https://github.com/sheffler/gcd4 <https://github.com/sheffler/gcd4\>
and the CDispatch module is checked in at https://github.com/sheffler/CDispatch <https://github.com/sheffler/CDispatch\>
If I try to "swift build" the project, it almost works but reports that dispatch_after is not found. It seems that this function is not defined if the "blocks" feature is not provided at compilation time.
========
Compiling Swift Module 'gcd4' (1 sources)
/home/sheffler/swift/gcd4/Sources/main.swift:42:1: error: module 'CDispatch' has no member named 'dispatch_after'
CDispatch.dispatch_after(time, queue, {
^~~~~~~~~ ~~~~~~~~~~~~~~
<unknown>:0: error: build had 1 command failures
swift-build: exit(1): ["/home/sheffler/src/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/bin/swift-build-tool", "-f", "/home/sheffler/swift/gcd4/.build/debug/gcd4.o/llbuild.yaml"]
I got the demo program to work by first using "swift build" to retrieve the CDispatch module, and then manually running the compiler like this (and including the "-Xcc -fblocks" arguments)
swiftc -v -o gcd4 Sources/main.swift -I .build/debug -j8 -Onone -g -Xcc -fblocks -Xcc -F-module-map=Packages/CDispatch-1.0.0/module.modulemap -I Packages/CDispatch-1.0.0 -I /usr/local/include