From 1c970c030a6196ef204b413cadb695fe89613e77 Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Thu, 15 Feb 2024 11:21:18 +0000 Subject: [PATCH 01/15] gh: bump minor code version --- .github/workflows/tests.yml | 4 ++-- Dockerfile | 2 +- VERSION | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 88f8c94..e1cddca 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -20,7 +20,7 @@ jobs: if: github.event.pull_request.draft == false runs-on: ubuntu-latest container: - image: faasm.azurecr.io/cpython:0.3.1 + image: faasm.azurecr.io/cpython:0.4.0 credentials: username: ${{ secrets.ACR_SERVICE_PRINCIPAL_ID }} password: ${{ secrets.ACR_SERVICE_PRINCIPAL_PASSWORD }} @@ -44,7 +44,7 @@ jobs: REDIS_QUEUE_HOST: redis REDIS_STATE_HOST: redis container: - image: faasm.azurecr.io/cpython:0.3.1 + image: faasm.azurecr.io/cpython:0.4.0 credentials: username: ${{ secrets.ACR_SERVICE_PRINCIPAL_ID }} password: ${{ secrets.ACR_SERVICE_PRINCIPAL_PASSWORD }} diff --git a/Dockerfile b/Dockerfile index a3fba6d..5fc14ce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM faasm.azurecr.io/cpp-sysroot:0.2.4 +FROM faasm.azurecr.io/cpp-sysroot:0.4.0 ARG FAASM_PYTHON_VERSION SHELL ["/bin/bash", "-c"] diff --git a/VERSION b/VERSION index 9e11b32..1d0ba9e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.1 +0.4.0 From 0c1b58d15fcdc909acf4183f050e1f1cdc6d19d8 Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Thu, 15 Feb 2024 11:24:01 +0000 Subject: [PATCH 02/15] third-party: remove unsupported submodules --- .gitmodules | 12 ------------ crossenv/tasks/modules.py | 1 + third-party/horovod | 1 - third-party/mxnet | 1 - third-party/numpy | 1 - 5 files changed, 1 insertion(+), 15 deletions(-) delete mode 160000 third-party/horovod delete mode 160000 third-party/mxnet delete mode 160000 third-party/numpy diff --git a/.gitmodules b/.gitmodules index 05f35f8..197ba36 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,22 +2,10 @@ path = third-party/cpython url = https://github.com/faasm/cpython branch = faasm -[submodule "third-party/numpy"] - path = third-party/numpy - url = https://github.com/faasm/numpy - branch = faasm [submodule "third-party/crossenv"] path = third-party/crossenv url = https://github.com/faasm/crossenv branch = faasm -[submodule "third-party/horovod"] - path = third-party/horovod - url = https://github.com/faasm/horovod - branch = faasm -[submodule "third-party/mxnet"] - path = third-party/mxnet - url = https://github.com/faasm/incubator-mxnet - branch = faasm [submodule "third-party/cpp"] path = third-party/cpp url = https://github.com/faasm/cpp diff --git a/crossenv/tasks/modules.py b/crossenv/tasks/modules.py index 561cc71..ea2fd01 100644 --- a/crossenv/tasks/modules.py +++ b/crossenv/tasks/modules.py @@ -25,6 +25,7 @@ MODIFIED_LIBS_EXPERIMENTAL = { # 15/11/2022 - Move Numpy back to experimental as either the upgrades # to the CPP toolchain or LLVM 13 break the build + # (experimental <=> not yet supported) "numpy": { "env": {"NPY_NUM_BUILD_JOBS": USABLE_CPUS}, }, diff --git a/third-party/horovod b/third-party/horovod deleted file mode 160000 index 9caabd5..0000000 --- a/third-party/horovod +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9caabd58db88d3a396cc016399e2a1c0128f9770 diff --git a/third-party/mxnet b/third-party/mxnet deleted file mode 160000 index b444f05..0000000 --- a/third-party/mxnet +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b444f05eb58dee8152eb744c66519417dde4ccf2 diff --git a/third-party/numpy b/third-party/numpy deleted file mode 160000 index ea6079d..0000000 --- a/third-party/numpy +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ea6079db9503e54982195aea2453bc45bbca7e0f From bc80f9275edbc4dfb9d677fce7ae4f9073f57663 Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Thu, 15 Feb 2024 11:29:09 +0000 Subject: [PATCH 03/15] tasks: bump to llvm 17 for clang formatting --- tasks/format_code.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tasks/format_code.py b/tasks/format_code.py index 2a6dbd9..496fc54 100644 --- a/tasks/format_code.py +++ b/tasks/format_code.py @@ -1,3 +1,4 @@ +from faasmtools.env import LLVM_VERSION from invoke import task from tasks.env import PROJ_ROOT from subprocess import run @@ -51,7 +52,7 @@ def format(ctx, check=False): ) clang_cmd = [ - "clang-format-13", + "clang-format-{}".format(LLVM_VERSION.split(".")[0]), "--dry-run --Werror" if check else "-i", " ".join(files_to_check), ] From 755a2fb3db3f123e9e57a77884265ef05f6ba6c1 Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Thu, 15 Feb 2024 11:30:03 +0000 Subject: [PATCH 04/15] remove unnecessary references to apps --- Dockerfile | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5fc14ce..191a1f4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,11 +41,6 @@ RUN cd /code/python \ && source ./venv/bin/activate \ && inv modules.install - -# TODO: enable these once the MXNet/ Horovod work is completed -# Build mxnet -# RUN inv mxnet - # TODO: Install experimental pacakges # RUN . ./cross_venv/bin/activate && inv libs.install --experimental From 57014942b8d65c4c1571446c4e49f9cbd07bb42b Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Thu, 15 Feb 2024 11:33:17 +0000 Subject: [PATCH 05/15] cpython: use lllvm-17 for the native build --- tasks/cpython.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tasks/cpython.py b/tasks/cpython.py index fa4b3f6..402aca8 100644 --- a/tasks/cpython.py +++ b/tasks/cpython.py @@ -8,7 +8,7 @@ build_config_cmd, ) from faasmtools.compile_util import wasm_cmake, wasm_copy_upload -from faasmtools.env import WASM_DIR +from faasmtools.env import LLVM_VERSION, WASM_DIR from invoke import task from os import environ, makedirs from os.path import join, exists @@ -187,12 +187,13 @@ def native(ctx, clean=False): run("wget {}".format(tar_url), shell=True, check=True, cwd=workdir) run("tar -xf {}".format(tar_name), shell=True, check=True, cwd=workdir) + llvm_version_major = LLVM_VERSION.split(".")[0] workdir = join(workdir, PYTHON_VERSION) native_configure_cmd = [ - 'CC="clang-13"', - 'CXX="clang++-13"', + 'CC="clang-{}"'.format(llvm_version_major), + 'CXX="clang++-{}"'.format(llvm_version_major), 'CFLAGS="-O3 -DANSI"', - 'LD="clang-13"', + 'LD="clang-{}"'.format(llvm_version_major), "./configure", "--prefix={}".format(PYTHON_INSTALL_DIR), ] From f5abbbc2a08857c5d151395aba98d6519d2cd086 Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Thu, 15 Feb 2024 11:35:52 +0000 Subject: [PATCH 06/15] cpp: point to llvm-17 branch --- third-party/cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third-party/cpp b/third-party/cpp index 16102b1..0f0125d 160000 --- a/third-party/cpp +++ b/third-party/cpp @@ -1 +1 @@ -Subproject commit 16102b14075c61491bf4a46f79672ea687413d53 +Subproject commit 0f0125d4d07c741cd0efae2c8418e88505de88a1 From 17d201b511f35c55da915018c3c1c64ffb018078 Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Mon, 19 Feb 2024 17:12:31 +0000 Subject: [PATCH 07/15] cpython: fix func compilation --- func/cpp/CMakeLists.txt | 10 +++++----- tasks/cpython.py | 28 +++++++++++++++------------- third-party/cpp | 2 +- third-party/cpython | 2 +- 4 files changed, 22 insertions(+), 20 deletions(-) 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 From a240269ac4354622de14b8c924a78aa0b666eb54 Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Mon, 19 Feb 2024 17:56:11 +0000 Subject: [PATCH 08/15] cpp: bump --- third-party/cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third-party/cpp b/third-party/cpp index 0b67978..eaaf4d5 160000 --- a/third-party/cpp +++ b/third-party/cpp @@ -1 +1 @@ -Subproject commit 0b6797865c49d0691f67a55424f415541ad84ee3 +Subproject commit eaaf4d5cd5b1ea440f25d09a7c1bb82aac0169b3 From b05df7a78d1816fb10a2adbc7ca690a77a4ca670 Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Mon, 19 Feb 2024 18:11:08 +0000 Subject: [PATCH 09/15] cpython: set the target in the func compilation --- func/cpp/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/func/cpp/CMakeLists.txt b/func/cpp/CMakeLists.txt index a3b44e2..0c7da02 100644 --- a/func/cpp/CMakeLists.txt +++ b/func/cpp/CMakeLists.txt @@ -4,10 +4,15 @@ project(faasm-func) set(CMAKE_CXX_STANDARD 17) if (CMAKE_SYSTEM_NAME STREQUAL "WASI") + # Set the right target so that we look in the right sysroot + set(CMAKE_C_FLAGS "--target=$ENV{FAASM_WASM_TRIPLE} ${CMAKE_C_FLAGS}") + set(CMAKE_CXX_FLAGS "--target=$ENV{FAASM_WASM_TRIPLE} ${CMAKE_CXX_FLAGS}") + # For Faasm functions, we add `_faasm_zygote` as an exported symbol set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Xlinker --export=_faasm_zygote" ) + message(STATUS "Detected wasm build (sysroot=$ENV{FAASM_WASM_SYSROOT})") set(CMAKE_EXECUTABLE_SUFFIX ".wasm") endif () From ad7700b2ccda6e9b2f096ea1855920a5dea0d2c4 Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Tue, 20 Feb 2024 16:42:56 +0000 Subject: [PATCH 10/15] cpp: bump dep --- third-party/cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third-party/cpp b/third-party/cpp index eaaf4d5..27aae15 160000 --- a/third-party/cpp +++ b/third-party/cpp @@ -1 +1 @@ -Subproject commit eaaf4d5cd5b1ea440f25d09a7c1bb82aac0169b3 +Subproject commit 27aae1519e5d4ada3704e7e546bdbaa18a077728 From 66fdd6e45cc898938946e963f4bdd71312a54ebb Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Thu, 22 Feb 2024 13:12:27 +0000 Subject: [PATCH 11/15] cpython: use llvm native version for native compilation --- tasks/cpython.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tasks/cpython.py b/tasks/cpython.py index 76b96ec..dfc028d 100644 --- a/tasks/cpython.py +++ b/tasks/cpython.py @@ -5,7 +5,7 @@ get_faasm_build_env_dict ) from faasmtools.compile_util import wasm_cmake, wasm_copy_upload -from faasmtools.env import LLVM_VERSION, WASM_DIR +from faasmtools.env import LLVM_NATIVE_VERSION, WASM_DIR from invoke import task from os import environ, makedirs from os.path import join, exists @@ -189,13 +189,13 @@ def native(ctx, clean=False): run("wget {}".format(tar_url), shell=True, check=True, cwd=workdir) run("tar -xf {}".format(tar_name), shell=True, check=True, cwd=workdir) - llvm_version_major = LLVM_VERSION.split(".")[0] + llvm_native_version_major = LLVM_NATIVE_VERSION.split(".")[0] workdir = join(workdir, PYTHON_VERSION) native_configure_cmd = [ - 'CC="clang-{}"'.format(llvm_version_major), - 'CXX="clang++-{}"'.format(llvm_version_major), + 'CC="clang-{}"'.format(llvm_native_version_major), + 'CXX="clang++-{}"'.format(llvm_native_version_major), 'CFLAGS="-O3 -DANSI"', - 'LD="clang-{}"'.format(llvm_version_major), + 'LD="clang-{}"'.format(llvm_native_version_major), "./configure", "--prefix={}".format(PYTHON_INSTALL_DIR), ] From e3f5a14c9a7e8aac08737e26a074638be5c22fa7 Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Fri, 1 Mar 2024 15:04:03 +0000 Subject: [PATCH 12/15] nits --- .clang-format | 7 +++++++ func/cpp/py_func.cpp | 18 ++++++------------ func/cpp/pyinit.c | 3 +-- func/cpp/pyinit.h | 5 ++--- tasks/cpython.py | 18 ++++++++++++------ tasks/format_code.py | 1 + third-party/cpp | 2 +- 7 files changed, 30 insertions(+), 24 deletions(-) diff --git a/.clang-format b/.clang-format index 0c2dc98..5b16353 100644 --- a/.clang-format +++ b/.clang-format @@ -10,4 +10,11 @@ AlwaysBreakAfterReturnType: None IndentWidth: 4 DerivePointerAlignment: false + +# Precise control over braces alignment +BreakBeforeBraces: Custom +BraceWrapping: + AfterClass: true + SplitEmptyFunction: false + SplitEmptyRecord: false --- diff --git a/func/cpp/py_func.cpp b/func/cpp/py_func.cpp index 6700b42..e2ce33d 100644 --- a/func/cpp/py_func.cpp +++ b/func/cpp/py_func.cpp @@ -1,5 +1,4 @@ -extern "C" -{ +extern "C" { #include "pyinit.h" } @@ -21,8 +20,7 @@ extern "C" * Returns the relevant Python entry function. We need to invoke different * functions depending on which Faasm function index we're dealing with. */ -const char* getPythonFunctionName() -{ +const char* getPythonFunctionName() { char* entryFunc = faasmGetPythonEntry(); if (strlen(entryFunc) == 0) { @@ -36,8 +34,7 @@ const char* getPythonFunctionName() * Returns the working dir we need to be in to import the Python module * for the required function. */ -const char* getPythonWorkingDir(const char* user, const char* funcName) -{ +const char* getPythonWorkingDir(const char* user, const char* funcName) { auto workingDir = new char[60]; #ifdef __wasm__ @@ -53,8 +50,7 @@ const char* getPythonWorkingDir(const char* user, const char* funcName) * Returns the name of the python module to execute. If executing in wasm this * will be different to when executing natively. */ -const char* getPythonModuleName(const char* funcName) -{ +const char* getPythonModuleName(const char* funcName) { #ifdef __wasm__ return "function"; #else @@ -65,8 +61,7 @@ const char* getPythonModuleName(const char* funcName) /** * Initialise CPython using a Faasm zygote to avoid doing so repeatedly */ -FAASM_ZYGOTE() -{ +FAASM_ZYGOTE() { Py_InitializeEx(0); // 21/12/2022 - Numpy support is broken @@ -95,8 +90,7 @@ FAASM_ZYGOTE() return 0; } -int main(int argc, char* argv[]) -{ +int main(int argc, char* argv[]) { // With this line uncommented, this file can be run as a normal executable // for testing setEmulatedMessageFromJson(R"({"user": "python", "function": // "py_func", "py_user": "python", "py_func": "lang_test", "py_entry": diff --git a/func/cpp/pyinit.c b/func/cpp/pyinit.c index 24a6861..93f1ef8 100644 --- a/func/cpp/pyinit.c +++ b/func/cpp/pyinit.c @@ -74,8 +74,7 @@ fprintf(devNull, "%p", trunc##sfx); \ fprintf(devNull, "%p", rint##sfx); -void setUpPyNumpy() -{ +void setUpPyNumpy() { FILE* devNull = fopen("/dev/null", "w"); // Maths diff --git a/func/cpp/pyinit.h b/func/cpp/pyinit.h index f41621a..a682b5b 100644 --- a/func/cpp/pyinit.h +++ b/func/cpp/pyinit.h @@ -2,11 +2,10 @@ #define FAASM_PYTHON_H #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif - void setUpPyNumpy(); +void setUpPyNumpy(); #ifdef __cplusplus } diff --git a/tasks/cpython.py b/tasks/cpython.py index dfc028d..a190c02 100644 --- a/tasks/cpython.py +++ b/tasks/cpython.py @@ -1,9 +1,6 @@ from copy import copy as deep_copy from faasmctl.util.upload import upload_wasm -from faasmtools.build import ( - build_config_cmd, - get_faasm_build_env_dict -) +from faasmtools.build import build_config_cmd, get_faasm_build_env_dict from faasmtools.compile_util import wasm_cmake, wasm_copy_upload from faasmtools.env import LLVM_NATIVE_VERSION, WASM_DIR from invoke import task @@ -57,7 +54,9 @@ LIB_DEST_DIR = join(FAASM_RUNTIME_ROOT, "lib") LIBPYTHON_SRC_PATH = join(LIB_SRC_DIR, "libpython3.8.a") -LIBPYTHON_DEST_PATH = join(ENV_VARS["FAASM_WASM_LIB_INSTALL_DIR"], "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(ENV_VARS["FAASM_WASM_HEADER_INSTALL_DIR"], "python3.8") @@ -233,7 +232,14 @@ 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, is_threads=True) + 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/tasks/format_code.py b/tasks/format_code.py index 496fc54..ba96f90 100644 --- a/tasks/format_code.py +++ b/tasks/format_code.py @@ -54,6 +54,7 @@ def format(ctx, check=False): clang_cmd = [ "clang-format-{}".format(LLVM_VERSION.split(".")[0]), "--dry-run --Werror" if check else "-i", + "-style=file", " ".join(files_to_check), ] clang_cmd = " ".join(clang_cmd) diff --git a/third-party/cpp b/third-party/cpp index 27aae15..89c98da 160000 --- a/third-party/cpp +++ b/third-party/cpp @@ -1 +1 @@ -Subproject commit 27aae1519e5d4ada3704e7e546bdbaa18a077728 +Subproject commit 89c98da474c75674dabf36bad7641a0768a04df7 From 0e6fc637f91611130f52f69a4e4f5f85bf97ad03 Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Mon, 4 Mar 2024 09:11:57 +0000 Subject: [PATCH 13/15] nits: clang-format-17 checks passing --- .clang-format | 5 +++++ func/cpp/py_func.cpp | 18 ++++++++++++------ func/cpp/pyinit.c | 3 ++- func/cpp/pyinit.h | 5 +++-- tasks/format_code.py | 4 ++-- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/.clang-format b/.clang-format index 5b16353..7e8982a 100644 --- a/.clang-format +++ b/.clang-format @@ -15,6 +15,11 @@ DerivePointerAlignment: false BreakBeforeBraces: Custom BraceWrapping: AfterClass: true + AfterEnum: true + AfterExternBlock: true + AfterFunction: true + AfterStruct: true + AfterUnion: true SplitEmptyFunction: false SplitEmptyRecord: false --- diff --git a/func/cpp/py_func.cpp b/func/cpp/py_func.cpp index e2ce33d..6700b42 100644 --- a/func/cpp/py_func.cpp +++ b/func/cpp/py_func.cpp @@ -1,4 +1,5 @@ -extern "C" { +extern "C" +{ #include "pyinit.h" } @@ -20,7 +21,8 @@ extern "C" { * Returns the relevant Python entry function. We need to invoke different * functions depending on which Faasm function index we're dealing with. */ -const char* getPythonFunctionName() { +const char* getPythonFunctionName() +{ char* entryFunc = faasmGetPythonEntry(); if (strlen(entryFunc) == 0) { @@ -34,7 +36,8 @@ const char* getPythonFunctionName() { * Returns the working dir we need to be in to import the Python module * for the required function. */ -const char* getPythonWorkingDir(const char* user, const char* funcName) { +const char* getPythonWorkingDir(const char* user, const char* funcName) +{ auto workingDir = new char[60]; #ifdef __wasm__ @@ -50,7 +53,8 @@ const char* getPythonWorkingDir(const char* user, const char* funcName) { * Returns the name of the python module to execute. If executing in wasm this * will be different to when executing natively. */ -const char* getPythonModuleName(const char* funcName) { +const char* getPythonModuleName(const char* funcName) +{ #ifdef __wasm__ return "function"; #else @@ -61,7 +65,8 @@ const char* getPythonModuleName(const char* funcName) { /** * Initialise CPython using a Faasm zygote to avoid doing so repeatedly */ -FAASM_ZYGOTE() { +FAASM_ZYGOTE() +{ Py_InitializeEx(0); // 21/12/2022 - Numpy support is broken @@ -90,7 +95,8 @@ FAASM_ZYGOTE() { return 0; } -int main(int argc, char* argv[]) { +int main(int argc, char* argv[]) +{ // With this line uncommented, this file can be run as a normal executable // for testing setEmulatedMessageFromJson(R"({"user": "python", "function": // "py_func", "py_user": "python", "py_func": "lang_test", "py_entry": diff --git a/func/cpp/pyinit.c b/func/cpp/pyinit.c index 93f1ef8..24a6861 100644 --- a/func/cpp/pyinit.c +++ b/func/cpp/pyinit.c @@ -74,7 +74,8 @@ fprintf(devNull, "%p", trunc##sfx); \ fprintf(devNull, "%p", rint##sfx); -void setUpPyNumpy() { +void setUpPyNumpy() +{ FILE* devNull = fopen("/dev/null", "w"); // Maths diff --git a/func/cpp/pyinit.h b/func/cpp/pyinit.h index a682b5b..f41621a 100644 --- a/func/cpp/pyinit.h +++ b/func/cpp/pyinit.h @@ -2,10 +2,11 @@ #define FAASM_PYTHON_H #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -void setUpPyNumpy(); + void setUpPyNumpy(); #ifdef __cplusplus } diff --git a/tasks/format_code.py b/tasks/format_code.py index ba96f90..0eebd27 100644 --- a/tasks/format_code.py +++ b/tasks/format_code.py @@ -1,4 +1,4 @@ -from faasmtools.env import LLVM_VERSION +from faasmtools.env import LLVM_NATIVE_VERSION from invoke import task from tasks.env import PROJ_ROOT from subprocess import run @@ -52,7 +52,7 @@ def format(ctx, check=False): ) clang_cmd = [ - "clang-format-{}".format(LLVM_VERSION.split(".")[0]), + "clang-format-{}".format(LLVM_NATIVE_VERSION.split(".")[0]), "--dry-run --Werror" if check else "-i", "-style=file", " ".join(files_to_check), From 1f2cbb9995997e02931133df1726e36c1710ec63 Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Mon, 4 Mar 2024 09:21:16 +0000 Subject: [PATCH 14/15] cpp: bump to latest version --- third-party/cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third-party/cpp b/third-party/cpp index 89c98da..8d5c4a9 160000 --- a/third-party/cpp +++ b/third-party/cpp @@ -1 +1 @@ -Subproject commit 89c98da474c75674dabf36bad7641a0768a04df7 +Subproject commit 8d5c4a995819a813f791e9aa33a317bed1fda881 From 4d3368b9da21eb151a24e5a25e1404faa2a85430 Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Tue, 12 Mar 2024 16:02:04 +0000 Subject: [PATCH 15/15] cpp: bump after merge to main --- third-party/cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third-party/cpp b/third-party/cpp index 8d5c4a9..d9fc3ac 160000 --- a/third-party/cpp +++ b/third-party/cpp @@ -1 +1 @@ -Subproject commit 8d5c4a995819a813f791e9aa33a317bed1fda881 +Subproject commit d9fc3acfaa96caebbe585389af79d5e7c0959c90