Wrapping ImageMagick in a Swift Package

Hi,

I am trying to create a Swift Package that wraps the ImageMagick C API. So I installed ImageMagick using MacPorts and
I was then able to build the sample program with the following commands:

export PKG_CONFIG_PATH=/opt/local/lib/pkgconfig
cc main.c `pkg-config --cflags --libs MagickWand`

Then I created a package with the command "swift package init --type=system-module" and I modified Package.swift to look
like this:

// swift-tools-version:4.0

import PackageDescription

let package = Package(
  name: "TestPkg",
  pkgConfig: "MagickWand"
)

and I modified module.modulemap to the following:

module TestPkg [system] {
  header "/opt/local/include/ImageMagick-6/wand/MagickWand.h"
  link "MagickWand-6.Q16"
  link "MagickCore-6.Q16"
  export *
}

Now when I run "swift build", I get the following error message:

<unknown>:0: error: unexpected 'commands' value (expected map)
<unknown>:0: error: unable to load build file
error: terminated(1): /Library/Developer/Toolchains/swift-4.0-DEVELOPMENT-SNAPSHOT-2017-08-27-a.xctoolchain/usr/bin/swift-build-tool -f /Users/tonisuter/Desktop/TestPkg/.build/debug.yaml main

Does anybody know how I can fix this error?

Thanks and best regards
Toni

Hi Toni,

You're not supposed to build the system module package (because there is
nothing to build). Tag and add this package as a dependency and then try to
import the `TestPkg` module that you defined in the modulemap. The error
here is bogus and is tracked by [SR-5383] Display appropriate message when trying to build system module packages · Issue #4988 · apple/swift-package-manager · GitHub

···

On Tue, Oct 3, 2017 at 12:32 AM, Toni Suter via swift-users < swift-users@swift.org> wrote:

Hi,

I am trying to create a Swift Package that wraps the ImageMagick C API. So
I installed ImageMagick using MacPorts and
I was then able to build the sample program with the following commands:

export PKG_CONFIG_PATH=/opt/local/lib/pkgconfig
cc main.c `pkg-config --cflags --libs MagickWand`

Then I created a package with the command "swift package init
--type=system-module" and I modified Package.swift to look
like this:

// swift-tools-version:4.0

import PackageDescription

let package = Package(
name: "TestPkg",
pkgConfig: "MagickWand"
)

and I modified module.modulemap to the following:

module TestPkg [system] {
  header "/opt/local/include/ImageMagick-6/wand/MagickWand.h"
  link "MagickWand-6.Q16"
  link "MagickCore-6.Q16"
  export *
}

Now when I run "swift build", I get the following error message:

<unknown>:0: error: unexpected 'commands' value (expected map)
<unknown>:0: error: unable to load build file
error: terminated(1): /Library/Developer/Toolchains/swift-4.0-DEVELOPMENT-
SNAPSHOT-2017-08-27-a.xctoolchain/usr/bin/swift-build-tool -f
/Users/tonisuter/Desktop/TestPkg/.build/debug.yaml main

Does anybody know how I can fix this error?

Thanks and best regards
Toni

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

Hi Ankit,

Thank you very much! It works now :-)

Best regards,
Toni

···

Am 03.10.2017 um 21:50 schrieb Ankit Aggarwal <ankit_aggarwal@apple.com>:

Hi Toni,

You're not supposed to build the system module package (because there is nothing to build). Tag and add this package as a dependency and then try to import the `TestPkg` module that you defined in the modulemap. The error here is bogus and is tracked by [SR-5383] Display appropriate message when trying to build system module packages · Issue #4988 · apple/swift-package-manager · GitHub

On Tue, Oct 3, 2017 at 12:32 AM, Toni Suter via swift-users <swift-users@swift.org <mailto:swift-users@swift.org>> wrote:
Hi,

I am trying to create a Swift Package that wraps the ImageMagick C API. So I installed ImageMagick using MacPorts and
I was then able to build the sample program with the following commands:

export PKG_CONFIG_PATH=/opt/local/lib/pkgconfig
cc main.c `pkg-config --cflags --libs MagickWand`

Then I created a package with the command "swift package init --type=system-module" and I modified Package.swift to look
like this:

// swift-tools-version:4.0

import PackageDescription

let package = Package(
  name: "TestPkg",
  pkgConfig: "MagickWand"
)

and I modified module.modulemap to the following:

module TestPkg [system] {
  header "/opt/local/include/ImageMagick-6/wand/MagickWand.h"
  link "MagickWand-6.Q16"
  link "MagickCore-6.Q16"
  export *
}

Now when I run "swift build", I get the following error message:

<unknown>:0: error: unexpected 'commands' value (expected map)
<unknown>:0: error: unable to load build file
error: terminated(1): /Library/Developer/Toolchains/swift-4.0-DEVELOPMENT-SNAPSHOT-2017-08-27-a.xctoolchain/usr/bin/swift-build-tool -f /Users/tonisuter/Desktop/TestPkg/.build/debug.yaml main

Does anybody know how I can fix this error?

Thanks and best regards
Toni

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