Module System

How does the module system actually work in Swift? From what I've seen so
far it seems to be pretty tied in with XCode and tools like the package
manager.

I come from languages like Rust where modules either map to files or to
folders with a `mod.rs` file inside. I can also define modules inside of
source files with the `mod` keyword.

···

From what I've seen the way modules work in Swift is not very flexible.

How does the module system actually work in Swift? From what I've seen so far it seems to be pretty tied in with XCode and tools like the package manager.

Can you clarify your question a little bit? What specific information are you looking for?

Here are some random notes which may help clarify things:

1. There are two kinds of modules, C-family modules (which come from Clang's module system, which is layered on top of C headers) and native Swift modules (.swiftmodule files).

a. For Clang modules, see Modules — Clang 18.0.0git documentation for information on these. Those modules are found via the Clang importer built into Swift. swiftc has command line options to expose search paths to the Clang compiler which in turn control how those modules are found -- those options aren't currently exposed by the package manager directly.

b. Swift modules are found using a much simpler search path mechanism, which can also be controlled via swiftc command line options. Again, the package manager doesn't expose those options directly.

2. The package manager currently assumes each "target" will be its own Swift module. It automatically adds search path options so that dependents can see their dependencies, whether in the same package or across packages.

3. If you run `swift build -v` you can see what options are going to swiftc to make this work. The interesting ones are -I (which controls search paths, as with Clang), and -emit-module*.

HTH,
- Daniel

···

On Dec 4, 2015, at 8:54 PM, Severen Redwood <severen.redwood@gmail.com> wrote:

I come from languages like Rust where modules either map to files or to folders with a `mod.rs <http://mod.rs/&gt;\` file inside. I can also define modules inside of source files with the `mod` keyword.

From what I've seen the way modules work in Swift is not very flexible.
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

You can get a simple module to work with :
$ swift -I /path/to/module/dir swiftysource.swift

with module dir containing a file named module.modulemap which is something
like

CSmurf [system] {
   header "/absolute/path/to/header.h"
   link "smurf" // to link against libsmurf.so
   export *
}

I am personnally currently struggling with it to get it working with more
complex libs but not everything (see Modules — Clang 18.0.0git documentation
for "everything"') seems implemented yet.

Regards

···

2015-12-05 5:54 GMT+01:00 Severen Redwood <severen.redwood@gmail.com>:

How does the module system actually work in Swift? From what I've seen so
far it seems to be pretty tied in with XCode and tools like the package
manager.

I come from languages like Rust where modules either map to files or to
folders with a `mod.rs` file inside. I can also define modules inside of
source files with the `mod` keyword.

From what I've seen the way modules work in Swift is not very flexible.

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