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

Can't expose native type (CBManagerState). #27

Open
maksimpetrovskycorewill opened this issue Feb 22, 2024 · 3 comments
Open

Can't expose native type (CBManagerState). #27

maksimpetrovskycorewill opened this issue Feb 22, 2024 · 3 comments

Comments

@maksimpetrovskycorewill
Copy link

maksimpetrovskycorewill commented Feb 22, 2024

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?

@IlyaGulya
Copy link
Collaborator

@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
Copy link
Author

maksimpetrovskycorewill commented Jul 26, 2024

@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.

@IlyaGulya
Copy link
Collaborator

@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 😀

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

2 participants