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
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
                        Here is the Folder structure for Swift package
And Here i have mentioned how to add the resources and add lines in Package

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With