Problem with new Package Manager System Library Targets

With the introduction of Swift 4.2 I got a deprecation warning stating that I have to use a system library:

warning: system packages are deprecated; use system library targets instead

The library that was being linked was a library that did not really link a library, it just loaded a header file which I needed to do some low level network requests. So the module.modulemap used to contain:

module Network [system] {
    header </usr/include/ifaddrs.h>
    export *
}

The Package.swift file contained:

// swift-tools-version:3.1

import PackageDescription

let package = Package(name: "Network")

It seems, if I read the SPM System Library Target correctly there is no longer an option to specify the header.

Am I missing something or is this still possible in 4.2? Or have we removed this possibility with this release?

Any advise would be appreciated.

1 Like

You need to update the manifest file and declare a system library target. The new manifest will probably look something like:

// swift-tools-version:4.2

import PackageDescription

let package = Package(
    name: "Network",
    products: [
        .library(name: "Network", targets: ["Network"]),
    ],
    targets: [
        .systemLibrary(name: "Network", path: "."),
    ]
)
1 Like

Thanks for your response. But where would I specify /usr/include/ifaddrs.h?

In the same module.modulemap file, that part hasn't changed.

So I have made the changes as you suggested and get the following errors when I use the library:

warning: Ignoring declared target(s) 'Network' in the system package
warning: system packages are deprecated; use system library targets instead

So it doesn't recognize that this is a system library. I tried removing the product section, given that I don't really build a library. It is all about the header nothing else. No luck. The message is identical.

Oh I think you also need to move the modulemap to a directory under Sources. So the modulemap file should be at:

<pkg>/Sources/Network/module.modulemap

Thanks. I got it working. I had to remove the path in systemLibrary definition.

1 Like

Great!

Side note. I ran into this error while trying to code along with the examples at:

Specifically the line swift package init --type system-module Is it possible to update these docs? I would update them myself and open a PR but as somebody just at the tutorials phase of this I'm not sure I'm qualified to write the tutorial yet. :stuck_out_tongue:

4 Likes

Is there an update now?