fix(build): resolve type ambiguity and macro redefinition in unity builds#512
Conversation
…ilds In downstream wasm projects that include tvm-ffi source files in a unity build alongside tvm::runtime, `using namespace tvm::ffi` in object.cc causes ambiguous type references (e.g. `Object` matches both `tvm::ffi::Object` and `tvm::runtime::Object`). Replace with a namespace alias and fully qualify all type names. Move the `TVM_FFI_DLL_EXPORT_INCLUDE_METADATA` define from testing/testing.cc into CMakeLists.txt via target_compile_definitions to avoid macro redefinition warnings when the macro is already set by the build system in unity builds.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses critical build issues related to C++ unity builds, specifically targeting type ambiguity and macro redefinitions. The changes ensure cleaner compilation for projects, especially those integrating Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors the FFI object registration by replacing a using namespace directive with explicit namespace aliases for tvm::ffi and tvm::ffi::reflection in src/ffi/object.cc. It also centralizes the definition of the TVM_FFI_DLL_EXPORT_INCLUDE_METADATA macro by moving it from src/ffi/testing/testing.cc to CMakeLists.txt, where it is now set as a compile definition for the tvm_ffi_testing target. There is no feedback to provide as no review comments were given.
Summary
src/ffi/object.cc: Replaceusing namespace tvm::ffi;with a namespace alias (namespace ffi = ::tvm::ffi;) and fully qualify all type names in the static init block. This prevents ambiguous type references (e.g.Objectmatching bothtvm::ffi::Objectandtvm::runtime::Object) in downstream wasm projects that include tvm-ffi sources in a unity build.src/ffi/testing/testing.cc: Remove the#define TVM_FFI_DLL_EXPORT_INCLUDE_METADATA 1from the source file to avoid macro redefinition warnings in unity builds where the macro is already set by the build system.CMakeLists.txt: Addtarget_compile_definitions(tvm_ffi_testing PRIVATE TVM_FFI_DLL_EXPORT_INCLUDE_METADATA=1)so the define is provided via the build system instead of hardcoded in source.Test plan
ctestin CI)