lolgear
(Dmitry Lobanov)
1
Hi!
I would like to setup Package for ObjC targets: Dynamic Library and Static Library.
I have following folder structure:
.
|── .git
|── .gitignore
|── Package.swift
|── Core
|── FolderOne
|── Worker.h
|── Worker.m
|── FolderTwo
|── Worker2.h
|── Worker2.m
|── FolderThree
|── FolderFour
|── Worker3.h
|── Worker3.m
|── FrameworkSupplement
|── UmbrellaHeader.h
|── map.modulemap
|-- Dependencies
|-- OneDependency
|-- OneDependency.h
|-- OneDependency.m
|── Framework
|── Name
|── Info.plist
|── Tests
|── iOS_Tests
|── Info.plist
|── macOS_Tests
|── Info.plist
|── SharedTests
|── SharedTest2.m
|── SharedTest3.m
and Package.swift:
import PackageDescription
let package = Package(
name: "SuperLibrary",
products: [
.library(
name: "SuperLibrary",
type: .dynamic,
targets: ["SuperLibrary"]),
],
targets: [
.target(name: "SuperLibrary",
path: ".",
exclude: [],
sources: ["Core", "Dependencies/OneDependency/OneDependency.m"],
publicHeadersPath: "Core"), // OneDependency.h is not public, it is private and had been added by hands as plain sources.
]
)
There is no warnings in REPL, but, it doesn't compile. Build action fails because SwiftPM can't find any of my header files ( umbrella or non-umbrella ). Also it can't handle neither framework #import <SuperLibrary/File.h> nor plain #import "File.h" ).
1 Like
I tried AFNetworking, and it works for me. Maybe publicHeadersPath: nil, and then put all your public headers in include directory.
1 Like
lolgear
(Dmitry Lobanov)
3
Is this folder virtual or physical ( file on disk )? I am not willing to change it for only swift package manager.
// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "SuperLibrary",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "SuperLibrary",
type: .dynamic,
targets: ["SuperLibrary"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "SuperLibrary",
path: "Sources",
exclude: [],
sources: ["Core", "Dependencies/OneDependency/OneDependency.m"],
publicHeadersPath: "Core"),
.testTarget(
name: "SuperLibraryTests",
dependencies: ["SuperLibrary"]),
]
)
Maybe this is what you need. No need to create include directory.
lolgear
(Dmitry Lobanov)
5
Can you share example project?
By the way, neither of these headers are included into each other.
So, they are pure public headers without headers imports?
lolgear
(Dmitry Lobanov)
7
Import statements in this example has relative paths.
So, I have reached "alternative" solution by putting all headers in "Core/Include" directory.
Ugly, though.
lolgear
(Dmitry Lobanov)
8
I still have issues with test targets. Headers can not be marked as public or private.
By the way, .testTarget even doesn't have headers, thus, it is impossible to mix helpers/scaffolding/fixtures and test targets.
lolgear
(Dmitry Lobanov)
9
Another interesting problem.
Since I can't use framework import #import <Library/Umbrella.h> ( because umbrella contains framework imports, hah ), I change imports to modern style @import Library;
Everything works fine in Xcode, but I can't build package from command line: swift build throws error: "@import Library; - module not found".
As I mentioned above, I can build package in Xcode and even run tests, but command line swift build/test doesn't work at all.
dreampiggy
(DreamPiggy)
10
Good News for the developers here:
Xcode 11.4 Beta2 (Doubt this is a feature or bug) now totally break publicHeadersPath usage, anything other than .h header file, will be ignored in Xcode's compile sources when put it under publicHeadersPath.
Means:
MyRepo
- Sources
-- Foo.h
-- Foo.m
-- Foo.cpp
-- Foo.c
using
path: "Sources"
publicHeadersPath: "."
Now all the source code will been ignored, this trick not work any more 
You have to arrange folder strcuture, or create symbol link like this
MyRepo
- include
-- Foo.h
- Sources
-- Foo.m
-- Foo.cpp
-- Foo.c
using
path: "Sources"
publicHeadersPath: nil
1 Like