Skip to content

Improve xmake.sh/configure and add ninja generator support#7019

Merged
waruqi merged 7 commits intodevfrom
configure
Nov 13, 2025
Merged

Improve xmake.sh/configure and add ninja generator support#7019
waruqi merged 7 commits intodevfrom
configure

Conversation

@waruqi
Copy link
Member

@waruqi waruqi commented Nov 12, 2025

@waruqi waruqi added this to the v3.0.5 milestone Nov 12, 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 significantly enhances the xmake.sh/configure script by introducing comprehensive support for the Ninja build system. This allows projects to leverage Ninja's speed and efficiency for builds. Additionally, the PR includes several internal improvements to the configure script's utility functions, making it more robust and maintainable across different environments.

Highlights

  • Ninja Build System Support: The configure script now fully supports generating build.ninja files, enabling projects to be built using the high-performance Ninja build system.
  • Improved configure Script Logic: Several core utility functions within the configure script have been refactored for better robustness, portability, and clarity, including string manipulation, argument parsing, and OS detection.
  • Submodule Update: The core/src/tbox/tbox submodule has been updated to a newer commit.
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 significantly improves the configure script by refactoring several functions to use pure shell, which enhances performance and portability. It also introduces comprehensive support for the Ninja generator. The changes are well-structured and the move away from external commands like sed is a great improvement. I've identified a few areas for further improvement, including some code simplification for maintainability and a potential bug in the run script logic for Windows-like environments. Overall, this is a solid contribution.

Comment on lines +4807 to +4816
if is_host "msys" "cygwin" "mingw"; then
local projectdir="${xmake_sh_projectdir}"
local targetfile_rel="./${targetfile}"
local targetfile_alt="./build/${targetfile#*/}"
local targetbuilddir="${targetfile%/*}"
local targetbuilddir_rel="./${targetbuilddir}"
local targetbuilddir_alt="./build/${targetbuilddir#*/}"
local run_script="cd \"${projectdir}\" && target=\"${targetfile_rel}\"; alt=\"${targetfile_alt}\"; if [ ! -f \"\$target\" ] && [ -f \"\$alt\" ]; then target=\"\$alt\"; fi; if [ ! -f \"\$target\" ]; then echo \"[ninja run] missing ${targetfile_rel} (and fallback ${targetfile_alt})\"; ls -l \"${targetbuilddir_rel}\" || true; ls -l \"${targetbuilddir_alt}\" || true; exit 1; fi; \"\$target\""
_shell_escape_single_quotes "${run_script}"; local run_script_escaped="${_ret}"
command="sh -lc ${run_script_escaped}"
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The fallback logic for finding the target executable on msys/mingw environments seems flawed. The expression ${targetfile#*/} on line 4810 strips all directory components from the path, which can lead to incorrect paths and name collisions if multiple targets share the same filename in different directories. For example, build/foo/bar becomes bar, and the fallback path becomes ./build/bar. This is likely not the intended behavior and can cause the run command to fail or run the wrong executable.

A similar issue exists on line 4813 with ${targetbuilddir#*/}.

I recommend removing this complex and fragile fallback logic, or fixing it to correctly handle paths. The primary path should be sufficient if correctly configured.

Comment on lines +132 to +155
_ninja_escape() {
local rest="${1}"
case "${rest}" in
*\$*)
local result=""
while :; do
case "${rest}" in
*\$*)
result="${result}${rest%%\$*}\$\$"
rest="${rest#*\$}"
;;
*)
result="${result}${rest}"
break
;;
esac
done
_ret="${result}"
;;
*)
_ret="${rest}"
;;
esac
}
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 while loop in this function can be made more concise. The inner case statement is a bit redundant and the loop can be expressed more directly, improving readability.

