libdispatch module on Linux


(Daniel Eggert) #1

I’ve create a system module for libdispatch, but when I import it, I don’t see anything guarded by __BLOCKS__.

Is there something I need to do when defining the system module to make that work?

Or something when I use it?

/Daniel

% cat Package.swift
import PackageDescription
let package = Package(name: "CDispatch”)

% cat module.modulemap
module CDispatch [system] {
umbrella header "/usr/local/include/dispatch/dispatch.h"
link "dispatch"
export *
}

% uname -a
Linux ubuntu 4.2.0-16-generic #19-Ubuntu SMP Thu Oct 8 15:35:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

% swift -I path/to/CDispatch-1.0.2
Welcome to Swift version 2.2-dev (LLVM 3ebdbb2c7e, Clang f66c5bb67b, Swift 1f2908b4f7). Type :help for assistance.
1> import CDispatch
2> dispatch_group_
Available completions:
  dispatch_group_async_f(group: dispatch_group_t, queue: dispatch_queue_t, context: UnsafeMutablePointer<Void>, work: dispatch_function_t(UnsafeMutablePointer<Void>) -> Void) -> Void
  dispatch_group_create() -> dispatch_group_t
  dispatch_group_enter(group: dispatch_group_t) -> Void
  dispatch_group_leave(group: dispatch_group_t) -> Void
  dispatch_group_notify_f(group: dispatch_group_t, queue: dispatch_queue_t, context: UnsafeMutablePointer<Void>, work: dispatch_function_t(UnsafeMutablePointer<Void>) -> Void) -> Void
  dispatch_group_t
  dispatch_group_wait(group: dispatch_group_t, timeout: dispatch_time_t) -> Int


(Philippe Hausler) #2

I noticed with importing CoreFoundation into swift-corelibs-foundation that we needed to pass -Xcc -fblocks to switfc to make it import a few things correctly on linux. I wonder if that is the same thing that is happening here too.

···

On Jan 18, 2016, at 8:31 AM, Daniel Eggert via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

I’ve create a system module for libdispatch, but when I import it, I don’t see anything guarded by __BLOCKS__.

Is there something I need to do when defining the system module to make that work?

Or something when I use it?

/Daniel

% cat Package.swift
import PackageDescription
let package = Package(name: "CDispatch”)

% cat module.modulemap
module CDispatch [system] {
umbrella header "/usr/local/include/dispatch/dispatch.h"
link "dispatch"
export *
}

% uname -a
Linux ubuntu 4.2.0-16-generic #19-Ubuntu SMP Thu Oct 8 15:35:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

% swift -I path/to/CDispatch-1.0.2
Welcome to Swift version 2.2-dev (LLVM 3ebdbb2c7e, Clang f66c5bb67b, Swift 1f2908b4f7). Type :help for assistance.
1> import CDispatch
2> dispatch_group_
Available completions:
  dispatch_group_async_f(group: dispatch_group_t, queue: dispatch_queue_t, context: UnsafeMutablePointer<Void>, work: dispatch_function_t(UnsafeMutablePointer<Void>) -> Void) -> Void
  dispatch_group_create() -> dispatch_group_t
  dispatch_group_enter(group: dispatch_group_t) -> Void
  dispatch_group_leave(group: dispatch_group_t) -> Void
  dispatch_group_notify_f(group: dispatch_group_t, queue: dispatch_queue_t, context: UnsafeMutablePointer<Void>, work: dispatch_function_t(UnsafeMutablePointer<Void>) -> Void) -> Void
  dispatch_group_t
  dispatch_group_wait(group: dispatch_group_t, timeout: dispatch_time_t) -> Int

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev


(Pierre Habouzit) #3

this is very likely as __BLOCKS__ is only defined when you pass -fblocks.

though, I’m told the blocks layout from swift and the one from libblocks-runtime-dev is not the same so it will likely crash (because dispatch as I said in another thread, uses that layout to get to the function pointer stored there). but worth trying.

-Pierre

···

On Jan 18, 2016, at 8:58 AM, Philippe Hausler via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

I noticed with importing CoreFoundation into swift-corelibs-foundation that we needed to pass -Xcc -fblocks to switfc to make it import a few things correctly on linux. I wonder if that is the same thing that is happening here too.

On Jan 18, 2016, at 8:31 AM, Daniel Eggert via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

I’ve create a system module for libdispatch, but when I import it, I don’t see anything guarded by __BLOCKS__.

Is there something I need to do when defining the system module to make that work?

Or something when I use it?

/Daniel

% cat Package.swift
import PackageDescription
let package = Package(name: "CDispatch”)

% cat module.modulemap
module CDispatch [system] {
umbrella header "/usr/local/include/dispatch/dispatch.h"
link "dispatch"
export *
}

% uname -a
Linux ubuntu 4.2.0-16-generic #19-Ubuntu SMP Thu Oct 8 15:35:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

% swift -I path/to/CDispatch-1.0.2
Welcome to Swift version 2.2-dev (LLVM 3ebdbb2c7e, Clang f66c5bb67b, Swift 1f2908b4f7). Type :help for assistance.
1> import CDispatch
2> dispatch_group_
Available completions:
  dispatch_group_async_f(group: dispatch_group_t, queue: dispatch_queue_t, context: UnsafeMutablePointer<Void>, work: dispatch_function_t(UnsafeMutablePointer<Void>) -> Void) -> Void
  dispatch_group_create() -> dispatch_group_t
  dispatch_group_enter(group: dispatch_group_t) -> Void
  dispatch_group_leave(group: dispatch_group_t) -> Void
  dispatch_group_notify_f(group: dispatch_group_t, queue: dispatch_queue_t, context: UnsafeMutablePointer<Void>, work: dispatch_function_t(UnsafeMutablePointer<Void>) -> Void) -> Void
  dispatch_group_t
  dispatch_group_wait(group: dispatch_group_t, timeout: dispatch_time_t) -> Int

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev


(Daniel Eggert) #4

How would I go about passing ‘-fblocks’ when building a module using ‘swift build’?

Should I file a bug to track this?

/Daniel

···

On 18 Jan 2016, at 18:00, Pierre Habouzit <phabouzit@apple.com> wrote:

this is very likely as __BLOCKS__ is only defined when you pass -fblocks.

though, I’m told the blocks layout from swift and the one from libblocks-runtime-dev is not the same so it will likely crash (because dispatch as I said in another thread, uses that layout to get to the function pointer stored there). but worth trying.

-Pierre

On Jan 18, 2016, at 8:58 AM, Philippe Hausler via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

I noticed with importing CoreFoundation into swift-corelibs-foundation that we needed to pass -Xcc -fblocks to switfc to make it import a few things correctly on linux. I wonder if that is the same thing that is happening here too.

On Jan 18, 2016, at 8:31 AM, Daniel Eggert via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

I’ve create a system module for libdispatch, but when I import it, I don’t see anything guarded by __BLOCKS__.

Is there something I need to do when defining the system module to make that work?

Or something when I use it?

/Daniel

% cat Package.swift
import PackageDescription
let package = Package(name: "CDispatch”)

% cat module.modulemap
module CDispatch [system] {
umbrella header "/usr/local/include/dispatch/dispatch.h"
link "dispatch"
export *
}

% uname -a
Linux ubuntu 4.2.0-16-generic #19-Ubuntu SMP Thu Oct 8 15:35:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

% swift -I path/to/CDispatch-1.0.2
Welcome to Swift version 2.2-dev (LLVM 3ebdbb2c7e, Clang f66c5bb67b, Swift 1f2908b4f7). Type :help for assistance.
1> import CDispatch
2> dispatch_group_
Available completions:
  dispatch_group_async_f(group: dispatch_group_t, queue: dispatch_queue_t, context: UnsafeMutablePointer<Void>, work: dispatch_function_t(UnsafeMutablePointer<Void>) -> Void) -> Void
  dispatch_group_create() -> dispatch_group_t
  dispatch_group_enter(group: dispatch_group_t) -> Void
  dispatch_group_leave(group: dispatch_group_t) -> Void
  dispatch_group_notify_f(group: dispatch_group_t, queue: dispatch_queue_t, context: UnsafeMutablePointer<Void>, work: dispatch_function_t(UnsafeMutablePointer<Void>) -> Void) -> Void
  dispatch_group_t
  dispatch_group_wait(group: dispatch_group_t, timeout: dispatch_time_t) -> Int

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev


(Philippe Hausler) #5

I am not certain on `swift build` but for swift and swiftc it is `-Xcc -fblocks`.

My rule of thumb is that if any time there is something that does not meet initial expectations filing a bug is always appreciated (even if it is marked as a dup/not-to-be-fixed/etc)

···

On Jan 18, 2016, at 10:03 AM, Daniel Eggert <danieleggert@me.com> wrote:

How would I go about passing ‘-fblocks’ when building a module using ‘swift build’?

Should I file a bug to track this?

/Daniel

On 18 Jan 2016, at 18:00, Pierre Habouzit <phabouzit@apple.com> wrote:

this is very likely as __BLOCKS__ is only defined when you pass -fblocks.

though, I’m told the blocks layout from swift and the one from libblocks-runtime-dev is not the same so it will likely crash (because dispatch as I said in another thread, uses that layout to get to the function pointer stored there). but worth trying.

-Pierre

On Jan 18, 2016, at 8:58 AM, Philippe Hausler via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

I noticed with importing CoreFoundation into swift-corelibs-foundation that we needed to pass -Xcc -fblocks to switfc to make it import a few things correctly on linux. I wonder if that is the same thing that is happening here too.

On Jan 18, 2016, at 8:31 AM, Daniel Eggert via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

I’ve create a system module for libdispatch, but when I import it, I don’t see anything guarded by __BLOCKS__.

Is there something I need to do when defining the system module to make that work?

Or something when I use it?

/Daniel

% cat Package.swift
import PackageDescription
let package = Package(name: "CDispatch”)

% cat module.modulemap
module CDispatch [system] {
umbrella header "/usr/local/include/dispatch/dispatch.h"
link "dispatch"
export *
}

% uname -a
Linux ubuntu 4.2.0-16-generic #19-Ubuntu SMP Thu Oct 8 15:35:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

% swift -I path/to/CDispatch-1.0.2
Welcome to Swift version 2.2-dev (LLVM 3ebdbb2c7e, Clang f66c5bb67b, Swift 1f2908b4f7). Type :help for assistance.
1> import CDispatch
2> dispatch_group_
Available completions:
  dispatch_group_async_f(group: dispatch_group_t, queue: dispatch_queue_t, context: UnsafeMutablePointer<Void>, work: dispatch_function_t(UnsafeMutablePointer<Void>) -> Void) -> Void
  dispatch_group_create() -> dispatch_group_t
  dispatch_group_enter(group: dispatch_group_t) -> Void
  dispatch_group_leave(group: dispatch_group_t) -> Void
  dispatch_group_notify_f(group: dispatch_group_t, queue: dispatch_queue_t, context: UnsafeMutablePointer<Void>, work: dispatch_function_t(UnsafeMutablePointer<Void>) -> Void) -> Void
  dispatch_group_t
  dispatch_group_wait(group: dispatch_group_t, timeout: dispatch_time_t) -> Int

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev


(Daniel Eggert) #6

I filed https://bugs.swift.org/browse/SR-577 “Compiler should pass -Xcc -fblocks when processing .h files”

/Daniel

···

On 18 Jan 2016, at 19:06, Philippe Hausler <phausler@apple.com> wrote:

I am not certain on `swift build` but for swift and swiftc it is `-Xcc -fblocks`.

My rule of thumb is that if any time there is something that does not meet initial expectations filing a bug is always appreciated (even if it is marked as a dup/not-to-be-fixed/etc)

On Jan 18, 2016, at 10:03 AM, Daniel Eggert <danieleggert@me.com> wrote:

How would I go about passing ‘-fblocks’ when building a module using ‘swift build’?

Should I file a bug to track this?

/Daniel

On 18 Jan 2016, at 18:00, Pierre Habouzit <phabouzit@apple.com> wrote:

this is very likely as __BLOCKS__ is only defined when you pass -fblocks.

though, I’m told the blocks layout from swift and the one from libblocks-runtime-dev is not the same so it will likely crash (because dispatch as I said in another thread, uses that layout to get to the function pointer stored there). but worth trying.

-Pierre

On Jan 18, 2016, at 8:58 AM, Philippe Hausler via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

I noticed with importing CoreFoundation into swift-corelibs-foundation that we needed to pass -Xcc -fblocks to switfc to make it import a few things correctly on linux. I wonder if that is the same thing that is happening here too.

On Jan 18, 2016, at 8:31 AM, Daniel Eggert via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

I’ve create a system module for libdispatch, but when I import it, I don’t see anything guarded by __BLOCKS__.

Is there something I need to do when defining the system module to make that work?

Or something when I use it?

/Daniel

% cat Package.swift
import PackageDescription
let package = Package(name: "CDispatch”)

% cat module.modulemap
module CDispatch [system] {
umbrella header "/usr/local/include/dispatch/dispatch.h"
link "dispatch"
export *
}

% uname -a
Linux ubuntu 4.2.0-16-generic #19-Ubuntu SMP Thu Oct 8 15:35:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

% swift -I path/to/CDispatch-1.0.2
Welcome to Swift version 2.2-dev (LLVM 3ebdbb2c7e, Clang f66c5bb67b, Swift 1f2908b4f7). Type :help for assistance.
1> import CDispatch
2> dispatch_group_
Available completions:
  dispatch_group_async_f(group: dispatch_group_t, queue: dispatch_queue_t, context: UnsafeMutablePointer<Void>, work: dispatch_function_t(UnsafeMutablePointer<Void>) -> Void) -> Void
  dispatch_group_create() -> dispatch_group_t
  dispatch_group_enter(group: dispatch_group_t) -> Void
  dispatch_group_leave(group: dispatch_group_t) -> Void
  dispatch_group_notify_f(group: dispatch_group_t, queue: dispatch_queue_t, context: UnsafeMutablePointer<Void>, work: dispatch_function_t(UnsafeMutablePointer<Void>) -> Void) -> Void
  dispatch_group_t
  dispatch_group_wait(group: dispatch_group_t, timeout: dispatch_time_t) -> Int

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev


(Max Howell) #7

How would I go about passing ‘-fblocks’ when building a module using ‘swift build’?

Since last week you can now: `swift build -Xcc -fblocks` and the build process will add those flags.

Should I file a bug to track this?

There’s already a few open tickets for this topic. We’re planning a more thorough solution, the above it to allow workarounds.


(Daniel Eggert) #8

Thanks.

I added a comment to https://bugs.swift.org/browse/SR-397 -- I think just having the _f variants working is totally fine. The block variants are nothing but a wrapper around them that can easily be re-created in Swift.

That approach would allow for a a different blocks ABI on Linux.

/Daniel

···

On 19 Jan 2016, at 20:22, Max Howell <max.howell@apple.com> wrote:

How would I go about passing ‘-fblocks’ when building a module using ‘swift build’?

Since last week you can now: `swift build -Xcc -fblocks` and the build process will add those flags.

Should I file a bug to track this?

There’s already a few open tickets for this topic. We’re planning a more thorough solution, the above it to allow workarounds.