Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-10782] Document system libraries #4860

Open
swift-ci opened this issue May 28, 2019 · 1 comment
Open

[SR-10782] Document system libraries #4860

swift-ci opened this issue May 28, 2019 · 1 comment

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-10782
Radar None
Original Reporter svanimpe (JIRA User)
Type Improvement
Additional Detail from JIRA
Votes 2
Component/s Package Manager
Labels Improvement
Assignee None
Priority Medium

md5: 8a6b5094e6c7e34715078574fcf37bec

Issue Description:

I'd like to request an update for https://github.com/apple/swift-package-manager/blob/master/Documentation/Usage.md

I wanted to learn about importing C libraries as modules but this documentation sent me on the wrong path.

The instructions no longer work. Following the steps from the libgit2 example doesn't lead to a buildable project:

warning: system packages are deprecated; use system library targets instead
error: the package does not contain a buildable target

This warning suggests I should use a system library instead, but the documentation doesn't mention these. The examples always create a separate package for a C library so I was using a system library inside that separate package, which caused me going in circles.

I eventually came across https://github.com/kelvin13/swift-package-manager/blob/d436338507b20c9ded0017474ab86e8c532fff2b/Documentation/SystemLibraryHowTo.md which led me to the following solution (in a single package):

// Manifest
let package = Package(
    name: "example",
    targets: [
        .systemLibrary(name: "Clibgit", pkgConfig: "libgit2"),
        .target(name: "example", dependencies: ["Clibgit"])
    ]
)

// Module map in Sources/Clibgit
module Clibgit [system] {
  header "/usr/local/include/git2.h"
  export *
}

Is this the correct approach?

Also, it's not clear to me if link statements in the module map are still required. Everything I've tried so far seems to work fine without them. Can they be removed if the pkgConfig attribute is used?

@belkadan
Copy link

cc @aciidb0mb3r

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants