Skip to content

Fix use zigcc with autotools when dynamic linking.#6959

Merged
waruqi merged 2 commits intoxmake-io:devfrom
Redbeanw44602:fix/zigcc-lld
Oct 22, 2025
Merged

Fix use zigcc with autotools when dynamic linking.#6959
waruqi merged 2 commits intoxmake-io:devfrom
Redbeanw44602:fix/zigcc-lld

Conversation

@Redbeanw44602
Copy link
Contributor

@Redbeanw44602 Redbeanw44602 commented Oct 22, 2025

This patch fixes a dynamic linking problem when using autotools with zigcc.

For more information( about this problem), please refer here:
https://github.com/xmake-io/xmake/blob/6b27644dd38664a1a2253faec53c88f0ea9fcf06/xmake/modules/package/tools/autoconf.lua#L434...L439


This patch has been tested and works, but there are two questions🤔:

  • I am not familiar with the syntax of toolchain definition scope. Maybe the definition of toolset is wrong (it will produce unknown toolkind).
  • zig ld.lld (and other tools added in this patch) are not documented in the zig, but I think they just forgot to update the documentation.

https://github.com/ziglang/zig/blob/a027fa8b8c03f8c325c4347500d0487c6d366f81/src/main.zig#L283
https://github.com/ziglang/zig/blob/a027fa8b8c03f8c325c4347500d0487c6d366f81/src/main.zig#L77...L117

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Redbeanw44602, 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 a critical dynamic linking problem encountered when integrating the zigcc toolchain with autoconf-based projects. By explicitly configuring autoconf to use zig ld.lld as the linker and expanding the zigcc wrapper to support additional linking and resource compilation tools, this change significantly enhances the compatibility and robustness of xmake when building projects that leverage Zig's compiler and autoconf.

Highlights

  • Dynamic Linking Fix: Resolves a dynamic linking issue encountered when using the zigcc toolchain with autoconf.
  • Linker Configuration: Ensures that autoconf explicitly uses zig ld.lld as the linker when zigcc is the active linker tool.
  • Expanded Tool Support: Adds lib, ld.lld, lld-link, wasm-ld, and rc to the list of tools that are wrapped by zigcc.
  • Toolchain Definition Update: Updates the zig toolchain's toolset configuration to correctly map the newly supported tools.
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 effectively fixes a dynamic linking issue when using zig cc with autotools by correctly setting the LD environment variable. The approach of extending the zig toolchain with more tools like ld.lld is sound and makes the toolchain more robust.

Regarding your questions:

  1. The way you've defined the new toolsets (e.g., ld.lld, lld-link) is functionally correct for xmake. While these are not standard toolkinds and might produce "unknown toolkind" warnings in verbose mode, this is an acceptable way to extend a toolchain for specific needs. The ideal long-term solution would be to register these toolkinds in xmake's core, but that's beyond the scope of this PR.
  2. Relying on undocumented zig subcommands is a calculated risk, but given they are present in the source and necessary for the toolchain's functionality, it's a reasonable choice.

I have one suggestion to improve the changes. The toolkind rc is typically used for the Rust compiler. For the Windows Resource Compiler, xmake uses the mrc toolkind. I've added comments to suggest this change for better consistency and to avoid potential conflicts.

@waruqi waruqi merged commit 6796d33 into xmake-io:dev Oct 22, 2025
21 of 22 checks passed
@waruqi waruqi added this to the v3.0.5 milestone Oct 22, 2025
@Redbeanw44602 Redbeanw44602 deleted the fix/zigcc-lld branch October 23, 2025 00:02
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