Skip to content

Commit 17d201b

Browse files
committed
cpython: fix func compilation
1 parent f5abbbc commit 17d201b

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

func/cpp/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ project(faasm-func)
33

44
set(CMAKE_CXX_STANDARD 17)
55

6-
if (CMAKE_SYSTEM_NAME STREQUAL "Wasm")
6+
if (CMAKE_SYSTEM_NAME STREQUAL "WASI")
77
# For Faasm functions, we add `_faasm_zygote` as an exported symbol
88
set(CMAKE_EXE_LINKER_FLAGS
99
"${CMAKE_EXE_LINKER_FLAGS} -Xlinker --export=_faasm_zygote"
@@ -12,18 +12,18 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Wasm")
1212
set(CMAKE_EXECUTABLE_SUFFIX ".wasm")
1313
endif ()
1414

15-
if (CMAKE_SYSTEM_NAME STREQUAL "Wasm")
15+
if (CMAKE_SYSTEM_NAME STREQUAL "WASI")
1616
set(FAASM_FUNC_LIBS faasm emscripten c-printscan-long-double)
1717

18-
set(PYTHON_LIBRARIES ${CMAKE_SYSROOT}/lib/wasm32-wasi/libpython3.8.a)
19-
set(PYTHON_INCLUDE_DIRS ${CMAKE_SYSROOT}/include/python3.8)
18+
set(PYTHON_LIBRARIES $ENV{FAASM_WASM_LIB_INSTALL_DIR}/libpython3.8.a)
19+
set(PYTHON_INCLUDE_DIRS $ENV{FAASM_WASM_HEADER_INSTALL_DIR}/python3.8)
2020
else ()
2121
find_package(PythonLibs)
2222
endif()
2323

2424
add_executable(py_func pyinit.c pyinit.h py_func.cpp)
2525

26-
if (CMAKE_SYSTEM_NAME STREQUAL "Wasm")
26+
if (CMAKE_SYSTEM_NAME STREQUAL "WASI")
2727
target_link_libraries(py_func ${FAASM_FUNC_LIBS} ${PYTHON_LIBRARIES} ffi)
2828
target_include_directories(py_func PUBLIC ${PYTHON_INCLUDE_DIRS})
2929

tasks/cpython.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
from copy import copy as deep_copy
22
from faasmctl.util.upload import upload_wasm
33
from faasmtools.build import (
4-
FAASM_BUILD_ENV_DICT,
5-
WASM_HEADER_INSTALL,
6-
WASM_LIB_INSTALL,
7-
WASM_WASI_LIBC_LDFLAGS,
84
build_config_cmd,
5+
get_faasm_build_env_dict
96
)
107
from faasmtools.compile_util import wasm_cmake, wasm_copy_upload
118
from faasmtools.env import LLVM_VERSION, WASM_DIR
@@ -54,16 +51,16 @@
5451
"PATH": PATH_ENV_VAR,
5552
}
5653
)
57-
ENV_VARS.update(FAASM_BUILD_ENV_DICT)
54+
ENV_VARS.update(get_faasm_build_env_dict(is_threads=True))
5855

5956
LIB_SRC_DIR = join(CPYTHON_INSTALL_DIR, "lib")
6057
LIB_DEST_DIR = join(FAASM_RUNTIME_ROOT, "lib")
6158

6259
LIBPYTHON_SRC_PATH = join(LIB_SRC_DIR, "libpython3.8.a")
63-
LIBPYTHON_DEST_PATH = join(WASM_LIB_INSTALL, "libpython3.8.a")
60+
LIBPYTHON_DEST_PATH = join(ENV_VARS["FAASM_WASM_LIB_INSTALL_DIR"], "libpython3.8.a")
6461

6562
INCLUDE_SRC_DIR = join(CPYTHON_INSTALL_DIR, "include", "python3.8")
66-
INCLUDE_DEST_DIR = join(WASM_HEADER_INSTALL, "python3.8")
63+
INCLUDE_DEST_DIR = join(ENV_VARS["FAASM_WASM_HEADER_INSTALL_DIR"], "python3.8")
6764

6865
# See the CPython docs for more info:
6966
# - General: https://devguide.python.org/setup/#compile-and-build
@@ -96,21 +93,26 @@ def wasm(ctx, clean=False, noconf=False, nobuild=False):
9693
# relevant in the module builds.
9794

9895
# Link in extra wasi-libc long double support (see wasi-libc docs)
99-
link_libs = ["-lfaasm"] + WASM_WASI_LIBC_LDFLAGS
100-
link_libs = " ".join(link_libs)
96+
link_libs = "-lfaasm " + ENV_VARS["FAASM_WASM_STATIC_LINKER_FLAGS"]
97+
# link_libs = " ".join(link_libs)
10198

10299
# Configure
103100
configure_cmd = build_config_cmd(
101+
ENV_VARS,
104102
[
105103
"CONFIG_SITE=./config.site",
106104
"READELF=true",
107105
"./configure",
108106
'LIBS="{}"'.format(link_libs),
107+
"--build=wasm32",
108+
"--host={}".format(ENV_VARS["FAASM_WASM_TRIPLE"]),
109109
"--disable-ipv6",
110110
"--disable-shared",
111111
"--prefix={}".format(CPYTHON_INSTALL_DIR),
112112
"--with-system-ffi",
113-
]
113+
],
114+
# Do not set the --host flag as we want to use the wasi-threads target
115+
conf_args=False,
114116
)
115117

116118
if not noconf:
@@ -133,8 +135,8 @@ def wasm(ctx, clean=False, noconf=False, nobuild=False):
133135
_run_cpython_cmd("bininstall", ["make", "bininstall"])
134136

135137
# Prepare destinations
136-
makedirs(WASM_HEADER_INSTALL, exist_ok=True)
137-
makedirs(WASM_LIB_INSTALL, exist_ok=True)
138+
makedirs(ENV_VARS["FAASM_WASM_HEADER_INSTALL_DIR"], exist_ok=True)
139+
makedirs(ENV_VARS["FAASM_WASM_LIB_INSTALL_DIR"], exist_ok=True)
138140

139141
rmtree(INCLUDE_DEST_DIR, ignore_errors=True)
140142

@@ -231,7 +233,7 @@ def func(ctx, clean=False, debug=False):
231233
wasm_file = join(func_build_dir, "{}.wasm".format(CPYTHON_FUNC_NAME))
232234

233235
# Build and install the wasm
234-
wasm_cmake(func_dir, func_build_dir, CPYTHON_FUNC_NAME, clean, debug)
236+
wasm_cmake(func_dir, func_build_dir, CPYTHON_FUNC_NAME, clean, debug, is_threads=True)
235237
wasm_copy_upload(CPYTHON_FUNC_USER, CPYTHON_FUNC_NAME, wasm_file)
236238

237239

0 commit comments

Comments
 (0)