How to define interdependent modules in a package?


(Tarun Joshi) #1

Hi,
I was following the github documentation to create multiple modules (
https://github.com/apple/swift-package-manager/blob/master/Documentation/SourceLayouts.md
)
in a package.

My package directory looks like this:
SwiftTest/Package.swift
SwiftTest/Sources/Bar/bar.swift
SwiftTest/Sources/Foo/foo.swift

bar.swift :
  public func bar() {
    print("bar")
  }

foo.swift :
  import Bar
  public func foo() {
    bar()
  }

Compiling this produces an error saying : foo.swift: error: no such module
'Bar'
When I remove dependency of 'Bar' module from foo.swift (by removing import
statement and call to 'bar'), it compiles fine.
Am I missing something here? Can't I use imports directly?

···

--
Regards,
`Tarun`


(David Turnbull) #2

Is this in your package file?
targets: [
    Target(
        name: "Foo",
        dependencies: [.Target(name: "Bar")]),
    Target(
        name: "Bar")
]

-david

···

On Tue, Dec 22, 2015 at 3:02 AM, Tarun Joshi via swift-users < swift-users@swift.org> wrote:

Hi,
I was following the github documentation to create multiple modules (
https://github.com/apple/swift-package-manager/blob/master/Documentation/SourceLayouts.md )
in a package.

My package directory looks like this:
SwiftTest/Package.swift
SwiftTest/Sources/Bar/bar.swift
SwiftTest/Sources/Foo/foo.swift

bar.swift :
  public func bar() {
    print("bar")
  }

foo.swift :
  import Bar
  public func foo() {
    bar()
  }

Compiling this produces an error saying : foo.swift: error: no such module
'Bar'
When I remove dependency of 'Bar' module from foo.swift (by removing
import statement and call to 'bar'), it compiles fine.
Am I missing something here? Can't I use imports directly?

--
Regards,
`Tarun`

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


(Max Howell) #3

Compiling this produces an error saying : foo.swift: error: no such module 'Bar'
When I remove dependency of 'Bar' module from foo.swift (by removing import statement and call to 'bar'), it compiles fine.
Am I missing something here? Can't I use imports directly?

You’re not missing anything, you can do this, in fact the package manager itself does this with many modules.

Can you post your Package.swift? It may help to just attach the whole example as a zip.


(Tarun Joshi) #4

Is this in your package file?
targets: [
    Target(
        name: "Foo",
        dependencies: [.Target(name: "Bar")]),
    Target(
        name: "Bar")

No. So for each module I write, I need to specify all the imported
stuff as dependency?
Shouldn't this be automatically picked in the build phase by seeing
imports in a file. Am I expecting too much?

···

--
Regards,
`Tarun`


(Pierre Monod-Broca) #5

It would be too costly to do that on each build, among other issues.

So you do have to add all imported stuff as dependencies.

If I recall correctly, SPM is planned to have an option to either list you all your imports so you can populate your dependencies, or edit the package manifest itself to add those dependencies.

···

--
Pierre

Le 23 déc. 2015 à 03:43, Tarun Joshi via swift-users <swift-users@swift.org> a écrit :

Is this in your package file?
targets: [
   Target(
       name: "Foo",
       dependencies: [.Target(name: "Bar")]),
   Target(
       name: "Bar")

No. So for each module I write, I need to specify all the imported
stuff as dependency?
Shouldn't this be automatically picked in the build phase by seeing
imports in a file. Am I expecting too much?

--
Regards,
`Tarun`
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(Pierre Monod-Broca) #6

here is link with more explanation : https://github.com/apple/swift-package-manager/blob/master/Documentation/PackageManagerCommunityProposal.md#module-interdependency-determination

···

--
Pierre

Le 23 déc. 2015 à 14:50, Pierre Monod-Broca <pierre@monod-broca.fr> a écrit :

It would be too costly to do that on each build, among other issues.

So you do have to add all imported stuff as dependencies.

If I recall correctly, SPM is planned to have an option to either list you all your imports so you can populate your dependencies, or edit the package manifest itself to add those dependencies.

--
Pierre

Le 23 déc. 2015 à 03:43, Tarun Joshi via swift-users <swift-users@swift.org <mailto:swift-users@swift.org>> a écrit :

Is this in your package file?
targets: [
   Target(
       name: "Foo",
       dependencies: [.Target(name: "Bar")]),
   Target(
       name: "Bar")

No. So for each module I write, I need to specify all the imported
stuff as dependency?
Shouldn't this be automatically picked in the build phase by seeing
imports in a file. Am I expecting too much?

--
Regards,
`Tarun`
_______________________________________________
swift-users mailing list
swift-users@swift.org <mailto:swift-users@swift.org>
https://lists.swift.org/mailman/listinfo/swift-users


(Daniel Dunbar) #7

What we hope to do here eventually is have swiftpm "notice" when a build has failed because of a missing dependency, and then automatically help you update the manifest to include it.

This allows the dependency specifications to continue to be explicit, which some people believe is important for maintenance of a large project, while still having a relatively painless workflow for incremental development.

We don't yet have anyone actively working on this feature, though...

- Daniel

···

On Dec 23, 2015, at 6:50 AM, Pierre Monod-Broca via swift-users <swift-users@swift.org> wrote:

It would be too costly to do that on each build, among other issues.

So you do have to add all imported stuff as dependencies.

If I recall correctly, SPM is planned to have an option to either list you all your imports so you can populate your dependencies, or edit the package manifest itself to add those dependencies.

--
Pierre

Le 23 déc. 2015 à 03:43, Tarun Joshi via swift-users <swift-users@swift.org <mailto:swift-users@swift.org>> a écrit :

Is this in your package file?
targets: [
   Target(
       name: "Foo",
       dependencies: [.Target(name: "Bar")]),
   Target(
       name: "Bar")

No. So for each module I write, I need to specify all the imported
stuff as dependency?
Shouldn't this be automatically picked in the build phase by seeing
imports in a file. Am I expecting too much?

--
Regards,
`Tarun`
_______________________________________________
swift-users mailing list
swift-users@swift.org <mailto:swift-users@swift.org>
https://lists.swift.org/mailman/listinfo/swift-users

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


(Tarun Joshi) #8

We don't yet have anyone actively working on this feature, though...

If its not pretty complex and you think a beginner like me can
implement it, I'd be happy to help. Some pointers would be helpful :slight_smile:

···

--
Regards,
`Tarun`


(Daniel Dunbar) #9

We don't yet have anyone actively working on this feature, though...

If its not pretty complex and you think a beginner like me can
implement it, I'd be happy to help. Some pointers would be helpful :slight_smile:

It's pretty complex. :slight_smile:

We need:
1. A way to detect (from `swiftc`) when a failure was due to a missing import. This should be a small focused feature proposal, and is the major minimal thing we need.
2. Once we have #1, we need a way to bubble that information back to swiftpm.
3. Once we have #2, we need to take some action. That could initially just be reporting the missing dependency.
4. Once we have #3, it would be nice to have a UI that offers to automatically update the manifest file to add the dependency. This depends on having the infrastructure for automatically editing the manifest file.

- Daniel

···

On Dec 27, 2015, at 10:15 PM, Tarun Joshi <tj.joshi7@gmail.com> wrote:

--
Regards,
`Tarun`