Skip to content

Commit ec3ce8c

Browse files
committed
Allow WASM targets to pre-define ABSL_HAVE_MMAP
WASM/WASI build systems using wasi-sdk need to pass -DABSL_HAVE_MMAP alongside -D_WASI_EMULATED_MMAN to enable emulated mmap support. The #error guard on ABSL_HAVE_MMAP blocks this. Exempt __wasm__ targets from the guard while keeping it for all other platforms. Add a CI script that builds abseil-cpp with wasi-sdk to catch WASI build regressions.
1 parent 638e17a commit ec3ce8c

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

absl/base/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
372372
//
373373
// Checks whether the platform has an mmap(2) implementation as defined in
374374
// POSIX.1-2001.
375-
#ifdef ABSL_HAVE_MMAP
375+
#if defined(ABSL_HAVE_MMAP) && !defined(__wasm__)
376376
#error ABSL_HAVE_MMAP cannot be directly set
377377
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
378378
defined(_AIX) || defined(__ros__) || defined(__asmjs__) || \

ci/linux_wasi_cmake.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2025 The Abseil Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Verify that abseil-cpp builds for WASI using wasi-sdk.
18+
19+
set -euox pipefail
20+
21+
if [[ -z ${ABSEIL_ROOT:-} ]]; then
22+
ABSEIL_ROOT="$(realpath $(dirname ${0})/..)"
23+
fi
24+
25+
WASI_SDK_VERSION="25.0"
26+
WASI_SDK_DIR="/opt/wasi-sdk-${WASI_SDK_VERSION}-x86_64-linux"
27+
28+
if [[ ! -d "${WASI_SDK_DIR}" ]]; then
29+
curl -fL "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-${WASI_SDK_VERSION}-x86_64-linux.tar.gz" \
30+
| tar xz -C /opt
31+
fi
32+
33+
cmake -B /tmp/abseil-wasi-build -S "${ABSEIL_ROOT}" \
34+
-DCMAKE_TOOLCHAIN_FILE="${WASI_SDK_DIR}/share/cmake/wasi-sdk-pthread.cmake" \
35+
-DCMAKE_C_FLAGS="-D_WASI_EMULATED_MMAN -D_WASI_EMULATED_SIGNAL -DABSL_HAVE_MMAP" \
36+
-DCMAKE_CXX_FLAGS="-D_WASI_EMULATED_MMAN -D_WASI_EMULATED_SIGNAL -DABSL_HAVE_MMAP -fno-exceptions" \
37+
-DCMAKE_EXE_LINKER_FLAGS="-lwasi-emulated-mman -lwasi-emulated-signal" \
38+
-DABSL_BUILD_TESTING=OFF
39+
40+
cmake --build /tmp/abseil-wasi-build -j"$(nproc)"
41+
42+
echo "PASS: abseil-cpp builds for WASI with wasi-sdk"

0 commit comments

Comments
 (0)