|
| 1 | +# Building Big Endian ASTC Encoder |
| 2 | + |
| 3 | +We don't officially support the big-endian compressor build, and it is only |
| 4 | +lightly tested, but ensuring that the code is BE-compatible is good practice |
| 5 | +and some of the open source distributions still support BE platforms. |
| 6 | + |
| 7 | +Even though Arm64 can run in a BE mode, it's now very rare in practice. It's no |
| 8 | +longer supported out of the box in the latest Arm upstream compiler releases, |
| 9 | +and getting hold of a sysroot is increasingly difficult. To test BE builds, I |
| 10 | +therefore cross-compile Linux builds for PPC64 and use `qemu-user` to run |
| 11 | +them. This doesn't use a real sysroot, and so everything must be compiled with |
| 12 | +`-static` linkage. |
| 13 | + |
| 14 | +## Host software |
| 15 | + |
| 16 | +Install the following host software: |
| 17 | + |
| 18 | +```bash |
| 19 | +# Compiler |
| 20 | +sudo apt-get install g++-powerpc64-linux-gnu |
| 21 | + |
| 22 | +# Multi-arch libraries |
| 23 | +sudo apt-get install g++-multilib-powerpc64-linux-gnu |
| 24 | + |
| 25 | +# QEMU |
| 26 | +sudo apt-get install qemu-user-static qemu-user-binfmt binfmt-support |
| 27 | +sudo mkdir /etc/qemu-binfmt |
| 28 | +sudo ln -s /usr/powerpc64-linux-gnu /etc/qemu-binfmt/ppc64 |
| 29 | +sudo update-binfmts --import qemu-ppc64 |
| 30 | +``` |
| 31 | + |
| 32 | +## CMake toolchain file |
| 33 | + |
| 34 | +Cross-compiling needs a correctly configured CMake, and the easiest way to |
| 35 | +do this consistently is to use a toolchain file. Create a `CMake-BE.toolchain` |
| 36 | +file in the root of the project, with the following content: |
| 37 | + |
| 38 | +``` |
| 39 | +# Operating system |
| 40 | +set(CMAKE_SYSTEM_NAME Linux) |
| 41 | +
|
| 42 | +# Cross-compilers for C and C++ |
| 43 | +set(CMAKE_C_COMPILER powerpc64-linux-gnu-gcc) |
| 44 | +set(CMAKE_CXX_COMPILER powerpc64-linux-gnu-g++) |
| 45 | +
|
| 46 | +# Compiler environment |
| 47 | +set(CMAKE_FIND_ROOT_PATH /usr/powerpc64-linux-gnu) |
| 48 | +
|
| 49 | +set(CMAKE_C_FLAGS_INIT -static) |
| 50 | +set(CMAKE_CXX_FLAGS_INIT -static) |
| 51 | +set(CMAKE_EXE_LINKER_FLAGS_INIT -static) |
| 52 | +set(CMAKE_SHARED_LINKER_FLAGS_INIT -static) |
| 53 | +set(CMAKE_MODULE_LINKER_FLAGS_INIT -static) |
| 54 | +
|
| 55 | +# Build options |
| 56 | +set(ASTCENC_BIG_ENDIAN ON) |
| 57 | +
|
| 58 | +# Never match host tools |
| 59 | +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) |
| 60 | +
|
| 61 | +# Only match headers and libraries in the compiler environment |
| 62 | +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) |
| 63 | +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) |
| 64 | +``` |
| 65 | + |
| 66 | +## Build astcenc |
| 67 | + |
| 68 | +Building uses CMake as normal, with the additional specification of the |
| 69 | +toolchain file to configure the build for cross-compilation. We don't have any |
| 70 | +SIMD implementations for big-endian architectures so these builds must compile |
| 71 | +for the reference C SIMD implementation, `ASTCENC_ISA_NONE`. |
| 72 | + |
| 73 | +``` |
| 74 | +cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../ -DASTCENC_ISA_NONE=ON -DCMAKE_TOOLCHAIN_FILE=../CMake-BE.toolchain .. |
| 75 | +``` |
| 76 | + |
| 77 | +## Run astcenc |
| 78 | + |
| 79 | +The cross-compiled `astcenc` binary runs as normal, and can access host files, |
| 80 | +but must run through QEMU to do the instruction set translation. |
| 81 | + |
| 82 | +If the binfmt setup performed earlier was successful you can just run the |
| 83 | +binary as if it were a native binary: |
| 84 | + |
| 85 | +``` |
| 86 | +./bin/astcenc-none ... |
| 87 | +``` |
| 88 | + |
| 89 | +... but otherwise you can run it manually using QEMU as a wrapper: |
| 90 | + |
| 91 | +``` |
| 92 | +qemu-ppc64 ./bin/astcenc-none ... |
| 93 | +``` |
| 94 | + |
| 95 | +- - - |
| 96 | + |
| 97 | +_Copyright © 2025, Arm Limited and contributors._ |
0 commit comments