diff --git a/func/cpp/CMakeLists.txt b/func/cpp/CMakeLists.txt index 79aeaaf..a3b44e2 100644 --- a/func/cpp/CMakeLists.txt +++ b/func/cpp/CMakeLists.txt @@ -3,7 +3,7 @@ project(faasm-func) set(CMAKE_CXX_STANDARD 17) -if (CMAKE_SYSTEM_NAME STREQUAL "Wasm") +if (CMAKE_SYSTEM_NAME STREQUAL "WASI") # For Faasm functions, we add `_faasm_zygote` as an exported symbol set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Xlinker --export=_faasm_zygote" @@ -12,18 +12,18 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Wasm") set(CMAKE_EXECUTABLE_SUFFIX ".wasm") endif () -if (CMAKE_SYSTEM_NAME STREQUAL "Wasm") +if (CMAKE_SYSTEM_NAME STREQUAL "WASI") set(FAASM_FUNC_LIBS faasm emscripten c-printscan-long-double) - set(PYTHON_LIBRARIES ${CMAKE_SYSROOT}/lib/wasm32-wasi/libpython3.8.a) - set(PYTHON_INCLUDE_DIRS ${CMAKE_SYSROOT}/include/python3.8) + set(PYTHON_LIBRARIES $ENV{FAASM_WASM_LIB_INSTALL_DIR}/libpython3.8.a) + set(PYTHON_INCLUDE_DIRS $ENV{FAASM_WASM_HEADER_INSTALL_DIR}/python3.8) else () find_package(PythonLibs) endif() add_executable(py_func pyinit.c pyinit.h py_func.cpp) -if (CMAKE_SYSTEM_NAME STREQUAL "Wasm") +if (CMAKE_SYSTEM_NAME STREQUAL "WASI") target_link_libraries(py_func ${FAASM_FUNC_LIBS} ${PYTHON_LIBRARIES} ffi) target_include_directories(py_func PUBLIC ${PYTHON_INCLUDE_DIRS}) diff --git a/tasks/cpython.py b/tasks/cpython.py index 402aca8..76b96ec 100644 --- a/tasks/cpython.py +++ b/tasks/cpython.py @@ -1,11 +1,8 @@ from copy import copy as deep_copy from faasmctl.util.upload import upload_wasm from faasmtools.build import ( - FAASM_BUILD_ENV_DICT, - WASM_HEADER_INSTALL, - WASM_LIB_INSTALL, - WASM_WASI_LIBC_LDFLAGS, build_config_cmd, + get_faasm_build_env_dict ) from faasmtools.compile_util import wasm_cmake, wasm_copy_upload from faasmtools.env import LLVM_VERSION, WASM_DIR @@ -54,16 +51,16 @@ "PATH": PATH_ENV_VAR, } ) -ENV_VARS.update(FAASM_BUILD_ENV_DICT) +ENV_VARS.update(get_faasm_build_env_dict(is_threads=True)) LIB_SRC_DIR = join(CPYTHON_INSTALL_DIR, "lib") LIB_DEST_DIR = join(FAASM_RUNTIME_ROOT, "lib") LIBPYTHON_SRC_PATH = join(LIB_SRC_DIR, "libpython3.8.a") -LIBPYTHON_DEST_PATH = join(WASM_LIB_INSTALL, "libpython3.8.a") +LIBPYTHON_DEST_PATH = join(ENV_VARS["FAASM_WASM_LIB_INSTALL_DIR"], "libpython3.8.a") INCLUDE_SRC_DIR = join(CPYTHON_INSTALL_DIR, "include", "python3.8") -INCLUDE_DEST_DIR = join(WASM_HEADER_INSTALL, "python3.8") +INCLUDE_DEST_DIR = join(ENV_VARS["FAASM_WASM_HEADER_INSTALL_DIR"], "python3.8") # See the CPython docs for more info: # - General: https://devguide.python.org/setup/#compile-and-build @@ -96,21 +93,26 @@ def wasm(ctx, clean=False, noconf=False, nobuild=False): # relevant in the module builds. # Link in extra wasi-libc long double support (see wasi-libc docs) - link_libs = ["-lfaasm"] + WASM_WASI_LIBC_LDFLAGS - link_libs = " ".join(link_libs) + link_libs = "-lfaasm " + ENV_VARS["FAASM_WASM_STATIC_LINKER_FLAGS"] + # link_libs = " ".join(link_libs) # Configure configure_cmd = build_config_cmd( + ENV_VARS, [ "CONFIG_SITE=./config.site", "READELF=true", "./configure", 'LIBS="{}"'.format(link_libs), + "--build=wasm32", + "--host={}".format(ENV_VARS["FAASM_WASM_TRIPLE"]), "--disable-ipv6", "--disable-shared", "--prefix={}".format(CPYTHON_INSTALL_DIR), "--with-system-ffi", - ] + ], + # Do not set the --host flag as we want to use the wasi-threads target + conf_args=False, ) if not noconf: @@ -133,8 +135,8 @@ def wasm(ctx, clean=False, noconf=False, nobuild=False): _run_cpython_cmd("bininstall", ["make", "bininstall"]) # Prepare destinations - makedirs(WASM_HEADER_INSTALL, exist_ok=True) - makedirs(WASM_LIB_INSTALL, exist_ok=True) + makedirs(ENV_VARS["FAASM_WASM_HEADER_INSTALL_DIR"], exist_ok=True) + makedirs(ENV_VARS["FAASM_WASM_LIB_INSTALL_DIR"], exist_ok=True) rmtree(INCLUDE_DEST_DIR, ignore_errors=True) @@ -231,7 +233,7 @@ def func(ctx, clean=False, debug=False): wasm_file = join(func_build_dir, "{}.wasm".format(CPYTHON_FUNC_NAME)) # Build and install the wasm - wasm_cmake(func_dir, func_build_dir, CPYTHON_FUNC_NAME, clean, debug) + wasm_cmake(func_dir, func_build_dir, CPYTHON_FUNC_NAME, clean, debug, is_threads=True) wasm_copy_upload(CPYTHON_FUNC_USER, CPYTHON_FUNC_NAME, wasm_file) diff --git a/third-party/cpp b/third-party/cpp index 0f0125d..0b67978 160000 --- a/third-party/cpp +++ b/third-party/cpp @@ -1 +1 @@ -Subproject commit 0f0125d4d07c741cd0efae2c8418e88505de88a1 +Subproject commit 0b6797865c49d0691f67a55424f415541ad84ee3 diff --git a/third-party/cpython b/third-party/cpython index f6890ba..7e1130f 160000 --- a/third-party/cpython +++ b/third-party/cpython @@ -1 +1 @@ -Subproject commit f6890ba59fc1fc1c86cf397175f4f8382e85e096 +Subproject commit 7e1130ff24992c3fe365ad22fb50c170948a6bed