Skip to content

Initial integration of Swift overlay into libdispatch build #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 9, 2016

Conversation

dgrove-oss
Copy link
Contributor

This commit adds a src/swift directory that contains
Dispatch.swift and Dispatch.c (based on existing files in
swift/stdlib/public/SDK/Dispatch) and a module.map.in template.
We made some initial changes to Dispatch.swift and Dispatch.c to
adapt them to Linux by dropping MACH API functions/adapters.

The libdispatch build process is extended to include Dispatch.o
in libdispatch.so and to generate Dispatch.swiftmodule,
Dispatch.swiftdoc and a module.map file when configure is
given a --with-swift-sdk argument.

Swift programs that import Dispatch can be compiled, linked,
and run against the generated files, but must include some
extra command line arguments due to the use of @convention(block)
to bridge from Swift blocks to the -fblocks expected by dispatch.
In particular, the following flags are currently needed to compile
a Swift program: -Xcc -fblocks -Xlinker -lBlocksRuntime

@billabt
Copy link

billabt commented Feb 4, 2016

In Dispatch.swift, typealias is deprecated, the new term is associatedtype. So, line 22:

public typealias dispatch_block_t = @convention(block) () -> Void

should be this instead...

public associatedtype dispatch_block_t = @convention(block) () -> Void

@ddunbar
Copy link

ddunbar commented Feb 4, 2016

Do we have a plan yet for how to get the -fblocks flag added when appropriate for Swift?

For the -lBlocksRuntime argument, you may be able to deal with this by adding a link declaration to your module map:
http://clang.llvm.org/docs/Modules.html#link-declaration

@mwwa
Copy link
Contributor

mwwa commented Feb 4, 2016

It's unfortunate that all the C-defines need computed variables to be shimmed over but it looks like that's also a direct mirror of the stdlib version of this code.

@mwwa
Copy link
Contributor

mwwa commented Feb 4, 2016

I mirror ddunbar's suggestion about using the module link line to try including BlocksRuntime. I'm not in a position to check if that works on Linux myself though.

@dgrove-oss
Copy link
Contributor Author

@billabt associatedtype doesn't work in this context (not sure if this is by design, or a bug). Using a swiftc I built from git as of this morning, I get:
``
/home/vagrant/test-build/../swift-corelibs-libdispatch/src/swift/Dispatch.swift:22:8:

error: associated types can only be defined in a protocol; define a type or introduce a 'typealias' to satisfy an associated type requirement
public associatedtype dispatch_block_t = @convention(block) () -> Void
^
/home/vagrant/test-build/../swift-corelibs-libdispatch/src/swift/Dispatch.swift:22:43: error: attribute can only be applied to types, not declarations
public associatedtype dispatch_block_t = @convention(block) () -> Void
^
/home/vagrant/test-build/../swift-corelibs-libdispatch/src/swift/Dispatch.swift:22:53: error: expected declaration
public associatedtype dispatch_block_t = @convention(block) () -> Void

@dgrove-oss
Copy link
Contributor Author

Thanks @mwwa and @ddunbar for the linker suggestion. I had missed that I could have multiple linker directives in the module.map file. I had tried putting both dispatch and BlocksRuntime into a single linker directive, which didn't work. Updated module.map.in to have two linker directives, which does work.

@dgrove-oss
Copy link
Contributor Author

Squashed changes into a single commit and updated commit comment to reflect now only needing -Xcc -fblocks.

This commit adds a src/swift directory that contains
Dispatch.swift and Dispatch.c (based on existing files in
swift/stdlib/public/SDK/Dispatch) and a module.map.in template.
We made some initial changes to Dispatch.swift and Dispatch.c to
adapt them to Linux by dropping MACH API functions/adapters.

The libdispatch build process is extended to include Dispatch.o
in libdispatch.so and to generate Dispatch.swiftmodule,
Dispatch.swiftdoc and a module.map file when configure is
given a --with-swift-toolchain argument.

Swift programs that import Dispatch can be compiled, linked,
and run against the generated files. However, because of
the use of @convention(block) to bridge from Swift blocks to
the -fblocks expected by dispatch, swiftc must be given the
extra command line arguments  -Xcc -fblocks
@dgrove-oss
Copy link
Contributor Author

Updated & squashed with a change to the command line argument of configure to --with-swift-toolchain as requested in the review of swiftlang/swift#1212

@dgrove-oss
Copy link
Contributor Author

@MadCoder @mwwa. Any additional changes needed? Would like to get this merged so we can continue with next steps. Thanks.

@mwwa
Copy link
Contributor

mwwa commented Feb 9, 2016

No I'm happy, I'll merge momentarily.

mwwa added a commit that referenced this pull request Feb 9, 2016
Initial integration of Swift overlay into libdispatch build
@mwwa mwwa merged commit c04488a into swiftlang:master Feb 9, 2016
@dgrove-oss dgrove-oss deleted the swift-overlay-cp1 branch February 16, 2016 13:22
das pushed a commit that referenced this pull request Jun 14, 2016
Initial integration of Swift overlay into libdispatch build

Signed-off-by: Daniel A. Steffen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants