Cross compiling for WebAssembly with Emscripten#
Prerequisites#
You need CMake and compilers etc. installed as per the normal build instructions. Before building with Emscripten, you also need to install Emscripten andactivate it using the commands below (seehttps://emscripten.org/docs/getting_started/downloads.html for details).
gitclonehttps://github.com/emscripten-core/emsdk.gitcdemsdk# replace <version> with the desired EMSDK version.# e.g. for Pyodide 0.26, you need EMSDK version 3.1.58# the versions can be found in the Makefile.envs file in the Pyodide repo:# https://github.com/pyodide/pyodide/blob/10b484cfe427e076c929a55dc35cfff01ea8d3bc/Makefile.envs./emsdkinstall<version>./emsdkactivate<version>source./emsdk_env.sh
If you want to build PyArrow forPyodide, youneedpyodide-build installed viapip, and to be running with thesame version of Python that Pyodide is built for, along with the sameversions of emsdk tools.
# install Pyodide build tools.# e.g., for version 0.26 of Pyodide, pyodide-build 0.26 and later workpipinstall"pyodide-build>=0.26"
Then build with theninja-release-emscripten CMake preset,like below:
emcmakecmake--preset"ninja-release-emscripten"ninjainstallThis will install a built static library version oflibarrow it into theEmscripten sysroot cache, meaning you can build things that depend on itand they will findlibarrow.
e.g. if you want to build for Pyodide, run the commands above, and thengo toarrow/python and run
pyodidebuild
It should make a wheel targeting the currently enabled version ofPyodide in thedist subdirectory.
Manual Build#
If you want to manually build for Emscripten, take a look at theCMakePresets.json file in thearrow/cpp directory for a list of thingsyou will need to override. In particular you will need:
Build dependencies set to
BUNDLED, so it uses properly crosscompiled build dependencies.CMAKE_TOOLCHAIN_FILEset by usingemcmakecmakeinstead of justcmake.You will need to set
ARROW_ENABLE_THREADINGtoOFFfor buildstargeting single-threaded Emscripten environments such as Pyodide.ARROW_FLIGHTand anything else that uses network probably won’twork.ARROW_JEMALLOCandARROW_MIMALLOCagain probably need to beOFFARROW_BUILD_STATICset toONandARROW_BUILD_SHAREDset toOFFis most likely to work.

