test: Try importing NitroTestExternal's Swift header inside NitroTest's C++ code#1154
Draft
test: Try importing NitroTestExternal's Swift header inside NitroTest's C++ code#1154
NitroTestExternal's Swift header inside NitroTest's C++ code#1154Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
NitroTestExternal's Swift header inside `NitroT…NitroTestExternal's Swift header inside NitroTest's C++ code
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
What I want to do is to allow extending a type from another module inside the user's Nitro Module.
Just passing a type from another module as a parameter, or returning it, works fine, but once we want to set up inheritance we need to know the type before including our generated Swift header, and that's where things break because the Swift compiler generates code like this in
*-Swift.h:As you can see,
FirstPod::Firstis used here (and can't be forward-declared), so we must import it (*-Swift.hdoesn't do this by itself, so we have to import/define it before importing our*-Swift.h).But here's where the problems start, because importing the external generated
FirstPod-Swift.hheader in our module is not as easy as it sounds.Findings
Here's my findings after trying to import a Swift generated type inside another module's C++ code (as title says):
-Swift.hheader is private to the specific module. SoNitroTest-Swift.hcan only be imported inNitroTest, andNitroTestExternal-Swift.hinNitroTestExternal. You cannot importNitroTestExternal-Swift.hinside theNitroTestmodule. To fix this, we can enableuse_frameworks!in thePodfile(we can maybe guard this with#if defined(FRAMEWORKS), not yet tested).Cxxwhich only exposes the headers, to avoid recursively importing the -Swift.h header.std::shared_ptr< HybridSomeExternalObjectSpec>- this one is defined inNitroTest-Swift.handNitroTestExternal-Swift.h. How do we fix that? No idea.Side Thoughts
The duplicate definitions are coming from what the Swift compiler emits as public API surface, and since both my Swift classes have public functions accepting or returning C++ types, those are part of the public API. And since the same type is used in two separate modules, the
-Swift.hheader redefines it, which breaks when I try to include both-Swift.hheaders in a single module (when not doing that it's fine as it's separate modules).I currently only see two solutions:
SwiftConverter<T>thingy I kept talking about, but this is gonna be super tricky since some types are simply not supported - e.g.swift::Dictionary<...>)