Repository navigation
tsbindgen: bind non-virtual C++ methods by @cppname, portable across OSes - #690
Merged
Merged
Conversation
…OSes A generated @cpp class bound each non-virtual method by the host's mangled symbol (@Linkname), so a binding made on Windows didn't link on Linux. HeaderParser now spells the method's C++ declaration in the subset @cppname mangles - builtins, <stdint.h>/<stddef.h> typedefs as written, records and enums by qualified name and tag, cv pointers and references, a const method - with the name always qualified by the C++ class (the TS class can be renamed by --strip-prefix or a namespace). The declaration is kept only when tslang's own mangler gives clang's symbol for the parse target; otherwise (a function pointer, a template specialization, a ref-qualified method, a header's own int64_t that the target defines otherwise) the method keeps @Linkname. TsClangImporter compiles CppMangler.cpp (LLVM-only) for that check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Follows #689. A generated
@cppclass bound each non-virtual method by the host's mangled symbol (@linkname("?id@Shape@geo@@QEAAHH@Z")), so bindings generated on Windows didn't link on Linux. tsbindgen now emits the C++ declaration instead, which@cppnamemangles for whichever target compiles it:HeaderParserspells the declaration from clang's AST in the subset@cppnameaccepts: builtins,<stdint.h>/<stddef.h>typedefs as written (other typedefs desugared), records/enums by qualified name withclass/union/enumtags, cv pointers and references, trailingconst.--strip-prefix, a dropped namespace), and an unqualified name would be mangled under the TS name.mangleCppNamefor the parse triple equals clang's symbol; otherwise the method keeps@linkname(function pointers, template specializations, ref-qualified methods, a header's ownint64_tthat differs from the target's).../TypeScript/CppMangler.cpp(LLVM-only) for that check — no dependency on MLIRTypeScript.extern "C"C++ functions; C functions keep@linkname.docs/cpp-classes.mdupdated (README example checked against real tsbindgen output).Tests
@cppnameon Windows and Linux), a type-spelling test across x86_64-windows-msvc, x86_64-linux, aarch64-darwin, aarch64-linux, fallback tests (unspellable, mangles-otherwise), and a--strip-prefixnaming test.ctest -C Release -R "bindgen|TsClangImporter|cppname|linkname|MLIRGenTests": 40/40 (Windows Release). The bindgen-cpp e2e test links and runsfx::Shape::idthrough the generated@cppname(exe + JIT).🤖 Generated with Claude Code