Skip to content
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

Add Wasm32 as target for cross compiling #2404

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
6 changes: 5 additions & 1 deletion ortools/base/raw_logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@
#include "ortools/base/logging.h"
#include "ortools/base/logging_utilities.h"

#if !defined(_MSC_VER)
#if !defined(_MSC_VER) && !defined(__EMSCRIPTEN__)
#include <sys/syscall.h> // for syscall()
#define safe_write(fd, s, len) syscall(SYS_write, fd, s, len)
#else
#if !defined(__EMSCRIPTEN__)
Mizux marked this conversation as resolved.
Show resolved Hide resolved
#include <io.h> // _write()
// Not so safe, but what can you do?
#define safe_write(fd, s, len) _write(fd, s, len)
#else
#define safe_write(fd, s, len) write(fd, s, len)
#endif
#endif

#if defined(_MSC_VER) && !defined(__MINGW32__)
Expand Down
2 changes: 2 additions & 0 deletions ortools/glop/lp_solver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ ProblemStatus LPSolver::SolveWithTimeLimit(const LinearProgram& lp,
// Note that we only activate the floating-point exceptions after we are sure
// that the program is valid. This way, if we have input NaNs, we will not
// crash.
#ifndef __EMSCRIPTEN__
ScopedFloatingPointEnv scoped_fenv;
if (absl::GetFlag(FLAGS_lp_solver_enable_fp_exceptions)) {
#ifdef _MSC_VER
Expand All @@ -168,6 +169,7 @@ ProblemStatus LPSolver::SolveWithTimeLimit(const LinearProgram& lp,
scoped_fenv.EnableExceptions(FE_DIVBYZERO | FE_INVALID);
#endif
}
#endif

// Make an internal copy of the problem for the preprocessing.
const bool log_info = parameters_.log_search_progress() || VLOG_IS_ON(1);
Expand Down
22 changes: 22 additions & 0 deletions tools/cross_compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,25 @@ function clean_build() {
mkdir -p "${BUILD_DIR}"
}

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}
Mizux marked this conversation as resolved.
Show resolved Hide resolved

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 expand_linaro_config() {
#ref: https://releases.linaro.org/components/toolchain/binaries/
local -r LINARO_VERSION=7.5-2019.12
Expand Down Expand Up @@ -322,6 +341,9 @@ function main() {
mips64el)
expand_codescape_config
declare -r QEMU_ARCH=mips64el ;;
wasm32)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note for myself, emscripten generate wasm32 by default
ref: https://emscripten.org/docs/tools_reference/settings_reference.html#memory64

expand_wasm_config
declare -r QEMU_ARCH=DISABLED ;;
*)
>&2 echo "Unknown TARGET '${TARGET}'..."
exit 1 ;;
Expand Down