ttypic/swift-klib-plugin

Can't expose native type (CBManagerState).

Opened this issue · 3 comments

While having public code with some types from native frameworks other than foundation , I'm getting an error:

/iosArm64/swiftBuild/.build/arm64-apple-macosx/release/BleCommunication.build/BleCommunication-Swift.h:366:33: error: unknown type name 'CBManagerState'

The code which I have is very simple

import CoreBluetooth

public static var state: CBManagerState { .unknown }

Currently I've wrapped my enum, but it's not a best trick.
Can we specify headers or other options?

@maksimpetrovskycorewill Hi!
If this issue is still relevant for you, please provide small reproducer and I would help you.
Otherwise, let me know and I will close the issue.

@maksimpetrovskycorewill Hi! If this issue is still relevant for you, please provide small reproducer and I would help you. Otherwise, let me know and I will close the issue.

Hello , the root cause of that issues , not relates to this lib, but caused by xcodebuild, unfortunately by default it's not exposing system libraries Headers used in swift. The example is using CBManagerState in code,

import CoreBluetooth

@objc public class CBManagerStateObserver: NSObject { 
    @obj public var state: CBManagerState = .unknown
}

in the result of build
LibName-Swift.h
doesn't contain
#include <CoreBluetooth/CoreBluetooth.h>
and kotlin fails klib due to missing header with error error: unknown type name 'CBManagerState'

I've tried pods and In the pods I've able to achieve this by adding CoreBluetooth.h with following code:

#include <CoreBluetooth/CoreBluetooth.h>

but SPM is not supporting language mixes inside one package, so I can't add header in Sources.
Of course we can add it manually to some directory and Link in def file, but currently we have no control over def file creation.
I've tried this manually and it was also worked.
But for now we simply exposing Int instead of such type.
As solution feature to inject headers to def file by specifying path can be very useful for such cases.

Offtopic: So currently , I'm in development state of the plugin , which is inspired by swiftklib, for building Xcode frameworks from xcodeproj.

  1. Flexible configuration of build phase
  2. Abilities to mix code inside framework
  3. Ability to use dependencies : SPM, frameworks etc.
    Btw in addition we're using xcodegen yml to define project and I'm using static_framework.yml template.

@maksimpetrovskycorewill Hi! If this issue is still relevant for you, please provide small reproducer and I would help you. Otherwise, let me know and I will close the issue.

Hello , the root cause of that issues , not relates to this lib, but caused by xcodebuild, unfortunately by default it's not exposing system libraries Headers used in swift. The example is using CBManagerState in code,

import CoreBluetooth

@objc public class CBManagerStateObserver: NSObject { 
    @obj public var state: CBManagerState = .unknown
}

in the result of build LibName-Swift.h doesn't contain #include <CoreBluetooth/CoreBluetooth.h> and kotlin fails klib due to missing header with error error: unknown type name 'CBManagerState'

I've tried pods and In the pods I've able to achieve this by adding CoreBluetooth.h with following code:

#include <CoreBluetooth/CoreBluetooth.h>

but SPM is not supporting language mixes inside one package, so I can't add header in Sources. Of course we can add it manually to some directory and Link in def file, but currently we have no control over def file creation. I've tried this manually and it was also worked. But for now we simply exposing Int instead of such type. As solution feature to inject headers to def file by specifying path can be very useful for such cases.

Offtopic: So currently , I'm in development state of the plugin , which is inspired by swiftklib, for building Xcode frameworks from xcodeproj.

  1. Flexible configuration of build phase
  2. Abilities to mix code inside framework
  3. Ability to use dependencies : SPM, frameworks etc.
    Btw in addition we're using xcodegen yml to define project and I'm using static_framework.yml template.

I see!
I'm currently in a process of writing a fix for proper system headers exposure 😀