Problem with new Package Manager System Library Targets


(Fred Appelman) #1

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.

(Ankit Aggarwal) #2

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: "."),

(Fred Appelman) #3

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

(Ankit Aggarwal) #4

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

(Fred Appelman) #5

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.

(Ankit Aggarwal) #6

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


(Fred Appelman) #7

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

(Ankit Aggarwal) #8