Suggested change
_ninja_escape() {
local rest="${1}"
case "${rest}" in
*\$*)
local result=""
while :; do
case "${rest}" in
*\$*)
result="${result}${rest%%\$*}\$\$"
rest="${rest#*\$}"
;;
*)
result="${result}${rest}"
break
;;
esac
done
_ret="${result}"
;;
*)
_ret="${rest}"
;;
esac
}
_ninja_escape() {
local rest="${1}"
case "${rest}" in
*\$*)
local result=""
while case "${rest}" in *\$*) true;; *) false;; esac; do
result="${result}${rest%%\$*}\$\$"
rest="${rest#*\$}"
done
_ret="${result}${rest}"
;;
*)
_ret="${rest}"
;;
esac
}

Comment on lines +157 to 180
_shell_escape_single_quotes() {
local value="${1}"
case "${value}" in
*"'"*)
local escaped=""
while :; do
case "${value}" in
*"'"*)
escaped="${escaped}${value%%\'*}'\"'\"'"
value="${value#*\'}"
;;
*)
escaped="${escaped}${value}"
break
;;
esac
done
_ret="'${escaped}'"
;;
*)
_ret="'${value}'"
;;
esac
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Similar to _ninja_escape, the while loop in this function can be simplified for better readability and conciseness.

Suggested change
_shell_escape_single_quotes() {
local value="${1}"
case "${value}" in
*"'"*)
local escaped=""
while :; do
case "${value}" in
*"'"*)
escaped="${escaped}${value%%\'*}'\"'\"'"
value="${value#*\'}"
;;
*)
escaped="${escaped}${value}"
break
;;
esac
done
_ret="'${escaped}'"
;;
*)
_ret="'${value}'"
;;
esac
}
_shell_escape_single_quotes() {
local value="${1}"
case "${value}" in
*"'"*)
local escaped=""
while case "${value}" in *"'"*) true;; *) false;; esac; do
escaped="${escaped}${value%%\'*}"'\"'\"'"
value="${value#*\'}"
done
_ret="'${escaped}${value}'"
;;
*)
_ret="'${value}'"
;;
esac
}

configure Outdated
Comment on lines +4660 to +4667
local command=""
local use_shell_wrapper=false
if is_host "msys" "cygwin" "mingw"; then
use_shell_wrapper=true
command="mkdir -p \"${objectdir}\" && ${compcmd}"
else
command="mkdir -p \"${objectdir}\" && ${compcmd}"
fi
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 if/else block contains identical code for setting the command variable. This can be simplified by setting command before the if block and only handling use_shell_wrapper inside it, which removes redundancy and improves maintainability.

Suggested change
local command=""
local use_shell_wrapper=false
if is_host "msys" "cygwin" "mingw"; then
use_shell_wrapper=true
command="mkdir -p \"${objectdir}\" && ${compcmd}"
else
command="mkdir -p \"${objectdir}\" && ${compcmd}"
fi
local use_shell_wrapper=false
local command="mkdir -p \"${objectdir}\" && ${compcmd}"
if is_host "msys" "cygwin" "mingw"; then
use_shell_wrapper=true
fi

configure Outdated
Comment on lines +4709 to +4716
local command=""
local use_shell_wrapper=false
if is_host "msys" "cygwin" "mingw"; then
use_shell_wrapper=true
command="mkdir -p \"${targetdir}\" && ${linkcmd}"
else
command="mkdir -p \"${targetdir}\" && ${linkcmd}"
fi
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 if/else block has duplicated code for setting the command variable. It can be simplified for better readability and maintainability.

Suggested change
local command=""
local use_shell_wrapper=false
if is_host "msys" "cygwin" "mingw"; then
use_shell_wrapper=true
command="mkdir -p \"${targetdir}\" && ${linkcmd}"
else
command="mkdir -p \"${targetdir}\" && ${linkcmd}"
fi
local use_shell_wrapper=false
local command="mkdir -p \"${targetdir}\" && ${linkcmd}"
if is_host "msys" "cygwin" "mingw"; then
use_shell_wrapper=true
fi

@waruqi waruqi merged commit 27cf241 into dev Nov 13, 2025
44 checks passed
@waruqi waruqi deleted the configure branch November 13, 2025 22:30
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.

1 participant