Skip to content

C++ Interop Example #139

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

Open
ADKaster opened this issue May 19, 2025 · 5 comments
Open

C++ Interop Example #139

ADKaster opened this issue May 19, 2025 · 5 comments

Comments

@ADKaster
Copy link

I took a crack at trying to create an example project for including a Swift library as a dependency to an existing C++ Zephyr project. Well by "existing" I mean, the app main is a C++ file, not that I have an existing Zephyr project to integrate with.

That example lives here: https://github.com/ADKaster/swift-embedded-export-zephyr

I based it off of some of the examples in this repository for Zephyr.

It's possible that "Zephyr + C++" is too tricky of a target to create this interop example for embedded from. But I doubt that this is a problem unique to me.

Would an example in a different operating environment be a good fit for this repo?

@rauhul
Copy link
Collaborator

rauhul commented May 23, 2025

Yeah this would be a good thing to include in an example attached to the integrate with zephyr guide in #140

@xtremekforever
Copy link
Contributor

This seems interesting, @ADKaster do you want a crack at adding the example to the document or shall I have a look later?

@ADKaster
Copy link
Author

@xtremekforever if my example worked, I wouldn't mind taking a crack at cleaning it up for use in your examples here. However, it doesn't quite build and I don't know enough about zephyr to fix all the compile errors I was seeing that are unrelated to Swift. They were mostly related to trying to use C++ in zephyr. Perhaps a non-zephyr example would be easier to handle?

I will note that the CMake files in my example repo are modified versions of what @etcwilde maintains at https://github.com/apple/swift-cmake-examples/tree/main/3_bidirectional_cxx_interop.

@ADKaster
Copy link
Author

Also iirc I filed swiftlang/swift#80570 while playing with this example. Evan's CMake scripts attempt to extract information about target-specific include dirs and lib dirs from swiftc -print-target-info. But this completely falls over when using -enable-experimental-feature Embedded.

Relevant script lines:
https://github.com/ADKaster/swift-embedded-export-zephyr/blob/main/cmake/InitializeSwift.cmake#L39

@xtremekforever
Copy link
Contributor

Oh okay, I thought the example was something that was already working. I could see a simple C++ interop example with embedded Swift could be more useful

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

3 participants