Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Source subdirectories in Swift package

Tags:

swift

In a library package, I would like to move some source files from the "Sources" folder to subdirectories, without changing language semantics (module name, visibility, etc).

Now I have a layout like:

LibraryProject
  Sources
    AnotherThing.swift
    FooProtocol.swift
    SomeFoo.swift
    OtherFoo.swift
    BarProtocol.swift
    SomeBar.swift
    OtherBar.swift

And, if I change it to something like:

LibraryProject
  Sources
    AnotherThing.swift
    Foo
      FooProtocol.swift
      SomeFoo.swift
      OtherFoo.swift
    Bar
      BarProtocol.swift
      SomeBar.swift
      OtherBar.swift

Then, invoking swift build fails:

error: the package has an unsupported layout, unexpected source file(s) found: [...]

Is this layout possible? I only found this issue https://bugs.swift.org/browse/SR-66 that suggests that it is not, but I cant find confirmation (or reason) in the documentation.

Thanks

like image 301
0xc0ffee Avatar asked Dec 11 '16 01:12

0xc0ffee


2 Answers

I have found two options that work for Swift projects on Linux, either all .swift files must be directly in the Sources folder, or there must be one subfolder in Sources and as many subfolders within that as you like.

Swift builds a Module out of the top-level subfolder in Sources and includes all the subfolders within that.

I don't believe it is possible to have two Modules within the same Sources folder, as a Module would not recognise any code outside itself.

So in your example a working structure would be:

LibraryProject
  Sources
    YourModuleName
      AnotherThing.swift
      Foo
        FooProtocol.swift
        SomeFoo.swift
        OtherFoo.swift
      Bar
        BarProtocol.swift
        SomeBar.swift
        OtherBar.swift
like image 183
Niall Avatar answered Sep 21 '22 12:09

Niall


Here is the Folder structure for Swift package And Here i have mentioned how to add the resources and add lines in Package enter image description here

like image 25
Anil Avatar answered Sep 21 '22 12:09

Anil