diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1ef1c19..64f0f1a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -87,6 +87,8 @@ jobs: run: ./bin/inv_wrapper.sh tensorflow - name: "Build PolyBench/C" run: ./bin/inv_wrapper.sh polybench polybench --native + - name: "Build Rabe" + run: ./bin/inv_wrapper.sh rabe - name: "Build functions used in the tests" run: ./bin/inv_wrapper.sh func.tests - name: "Get CPP/Python commits" @@ -280,6 +282,9 @@ jobs: - name: "Run FFmpeg check" timeout-minutes: 1 run: faasmctl invoke ffmpeg check + - name: "Run Rabe test" + timeout-minutes: 1 + run: faasmctl invoke rabe test - name: "Print logs in case of failure" if: failure() run: faasmctl logs -s worker diff --git a/.gitmodules b/.gitmodules index 14ce3b2..f32b5e8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -47,3 +47,7 @@ path = examples/Kernels-elastic url = https://github.com/faasm/Kernels branch = faasm-elastic +[submodule "examples/rabe"] + path = examples/rabe + url = https://github.com/faasm/rabe.git + branch = faasm diff --git a/cpp b/cpp index 4590053..0c8c17c 160000 --- a/cpp +++ b/cpp @@ -1 +1 @@ -Subproject commit 45900530ebdaa1ab2efd944a7a5e59b3346e8aaa +Subproject commit 0c8c17c24a1bafe34bde60d53a07a88405ab3dde diff --git a/docker-compose.yml b/docker-compose.yml index 57ad220..a3aea0b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: "3" - services: build: image: faasm.azurecr.io/examples-build:${EXAMPLES_BUILD_VERSION} diff --git a/docker/base.dockerfile b/docker/base.dockerfile index ac313cc..9ee1048 100644 --- a/docker/base.dockerfile +++ b/docker/base.dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:22.04 as base +FROM ubuntu:22.04 AS base RUN apt update \ && apt install -y \ diff --git a/docker/build.dockerfile b/docker/build.dockerfile index da05f91..71d59d4 100644 --- a/docker/build.dockerfile +++ b/docker/build.dockerfile @@ -1,7 +1,7 @@ ARG CPP_VERSION ARG EXAMPLES_VERSION # Base image is not re-built often and tag may lag behind -FROM faasm.azurecr.io/examples-base:0.4.0_0.4.0 as base +FROM faasm.azurecr.io/examples-base:0.6.0_0.4.0 AS base FROM faasm.azurecr.io/cpp-sysroot:${CPP_VERSION} SHELL ["/bin/bash", "-c"] @@ -21,6 +21,12 @@ ARG DEBIAN_FRONTEND=noninteractive RUN apt update \ && apt install -y libomp-17-dev +# Install rust +RUN curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh -s -- -y \ + && source ~/.cargo/env \ + && rustup target add wasm32-wasi + + # Fetch the code and update submodules ARG EXAMPLES_VERSION RUN mkdir -p code \ @@ -40,6 +46,7 @@ RUN mkdir -p code \ && git submodule update --init -f examples/LULESH \ && git submodule update --init -f examples/libpng \ && git submodule update --init -f examples/polybench \ + && git submodule update --init -f examples/rabe \ && git submodule update --init -f examples/tensorflow # Build the examples and demo functions @@ -63,14 +70,17 @@ RUN cd /code/examples \ && inv lammps --migration-net \ && inv lulesh \ && inv polybench \ + && inv rabe \ && inv tensorflow \ # These demo functions link with the cross-compiled static libraries && inv func ffmpeg check \ && inv func lammps chain \ && inv func mpi migrate \ + && inv func rabe test \ && inv func tf check # Prepare bashrc WORKDIR /code/examples RUN echo ". /code/examples/bin/workon.sh" >> ~/.bashrc +RUN echo ". $HOME/.cargo/env" >> ~/.bashrc CMD ["/bin/bash", "-l"] diff --git a/examples/rabe b/examples/rabe new file mode 160000 index 0000000..2c93ece --- /dev/null +++ b/examples/rabe @@ -0,0 +1 @@ +Subproject commit 2c93ecedd7eec1910479addd7a6ad9720a2e67d4 diff --git a/func/CMakeLists.txt b/func/CMakeLists.txt index 9e33fa8..a198b88 100644 --- a/func/CMakeLists.txt +++ b/func/CMakeLists.txt @@ -34,4 +34,5 @@ endfunction(faasm_example_func) add_subdirectory(ffmpeg) add_subdirectory(lammps) add_subdirectory(mpi) +add_subdirectory(rabe) add_subdirectory(tf) diff --git a/func/rabe/CMakeLists.txt b/func/rabe/CMakeLists.txt new file mode 100644 index 0000000..341b9e2 --- /dev/null +++ b/func/rabe/CMakeLists.txt @@ -0,0 +1,4 @@ +set(FAASM_USER rabe) + +faasm_example_func(test test.cpp) +target_link_libraries(rabe_test librabe-cpp.a librabe.a) diff --git a/func/rabe/test.cpp b/func/rabe/test.cpp new file mode 100644 index 0000000..077b6a2 --- /dev/null +++ b/func/rabe/test.cpp @@ -0,0 +1,29 @@ +#include +#include +#include + +int main() +{ + // Create temporary encryption context for this test + auto& ctx = rabe::CpAbeContextWrapper::get(rabe::ContextFetchMode::Create); + + // Prepare encryption + std::string plainText = "dance like no one's watching, encrypt like everyone is!"; + std::string policy = "\"A\" and \"B\""; + auto cipherText = ctx.cpAbeEncrypt(policy, plainText); + + // Prepare decryption + std::vector attributes = {"A", "B"}; + auto actualPlainText = ctx.cpAbeDecrypt(attributes, cipherText); + + // Compare + std::string actualPlainTextStr; + actualPlainTextStr.assign(reinterpret_cast(actualPlainText.data()), actualPlainText.size()); + if (plainText != actualPlainTextStr) { + std::cerr << "Encryption/decryption test failed!" << std::endl; + return -1; + } + + std::cout << "Encryption worked!" << std::endl; + return 0; +} diff --git a/tasks/__init__.py b/tasks/__init__.py index e69f253..4759533 100644 --- a/tasks/__init__.py +++ b/tasks/__init__.py @@ -13,6 +13,7 @@ from . import libpng from . import lulesh from . import polybench +from . import rabe from . import tensorflow from . import wasm @@ -30,6 +31,7 @@ libpng, lulesh, polybench, + rabe, tensorflow, wasm, ) diff --git a/tasks/cli.py b/tasks/cli.py index 392bd78..a00d0f1 100644 --- a/tasks/cli.py +++ b/tasks/cli.py @@ -19,10 +19,10 @@ def cli(ctx, clean=False): """ service = "build" - if clean: - # Clean existing build + if not exists(DEV_FAASM_LOCAL) or clean: if exists(DEV_FAASM_LOCAL): rmtree(DEV_FAASM_LOCAL) + makedirs(DEV_FAASM_LOCAL) # Populate the local mounts with the existing content diff --git a/tasks/func.py b/tasks/func.py index a7be404..bdc0b18 100644 --- a/tasks/func.py +++ b/tasks/func.py @@ -42,6 +42,7 @@ def tests(ctx, clean=False): """ funcs = [ ["ffmpeg", "check"], + ["rabe", "test"], ["tf", "check"], # TODO: this two functions are not used in the tests, as they are used # to exercise migration, for what we need a distributed test setting diff --git a/tasks/rabe.py b/tasks/rabe.py new file mode 100644 index 0000000..9992131 --- /dev/null +++ b/tasks/rabe.py @@ -0,0 +1,66 @@ +from faasmtools.build import CMAKE_TOOLCHAIN_FILE, get_faasm_build_env_dict +from invoke import task +from os import environ, makedirs +from os.path import exists, join +from shutil import copy, rmtree +from subprocess import run +from tasks.env import EXAMPLES_DIR + + +@task(default=True) +def build(ctx, clean=False): + """ + Compile rabe library (in Rust) and C++ bindings into a WASM library + """ + rabe_dir = join(EXAMPLES_DIR, "rabe") + + if clean: + rmtree(join(rabe_dir, "target")) + + # First, cross-compile the rust library to WASM + # TODO: rename to wasm32-wasip1 + cargo_cmd = "cargo build --release --target=wasm32-wasi" + run(cargo_cmd, shell=True, check=True, cwd=rabe_dir) + + # Install it in the WASM sysroot + build_env = get_faasm_build_env_dict() + src_lib = join(rabe_dir, "target", "wasm32-wasi", "release", "librabe.a") + dst_lib = join(build_env["FAASM_WASM_LIB_INSTALL_DIR"], "librabe.a") + copy(src_lib, dst_lib) + + # Build the CPP bindings library, and cross-compile it to WASM + rabe_cpp_dir = join(rabe_dir, "cpp-bindings") + build_dir = join(rabe_cpp_dir, "build") + + if clean and exists(build_dir): + rmtree(build_dir) + if not exists(build_dir): + makedirs(build_dir) + + cmake_cmd = [ + "cmake", + "-GNinja", + "-DCMAKE_BUILD_TYPE=Release", + "-DCMAKE_TOOLCHAIN_FILE={}".format(CMAKE_TOOLCHAIN_FILE), + rabe_cpp_dir, + ] + cmake_cmd = " ".join(cmake_cmd) + print(cmake_cmd) + + work_env = environ.copy() + work_env.update(get_faasm_build_env_dict()) + print(build_dir) + run(cmake_cmd, shell=True, check=True, cwd=build_dir, env=work_env) + run("ninja", shell=True, check=True, cwd=build_dir) + + # Install the library in the WASM sysroot + src_lib = join(build_dir, "librabe-cpp.a") + dst_lib = join(build_env["FAASM_WASM_LIB_INSTALL_DIR"], "librabe-cpp.a") + copy(src_lib, dst_lib) + + # Install the header in the WASM sysroot too + src_header = join(rabe_cpp_dir, "rabe_bindings.hpp") + dst_header = join( + build_env["FAASM_WASM_HEADER_INSTALL_DIR"], "rabe_bindings.hpp" + ) + copy(src_header, dst_header)