Porting bridging header to Linux

I've build a command line tool in Swift under Xcode to parse frames captured off an Ethernet. Doing so required defining headers as C include files so that '''attribute((packed))''' was available. Now that it's working well, I want to port the code to Linux where we plan to actually use the tool.

I'm trying to do this via the Package Manager, but can't find a way to work the equivalent of telling Xcode to use the bridging header. Is there a way to do this?

I did try a makefile and '''-import-objc-header''', but then couldn't find the right way to get the '''swift''' command to find the SwiftProtobuf module.

You cannot use an ObjC bridging header outside of Apple Application development in Xcode. You also wouldn't want to use one on Linux because Swift on Linux doesn't support the ObjC runtime at all.

You will need to convert it have a proper umbrella header or to create a modulemap for SwiftPM to use.

It wasn't so much wanting ObjC as wanting C include files so that attribute ((packed)) was available - literally, I just need types.h and one of my own includes to be imported. I did try making it work via SwiftPM, but can't find a way to get that to work either - nothing I tried even parsed, so I'm clearly not seeing what I need to do.

You will need to put your headers where they are expected by SwiftPM (see this). The C code will need to be its own target. If you just have a header an no actual C code, you will need a dummy C file like SwiftPM does internally here.

Outside of SwiftPM's clibc target as an example the repos that I have on GitHub doing this can be found here and here. You will want to look at the include/ in the C targets of those projects to see how the headers/modulemap are setup.

If your project is open source I am happy to look at it as well.

1 Like
Terms of Service

Privacy Policy

Cookie Policy