def compile(context, clean=False, func=None, debug=False, user=None, ts=False): # Typescript compilation if ts: return _ts_compile(func) 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, ] res = call(" ".join(build_cmd), shell=True, cwd=FUNC_BUILD_DIR) if res != 0: print("Failed to compile") return target = "" if func: target = func elif user: target = "{}_all_funcs".format(user) cmd = "VERBOSE=1 make {}".format(target) if target else "make -j" res = call(cmd, shell=True, cwd=FUNC_BUILD_DIR) if res != 0: print("Failed to make") return
def build_knative_native(ctx, user, func, host=False, clean=False, nopush=False): 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", "-DFAASM_AWS_SUPPORT=OFF", 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 _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, ] res = call(" ".join(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))