Any way to create a module without creating a new Xcode target?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Any way to create a module without creating a new Xcode target?

Jens Alfke
I need to write unit tests for some code of mine that accesses Obj-C runtime metadata. It appears that my code has trouble with the metadata (or it’s simply missing) when it involves a Swift class declared in a module

The problem is that to test this I need a class in a module, and from looking at the docs, the only way to do that is to create a new Xcode framework target, with all the rigamarole that entails. (Actually I’d need two, one for iOS and one for Mac.) Is there any other way to do this? Like a “module Foo” statement, similar to every single other existing language that supports modules?

—Jens

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/8C2BE3B4-7CBF-4D46-909D-25FCFBB88329%40mooseyard.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Any way to create a module without creating a new Xcode target?

Adam Sharp
On 16 May 2015, at 4:29 am, Jens Alfke <[hidden email]> wrote:

> The problem is that to test this I need a class in a module, and from looking at the docs, the only way to do that is to create a new Xcode framework target, with all the rigamarole that entails. (Actually I’d need two, one for iOS and one for Mac.) Is there any other way to do this? Like a “module Foo” statement, similar to every single other existing language that supports modules?

I don't think there's anything language-level like that. The way I've done it is to use swiftc to build a dynamic library, e.g.:

        $ swiftc -emit-library -o build/libFoo.dylib -module-name Foo Foo/*.swift
        $ swiftc -emit-module -o build/Foo.swiftmodule -module-name Foo Foo/*.swift
        $ swiftc -Lbuild -Ibuild -lFoo main.swift

Managing the linker search paths, linked libraries and import search paths like this kinda sucks, and frameworks do abstract away some of that for you. But the tradeoff is that building the framework bundle itself is a bit more complicated. It's definitely doable though, and easier once you write a build script or something to automate it.

It would be nice if there was a simpler way, but I think tooling can definitely solve the problem.

–Adam

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/4BFA3CEE-ED4A-4170-B865-ED687239AD54%40me.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Any way to create a module without creating a new Xcode target?

Jens Alfke

On May 17, 2015, at 3:30 AM, Adam Sharp <[hidden email]> wrote:

It would be nice if there was a simpler way, but I think tooling can definitely solve the problem.

I don’t think it solves everything. I don’t want the overhead of multiple dylibs (losing link-level optimization, incurring load-time costs, losing iOS 7 support, etc.) just to have modular code.

—Jens

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/7B4A934C-A7F6-4CE0-A6AD-9A505B28FA96%40mooseyard.com.
For more options, visit https://groups.google.com/d/optout.