Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
5503984
cmake changes for emscripten
joemarshall Sep 21, 2023
331aaa3
reverted cmakelists from python
joemarshall Sep 21, 2023
3e4156e
documentation tidying after review
joemarshall Sep 25, 2023
80b21d1
preset fixes
joemarshall Sep 25, 2023
908abf9
updates to simplify emscripten build process
joemarshall Sep 25, 2023
6effae5
Merge branch 'main' of github.com:apache/arrow into emscripten_cmake_…
joemarshall Sep 25, 2023
31ca7f9
build fixes
joemarshall Sep 25, 2023
c26d68c
better comments
joemarshall Sep 25, 2023
f5ec444
cmake fixes for python emscripten build to work
joemarshall Sep 27, 2023
3c2f179
fix pyodide stdc version number
joemarshall Sep 27, 2023
aec8a79
made substrait, ipc, brotli build on emscripten
joemarshall Sep 28, 2023
0db01d7
docs fix
joemarshall Sep 28, 2023
0daa670
bad if statement fix
joemarshall Sep 28, 2023
ff58481
cmake-format
joemarshall Sep 28, 2023
008b3dc
Merge branch 'main' of github.com:apache/arrow into emscripten_cmake_…
joemarshall Oct 2, 2023
20f9f05
removed python cmake changes from emscripten C++ build pr
joemarshall Oct 2, 2023
b777f69
documentation fix
joemarshall Oct 2, 2023
d93d8cc
preset fixes
joemarshall Oct 2, 2023
831715d
toolchain fixes
joemarshall Oct 2, 2023
3fd8a1c
typo
joemarshall Oct 2, 2023
28f675d
fix for webassembly where size_t != int64_t
joemarshall Oct 2, 2023
97e58f9
size_t not always == in64_t
joemarshall Oct 2, 2023
a00f068
reverting size_t fixes
joemarshall Oct 2, 2023
bda2b26
debug build fixes
joemarshall Oct 2, 2023
14b4968
fixed order of build preset dependencies
joemarshall Oct 2, 2023
834b5a3
debug build fixes
joemarshall Oct 4, 2023
ff2a7c9
cmake format
joemarshall Oct 4, 2023
45ece1e
typos etc. from code review
joemarshall Oct 4, 2023
28ccba9
review fixes
joemarshall Oct 4, 2023
7a8d71a
Merge branch 'emscripten_cmake_changes' of github.com:joemarshall/arr…
joemarshall Oct 4, 2023
adc68e8
docs fixes
joemarshall Oct 4, 2023
7cb0da9
comments grammar
joemarshall Oct 4, 2023
e3f1a81
lint
joemarshall Oct 4, 2023
123813f
correct separators in externalproject call
joemarshall Oct 9, 2023
9fff2ce
test changes for emscripten
joemarshall Oct 9, 2023
0b5cc3b
emscripten archery fixes
joemarshall Oct 11, 2023
b5fedaa
force non-parallel emscripten debug build
joemarshall Oct 11, 2023
76d464b
split dwarf debug info on emscripten
joemarshall Oct 12, 2023
b2dd85b
use limited debug info on emscripten builds
joemarshall Oct 13, 2023
8d3b255
disable test that won't work on emscripten
joemarshall Oct 13, 2023
8b7d2e4
Merge branch 'main' of github.com:apache/arrow into emscripten_cmake_…
joemarshall Oct 13, 2023
84867d2
set debug flag to g2
joemarshall Oct 13, 2023
9c7ad2e
lint
joemarshall Oct 13, 2023
275c08a
typo
joemarshall Oct 13, 2023
22ace85
test fixes
joemarshall Oct 16, 2023
527e477
fixes to tests for emscripten
joemarshall Oct 18, 2023
a96f793
emscripten test fixes
joemarshall Oct 18, 2023
5e8ee70
more test fixes
joemarshall Oct 18, 2023
ae1c579
fix to tests for emscripten
joemarshall Oct 18, 2023
688d1ab
lint
joemarshall Oct 19, 2023
da548e6
formatting
joemarshall Oct 19, 2023
b457d7c
dockerfile fixes in code review
joemarshall Oct 19, 2023
92ead7c
review updates
joemarshall Oct 19, 2023
2a1d67f
Merge branch 'emscripten_cmake_changes' of github.com:joemarshall/arr…
joemarshall Oct 19, 2023
58fbdfe
cmake-format updated version
joemarshall Oct 19, 2023
e9e1988
lint
joemarshall Oct 19, 2023
ddbcf56
licence on test init js
joemarshall Oct 19, 2023
1d4cc2c
fix to preprocessor directive check
joemarshall Oct 19, 2023
e3631fd
Merge branch 'main' of github.com:apache/arrow into emscripten_cmake_…
joemarshall Oct 19, 2023
8b8f8d0
fix #defines
joemarshall Oct 27, 2023
63d497a
Merge branch 'main' of github.com:apache/arrow into emscripten_cmake_…
joemarshall Oct 27, 2023
6124d53
review fixes
joemarshall Nov 7, 2023
b10b415
use __EMSCRIPTEN__ because emscripten docs say so
joemarshall Nov 7, 2023
09bffa0
Merge branch 'main' of github.com:apache/arrow into emscripten_cmake_…
joemarshall Nov 7, 2023
c9a79cc
whitespace
joemarshall Nov 7, 2023
4980d48
build fixes after review
joemarshall Nov 7, 2023
d6026f9
fix zlib on wasm
joemarshall Nov 7, 2023
fed5439
fix to csv test
joemarshall Nov 8, 2023
48c795b
typo #if! instead of ifndef
joemarshall Nov 8, 2023
4f2ebfb
Merge branch 'emscripten_cmake_changes' of github.com:joemarshall/arr…
joemarshall Nov 8, 2023
7b01717
revert test changes
joemarshall Nov 8, 2023
f780784
include config.h for threading define
joemarshall Nov 8, 2023
d23f1a1
lint
joemarshall Nov 8, 2023
bdd051d
Merge branch 'main' of github.com:apache/arrow into emscripten_cmake_…
joemarshall Nov 8, 2023
f79e49f
dead code elimination in test executables
joemarshall Nov 8, 2023
232d7f5
revert main_module change
joemarshall Nov 8, 2023
5b65a36
default to -O1 for emscripten
joemarshall Nov 9, 2023
72481cf
lint
joemarshall Nov 9, 2023
57e1b65
Apply suggestions from code review
joemarshall Nov 22, 2023
9506ca5
use -sRELOCATABLE instead of -fPIC
joemarshall Nov 22, 2023
617ba51
remove emscriptenoverrides
joemarshall Nov 22, 2023
dd2c662
review changes
joemarshall Nov 22, 2023
b1050f5
Update cpp/src/arrow/util/io_util.cc
joemarshall Nov 22, 2023
145426f
restrict number of concurrent processes in emscripten
joemarshall Nov 22, 2023
064659c
Merge branch 'emscripten_cmake_changes' of github.com:joemarshall/arr…
joemarshall Nov 22, 2023
8cc5ae3
lint fixes
joemarshall Nov 24, 2023
2429261
Apply suggestions from code review
joemarshall Mar 21, 2024
370b1ff
Apply suggestions from code review
joemarshall Mar 21, 2024
d0fa881
Apply suggestions from code review
joemarshall Mar 21, 2024
da176ad
documentation consistency
joemarshall Mar 21, 2024
5f058c9
don't ignore conversion errors any more
joemarshall Mar 21, 2024
51705de
build fixes from review
joemarshall Mar 21, 2024
225cef4
Merge branch 'emscripten_cmake_changes' of github.com:joemarshall/arr…
joemarshall Mar 21, 2024
3179e57
Merge branch 'main' of github.com:apache/arrow into emscripten_cmake_…
joemarshall Mar 21, 2024
d3e0770
typo
joemarshall Mar 21, 2024
abcd7df
fix script permissions
joemarshall Mar 21, 2024
cc0c1d5
toolchain lint
joemarshall Mar 22, 2024
701d5af
test commit:
joemarshall Mar 25, 2024
0064fa0
reverted test commit
joemarshall Mar 25, 2024
91a6e36
Merge branch 'main' of github.com:apache/arrow into emscripten_cmake_…
joemarshall Mar 27, 2024
07f2268
Merge branch 'emscripten_cmake_changes' of github.com:joemarshall/arr…
joemarshall Mar 27, 2024
028682e
Apply suggestions from code review
joemarshall Mar 28, 2024
d36fca2
code review changes
joemarshall Mar 28, 2024
ee99e5e
toolchain build fix
joemarshall Mar 28, 2024
b73740a
cmake fixes for emscripten
joemarshall Mar 28, 2024
4dc3d03
alphabetical order oops
joemarshall Mar 29, 2024
8b07ebf
remove dynamic linking test on emsripten
joemarshall Mar 29, 2024
c0692da
lint
joemarshall Mar 29, 2024
d3bc3b4
Use arrow/util/config.h
kou Apr 4, 2024
1307910
Remove trailing spaces
kou Apr 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions cpp/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,32 @@
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "emscripten-overrides",
Comment thread
joemarshall marked this conversation as resolved.
Outdated
"hidden": true,
"cacheVariables": {
"ARROW_BUILD_SHARED": "OFF",
"ARROW_BUILD_STATIC": "ON",
"ARROW_BUILD_TESTS": "OFF",
"ARROW_ENABLE_THREADING": "OFF",
"ARROW_CUDA": "OFF",
"ARROW_MIMALLOC": "OFF",
"ARROW_JEMALLOC": "OFF",
"ARROW_S3": "OFF",
"ARROW_DEPENDENCY_SOURCE": "BUNDLED",
"ZLIB_SOURCE": "SYSTEM",
Comment thread
joemarshall marked this conversation as resolved.
Outdated
"ARROW_IPC": "OFF",
Comment thread
joemarshall marked this conversation as resolved.
Outdated
"ARROW_ORC": "OFF",
"ARROW_SUBSTRAIT": "OFF",
"ARROW_DEPENDENCY_USE_SHARED": "OFF",
"ARROW_WITH_BROTLI": "OFF",
"ARROW_SIMD_LEVEL":"NONE",
Comment thread
joemarshall marked this conversation as resolved.
Outdated
"ARROW_RUNTIME_SIMD_LEVEL":"NONE",
Comment thread
joemarshall marked this conversation as resolved.
Outdated
"CMAKE_C_BYTE_ORDER":"LITTLE_ENDIAN",
Comment thread
joemarshall marked this conversation as resolved.
Outdated
"ARROW_WITH_OPENTELEMETRY":"OFF",
Comment thread
joemarshall marked this conversation as resolved.
Outdated
"CMAKE_TOOLCHAIN_FILE": { "type": "PATH", "value": "${sourceDir}/cmake_modules/Emscripten/Platform/EmscriptenOverrides.cmake" }
}
},
{
"name": "features-minimal",
"hidden": true,
Expand Down Expand Up @@ -395,6 +421,16 @@
"displayName": "Release build for PyArrow with everything enabled",
"cacheVariables": {}
},
{
"name": "ninja-release-emscripten-python",
Comment thread
joemarshall marked this conversation as resolved.
Outdated
Comment thread
joemarshall marked this conversation as resolved.
Outdated
"inherits": [
"emscripten-overrides",
"base-release",
"features-python"
],
"displayName": "Release build which builds an emscripten library, plus PyArrow for Pyodide",
Comment thread
joemarshall marked this conversation as resolved.
Outdated
"cacheVariables": {}
},
{
"name": "ninja-release-maximal",
"inherits": [
Expand Down
56 changes: 56 additions & 0 deletions cpp/cmake_modules/Emscripten/Platform/EmscriptenOverrides.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# Force some variables for emscripten
Comment thread
joemarshall marked this conversation as resolved.
Outdated
# to disable things that won't work there

# make us be on the platforms list for cmake
get_filename_component(PLATFORM_FOLDER_PARENT ${CMAKE_CURRENT_LIST_DIR} DIRECTORY)
list(APPEND CMAKE_MODULE_PATH "${PLATFORM_FOLDER_PARENT}")

include($ENV{EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake)
Comment thread
joemarshall marked this conversation as resolved.
Outdated

# ensure zlib is built with -fpic
# and force us to link to the version in emscripten ports
if(NOT EXISTS ${EMSCRIPTEN_SYSROOT}/lib/wasm32-emscripten/pic/libz.a)
execute_process(COMMAND embuilder --pic --force build zlib)
endif()
set(ZLIB_LIBRARY ${EMSCRIPTEN_SYSROOT}/lib/wasm32-emscripten/pic/libz.a)
Comment thread
joemarshall marked this conversation as resolved.
Outdated

# # override default in emscripten which is to not use shared libs
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
Comment thread
joemarshall marked this conversation as resolved.
Outdated

# if we leave the system name as Emscripten, then it reloads the original Emscripten.cmake every time a project() command
# is run, which does bad things like disabling shared libraries
set(CMAKE_SYSTEM_NAME EmscriptenOverrides)

set(CMAKE_C_FLAGS "-sUSE_ZLIB=1 -sSIDE_MODULE=1 -fPIC -fexceptions")
set(CMAKE_CXX_FLAGS "-sUSE_ZLIB=1 -sSIDE_MODULE=1 -fPIC -fexceptions")
Comment thread
joemarshall marked this conversation as resolved.
Outdated

#set(PYARROW_CPP_HOME "$ENV{ARROW_HOME}/lib")
#list(APPEND CMAKE_FIND_ROOT_PATH "${CMAKE_INSTALL_PREFIX}/cmake")
Comment thread
joemarshall marked this conversation as resolved.
Outdated

set(Python3_INCLUDE_DIR $ENV{PYTHONINCLUDE})
set(Python3_LIBRARY $ENV{CPYTHONLIB})
set(Python3_NumPy_INCLUDE_DIR $ENV{NUMPY_LIB}/core/include)
set(Python3_EXECUTABLE)
Comment thread
joemarshall marked this conversation as resolved.
Outdated
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-sUSE_ZLIB=1 -sWASM_BIGINT=1 -fexceptions")
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-sUSE_ZLIB=1 -sWASM_BIGINT=1 -fexceptions")
set(CMAKE_SHARED_LINKER_FLAGS "-sUSE_ZLIB=1 -sWASM_BIGINT=1 -fexceptions")
Comment thread
joemarshall marked this conversation as resolved.
Outdated
set(CMAKE_STRIP FALSE)
Comment thread
joemarshall marked this conversation as resolved.
Outdated

set(ENV{_PYTHON_SYSCONFIGDATA_NAME} $ENV{SYSCONFIG_NAME})
Comment thread
joemarshall marked this conversation as resolved.
Outdated
4 changes: 3 additions & 1 deletion cpp/cmake_modules/SetupCxxFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ include(CheckCXXSourceCompiles)
message(STATUS "System processor: ${CMAKE_SYSTEM_PROCESSOR}")

if(NOT DEFINED ARROW_CPU_FLAG)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|amd64|X86|x86|i[3456]86|x64")
if(CMAKE_SYSTEM_NAME MATCHES "Emscripten")
Comment thread
joemarshall marked this conversation as resolved.
Outdated
set(ARROW_CPU_FLAG "emscripten")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|amd64|X86|x86|i[3456]86|x64")
set(ARROW_CPU_FLAG "x86")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|ARM64|arm64")
set(ARROW_CPU_FLAG "aarch64")
Expand Down
8 changes: 8 additions & 0 deletions cpp/cmake_modules/ThirdpartyToolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,11 @@ set(EP_COMMON_CMAKE_ARGS
-DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}
-DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE_MAKEFILE})

# if building with a toolchain file, pass that through
if(CMAKE_TOOLCHAIN_FILE)
list(APPEND EP_COMMON_CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE})
endif()

