轩辕镜像 官方专业版
轩辕镜像
专业版
轩辕镜像 官方专业版
轩辕镜像
专业版
首页个人中心搜索镜像
交易
充值流量¥8起我的订单
文档
工具
提交工单页面收录
cargo-zigbuild

messense/cargo-zigbuild

messense

使用zig作为链接器编译Cargo项目,简化交叉编译过程。

2 次收藏下载次数: 0状态:社区镜像维护者:messense仓库类型:镜像最近更新:13 天前
让 AI 帮你使用轩辕镜像? · 展开查看说明 · 点击收起说明

如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。

只需在 AI 对话中先发送下面这段话即可:

请先阅读并遵守:https://xuanyuan.cloud/agents.md

未读文档前不要生成 pull 命令或排错方案。

查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。

DockerHub 官方简介
轩辕镜像中文简介
下载命令
镜像标签列表与下载命令
使用轩辕镜像,把时间还给真正重要的事。
点击查看

cargo-zigbuild

🚀 Help me to become a full-time open-source developer by https://github.com/***/messense

Compile Cargo project with https://github.com/ziglang/zig as linker for easier cross compiling.

Installation

bash
cargo install --locked cargo-zigbuild

You can also install it using pip which will also install https://pypi.org/project/ziglang/ automatically:

bash
pip install cargo-zigbuild

