11from copy import copy as deep_copy
22from faasmctl .util .upload import upload_wasm
3- from faasmtools .build import (
4- FAASM_BUILD_ENV_DICT ,
5- WASM_HEADER_INSTALL ,
6- WASM_LIB_INSTALL ,
7- WASM_WASI_LIBC_LDFLAGS ,
8- build_config_cmd ,
9- )
3+ from faasmtools .build import build_config_cmd , get_faasm_build_env_dict
104from faasmtools .compile_util import wasm_cmake , wasm_copy_upload
11- from faasmtools .env import WASM_DIR
5+ from faasmtools .env import LLVM_NATIVE_VERSION , WASM_DIR
126from invoke import task
137from os import environ , makedirs
148from os .path import join , exists
5448 "PATH" : PATH_ENV_VAR ,
5549 }
5650)
57- ENV_VARS .update (FAASM_BUILD_ENV_DICT )
51+ ENV_VARS .update (get_faasm_build_env_dict ( is_threads = True ) )
5852
5953LIB_SRC_DIR = join (CPYTHON_INSTALL_DIR , "lib" )
6054LIB_DEST_DIR = join (FAASM_RUNTIME_ROOT , "lib" )
6155
6256LIBPYTHON_SRC_PATH = join (LIB_SRC_DIR , "libpython3.8.a" )
63- LIBPYTHON_DEST_PATH = join (WASM_LIB_INSTALL , "libpython3.8.a" )
57+ LIBPYTHON_DEST_PATH = join (
58+ ENV_VARS ["FAASM_WASM_LIB_INSTALL_DIR" ], "libpython3.8.a"
59+ )
6460
6561INCLUDE_SRC_DIR = join (CPYTHON_INSTALL_DIR , "include" , "python3.8" )
66- INCLUDE_DEST_DIR = join (WASM_HEADER_INSTALL , "python3.8" )
62+ INCLUDE_DEST_DIR = join (ENV_VARS [ "FAASM_WASM_HEADER_INSTALL_DIR" ] , "python3.8" )
6763
6864# See the CPython docs for more info:
6965# - General: https://devguide.python.org/setup/#compile-and-build
@@ -96,21 +92,26 @@ def wasm(ctx, clean=False, noconf=False, nobuild=False):
9692 # relevant in the module builds.
9793
9894 # 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 )
95+ link_libs = "-lfaasm " + ENV_VARS [ "FAASM_WASM_STATIC_LINKER_FLAGS" ]
96+ # link_libs = " ".join(link_libs)
10197
10298 # Configure
10399 configure_cmd = build_config_cmd (
100+ ENV_VARS ,
104101 [
105102 "CONFIG_SITE=./config.site" ,
106103 "READELF=true" ,
107104 "./configure" ,
108105 'LIBS="{}"' .format (link_libs ),
106+ "--build=wasm32" ,
107+ "--host={}" .format (ENV_VARS ["FAASM_WASM_TRIPLE" ]),
109108 "--disable-ipv6" ,
110109 "--disable-shared" ,
111110 "--prefix={}" .format (CPYTHON_INSTALL_DIR ),
112111 "--with-system-ffi" ,
113- ]
112+ ],
113+ # Do not set the --host flag as we want to use the wasi-threads target
114+ conf_args = False ,
114115 )
115116
116117 if not noconf :
@@ -133,8 +134,8 @@ def wasm(ctx, clean=False, noconf=False, nobuild=False):
133134 _run_cpython_cmd ("bininstall" , ["make" , "bininstall" ])
134135
135136 # Prepare destinations
136- makedirs (WASM_HEADER_INSTALL , exist_ok = True )
137- makedirs (WASM_LIB_INSTALL , exist_ok = True )
137+ makedirs (ENV_VARS [ "FAASM_WASM_HEADER_INSTALL_DIR" ] , exist_ok = True )
138+ makedirs (ENV_VARS [ "FAASM_WASM_LIB_INSTALL_DIR" ] , exist_ok = True )
138139
139140 rmtree (INCLUDE_DEST_DIR , ignore_errors = True )
140141
@@ -187,12 +188,13 @@ def native(ctx, clean=False):
187188 run ("wget {}" .format (tar_url ), shell = True , check = True , cwd = workdir )
188189 run ("tar -xf {}" .format (tar_name ), shell = True , check = True , cwd = workdir )
189190
191+ llvm_native_version_major = LLVM_NATIVE_VERSION .split ("." )[0 ]
190192 workdir = join (workdir , PYTHON_VERSION )
191193 native_configure_cmd = [
192- 'CC="clang-13"' ,
193- 'CXX="clang++-13"' ,
194+ 'CC="clang-{}"' . format ( llvm_native_version_major ) ,
195+ 'CXX="clang++-{}"' . format ( llvm_native_version_major ) ,
194196 'CFLAGS="-O3 -DANSI"' ,
195- 'LD="clang-13"' ,
197+ 'LD="clang-{}"' . format ( llvm_native_version_major ) ,
196198 "./configure" ,
197199 "--prefix={}" .format (PYTHON_INSTALL_DIR ),
198200 ]
@@ -230,7 +232,14 @@ def func(ctx, clean=False, debug=False):
230232 wasm_file = join (func_build_dir , "{}.wasm" .format (CPYTHON_FUNC_NAME ))
231233
232234 # Build and install the wasm
233- wasm_cmake (func_dir , func_build_dir , CPYTHON_FUNC_NAME , clean , debug )
235+ wasm_cmake (
236+ func_dir ,
237+ func_build_dir ,
238+ CPYTHON_FUNC_NAME ,
239+ clean ,
240+ debug ,
241+ is_threads = True ,
242+ )
234243 wasm_copy_upload (CPYTHON_FUNC_USER , CPYTHON_FUNC_NAME , wasm_file )
235244
236245
0 commit comments