Building XNNPACK

This is a quick-start guide for building XNNPACK in some common configurations. XNNPACK currently supports these build systems:

Some combinations of operating systems, compilers and CPU architectures are tested regularly via GitHub Actions (see build.yml).

Building with CMake, testing with CTest

Build without cross-compilation, default compiler

scripts/build-local.sh automatically configures and runs CMake for the host CPU and operating system.

# In the XNNPACK root directory
scripts/build-local.sh
# Build artifacts will be created in build/local
cd build/local
# Run the test suite
ctest --output-on-failure --parallel $(nproc)

Specifying an alternate compiler

Standard CMake arguments like -DCMAKE_CXX_COMPILER and -DCMAKE_C_COMPILER are used like this:

scripts/build-local.sh -DCMAKE_CXX_COMPILER=clang++-19 -DCMAKE_C_COMPILER=clang-19
cd build/local
ctest --output-on-failure --parallel $(nproc)

Note: nproc uses the number of CPU cores in your host system.

Build for Android

  • Building for Android requires setting the ANDROID_NDK environment variable.
  • You can download the NDK from here.
# Set ANDROID_NDK to wherever the NDK is unpacked
export ANDROID_NDK=$HOME/bin/android-ndk-r27c
# Build for 32-bit Arm
./scripts/build-android-armv7.sh
# Push the compiled benchmarks onto an ADB-connected device
adb push ./build/android/armeabi-v7a/bench /data/local/tmp

Combinations known to work

PlatformTargetHost CPUTarget CPUCompilerWorksSupported**Notes
LinuxLinuxx64x64Clang 19.1.7
LinuxLinuxx64x64Clang 18
LinuxLinuxx64x64GCC 14.2.0Various GCC versions are supported.
LinuxLinuxAArch64*Armv7-AGCC
MacOSMacOSAArch64AArch64Clang
LinuxAndroidx64Armv7-A(NDK r27c provided)
LinuxAndroidx64AArch64(NDK r27c provided)
LinuxAndroidx64x64(NDK r27c provided)
MacOSiOSAArch64AArch64Clang
MacOSiOSAArch64x86Clang
WindowsWindowsx64x64Clang/MSVC
WindowsWindowsx64x86Clang/MSVC
WindowsWindowsx64AArch64Clang/MSVC

(* Note: AArch64 is the official name for the arm64 CPU architecture).

(** Note: Supported combinations are regularly tested and should always work. If they don't, raise a GitHub issue).

Building with Bazel

  • Optional features are behind Bazel flags like --define=xnn_enable_avxvnni=false.
  • ⚠️ Cross-compilation to another operating system (e.g. Android) or CPU architecture doesn't work on recent versions of Bazel.
  • Using Bazel's :all meta-target is not supported. Instead, use explicit targets like //bench/....
  • The -c parameter controls the optimization level:
    • -c opt enables -O2, with no assertions or debug information (recommended for production).
    • -c fastbuild means no optimization, minimal debug information, and assertions (for fast development and testing).
    • -c dbg means build with debug information enabled, no optimization (for debugging).

Build benchmarks and test suites without cross-compilation, default compiler

bazel build -c fastbuild //bench/... //test/...
bazel test -c fastbuild --local_test_jobs=HOST_CPUS //bench/... //test/...

Build benchmarks and test suites using an alternate compiler

Bazel listens to the CC and CCX environment variables, which specify another compiler.

CC=clang-19 CXX=clang++-19 bazel build -c fastbuild //bench/... //test/...
CC=clang-19 CXX=clang++-19 bazel test -c fastbuild --local_test_jobs=HOST_CPUS //bench/... //test/...

Combinations known to work

PlatformCPUCompiler-c configWorksSupportedNotes
Linuxx64GCC 14.2.0fastbuild
Linuxx64GCC 14.2.0opt
Linuxx64Clang 19.1.7fastbuild
Linuxx64Clang 19.1.7opt
Linuxx64Clang 18fastbuild
Linuxx64GCC 9fastbuildWith appropriate defines.
LinuxAArch64Clang 18fastbuild
LinuxAArch64Clang 20fastbuild
LinuxAArch64GCC 13fastbuild

Building with GN

  • GN is the build system used by the Chromium project.
  • GN support is incomplete and experimental as of November 2025 and is not automatically tested yet. If these instructions do not work for you, open an issue.

Getting the code

When building with GN, XNNPACK uses Chromium's depot_tools to fetch some dependencies. To check out the code:

  1. Install depot_tools according to the upstream instructions.
  2. Create an enter a new directory for XNNPACK with
    mkdir XNNPACK && cd XNNPACK
    
  3. Create a file named .gclient with these contents:
     solutions = [
       { "name"        : 'xnnpack',
         "url"         : 'https://github.com/google/XNNPACK',
         "deps_file"   : 'DEPS',
         "managed"     : False,
         "custom_deps" : {
        },
        "custom_vars": {},
      },
    ]
    
  4. Run gclient sync to get the source.