Skip to content

Add xmake check syntax support#7094

Merged
waruqi merged 12 commits intodevfrom
syntax
Dec 2, 2025
Merged

Add xmake check syntax support#7094
waruqi merged 12 commits intodevfrom
syntax

Conversation

@waruqi
Copy link
Member

@waruqi waruqi commented Dec 2, 2025

xmake check syntax

mesonbuild/meson#12228

ruki:tbox ruki$ xmake -r
[ 85%]: compiling.release src/tbox/platform/file.c
In file included from src/tbox/platform/file.c:99:
src/tbox/platform/posix/file.c:206:14: warning: 'lstat64' is deprecated: first deprecated in macOS 10.6 [-Wdeprecated-declarations]
  206 |         if (!lstat64(path, &st))
      |              ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/include/sys/stat.h:431:9: note: 'lstat64' has been explicitly marked deprecated here
  431 | int     lstat64(const char *, struct stat64 *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_NA, __IPHONE_NA);
      |         ^
In file included from src/tbox/platform/file.c:99:
src/tbox/platform/posix/file.c:223:22: warning: 'stat64' is deprecated: first deprecated in macOS 10.6 [-Wdeprecated-declarations]
  223 |                 if (!stat64(path, &st))
      |                      ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/include/sys/stat.h:432:9: note: 'stat64' has been explicitly marked deprecated here
  432 | int     stat64(const char *, struct stat64 *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_NA, __IPHONE_NA);
      |         ^
In file included from src/tbox/platform/file.c:99:
src/tbox/platform/posix/file.c:496:13: warning: 'stat64' is deprecated: first deprecated in macOS 10.6 [-Wdeprecated-declarations]
[100%]: build ok, spent 20.103s
ruki:tbox ruki$ xmake check syntax
[ 59%]: compiling.release src/tbox/platform/file.c
In file included from src/tbox/platform/file.c:99:
src/tbox/platform/posix/file.c:206:14: warning: 'lstat64' is deprecated: first deprecated in macOS 10.6 [-Wdeprecated-declarations]
  206 |         if (!lstat64(path, &st))
      |              ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/include/sys/stat.h:431:9: note: 'lstat64' has been explicitly marked deprecated here
  431 | int     lstat64(const char *, struct stat64 *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_NA, __IPHONE_NA);
      |         ^
In file included from src/tbox/platform/file.c:99:
src/tbox/platform/posix/file.c:223:22: warning: 'stat64' is deprecated: first deprecated in macOS 10.6 [-Wdeprecated-declarations]
  223 |                 if (!stat64(path, &st))
      |                      ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/include/sys/stat.h:432:9: note: 'stat64' has been explicitly marked deprecated here
  432 | int     stat64(const char *, struct stat64 *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_NA, __IPHONE_NA);
      |         ^
In file included from src/tbox/platform/file.c:99:
src/tbox/platform/posix/file.c:496:13: warning: 'stat64' is deprecated: first deprecated in macOS 10.6 [-Wdeprecated-declarations]
[100%]: syntax check ok, spent 13.641s
ruki:tbox ruki$

@waruqi waruqi added this to the v3.0.6 milestone Dec 2, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @waruqi, 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 introduces a significant new feature to Xmake: the xmake check syntax command. This command allows developers to quickly verify the syntactic correctness of their C/C++ source code without incurring the overhead of a full compilation and linking process. It integrates compiler-specific flags to perform these checks efficiently and ensures that only relevant files are processed, providing faster feedback on code quality.

Highlights

  • New xmake check syntax command: Introduced a new command to perform syntax-only checks on C/C++ source code without a full build or linking, improving code verification efficiency.
  • Compiler-specific syntax-only flags: Implemented logic to automatically apply compiler-specific flags for syntax-only checks: /Zs for MSVC and -fsyntax-only for GCC/Clang.
  • Skipping linking phase: Modified the build process to explicitly skip the linking phase when performing syntax checks, further optimizing the check duration.
  • New project.policy_set function: Added a new internal function project.policy_set to programmatically set project policies in memory, used here to disable ccache during syntax checks.
  • Improved file handling robustness: Enhanced _get_file_patterns to handle nil sourcefiles gracefully and provided a more informative warning message in _build_files when no files are found.
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
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 introduces xmake check syntax support, a valuable feature for performing syntax checks without a full build. The implementation is well-thought-out, correctly modifying the build process to inject syntax-check flags and bypass linking. The new checker is cleanly implemented. I've provided a few suggestions to enhance code clarity and maintainability by refactoring some functions and addressing minor code duplication. Overall, this is a solid contribution.

Comment on lines +97 to +100
-- is syntax check enabled?
function _is_syntax_check()
return memcache.get("syntax_check", "enabled") or false
end
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This _is_syntax_check function is identical to the one in xmake/modules/core/tools/gcc.lua. To avoid code duplication and improve maintainability, consider moving this function to a shared utility module, for instance, in xmake/modules/private/utils/.

Comment on lines +968 to +983
function project.policy_set(name, value)
-- get current policies from cache or initialize
local policies = project._memcache():get("policies")
if not policies then
-- force initialization by calling policy() once
project.policy(name)
policies = project._memcache():get("policies")
end
policies = policies or {}

-- set the policy value
policies[name] = value

-- update cache
project._memcache():set("policies", policies)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The logic for initializing and setting policies can be simplified. You can make the implementation more straightforward by always calling project.policy() to ensure policies are loaded, and then retrieving them from the cache.

function project.policy_set(name, value)
    -- ensure policies are loaded and get them
    project.policy(name)
    local policies = project._memcache():get("policies") or {}

    -- set the policy value
    policies[name] = value

    -- update cache
    project._memcache():set("policies", policies)
end

Comment on lines +45 to +54
function _has_cpp_rules(target)
for _, ruleinst in ipairs(target:orderules()) do
local rulename = ruleinst:name()
if rulename == "c++.build" or rulename == "c.build" or
rulename == "objc++.build" or rulename == "objc.build" then
return true
end
end
return false
end
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This function can be made more readable and maintainable by using a table lookup for the rule names. This avoids a long chain of or conditions and makes it easier to manage the list of supported rules.

function _has_cpp_rules(target)
    local cpp_rules = {["c++.build"] = true, ["c.build"] = true, ["objc++.build"] = true, ["objc.build"] = true}
    for _, ruleinst in ipairs(target:orderules()) do
        if cpp_rules[ruleinst:name()] then
            return true
        end
    end
    return false
end

Comment on lines +57 to +67
function _check_compiler_support(target)
local has_support = false
if target:has_tool("cc", "gcc", "clang") or target:has_tool("cxx", "gxx", "clangxx") then
-- gcc/clang: -fsyntax-only
has_support = true
elseif target:has_tool("cc", "cl") or target:has_tool("cxx", "cl") then
-- MSVC: /Zs
has_support = true
end
return has_support
end
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This function can be simplified to be more concise and readable by returning the boolean expression directly.

function _check_compiler_support(target)
    -- gcc/clang: -fsyntax-only
    -- MSVC: /Zs
    return (target:has_tool("cc", "gcc", "clang") or target:has_tool("cxx", "gxx", "clangxx"))
        or (target:has_tool("cc", "cl") or target:has_tool("cxx", "cl"))
end

@waruqi waruqi merged commit 605ce1f into dev Dec 2, 2025
66 checks passed
@waruqi waruqi deleted the syntax branch December 2, 2025 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants