-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfd6987
commit d50521f
Showing
14 changed files
with
128 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
version: "3" | ||
|
||
services: | ||
build: | ||
image: faasm.azurecr.io/examples-build:${EXAMPLES_BUILD_VERSION} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM ubuntu:22.04 as base | ||
FROM ubuntu:22.04 AS base | ||
|
||
RUN apt update \ | ||
&& apt install -y \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
set(FAASM_USER rabe) | ||
|
||
faasm_example_func(test test.cpp) | ||
target_link_libraries(rabe_test librabe-cpp.a librabe.a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <rabe_bindings.hpp> | ||
#include <iostream> | ||
#include <string> | ||
|
||
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<std::string> attributes = {"A", "B"}; | ||
auto actualPlainText = ctx.cpAbeDecrypt(attributes, cipherText); | ||
|
||
// Compare | ||
std::string actualPlainTextStr; | ||
actualPlainTextStr.assign(reinterpret_cast<char*>(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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |