def native(ctx, clean=False): """ Compile and install Faasm native tools """ if not exists(FAASM_INSTALL_DIR): makedirs(FAASM_INSTALL_DIR) build_dir = join(PROJ_ROOT, "build", "native_tools") clean_dir(build_dir, clean) build_cmd = [ "cmake", "-DFAASM_BUILD_TYPE=native-tools", "-DFAASM_STATIC_LIBS=OFF", "-DCMAKE_BUILD_TYPE=Release", "-DCMAKE_INSTALL_PREFIX={}".format(FAASM_INSTALL_DIR), PROJ_ROOT, ] build_cmd_str = " ".join(build_cmd) print(build_cmd_str) res = call(build_cmd_str, shell=True, cwd=build_dir) if res != 0: raise RuntimeError("Failed to build native tools") res = call("make -j", shell=True, cwd=build_dir) if res != 0: raise RuntimeError("Failed to make native tools") call("sudo make install", shell=True, cwd=build_dir)
def _build_faasm_lib(dir_name, clean, verbose): work_dir = join(PROJ_ROOT, "libs", dir_name) build_dir = join(PROJ_ROOT, "build", dir_name) clean_dir(build_dir, clean) verbose_str = "VERBOSE=1" if verbose else "" build_cmd = [ verbose_str, "cmake", "-DFAASM_BUILD_TYPE=wasm", "-DCMAKE_BUILD_TYPE=Release", "-DCMAKE_TOOLCHAIN_FILE={}".format(FAASM_TOOLCHAIN_FILE), work_dir, ] build_cmd_str = " ".join(build_cmd) print(build_cmd_str) res = call(build_cmd_str, shell=True, cwd=build_dir) if res != 0: exit(1) res = call("{} make".format(verbose_str), shell=True, cwd=build_dir) if res != 0: exit(1) res = call("make install", shell=True, cwd=build_dir) if res != 0: exit(1)
def native(ctx, clean=False): """ Compile and install Faasm native tools """ if not exists(FAASM_INSTALL_DIR): makedirs(FAASM_INSTALL_DIR) build_dir = join(PROJ_ROOT, "build", "native_tools") clean_dir(build_dir, clean) build_cmd = [ "cmake", "-GNinja", "-DCMAKE_CXX_COMPILER=/usr/bin/clang++-10", "-DCMAKE_C_COMPILER=/usr/bin/clang-10", "-DFAASM_BUILD_TYPE=native-tools", "-DFAASM_STATIC_LIBS=OFF", "-DFAABRIC_BUILD_TESTS=OFF", "-DCMAKE_BUILD_TYPE=Release", "-DCMAKE_INSTALL_PREFIX={}".format(FAASM_INSTALL_DIR), PROJ_ROOT, ] build_cmd_str = " ".join(build_cmd) print(build_cmd_str) run(build_cmd_str, shell=True, cwd=build_dir, check=True) run("ninja", shell=True, cwd=build_dir, check=True) run("sudo ninja install", shell=True, cwd=build_dir, check=True)
def _do_compile(target, clean, debug): build_type = "wasm" cmake_build_type = "Debug" if debug else "Release" clean_dir(FUNC_BUILD_DIR, clean) build_cmd = [ "cmake", "-DFAASM_BUILD_TYPE={}".format(build_type), "-DCMAKE_TOOLCHAIN_FILE={}".format(FAASM_TOOLCHAIN_FILE), "-DCMAKE_BUILD_TYPE={}".format(cmake_build_type), FUNC_DIR, ] build_cmd = " ".join(build_cmd) print(build_cmd) res = call(build_cmd, shell=True, cwd=FUNC_BUILD_DIR) if res != 0: raise RuntimeError("Failed on cmake for {}".format(target)) cmd = "make {}".format(target) if target else "make -j" cmd = "VERBOSE=1 {}".format(cmd) if debug else cmd res = call(cmd, shell=True, cwd=FUNC_BUILD_DIR) if res != 0: raise RuntimeError("Failed on make for {}".format(target))
def wasm_cmake(src_dir, build_dir, target, clean=False, debug=False): build_type = "wasm" cmake_build_type = "Debug" if debug else "Release" clean_dir(build_dir, clean) build_cmd = [ "cmake", "-GNinja", "-DFAASM_BUILD_TYPE={}".format(build_type), "-DCMAKE_TOOLCHAIN_FILE={}".format(CMAKE_TOOLCHAIN_FILE), "-DCMAKE_BUILD_TYPE={}".format(cmake_build_type), src_dir, ] build_cmd = " ".join(build_cmd) print(build_cmd) res = run(build_cmd, shell=True, cwd=build_dir) if res.returncode != 0: raise RuntimeError("Failed on cmake for {}".format(target)) cmd = "ninja -vv" if debug else "ninja" cmd = "{} {}".format(cmd, target) if target else cmd res = run(cmd, shell=True, cwd=build_dir) if res.returncode != 0: raise RuntimeError("failed on make for {}".format(target))
def fake(ctx, clean=False): """ Compile and install the fake library used for testing """ work_dir = join(PROJ_ROOT, "func", "dynlink") build_dir = join(PROJ_ROOT, "build", "libfake") clean_dir(build_dir, clean) build_cmd = [ "cmake", "-GNinja", "-DFAASM_BUILD_SHARED=ON", "-DFAASM_BUILD_TYPE=wasm", "-DCMAKE_TOOLCHAIN_FILE={}".format(CMAKE_TOOLCHAIN_FILE), "-DCMAKE_BUILD_TYPE=Release", "-DCMAKE_INSTALL_PREFIX={}".format(WASM_SYSROOT), work_dir, ] run(" ".join(build_cmd), shell=True, cwd=build_dir, check=True) run("ninja", shell=True, cwd=build_dir, check=True) run("ninja install", shell=True, cwd=build_dir, check=True) # Copy shared object into place sysroot_files = join(WASM_SYSROOT, "lib", "wasm32-wasi", "libfake*.so") runtime_lib_dir = join(FAASM_RUNTIME_ROOT, "lib") if not exists(runtime_lib_dir): makedirs(runtime_lib_dir) run( "cp {} {}".format(sysroot_files, runtime_lib_dir), shell=True, check=True, ) # Update env shell_env = copy(environ) shell_env.update({ "LD_LIBRARY_PATH": "/usr/local/lib/", }) # Run codegen shared_objs = [ join(FAASM_RUNTIME_ROOT, "lib", "libfakeLibA.so"), join(FAASM_RUNTIME_ROOT, "lib", "libfakeLibB.so"), ] binary = find_codegen_shared_lib() for so in shared_objs: print("Running codegen for {}".format(so)) run("{} {}".format(binary, so), env=shell_env, shell=True, check=True)
def build_native(ctx, user, func, host=False, clean=False, nopush=False): """ Build a native Knative container for the given function """ if host: build_dir = join(PROJ_ROOT, "build", "knative_native") target = "{}-knative".format(func) clean_dir(build_dir, clean) cmd = [ "cmake", "-DCMAKE_CXX_COMPILER=/usr/bin/clang++", "-DCMAKE_C_COMPILER=/usr/bin/clang", "-DFAASM_BUILD_TYPE=knative-native", "-DCMAKE_BUILD_TYPE=Debug", PROJ_ROOT ] call(" ".join(cmd), cwd=build_dir, shell=True) make_cmd = "cmake --build . --target {} -- -j".format(target) call(make_cmd, cwd=build_dir, shell=True) else: # Build the container version = get_faasm_version() tag_name = "{}:{}".format(_native_image_name(func), version) cmd = [ "docker", "build", "--no-cache" if clean else "", "-t", tag_name, "--build-arg", "FAASM_VERSION={}".format(version), "--build-arg", "FAASM_USER={}".format(user), "--build-arg", "FAASM_FUNC={}".format(func), "-f", "docker/knative-native.dockerfile", "." ] env = copy(os.environ) env["DOCKER_BUILDKIT"] = "1" cmd_string = " ".join(cmd) print(cmd_string) res = call(cmd_string, shell=True, cwd=PROJ_ROOT) if res != 0: print("Building container failed") return 1 # Push the container if not nopush: cmd = "docker push {}".format(tag_name) call(cmd, shell=True, cwd=PROJ_ROOT)
def fake(ctx, clean=False): """ Compile and install the fake library used for testing """ work_dir = join(PROJ_ROOT, "func", "dynlink") build_dir = join(PROJ_ROOT, "build", "libfake") clean_dir(build_dir, clean) build_cmd = [ "cmake", "-GNinja", "-DFAASM_BUILD_TYPE=wasm", "-DCMAKE_TOOLCHAIN_FILE={}".format(FAASM_TOOLCHAIN_FILE), "-DCMAKE_BUILD_TYPE=Release", "-DCMAKE_INSTALL_PREFIX={}".format(SYSROOT_INSTALL_PREFIX), work_dir, ] call(" ".join(build_cmd), shell=True, cwd=build_dir) call("ninja VERBOSE=1 ", shell=True, cwd=build_dir) call("ninja install", shell=True, cwd=build_dir) # Copy shared object into place sysroot_files = join(SYSROOT_INSTALL_PREFIX, "lib", "wasm32-wasi", "libfake*.so") runtime_lib_dir = join(FAASM_RUNTIME_ROOT, "lib") if not exists(runtime_lib_dir): makedirs(runtime_lib_dir) call("cp {} {}".format(sysroot_files, runtime_lib_dir), shell=True) # Run codegen shared_objs = [ join(FAASM_RUNTIME_ROOT, "lib", "libfakeLibA.so"), join(FAASM_RUNTIME_ROOT, "lib", "libfakeLibB.so"), ] binary = find_codegen_shared_lib() for so in shared_objs: print("Running codegen for {}".format(so)) check_output("{} {}".format(binary, so), shell=True)
def _build_faasm_lib(dir_name, clean, verbose, target=None): work_dir = join(PROJ_ROOT, dir_name) build_dir = join(PROJ_ROOT, "build", dir_name) clean_dir(build_dir, clean) build_cmd = [ "cmake", "-GNinja", "-DFAASM_BUILD_TYPE=wasm", "-DCMAKE_BUILD_TYPE=Release", "-DCMAKE_TOOLCHAIN_FILE={}".format(CMAKE_TOOLCHAIN_FILE), work_dir, ] build_cmd_str = " ".join(build_cmd) print(build_cmd_str) run(build_cmd_str, shell=True, cwd=build_dir, check=True) build_cmd = ["ninja", target if target else ""] run(" ".join(build_cmd), shell=True, cwd=build_dir, check=True) run("ninja install", shell=True, cwd=build_dir, check=True)