Skip to content

Implement logic add_deps with {public = false}#7350

Closed
luadebug wants to merge 7 commits into
xmake-io:devfrom
luadebug:add
Closed

Implement logic add_deps with {public = false}#7350
luadebug wants to merge 7 commits into
xmake-io:devfrom
luadebug:add

Conversation

@luadebug
Copy link
Copy Markdown
Member

@luadebug luadebug commented Feb 25, 2026

Resolves: #7079

b.c(直接依赖 — 必须继承):

  • #include "*.h" — 证明包含路径继承(否则无法编译)
  • #ifndef HAS_* / #error — 证明 define 是继承的

main.c(传递式依赖 — 必须不继承):

  • #if __has_include("*.h") / #error — 证明包含路径继承
  • #ifdef HAS_* / #error — 证明定义不是继承的
场景 A 类型 B 类型 b 得到 -I? b 得到 -D? c 得到 -I? c 得到 -D?
1 仅标题 静态 -Iheaderonly_dir -DHAS_HEADERONLY_A=1 (无) (无)
2 静态 静态 -Istatic_static_dir -DHAS_SS_A=2 (无) (无)
3 共享 静态 -Ishared_static_dir -DHAS_DS_A=3 (无) (无)
4 静态 共享 -Istatic_shared_dir -DHAS_SD_A=4 (无) (无)

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @luadebug, 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 refines Xmake's dependency management by introducing a mechanism to control the transitivity of build flag inheritance. Specifically, it enables users to declare a dependency as non-public, preventing its build flags from propagating further down the dependency chain to indirect dependents. This change enhances modularity and prevents unintended flag pollution in complex projects, ensuring that only direct dependents receive necessary build configurations.

Highlights

  • Dependency Inheritance Logic: Implemented the public = false logic for add_deps in Xmake, ensuring that build flags (like includedirs and defines) are not transitively inherited by downstream dependencies when explicitly marked as non-public.
  • New Test Cases: Added comprehensive test cases to validate the public = false behavior across various target kinds, including header-only, static, and shared libraries, and their combinations.

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

Changelog
  • tests/apis/add_deps_public/headeronly_dir/headeronly_a.h
    • Added a header-only library definition for testing public = false behavior.
  • tests/apis/add_deps_public/shared_static_dir/ds_a.h
    • Added a header for a shared library component used in testing.
  • tests/apis/add_deps_public/src/headeronly/b.c
    • Added source file for a static library b depending on header-only a.
  • tests/apis/add_deps_public/src/headeronly/main.c
    • Added main application source file to test non-transitive inheritance from header-only a.
  • tests/apis/add_deps_public/src/shared_static/a.c
    • Added source file for a shared library a component.
  • tests/apis/add_deps_public/src/shared_static/b.c
    • Added source file for a static library b depending on shared a.
  • tests/apis/add_deps_public/src/shared_static/main.c
    • Added main application source file to test non-transitive inheritance from shared a.
  • tests/apis/add_deps_public/src/static_shared/a.c
    • Added source file for a static library a component.
  • tests/apis/add_deps_public/src/static_shared/b.c
    • Added source file for a shared library b depending on static a.
  • tests/apis/add_deps_public/src/static_shared/main.c
    • Added main application source file to test non-transitive inheritance from static a.
  • tests/apis/add_deps_public/src/static_static/a.c
    • Added source file for a static library a component.
  • tests/apis/add_deps_public/src/static_static/b.c
    • Added source file for a static library b depending on static a.
  • tests/apis/add_deps_public/src/static_static/main.c
    • Added main application source file to test non-transitive inheritance from static a.
  • tests/apis/add_deps_public/static_shared_dir/sd_a.h
    • Added a header for a static library component used in testing.
  • tests/apis/add_deps_public/static_static_dir/ss_a.h
    • Added a header for a static library component used in testing.
  • tests/apis/add_deps_public/xmake.lua
    • Added a new Xmake configuration file to define and orchestrate the public = false test scenarios.
  • xmake/core/project/target.lua
    • Modified the _build_deps function to incorporate public = false logic for dependency inheritance.
    • Ensured that public = false blocks transitive inheritance of build flags while still allowing direct inheritance.
Activity
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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 implements the {public = false} option for add_deps to control transitive dependency inheritance. The core logic change in xmake/core/project/target.lua correctly handles this by checking the public flag for transitive dependencies. The accompanying tests are comprehensive, covering various target kinds and dependency scenarios to ensure the new logic works as expected. I have one suggestion to improve code conciseness in the logic implementation.

Comment thread xmake/core/project/target.lua Outdated
@luadebug
Copy link
Copy Markdown
Member Author

/gemini review

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 correctly implements the {public = false} option for add_deps, which prevents transitive inheritance of dependency properties like defines and include directories. The core logic change in xmake/core/project/target.lua is sound. The accompanying tests are thorough, covering a variety of target types (header-only, static, shared) and ensuring the new behavior is verified. I have one suggestion to improve the readability of the implementation.

Comment thread xmake/core/project/target.lua Outdated
Comment thread xmake/core/project/target.lua Outdated
if t ~= self then
local deppublic = t:extraconf("deps", dep:name(), "public") or t:extraconf("deps", dep:fullname(), "public")
if deppublic ~= nil and not deppublic then
return false
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is no different from using {inherit = false}.

The point of this issue is that deps themselves should also have visibility configurations such as private/public.

It does not control whether the visibility of defines/incudedirs is inherited.

In other words, add_deps("xxx", {public = false}) will be a private dependency of the current target, and will not export any of its configuration, including links.

It also does not affect the dependency order of the top-level target compilation.

This is not something that can be easily achieved; there are many details to consider, so I haven't implemented it yet.

@luadebug luadebug closed this May 7, 2026
@luadebug luadebug deleted the add branch May 7, 2026 17:05
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.

add_deps support {public = false}

2 participants