ios – Swift Package containing cpp, objc and swift to XCFramework

0
28

[ad_1]

For one of the projects I’ve inherited I need to do the transition to ASM so as to be able to run the app on M1/2 MacBook simulators. The last framework that I need to update
is Garmin’s FitSDK that comes as a Swift Package

let package = Package(
    name: "FIT",
    platforms: [
            #here I've modified it to be also deployed on iOS12
            .iOS(.v12),
    ],
    products: [
        // Products define the executables and libraries a package produces, and make them visible to other packages.
        .library(
            name: "FIT",
            targets: ["SwiftFIT","ObjcFIT"]),
    ],
    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 this package depends on.
        .target(
            name: "cppfit",
            dependencies: [],
             resources: [
                .copy("include")],
            cSettings: [
                .headerSearchPath("./include/")]),
        .target(
            name: "ObjcFIT",
            dependencies: ["cppfit"],
            cSettings: [
                .headerSearchPath("../cppfit/include")]),
        .target(
            name: "SwiftFIT",
            dependencies: ["ObjcFIT"]),
        .testTarget(
            name: "FITTests",
            dependencies: ["SwiftFIT"]),
    ],
    cxxLanguageStandard: .gnucxx11
)

In order to creation of the XCFramework to support ios-arm64_x86_64-simulator I’m trying to use Srdan’s script from Swift Forums but I have 2 issues:

  1. The generated modulemap if I use it

module FitSDK { export * }

I get a

Include of non-modular header inside framework module 'Project': [...]

at

#import <FitSDK/FitSDK.h>

  1. If I update the modulemap to the old one
framework module FitSDK {
  umbrella header "FitSDK.h"

  export *
  module * { export * }
}

now it won’t find to import the header "FitSDK.h.

If I manually try to copy the headers from the old .framework which was only for arm64 (iOS Device) I get some symbols not found for arm64

Undefined symbols for architecture arm64:
  "_FitCRC_Calc16", referenced from:
      -[FITFileEncoder writeFileHeaderToFile:] in FITFileEncoder-121bb2ba48ce985896496c5403a05f7e.o
  "_FitCRC_Get16", referenced from:
      -[FITFileEncoder writeData:dataSize:file:] in FITFileEncoder-121bb2ba48ce985896496c5403a05f7e.o
  "_Fit_InitMesg", referenced from:
      -[FITFileEncoder writeFileIdMessageToFile:] in FITFileEncoder-121bb2ba48ce985896496c5403a05f7e.o
  "_fit_mesg_defs", referenced from:
      -[FITFileEncoder writeFileIdMessageToFile:] in FITFileEncoder-121bb2ba48ce985896496c5403a05f7e.o
ld: symbol(s) not found for architecture arm64

I realise and (not just) a bit lost but I have no clue on how to get this working.

[ad_2]