We also provide Docker images which has macOS SDK pre-installed in addition to cargo-zigbuild and Rust, for example to build for x86_64 macOS:

  • Linux docker image (https://github.com/rust-cross/cargo-zigbuild/pkgs/container/cargo-zigbuild, https://hub.docker.com/r/messense/cargo-zigbuild):
bash
docker run --rm -it -v $(pwd):/io -w /io ghcr.io/rust-cross/cargo-zigbuild \
  cargo zigbuild --release --target x86_64-apple-darwin

Usage

  1. Install zig following the official documentation, on macOS, Windows and Linux you can also install zig from PyPI via pip3 install ziglang
  2. Install Rust target via rustup, for example, rustup target add aarch64-unknown-linux-gnu
  3. Run cargo zigbuild, for example, cargo zigbuild --target aarch64-unknown-linux-gnu

Environment Variables

VariableDescription
CARGO_ZIGBUILD_PYTHON_PATHPython executable path when using Python ziglang package (default: python3)
CARGO_ZIGBUILD_ZIG_PATHZig executable path (default: zig)
CARGO_ZIGBUILD_CACHE_DIRCache directory for zig tools and wrappers
CARGO_ZIGBUILD_RUSTC_VERSIONOverride detected rustc version
CARGO_ZIGBUILD_TARGETResolved zig target triple exported to build scripts, for example x86_64-linux-gnu.2.36 (also CARGO_ZIGBUILD_TARGET_<target>, which is always set; the unsuffixed name only when a single --target is given)
SDKROOTPath to macOS SDK (auto-detected on macOS)
CMAKE_TOOLCHAIN_FILEPath to CMake toolchain file (also CMAKE_TOOLCHAIN_FILE_<target>, TARGET_CMAKE_TOOLCHAIN_FILE)
BINDGEN_EXTRA_CLANG_ARGSExtra clang arguments for bindgen (also BINDGEN_EXTRA_CLANG_ARGS_<target>)
PKG_CONFIG_SYSROOT_DIRSystem root for pkg-config (auto-set to SDKROOT for Apple targets)
OHOS_NDK_HOMEPath to OpenHarmony NDK (required for ohos targets)
CFLAGSAdditional C compiler flags
RUSTFLAGSAdditional Rust compiler flags

Specify glibc version

By default --target for *-gnu will have Zig implicitly build for a default version of glibc that varies based on the release of Zig (https://github.com/ziglang/zig/blob/0.14.1/lib/std/Target.zig#L473).

To build for a specific minimum glibc version, add that version as a suffix to the --target value. For example, to compile with --target aarch64-unknown-linux-gnu for glibc 2.17:

bash
cargo zigbuild --target aarch64-unknown-linux-gnu.2.17

[!NOTE] There are https://github.com/rust-cross/cargo-zigbuild/issues/231#issuecomment-*** with the glibc version targeting feature:

  • If you do not provide a --target, Zig is not used and the command effectively runs a regular cargo build.
  • If you specify an invalid glibc version, cargo zigbuild will not relay the warning emitted from zig cc about the fallback version selected.
  • This feature does not necessarily match the behaviour of dynamically linking to a specific version of glibc on the build host.
    • Version 2.32 can be specified, but runs on a host with only 2.31 available when it should instead abort with an error.
    • Meanwhile specifying 2.33 will correctly be detected as incompatible when run on a host with glibc 2.31.
  • Certain RUSTFLAGS like -C linker opt-out of using Zig, while -L path/to/files will have Zig ignore -C target-feature=+crt-static.
  • -C target-feature=+crt-static for statically linking to a glibc version is not supported (upstream zig cc lacks support). Use a *-musl target instead if you need a fully static binary.

Tip - cargo zigbuild cannot find headers (*.h files) or libraries that exist

You may need to prepend the following ENV to your cargo zigbuild command with the following system paths or similar:

  • CFLAGS='-isystem /usr/include'
  • RUSTFLAGS='-L /usr/lib64'

cargo zigbuild always uses the zig cc option -nostdinc which excludes standard header locations like /usr/include. This is also a default behaviour for Zig whenever it is configured with a --target, which additionally opts out of standard system search paths.

This can lead to a common difference between cargo build being successful, while cargo zigbuild fails without extra configuration:

console
# Cannot find a header file to build:
fatal error: 'libelf.h' file not found

# Cannot find a shared library to link:
error: unable to find dynamic system library 'elf' using strategy 'no_fallback'. searched paths

There is a variety of ways to resolve this, but for system paths like /usr/include you must be careful to avoid getting the system glibc headers mixed with the glibc headers Zig provides itself, otherwise this will produce errors like from CPATH=/usr/include:

rust
In file included from /usr/local/lib64/python3.13/site-packages/ziglang/lib/libunwind/src/gcc_personality_v0.c:21:
In file included from /usr/local/lib64/python3.13/site-packages/ziglang/lib/libunwind/include/unwind.h:18:
In file included from /usr/include/stdint.h:26:
In file included from /usr/include/bits/libc-header-start.h:33:
/usr/include/features.h:516:9: warning: '__GLIBC_MINOR__' macro redefined [-Wmacro-redefined]
  516 | #define __GLIBC_MINOR__ 41
      |         ^
<command line>:2:9: note: previous definition is here
    2 | #define __GLIBC_MINOR__ 37
      |

When you have installed system packages that added headers to /usr/include that your project needs to build, you will want Zig to fallback to /usr/include just for those headers while using it's own for glibc. This can be done with zig cc -isystem /usr/include, which for cargo zigbuild can be configured through the common ENV CFLAGS='-isystem /usr/include'.

For the similar issue with shared libraries, if your packages are installing system libraries at /usr/lib64 you would normally use LDFLAGS='-L /usr/lib64', but rustc and cargo do not read this ENV but they must be configured with the search path for crates with a build.rs that searches for a library to link dynamically/statically. Instead you will need to use RUSTFLAGS='-L /usr/lib64'.

Tip - Verify minimum GLIBC version required

Provided you have no stripped the symbols from your binary built, on Linux you can run the following script to scan for glibc versioned symbols and find the highest version (the minimum required to run)

  1. Create a file /usr/local/bin/get-min-glibc:

    bash
    #!/bin/bash
    
    FILE_NAME=$1
    LANG=C readelf -W --version-info --dyn-syms ${FILE_NAME} \
      | grep 'Name: GLIBC' \
      | sed -re 's/.*GLIBC_(.+) Flags.*/\1/g' \
      | sort -t . -k1,1n -k2,2n \
      | tail -n 1
    
  2. Make the script command executable:

    bash
    chmod +x /usr/local/bin/get-min-glibc
    
  3. Run the command with the path to your executable / library to check:

    console
    $ get-min-glibc target/x86_64-unknown-linux-gnu/release/hello-world
    2.28
    

Specify target CPU

When cross-compiling for a CPU newer than the target's baseline — for example AWS Graviton (ARM Neoverse) instances — specify the target CPU via RUSTFLAGS, or you may hit hard-to-diagnose Illegal instruction (SIGILL, exit code 132) errors at runtime, or leave performance on the table:

bash
RUSTFLAGS='-C target-cpu=neoverse-n1' cargo zigbuild --release --target aarch64-unknown-linux-gnu.2.34

cargo zigbuild picks up -C target-cpu and passes a matching -mcpu to zig cc so that C/C++ dependencies are built for the same CPU.

Since environment variables can't be set in cargo aliases, you can also pass the rustflags via cargo's --config option — cargo zigbuild honors it the same way:

bash
cargo zigbuild --release --target x86_64-unknown-linux-gnu \
    --config "target.x86_64-unknown-linux-gnu.rustflags=['-C', 'target-cpu=x86-64-v4']"

This makes it possible to scope a target-cpu to a specific alias in .cargo/config.toml instead of applying it to every build for that target:

toml
[alias]
build-prod = "zigbuild --release --target x86_64-unknown-linux-gnu --config target.x86_64-unknown-linux-gnu.rustflags=['-C','target-cpu=x86-64-v4']"

Conversely, if a binary built for x86_64-unknown-linux-gnu dies with Illegal instruction on older hardware, check whether your RUSTFLAGS/.cargo/config.toml sets a target-cpu newer than the machines you deploy to.

macOS universal2 target

cargo zigbuild supports a special universal2-apple-darwin target for building macOS universal2 binaries/libraries on Rust 1.64.0 and later.

bash
rustup target add x86_64-apple-darwin
rustup target add aarch64-apple-darwin
cargo zigbuild --target universal2-apple-darwin

Note

Note that Cargo --message-format option doesn't work with universal2 target currently.

Caveats

  1. Currently only Linux and macOS targets are supported, other target platforms can be added if you can make it work, pull requests are welcome.
  2. Only current Rust stable and nightly versions are regularly tested on CI, other versions may not work.
  3. When using zig 0.15+ with crates that use https://github.com/rust-lang/rust-bindgen, you may need clang 18+ installed for bindgen to work correctly. This is because zig 0.15+ bundles libc++ 19 headers which require a compatible libclang version.

Known upstream zig https://github.com/ziglang/zig/labels/zig cc:

  1. https://github.com/ziglang/zig/issues/4911: Some Rust targets aren't recognized by zig cc, for example armv7-unknown-linux-gnueabihf, workaround by using -mcpu=generic and explicitly passing target features in https://github.com/rust-cross/cargo-zigbuild/pull/58
  2. https://github.com/ziglang/zig/issues/1349: Set the SDKROOT environment variable to a macOS SDK path to workaround it
  3. https://github.com/ziglang/zig/issues/1290 that may lead to undefined symbol error for certain targets. See also: https://github.com/ziglang/zig/blob/master/lib/compiler_rt/README.md.
  4. https://github.com/ziglang/zig/issues/***

License

This work is released under the MIT license. A copy of the license is provided in the LICENSE file.

镜像拉取方式

您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。

轩辕镜像加速拉取命令点我查看更多 cargo-zigbuild 镜像标签

docker pull docker.xuanyuan.run/messense/cargo-zigbuild:<标签>

使用方法:

  • 登录认证方式
  • 免认证方式

DockerHub 原生拉取命令

docker pull messense/cargo-zigbuild:<标签>

轩辕镜像配置手册

按平台快速找到配置文档

一键安装

一键安装 Docker

Linux Docker 一键安装

AI

用 AI 使用轩辕镜像

agents.md · AI 对话 · 提示词

Docker

登录仓库拉取

登录认证 · 私有仓库

专属域名拉取

免登录 · 高速拉取

Linux

Docker 镜像配置

Windows / Mac

Docker Desktop 配置

MacOS OrbStack

OrbStack 容器

Apple Container

macOS 原生容器

Docker Compose

Compose 项目配置

NAS

群晖

Synology 配置

飞牛

fnOS 镜像配置

绿联

绿联 NAS

威联通

QNAP 配置

极空间

极空间 NAS

Unraid

Unraid NAS

企业仓库

其他仓库

ghcr · Quay · nvcr

Harbor 镜像源

Proxy Repository 对接

Portainer 镜像源

Registries 配置

Nexus 镜像源

Docker Proxy 缓存

开发工具

Dev Containers

VS Code 开发容器

Podman

Podman 配置指南

Singularity / Apptainer

HPC 科学计算容器

Kubernetes

K8s Containerd

Kubernetes · Containerd

K3s

轻量级集群

面板 / 网络

爱快路由

爱快 4.0 · iKuai 镜像加速

宝塔面板

一键配置镜像源

需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单

镜像拉取常见问题

功能

版本功能对比

功能对比 · 版本选择

支持的镜像仓库

Docker Hub · GCR · GHCR

专属域名用法

专属域名 · 开启停用 · 多仓库

新手拉取配置

登录 · 专属域名 · 配置

docker search 限制

专属域名 · Hub 搜索

不支持 push

仅支持 pull · 不支持

拉取速度原因

带宽 · 缓存 · 冷热镜像

错误码

402 与流量用尽

402 · 流量包 · 充值

401 认证失败

401 · docker login

manifest unknown

标签错误 · 镜像不存在

410 Gone 排查

410 · Docker 升级

429 限流

免费版 · 专业版 · 企业版 · 请求频率

其他报错

DNS 超时

DNS 解析 · 网络超时

TLS 证书失败

no matching manifest(架构)

docker.sock / daemon

账号

失败是否计费

manifest · blob · 计费

申请开票(企业 / 个人)

开票 · 发票 · 工单

修改登录密码

网站 · 仓库 · 重置

注销账户

工单 · 数据 · 注销

原理

mirrors 不生效

daemon.json · 重启

去掉域名前缀

docker tag · 重命名

指定架构拉取

ARM64 · AMD64 · 多架构

latest 与「最新」

digest · 版本号 · 标签

查看全部问题→

用户好评

来自真实用户的反馈,见证轩辕镜像的优质服务

用户头像

oldzhang

运维工程师

Linux服务器

5

"Docker访问体验非常流畅,大镜像也能快速完成下载。"

轩辕镜像
镜像详情
...
messense/cargo-zigbuild
定价查看流量套餐与价格
博客Docker 镜像公告与技术博客
官方技术交流群:|问题咨询请:提交工单
服务号:轩辕镜像|公众号:源码跳动|小程序:轩辕镜像|官方技术交流群:|问题咨询请:提交工单
专业版 · 高速稳定拉取镜像
高速镜像下载·在线技术支持·99.95% SLA 保障·付费会员免广告
50GB 仅 ¥8/年
专业版 · 高速稳定拉取镜像
50GB 仅 ¥8/年
高速镜像下载·在线技术支持·99.95% SLA 保障·付费会员免广告
用户协议·隐私政策·增值电信业务经营许可证:浙B2-20261007·©2024-2026 源码跳动©2024-2026 杭州源码跳动科技有限公司·商务合作:点击复制邮箱

更多 cargo-zigbuild 镜像推荐

start9/cargo-zigbuild logo

start9/cargo-zigbuild

start9
暂无描述
5万+ 次下载
1 个月前更新
lukemathwalker/cargo-chef logo

lukemathwalker/cargo-chef

lukemathwalker
在Rust工具链基础上预安装cargo-chef的CI镜像,用于优化Rust Docker构建中的层缓存,加速依赖处理流程。
19 次收藏500万+ 次下载
5 天前更新
cargoxio/drone-cleanup logo

cargoxio/drone-cleanup

cargoxio
暂无描述
100万+ 次下载
7 年前更新
cargogenerate/cargo-generate-action logo

cargogenerate/cargo-generate-action

cargogenerate
此GitHub Action用于运行cargo-generate工具,以扩展项目模板。
5万+ 次下载
2 年前更新
materialize/ci-cargo-test logo

materialize/ci-cargo-test

materialize
暂无描述
10万+ 次下载
3 年前更新
paketocommunity/cargo logo

paketocommunity/cargo

paketocommunity
暂无描述
10万+ 次下载
29 天前更新

查看更多 cargo-zigbuild 相关镜像

更多相关 Docker 镜像与资源

以下是 messense/cargo-zigbuild 相关的常用 Docker 镜像,适用于 不同场景 等不同场景:

  • library/golang Docker 镜像说明(Go 语言运行时,适合高性能网络服务和微服务)
  • bitnami/golang Docker 镜像说明(Go 语言运行时,Bitnami 企业级配置)
  • alpinelinux/golang Docker 镜像说明(Alpine Linux 官方 Go 工具链,适合静态编译与小镜像构建)
  • antrea/golang Docker 镜像说明(Antrea Golang 构建环境,适合 Kubernetes 网络插件开发)
  • arm32v7/golang Docker 镜像说明(Golang 镜像变体,适合 Golang、Go 相关部署场景)