跳至正文
OpenAgentSkill
浏览已开放 · 目录记录日期 2026-11-21 · 自动更新和账户服务暂时关闭。
开发与测试

xmake-trybuild

Use when you want to build a third-party project that uses CMake, Autotools, Meson, Ninja, Bazel, Make, MSBuild, Xcodebuild, or NdkBuild — through xmake, so you inherit xmake's cross-compilation and toolchain detection. Covers `xmake` auto-detection, `--trybuild=<system>`, `--tryconfigs="..."`, and cross-compile recipes for Android / iOS / MinGW / custom SDKs.

xmake-io · 已有静态检查记录

安装与使用

运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。

npx skills add xmake-io/xmake-skills --skill xmake-trybuild

技能说明


name: xmake-trybuild description: Use when you want to build a third-party project that uses CMake, Autotools, Meson, Ninja, Bazel, Make, MSBuild, Xcodebuild, or NdkBuild — through xmake, so you inherit xmake's cross-compilation and toolchain detection. Covers xmake auto-detection, --trybuild=<system>, --tryconfigs="...", and cross-compile recipes for Android / iOS / MinGW / custom SDKs.

Xmake TryBuild — Drive Third-Party Build Systems

trybuild lets xmake invoke another build system (CMake, Autotools, Meson, …) while still providing its own platform/toolchain detection, cross-compile support, and incremental-build wrappers. Use it when you need to build an upstream project that doesn't use xmake.lua, but still want xmake's cross-compilation ergonomics.

Supported backends

--trybuild=Backend
autotools./configure + make (cross-compile supported)
cmakecmake + generator (cross-compile supported)
mesonmeson + ninja
ninjadirect ninja
makemake / Makefile
msbuildVisual Studio MSBuild
xcodebuildXcode CLI builds
sconsSCons
bazelBazel
ndkbuildAndroid NDK ndk-build

1. Auto-detect mode

Run plain xmake inside a project root that has a recognized file (CMakeLists.txt, configure, Makefile, meson.build, …). Xmake prompts before building:

$ cd libpng-1.6.35
$ xmake
note: CMakeLists.txt found, try building it (pass -y or --confirm=y/n/d to skip confirm)?
please input: y (y/n)
-- Configuring done
-- Generating done
...
output to /Users/ruki/Downloads/libpng-1.6.35/build/artifacts
build ok!

Add -y to skip the prompt in CI:

xmake -y

Artifacts land under build/artifacts/.

2. Force a specific backend

When a project ships multiple build systems (e.g. both configure and CMakeLists.txt):

xmake f --trybuild=cmake
xmake

Once set, subsequent xmake / xmake clean calls use the configured backend — no re-prompting.

3. Standard xmake commands work

Once trybuild is configured, normal xmake commands drive the upstream build:

xmake                    # build
xmake --rebuild          # force full rebuild
xmake clean              # clean objects
xmake clean --all        # wipe everything (configure cache, artifacts)
xmake f -m debug         # switch to debug build
xmake f -m release

Behavior is mapped onto each backend — e.g. for autotools, xmake clean --all runs make distclean.

4. Cross-compilation via trybuild

The killer feature: xmake's cross-compilation config works for CMake/Autotools projects too.

Android

xmake f -p android --trybuild=cmake [--ndk=/path/to/ndk]
xmake

Equivalent of setting up CMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake + ANDROID_ABI + ANDROID_NATIVE_API_LEVEL by hand.

xmake f -p android --trybuild=autotools [--ndk=/path/to/ndk]
xmake

Equivalent of exporting CC, CXX, AR, LD, RANLIB, STRIP and passing --host=aarch64-linux-android to ./configure.

iOS / macOS

xmake f -p iphoneos --trybuild=cmake
xmake

xmake f -p iphoneos --trybuild=autotools
xmake

MinGW (Windows from any host)

xmake f -p mingw --trybuild=cmake [--mingw=/opt/llvm-mingw]
xmake

Generic cross-SDK

xmake f -p cross --trybuild=cmake --sdk=/opt/arm-linux-gnueabihf
xmake

All the cross flags from xmake-cross-compilation work identically with --trybuild=... appended.

5. Passing arguments to the backend

--tryconfigs

Extra flags forwarded to the backend's config step:

# autotools: passed to ./configure
xmake f --trybuild=autotools --tryconfigs="--enable-shared=no --disable-tests"

# cmake: passed to cmake
xmake f --trybuild=cmake --tryconfigs="-DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF"

# meson: passed to meson setup
xmake f --trybuild=meson --tryconfigs="-Doption=value"

Compile/link flag passthrough

Built-in xmake flags automatically propagate — no --tryconfigs needed for these:

xmake f --trybuild=cmake --cflags="-DNDEBUG" --ldflags="-lm" --includedirs=/opt/xyz/include
xmake

6. Android JNI (ndkbuild)

If jni/Android.mk exists:

xmake f -p android --trybuild=ndkbuild [--ndk=...]
xmake

For gradle integration see the xmake-gradle plugin.

7. Typical recipes

Build a CMake project for the host

cd upstream-project
xmake f --trybuild=cmake --tryconfigs="-DBUILD_SHARED_LIBS=ON"
xmake
ls build/artifacts

Cross-compile libpng for Android

cd libpng-1.6.40
xmake f -p android -a arm64-v8a --trybuild=cmake --ndk=~/android-ndk-r26 \
        --tryconfigs="-DPNG_SHARED=ON -DPNG_STATIC=OFF"
xmake

Autotools project for MinGW from Linux

cd autotools-thing
xmake f -p mingw --mingw=/usr/x86_64-w64-mingw32 --trybuild=autotools \
        --tryconfigs="--disable-tests"
xmake

Meson + Ninja for the host

xmake f --trybuild=meson
xmake -j $(nproc)

8. When to prefer trybuild vs a package recipe

  • One-off local build of upstream code → trybuild.
  • Reusable dependency consumed by add_requires → write a package recipe that uses import("package.tools.cmake") (or autoconf, meson) — see xmake-private-packages and xmake-repo-testing. The recipe gets proper version pinning, hash checks, and caching, which trybuild does not.

Pitfalls

  • Missing backend tool. Trybuild shells out to cmake/autotools/meson/… — make sure the binary is installed. On failure, xmake -vD shows the missing tool.
  • Auto-detect picks the wrong backend. Projects that ship both Makefile and CMakeLists.txt may auto-select the "wrong" one; use xmake f --trybuild=cmake to pin.
  • Clean doesn't clean configure cache. xmake clean removes objects only. Use xmake clean --all to also wipe the backend's c
阅读完整来源 ↗