Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
43 changes: 43 additions & 0 deletions .github/workflows/emscripten.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Emscripten

on:
push:
paths-ignore:
- 'docs/**'
pull_request:
paths-ignore:
- 'docs/**'


concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:

emscripten:
runs-on: ubuntu-latest

if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
steps:
- name: Checkout
uses: actions/checkout@v5

- name: Build docker
run: docker build -t proj-emscripten-builder scripts/ci/emscripten/

- name: Artifacts folder
run: mkdir -p "$PWD"/wasm_out

- name: Run docker
run: docker run --rm -v "$PWD":/build/proj_src -v "$PWD"/wasm_out:/usr/local/wasm proj-emscripten-builder

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: proj-js-wasm
retention-days: 15
path: wasm_out/projModule.*
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,16 @@ if(ENABLE_CURL)
endif()
endif()

################################################################################
# Check for Emscripten fetch
################################################################################

option(ENABLE_EMSCRIPTEN_FETCH "Enable Emscripten fetch support" OFF)
set(EMSCRIPTEN_FETCH_ENABLED FALSE)
if(ENABLE_EMSCRIPTEN_FETCH)
set(EMSCRIPTEN_FETCH_ENABLED TRUE)
endif()

################################################################################

option(EMBED_PROJ_DATA_PATH "Whether the PROJ_DATA_PATH should be embedded" ON)
Expand Down Expand Up @@ -365,7 +375,7 @@ endif()

include(CheckCSourceCompiles)
function (is_sharp_embed_available res)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.21 AND
if (NOT EMSCRIPTEN AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.21 AND
((CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 15.0) OR
(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 19.0)))
# CMAKE_C_STANDARD=23 only supported since CMake 3.21
Expand Down
13 changes: 13 additions & 0 deletions docs/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,19 @@ All cached entries can be viewed using ``cmake -LAH`` from a build directory.
Users will also typically want to set EMBED_PROJ_DATA_PATH=OFF if setting
USE_ONLY_EMBEDDED_RESOURCE_FILES=OFF.

.. _install_emscripten_fetch:
.. option:: ENABLE_EMSCRIPTEN_FETCH=ON/OFF

.. versionadded:: 9.8

When ON, the function emscripten_fetch is used to get files
from the network (grid files, etc), in a similar way as with cURL.
PROJ is doing synchronous fetch calls, so emscripten must have the `-pthread` flag enabled.
In addition to that, it is very recommended to run it in a Web Worker in the browser,
to not block the main thread.
It is incompatible with cURL, so ``ENABLE_CURL`` must be OFF.
Default: OFF.


Building on Windows with vcpkg and Visual Studio 2017 or 2019
--------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions docs/source/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ eg
egm
ellps
emphasize
emscripten
encodings
endian
engsager
Expand Down
6 changes: 6 additions & 0 deletions docs/source/usage/network.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ Authorizing network access can be done in multiple ways:
with :cpp:func:`proj_context_set_network_callbacks`. Enabling network use
must still be done with one of the above mentioned method.

Emscripten
^^^^^^^^^^

To compile with emscripten (to produce a WASM file) with network capability,
the CMake configure option :ref:`ENABLE_EMSCRIPTEN_FETCH<install_emscripten_fetch>` can be used.

Setting endpoint
----------------

Expand Down
31 changes: 31 additions & 0 deletions scripts/ci/emscripten/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Use the official Emscripten SDK image.
FROM emscripten/emsdk:4.0.5

# Set non-interactive frontend for package installations
ENV DEBIAN_FRONTEND="noninteractive"

# --- Install System Dependencies ---
RUN apt-get update && \
apt-get install -y \
sqlite3 \
ninja-build && \
# Clean up apt cache to reduce image size
rm -rf /var/lib/apt/lists/*

# --- Setup Build Directories ---
# Define standard locations for building and installing
ENV BUILD_DIR="/build"
ENV INSTALL_DIR="/usr/local/wasm"

# Create the directories
RUN mkdir -p ${BUILD_DIR}/proj_src \
${BUILD_DIR}/deps_src \
${INSTALL_DIR}

# Copy the build script into the container
COPY build_wasm.sh /scripts/build_wasm.sh
RUN chmod +x /scripts/build_wasm.sh

# Set the main command to execute the build script
WORKDIR /build
CMD ["/scripts/build_wasm.sh"]
Loading
Loading