Skip to content

Rewrite golang support#7098

Merged
waruqi merged 6 commits intodevfrom
go
Dec 5, 2025
Merged

Rewrite golang support#7098
waruqi merged 6 commits intodevfrom
go

Conversation

@waruqi
Copy link
Member

@waruqi waruqi commented Dec 5, 2025

  • Before adding new features and new modules, please go to issues to submit the relevant feature description first.
  • Write good commit messages and use the same coding conventions as the rest of the project.
  • Please commit code to dev branch and we will merge into master branch in feature
  • Ensure your edited codes with four spaces instead of TAB.

  • 增加新特性和新模块之前,请先到issues提交相关特性说明,经过讨论评估确认后,再进行相应的代码提交,避免做无用工作。
  • 编写友好可读的提交信息,并使用与工程代码相同的代码规范,代码请用4个空格字符代替tab缩进。
  • 请提交代码到dev分支,如果通过,我们会在特定时间合并到master分支上。
  • 为了规范化提交日志的格式,commit消息,不要用中文,请用英文描述。

@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 comprehensive rewrite of Xmake's Go language support, aiming to modernize and simplify the build experience. By transitioning to the unified go build command, the changes streamline the compilation and linking process, enhance cross-compilation capabilities across various platforms and architectures, and improve the overall robustness of Go project management within Xmake. The refactor also includes updates to flag detection and environment variable handling, making Go builds more consistent and easier to configure.

Highlights

  • Modernized Go Build Process: The Go build system has been refactored to exclusively use the unified go build command, replacing the previous reliance on separate go tool compile and go tool link commands. This simplifies the build logic and aligns with modern Go practices.
  • Enhanced Cross-Compilation Support: Expanded mappings for GOOS (Go Operating System) and GOARCH (Go Architecture) now cover a broader range of platforms and architectures, significantly improving Xmake's ability to cross-compile Go projects. Default environment variables like CGO_ENABLED=0, GO111MODULE=off, and GOPATH are now set to facilitate smoother cross-compilation and module handling.
  • Streamlined Flag Detection and Build Rules: The logic for detecting Go compiler/linker flags has been updated to query go help build and go build -h, making it more robust. Additionally, the build rules have been simplified, moving from on_build_files("build.object") to a single on_build("build.target").
  • Removed Legacy Build Components: Several legacy files and rules related to separate object file compilation (xmake/rules/go/build/object.lua) and Go environment setup (xmake/rules/go/env/xmake.lua) have been removed, reflecting the consolidated approach of the new build system.
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 is a significant and valuable rewrite of the Go language support, modernizing it to use the go build command and greatly improving cross-compilation capabilities. The changes are well-structured and move xmake's Go support in the right direction. However, I've identified a few critical issues: a compilation error in a test file, a missing build script that will likely break all Go builds, and a new default configuration that disables Go modules, which could be problematic for modern Go projects. Addressing these points will make this excellent contribution ready for merging.

import (
"fmt"
"module"
"test"
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The import path has been changed from "module" to "test", but the function calls in Run() still use module.Add and module.Sub. This will cause a compilation error as the imported package is now test. The function calls should be updated to use the new package name, for example test.Add(...).

end
end)
on_build_files("build.object")
on_build("build.target")
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The build process is now correctly hooked into on_build("build.target"). However, this requires a corresponding script file at xmake/rules/go/build/target.lua to define the build implementation. This file appears to be missing from the pull request. Without it, any attempt to build a Go target will fail as xmake won't be able to find the build script. You should add a target.lua file for the go rule, similar in structure to those for other languages like Rust or Nim.

Comment on lines +55 to +59
-- Disable Go modules mode to use GOPATH mode
-- This allows Go to find packages using GOPATH
if not os.getenv("GO111MODULE") then
toolchain:add("runenvs", "GO111MODULE", "off")
end
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Forcing GO111MODULE=off disables Go modules, which is the standard for dependency management in modern Go projects. This is a very restrictive default that will break builds for most current Go projects relying on go.mod. A better approach would be to not set this variable, allowing the Go toolchain to use its own defaults (which are module-aware), or to set it to "auto" to support both module-based and GOPATH-based projects.

        -- Set Go modules mode. 'auto' is a flexible default.
        -- This allows using Go modules or GOPATH depending on project structure.
        if not os.getenv("GO111MODULE") then
            toolchain:add("runenvs", "GO111MODULE", "auto")
        end


-- add build flags
if flags then
table.join2(argv, flags)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using table.join2 is effective, but for combining flags which can be complex (e.g., multiple -ldflags), it might be safer and clearer to handle them more granularly. The current implementation merges all flags into a single list, which could lead to issues if flags need to be paired with their values, especially with how -ldflags are constructed elsewhere as a two-element table. A more robust approach would be to process flags, particularly those like -ldflags, to ensure they are correctly formatted and merged.

@waruqi waruqi marked this pull request as ready for review December 5, 2025 05:19
@waruqi waruqi added this to the v3.0.6 milestone Dec 5, 2025
@waruqi waruqi merged commit 741f725 into dev Dec 5, 2025
71 of 72 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.

1 participant