Skip to content

add target architecture validation for cross-compilation in zig toolchain#7269

Merged
waruqi merged 4 commits intoxmake-io:devfrom
luadebug:zig-cross
Jan 27, 2026
Merged

add target architecture validation for cross-compilation in zig toolchain#7269
waruqi merged 4 commits intoxmake-io:devfrom
luadebug:zig-cross

Conversation

@luadebug
Copy link
Member

@luadebug luadebug commented Jan 27, 2026

#7180

hello.cpp

#include <iostream>
#include <opencc/Config.hpp>

int main() {
    opencc::Config config;
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

xmake.lua

set_project("zig_cross_compilation_host_aarch64")
add_rules("mode.debug", "mode.release")

add_requires("opencc", {system = false, configs = {shared = false}}) 
add_packages("opencc")

target("zig_cross_compilation_host_aarch64")
    set_kind("binary")
    add_files("hello.cpp")

Lets assume we cross-compile from amd64 to aarch64... Run xmake f -vD -p linux -m debug -a arm64-v8a --toolchain=zig --cross=aarch64-linux-gnu && xmake

So issue is that it tries to execute aarch64 executable on my amd64 machine... We need to make sure ~host postfix packages are being built to host processor not to target processor.
As /home/lin/Downloads/packages/2601/o/opencc~host/1.1.9/source/build_cc7a577c/src/tools/opencc_dict is very good example of arm64 executable file according to file /home/lin/Downloads/packages/2601/o/opencc~host/1.1.9/source/build_cc7a577c/src/tools/opencc_dict

@gemini-code-assist
Copy link
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 enhances the Xmake build system's Zig toolchain integration by introducing architecture validation for cross-compilation. It prevents potentially invalid or unsupported cross-compilation configurations, specifically for x86_64 and aarch64 architectures, by nullifying the target if a mismatch is detected. This ensures more robust and predictable build behavior when using the Zig toolchain for different platforms.

Highlights

  • Cross-compilation target validation: Introduced validation logic within the Zig toolchain configuration to ensure that cross-compilation targets are compatible with the host architecture.
  • Architecture-specific checks: Specifically added checks for x86_64 and aarch64 architectures, where if the host architecture is one of these, the target architecture must match it exactly for cross-compilation to proceed.
  • Disabling invalid targets: If an x86_64 or aarch64 host attempts to cross-compile to a different architecture, the target is now explicitly set to nil, effectively preventing the unsupported cross-compilation configuration.

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

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.

@luadebug luadebug changed the title add target architecture validation for cross-compilation in zig toolc… add target architecture validation for cross-compilation in zig toolchain Jan 27, 2026
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 adds validation for the target architecture during cross-compilation with the Zig toolchain. The change ensures that if a cross-compilation target is specified, its architecture is consistent with the build's target architecture for x86_64 and aarch64. My review includes a suggestion to refactor the validation logic to be more concise and maintainable, and raises a question about the scope of the validation.

luadebug and others added 2 commits January 27, 2026 08:42
Refactor target and architecture initialization logic for cross-compilation support.
@waruqi waruqi added this to the v3.0.7 milestone Jan 27, 2026
@waruqi waruqi merged commit e1d3f35 into xmake-io:dev Jan 27, 2026
38 checks passed
@Redbeanw44602
Copy link
Contributor

Redbeanw44602 commented Jan 27, 2026

[37/49] cd /home/neko/.xmake/cache/packages/2601/o/opencc/1.1.9/source/build_2a9b6ed8/data && /home/neko/.xmake/packages/o/opencc/1.1.9/8122471a83e545cfba0149a3418b377e/bin/opencc_dict --input /home/neko/.xmake/cache/packages/2601/o/opencc/1.1.9/source/data/dictionary/TWVariantsRevPhrases.txt --output TWVariantsRevPhrases.ocd2 --from text --to ocd2
FAILED: [code=127] data/TWVariantsRevPhrases.ocd2 /home/neko/.xmake/cache/packages/2601/o/opencc/1.1.9/source/build_2a9b6ed8/data/TWVariantsRevPhrases.ocd2 
cd /home/neko/.xmake/cache/packages/2601/o/opencc/1.1.9/source/build_2a9b6ed8/data && /home/neko/.xmake/packages/o/opencc/1.1.9/8122471a83e545cfba0149a3418b377e/bin/opencc_dict --input /home/neko/.xmake/cache/packages/2601/o/opencc/1.1.9/source/data/dictionary/TWVariantsRevPhrases.txt --output TWVariantsRevPhrases.ocd2 --from text --to ocd2
/bin/sh: line 1: /home/neko/.xmake/packages/o/opencc/1.1.9/8122471a83e545cfba0149a3418b377e/bin/opencc_dict: No such file or directory

It's a bit strange; the opencc~host build doesn't seem to be triggered.

$ xmake --version
xmake v3.0.6+dev.e1d3f3555, ...

@luadebug
Copy link
Member Author

If you remove rm -rf /home/neko/.xmake/packages/o/opencc/ I think nothing would change?
Well as for me this works without issues :(

@Redbeanw44602
Copy link
Contributor

I just tested it with actions, and everything works perfectly. It's mysterious xmake on my pc always has some issues that others can't reproduce...

@Redbeanw44602
Copy link
Contributor

Redbeanw44602 commented Jan 28, 2026

The problem is that I have the opencc installed on my Archlinux system, and xmake works correctly if I use a clean container.

opencc's system = false setting is not passed to opencc~host (but it's reasonable?),

Considering that any build using zigcc should use add_requireconfs('**', {system = false}).

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.

3 participants