-
Notifications
You must be signed in to change notification settings - Fork 4.1k
GH-23221: [C++] Add support for building with Emscripten #37821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 331aaa3
reverted cmakelists from python
joemarshall 3e4156e
documentation tidying after review
joemarshall 80b21d1
preset fixes
joemarshall 908abf9
updates to simplify emscripten build process
joemarshall 6effae5
Merge branch 'main' of github.com:apache/arrow into emscripten_cmake_…
joemarshall 31ca7f9
build fixes
joemarshall c26d68c
better comments
joemarshall f5ec444
cmake fixes for python emscripten build to work
joemarshall 3c2f179
fix pyodide stdc version number
joemarshall aec8a79
made substrait, ipc, brotli build on emscripten
joemarshall 0db01d7
docs fix
joemarshall 0daa670
bad if statement fix
joemarshall ff58481
cmake-format
joemarshall 008b3dc
Merge branch 'main' of github.com:apache/arrow into emscripten_cmake_…
joemarshall 20f9f05
removed python cmake changes from emscripten C++ build pr
joemarshall b777f69
documentation fix
joemarshall d93d8cc
preset fixes
joemarshall 831715d
toolchain fixes
joemarshall 3fd8a1c
typo
joemarshall 28f675d
fix for webassembly where size_t != int64_t
joemarshall 97e58f9
size_t not always == in64_t
joemarshall a00f068
reverting size_t fixes
joemarshall bda2b26
debug build fixes
joemarshall 14b4968
fixed order of build preset dependencies
joemarshall 834b5a3
debug build fixes
joemarshall ff2a7c9
cmake format
joemarshall 45ece1e
typos etc. from code review
joemarshall 28ccba9
review fixes
joemarshall 7a8d71a
Merge branch 'emscripten_cmake_changes' of github.com:joemarshall/arr…
joemarshall adc68e8
docs fixes
joemarshall 7cb0da9
comments grammar
joemarshall e3f1a81
lint
joemarshall 123813f
correct separators in externalproject call
joemarshall 9fff2ce
test changes for emscripten
joemarshall 0b5cc3b
emscripten archery fixes
joemarshall b5fedaa
force non-parallel emscripten debug build
joemarshall 76d464b
split dwarf debug info on emscripten
joemarshall b2dd85b
use limited debug info on emscripten builds
joemarshall 8d3b255
disable test that won't work on emscripten
joemarshall 8b7d2e4
Merge branch 'main' of github.com:apache/arrow into emscripten_cmake_…
joemarshall 84867d2
set debug flag to g2
joemarshall 9c7ad2e
lint
joemarshall 275c08a
typo
joemarshall 22ace85
test fixes
joemarshall 527e477
fixes to tests for emscripten
joemarshall a96f793
emscripten test fixes
joemarshall 5e8ee70
more test fixes
joemarshall ae1c579
fix to tests for emscripten
joemarshall 688d1ab
lint
joemarshall da548e6
formatting
joemarshall b457d7c
dockerfile fixes in code review
joemarshall 92ead7c
review updates
joemarshall 2a1d67f
Merge branch 'emscripten_cmake_changes' of github.com:joemarshall/arr…
joemarshall 58fbdfe
cmake-format updated version
joemarshall e9e1988
lint
joemarshall ddbcf56
licence on test init js
joemarshall 1d4cc2c
fix to preprocessor directive check
joemarshall e3631fd
Merge branch 'main' of github.com:apache/arrow into emscripten_cmake_…
joemarshall 8b8f8d0
fix #defines
joemarshall 63d497a
Merge branch 'main' of github.com:apache/arrow into emscripten_cmake_…
joemarshall 6124d53
review fixes
joemarshall b10b415
use __EMSCRIPTEN__ because emscripten docs say so
joemarshall 09bffa0
Merge branch 'main' of github.com:apache/arrow into emscripten_cmake_…
joemarshall c9a79cc
whitespace
joemarshall 4980d48
build fixes after review
joemarshall d6026f9
fix zlib on wasm
joemarshall fed5439
fix to csv test
joemarshall 48c795b
typo #if! instead of ifndef
joemarshall 4f2ebfb
Merge branch 'emscripten_cmake_changes' of github.com:joemarshall/arr…
joemarshall 7b01717
revert test changes
joemarshall f780784
include config.h for threading define
joemarshall d23f1a1
lint
joemarshall bdd051d
Merge branch 'main' of github.com:apache/arrow into emscripten_cmake_…
joemarshall f79e49f
dead code elimination in test executables
joemarshall 232d7f5
revert main_module change
joemarshall 5b65a36
default to -O1 for emscripten
joemarshall 72481cf
lint
joemarshall 57e1b65
Apply suggestions from code review
joemarshall 9506ca5
use -sRELOCATABLE instead of -fPIC
joemarshall 617ba51
remove emscriptenoverrides
joemarshall dd2c662
review changes
joemarshall b1050f5
Update cpp/src/arrow/util/io_util.cc
joemarshall 145426f
restrict number of concurrent processes in emscripten
joemarshall 064659c
Merge branch 'emscripten_cmake_changes' of github.com:joemarshall/arr…
joemarshall 8cc5ae3
lint fixes
joemarshall 2429261
Apply suggestions from code review
joemarshall 370b1ff
Apply suggestions from code review
joemarshall d0fa881
Apply suggestions from code review
joemarshall da176ad
documentation consistency
joemarshall 5f058c9
don't ignore conversion errors any more
joemarshall 51705de
build fixes from review
joemarshall 225cef4
Merge branch 'emscripten_cmake_changes' of github.com:joemarshall/arr…
joemarshall 3179e57
Merge branch 'main' of github.com:apache/arrow into emscripten_cmake_…
joemarshall d3e0770
typo
joemarshall abcd7df
fix script permissions
joemarshall cc0c1d5
toolchain lint
joemarshall 701d5af
test commit:
joemarshall 0064fa0
reverted test commit
joemarshall 91a6e36
Merge branch 'main' of github.com:apache/arrow into emscripten_cmake_…
joemarshall 07f2268
Merge branch 'emscripten_cmake_changes' of github.com:joemarshall/arr…
joemarshall 028682e
Apply suggestions from code review
joemarshall d36fca2
code review changes
joemarshall ee99e5e
toolchain build fix
joemarshall b73740a
cmake fixes for emscripten
joemarshall 4dc3d03
alphabetical order oops
joemarshall 8b07ebf
remove dynamic linking test on emsripten
joemarshall c0692da
lint
joemarshall d3bc3b4
Use arrow/util/config.h
kou 1307910
Remove trailing spaces
kou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
cpp/cmake_modules/Emscripten/Platform/EmscriptenOverrides.cmake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
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) | ||
|
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) | ||
|
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) | ||
|
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") | ||
|
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") | ||
|
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) | ||
|
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") | ||
|
joemarshall marked this conversation as resolved.
Outdated
|
||
| set(CMAKE_STRIP FALSE) | ||
|
joemarshall marked this conversation as resolved.
Outdated
|
||
|
|
||
| set(ENV{_PYTHON_SYSCONFIGDATA_NAME} $ENV{SYSCONFIG_NAME}) | ||
|
joemarshall marked this conversation as resolved.
Outdated
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: | ||
|
|
||
|
joemarshall marked this conversation as resolved.
Outdated
|
||
| ################################################# | ||
| Cross compiling for Webassembly with Emscripten | ||
|
joemarshall marked this conversation as resolved.
Outdated
|
||
| ################################################# | ||
|
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 | ||
|
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 | ||
|
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 | ||
|
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 | ||
|
joemarshall marked this conversation as resolved.
Outdated
|
||
| emscripten sysroot cache, meaning you can build things that depend on it | ||
|
joemarshall marked this conversation as resolved.
Outdated
|
||
| and they will find libarrow. | ||
|
joemarshall marked this conversation as resolved.
Outdated
|
||
|
|
||
| e.g. if you want to build for pyodide, run the commands above, and then | ||
|
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 | ||
|
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 | ||
|
joemarshall marked this conversation as resolved.
Outdated
|
||
| CMakePresets.json file in the arrow/cpp directory for a list of things | ||
|
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 | ||
|
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. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,5 +27,6 @@ C++ Development | |
| building | ||
| development | ||
| windows | ||
| emscripten | ||
| conventions | ||
| fuzzing | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.