diff --git a/ortools/base/raw_logging.cc b/ortools/base/raw_logging.cc index 2b60477324a..a0ba9a7ca16 100644 --- a/ortools/base/raw_logging.cc +++ b/ortools/base/raw_logging.cc @@ -26,14 +26,18 @@ #include "ortools/base/log_severity.h" #include "ortools/base/logging_utilities.h" -#if !defined(_MSC_VER) +#if !defined(_MSC_VER) && !defined(__EMSCRIPTEN__) #include // for syscall() #define safe_write(fd, s, len) syscall(SYS_write, fd, s, len) #else +#if defined(__EMSCRIPTEN__) +#define safe_write(fd, s, len) write(fd, s, len) +#else #include // _write() // Not so safe, but what can you do? #define safe_write(fd, s, len) _write(fd, s, len) #endif +#endif #if defined(_MSC_VER) && !defined(__MINGW32__) enum { STDIN_FILENO = 0, STDOUT_FILENO = 1, STDERR_FILENO = 2 }; diff --git a/tools/cross_compile.sh b/tools/cross_compile.sh old mode 100755 new mode 100644 index 774396ecb87..20d433f2a1d --- a/tools/cross_compile.sh +++ b/tools/cross_compile.sh @@ -265,6 +265,25 @@ QEMU_ARGS+=( -L "${SYSROOT_DIR}" ) QEMU_ARGS+=( -E LD_PRELOAD="${SYSROOT_DIR}/usr/lib/libstdc++.so.6:${SYSROOT_DIR}/lib/libgcc_s.so.1" ) } +function expand_wasm_config() { + local -r EMSDK_VERSION=2.0.14 + local -r EMSDK_URL=https://github.com/emscripten-core/emsdk/archive/${EMSDK_VERSION}.tar.gz + local -r EMSDK_RELATIVE_DIR="emsdk-${EMSDK_VERSION}" + local -r EMSDK="${ARCHIVE_DIR}/${EMSDK_RELATIVE_DIR}" + if [ ! -d "${EMSDK}" ]; then + echo "Fetching emscripten" + unpack "${EMSDK_URL}" "${EMSDK_RELATIVE_DIR}" + echo "Installing Emscripten ..." + ${EMSDK}/emsdk install ${EMSDK_VERSION} + + echo "Activating Emscripten ..." + ${EMSDK}/emsdk activate ${EMSDK_VERSION} + fi + + declare -r TOOLCHAIN_FILE=${EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake + CMAKE_ADDITIONAL_ARGS+=( -DCMAKE_TOOLCHAIN_FILE="${TOOLCHAIN_FILE}" -DBUILD_SAMPLES=OFF -DBUILD_EXAMPLES=OFF -DBUILD_TESTING=OFF) +} + function build() { cd "${PROJECT_DIR}" || exit 2 set -x @@ -323,6 +342,7 @@ DESCRIPTION \t\tmips64 mips64el (codespace) \t\tppc (bootlin) \t\tppc64 ppc64le (bootlin) +\t\twasm32 (emscripten) OPTIONS \t-h --help: show this help text @@ -403,6 +423,9 @@ function main() { ppc) expand_bootlin_config declare -r QEMU_ARCH=ppc ;; + wasm32) + expand_wasm_config + declare -r QEMU_ARCH=DISABLED ;; *) >&2 echo "Unknown TARGET '${TARGET}'..." exit 1 ;;