# Enable s/ccache if set by parent.
if(CMAKE_C_COMPILER_LAUNCHER AND CMAKE_CXX_COMPILER_LAUNCHER)
list(APPEND EP_COMMON_CMAKE_ARGS
Expand Down Expand Up @@ -1614,6 +1619,9 @@ macro(build_thrift)
if(DEFINED BOOST_ROOT)
list(APPEND THRIFT_CMAKE_ARGS "-DBOOST_ROOT=${BOOST_ROOT}")
endif()
if(DEFINED Boost_INCLUDE_DIR)
list(APPEND THRIFT_CMAKE_ARGS "-DBoost_INCLUDE_DIR=${Boost_INCLUDE_DIR}")
Comment thread
joemarshall marked this conversation as resolved.
endif()
if(DEFINED Boost_NAMESPACE)
list(APPEND THRIFT_CMAKE_ARGS "-DBoost_NAMESPACE=${Boost_NAMESPACE}")
endif()
Expand Down
100 changes: 100 additions & 0 deletions docs/source/developers/cpp/emscripten.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
.. Licensed to the Apache Software Foundation (ASF) under one
.. or more contributor license agreements. See the NOTICE file
.. distributed with this work for additional information
.. regarding copyright ownership. The ASF licenses this file
.. to you under the Apache License, Version 2.0 (the
.. "License"); you may not use this file except in compliance
.. with the License. You may obtain a copy of the License at

.. http://www.apache.org/licenses/LICENSE-2.0

.. Unless required by applicable law or agreed to in writing,
.. software distributed under the License is distributed on an
.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
.. KIND, either express or implied. See the License for the
.. specific language governing permissions and limitations
.. under the License.


.. highlight:: console .. _developers-cpp-emscripten:

Comment thread
joemarshall marked this conversation as resolved.
Outdated
#################################################
Cross compiling for Webassembly with Emscripten
Comment thread
joemarshall marked this conversation as resolved.
Outdated
#################################################
Comment thread
joemarshall marked this conversation as resolved.
Outdated

***************
Prerequisites
***************
You need cmake and compilers etc. installed as per the normal build instructions. Before building with emscripten, you also need to install emscripten and
Comment thread
joemarshall marked this conversation as resolved.
Outdated
activate it using the commands below (see https://emscripten.org/docs/getting_started/downloads.html for details).

.. code:: shell

git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
# replace <version> with the desired EMSDK version.
# e.g. for pyodide 0.24, you need EMSDK version 3.1.45
./emsdk install <version>
./emsdk activate <version>
source ./emsdk_env.sh

If you want to build pyarrow for `pyodide <https://pyodide.org>`_, you
Comment thread
joemarshall marked this conversation as resolved.
Outdated
need ``pyodide-build`` installed via ``pip``, and to be running with the
same version of python that pyodide is built for, along with the same
Comment thread
joemarshall marked this conversation as resolved.
Outdated
versions of emsdk.

.. code:: shell

# install pyodide build tools.
# e.g. for version 0.24 of pyodide:
pip install pyodide-build==0.24

Then build with the ``ninja-release-emscripten-python`` cmake preset,
like below:

.. code:: shell

cmake --preset "ninja-release-emscripten-python"
ninja install

This will install a built static library version of libarrow it into the
Comment thread
joemarshall marked this conversation as resolved.
Outdated
emscripten sysroot cache, meaning you can build things that depend on it
Comment thread
joemarshall marked this conversation as resolved.
Outdated
and they will find libarrow.
Comment thread
joemarshall marked this conversation as resolved.
Outdated

e.g. if you want to build for pyodide, run the commands above, and then
Comment thread
joemarshall marked this conversation as resolved.
Outdated
go to ``arrow/python`` and run

.. code:: shell

pyodide build

It should make a wheel targeting the currently enabled version of
pyodide (i.e. the version corresponding to the currently installed
Comment thread
joemarshall marked this conversation as resolved.
Outdated
``pyodide-build``) in the ``dist`` subdirectory.

**************
Manual Build
**************

If you want to manually build for emscripten, take a look at the
Comment thread
joemarshall marked this conversation as resolved.
Outdated
CMakePresets.json file in the arrow/cpp directory for a list of things
Comment thread
joemarshall marked this conversation as resolved.
Outdated
you will need to override. In particular you will need:

#. Build dependencies set to ``BUNDLED``, so it uses properly cross
compiled build dependencies.

#. ``CMAKE_TOOLCHAIN_FILE`` set to
``arrow/cpp/cmake_modules/Emscripten/Platform/EmscriptenOverrides.cmake``

#. You will quite likely need to set ``ARROW_ENABLE_THREADING`` to ``OFF``
for builds targeting single threaded emscripten environments such as
Comment thread
joemarshall marked this conversation as resolved.
Outdated
pyodide.

#. ``ARROW_IPC`` and anything else that uses network probably won't
work.

#. ``ARROW_JEMALLOC`` and ``ARROW_MIMALLOC`` again probably need to be
``OFF``

#. ``ARROW_BUILD_STATIC`` set to ``ON`` and ``ARROW_BUILD_SHARED`` set to
``OFF`` is most likely to work.
1 change: 1 addition & 0 deletions docs/source/developers/cpp/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ C++ Development
building
development
windows
emscripten
conventions
fuzzing