Skip to content

fix(build): resolve type ambiguity and macro redefinition in unity builds#512

Merged
junrushao merged 1 commit intoapache:mainfrom
junrushao:junrus/2026-03-24/fix-web-runtime-compile
Mar 24, 2026
Merged

fix(build): resolve type ambiguity and macro redefinition in unity builds#512
junrushao merged 1 commit intoapache:mainfrom
junrushao:junrus/2026-03-24/fix-web-runtime-compile

Conversation

@junrushao
Copy link
Copy Markdown
Member

Summary

  • src/ffi/object.cc: Replace using 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. Object matching both tvm::ffi::Object and tvm::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 1 from the source file to avoid macro redefinition warnings in unity builds where the macro is already set by the build system.
  • CMakeLists.txt: Add target_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

  • Verify existing C++ tests pass (ctest in CI)
  • Verify downstream wasm unity builds compile without ambiguity errors or macro redefinition warnings

…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.
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 tvm-ffi sources into WebAssembly environments, by standardizing namespace usage and centralizing macro definitions within the build system.

Highlights

  • Type Ambiguity Resolution: Replaced a global using namespace tvm::ffi; with a namespace alias and fully qualified type names within a static initialization block in src/ffi/object.cc. This change specifically addresses ambiguous type references that can occur in unity builds, particularly in downstream WebAssembly projects.
  • Macro Redefinition Fix: Removed a hardcoded #define TVM_FFI_DLL_EXPORT_INCLUDE_METADATA 1 from src/ffi/testing/testing.cc. This prevents macro redefinition warnings when the macro is already defined by the build system in unity build scenarios.
  • CMake Build System Update: Added target_compile_definitions(tvm_ffi_testing PRIVATE TVM_FFI_DLL_EXPORT_INCLUDE_METADATA=1) to CMakeLists.txt. This ensures the TVM_FFI_DLL_EXPORT_INCLUDE_METADATA macro is provided via the build system, aligning with the removal of its hardcoded definition in the source file.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@junrushao junrushao merged commit 63224e3 into apache:main Mar 24, 2026
8 checks passed
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

Successfully merging this pull request may close these issues.

2 participants