Skip to content

Commit 173c29b

Browse files
authored
examples: add rabe example (#42)
* examples: add rabe example * docker: few nits * rust: move to p1 target * gha: fix cargo build
1 parent dfd6987 commit 173c29b

File tree

14 files changed

+137
-9
lines changed

14 files changed

+137
-9
lines changed

.github/workflows/tests.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ jobs:
6767
uses: actions/checkout@v4
6868
with:
6969
submodules: true
70+
- name: "Build Rabe"
71+
run: |
72+
export PATH=$PATH:/root/.cargo/env
73+
rustup default stable
74+
rustup target add wasm32-wasip1
75+
./bin/inv_wrapper.sh rabe
7076
- name: "Build FFmpeg"
7177
run: ./bin/inv_wrapper.sh ffmpeg
7278
- name: "Build ImageMagick"
@@ -122,7 +128,7 @@ jobs:
122128
shell: bash
123129
env:
124130
FAASM_INI_FILE: ./faasm.ini
125-
FAASM_VERSION: 0.22.0
131+
FAASM_VERSION: 0.27.0
126132
FAASM_WASM_VM: ${{ matrix.faasm_wasm_vm }}
127133
steps:
128134
- uses: csegarragonz/set-compose-version-action@main
@@ -280,6 +286,12 @@ jobs:
280286
- name: "Run FFmpeg check"
281287
timeout-minutes: 1
282288
run: faasmctl invoke ffmpeg check
289+
# TODO(faasm-bump): this is working, but we need to cut a new faasm release, uncomment
290+
# when we do
291+
# - name: "Run Rabe test"
292+
# if: "contains(env.FAASM_WASM_VM, 'wamr')"
293+
# timeout-minutes: 1
294+
# run: faasmctl invoke rabe test
283295
- name: "Print logs in case of failure"
284296
if: failure()
285297
run: faasmctl logs -s worker

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@
4747
path = examples/Kernels-elastic
4848
url = https://github.com/faasm/Kernels
4949
branch = faasm-elastic
50+
[submodule "examples/rabe"]
51+
path = examples/rabe
52+
url = https://github.com/faasm/rabe.git
53+
branch = faasm

cpp

docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3"
2-
31
services:
42
build:
53
image: faasm.azurecr.io/examples-build:${EXAMPLES_BUILD_VERSION}

docker/base.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:22.04 as base
1+
FROM ubuntu:22.04 AS base
22

33
RUN apt update \
44
&& apt install -y \

docker/build.dockerfile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
ARG CPP_VERSION
22
ARG EXAMPLES_VERSION
33
# Base image is not re-built often and tag may lag behind
4-
FROM faasm.azurecr.io/examples-base:0.4.0_0.4.0 as base
5-
FROM faasm.azurecr.io/cpp-sysroot:${CPP_VERSION}
4+
FROM faasm.azurecr.io/examples-base:0.6.0_0.4.0 AS base
5+
FROM faasm.azurecr.io/cpp-sysroot:${CPP_VERSION:-dead}
66

77
SHELL ["/bin/bash", "-c"]
88
ENV IN_DOCKER="on"
@@ -21,6 +21,12 @@ ARG DEBIAN_FRONTEND=noninteractive
2121
RUN apt update \
2222
&& apt install -y libomp-17-dev
2323

24+
# Install rust
25+
RUN curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh -s -- -y \
26+
&& source ~/.cargo/env \
27+
&& rustup target add wasm32-wasip1
28+
29+
2430
# Fetch the code and update submodules
2531
ARG EXAMPLES_VERSION
2632
RUN mkdir -p code \
@@ -40,9 +46,11 @@ RUN mkdir -p code \
4046
&& git submodule update --init -f examples/LULESH \
4147
&& git submodule update --init -f examples/libpng \
4248
&& git submodule update --init -f examples/polybench \
49+
&& git submodule update --init -f examples/rabe \
4350
&& git submodule update --init -f examples/tensorflow
4451

4552
# Build the examples and demo functions
53+
ENV PATH=${PATH}:/root/.cargo/bin
4654
RUN cd /code/examples \
4755
&& ./bin/create_venv.sh \
4856
&& source venv/bin/activate \
@@ -63,14 +71,17 @@ RUN cd /code/examples \
6371
&& inv lammps --migration-net \
6472
&& inv lulesh \
6573
&& inv polybench \
74+
&& inv rabe \
6675
&& inv tensorflow \
6776
# These demo functions link with the cross-compiled static libraries
6877
&& inv func ffmpeg check \
6978
&& inv func lammps chain \
7079
&& inv func mpi migrate \
80+
&& inv func rabe test \
7181
&& inv func tf check
7282

7383
# Prepare bashrc
7484
WORKDIR /code/examples
7585
RUN echo ". /code/examples/bin/workon.sh" >> ~/.bashrc
86+
RUN echo ". $HOME/.cargo/env" >> ~/.bashrc
7687
CMD ["/bin/bash", "-l"]

examples/rabe

Submodule rabe added at 2c93ece

func/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ endfunction(faasm_example_func)
3434
add_subdirectory(ffmpeg)
3535
add_subdirectory(lammps)
3636
add_subdirectory(mpi)
37+
add_subdirectory(rabe)
3738
add_subdirectory(tf)

func/rabe/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(FAASM_USER rabe)
2+
3+
faasm_example_func(test test.cpp)
4+
target_link_libraries(rabe_test librabe-cpp.a librabe.a)

func/rabe/test.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <rabe_bindings.hpp>
2+
#include <iostream>
3+
#include <string>
4+
5+
int main()
6+
{
7+
// Create temporary encryption context for this test
8+
auto& ctx = rabe::CpAbeContextWrapper::get(rabe::ContextFetchMode::Create);
9+
10+
// Prepare encryption
11+
std::string plainText = "dance like no one's watching, encrypt like everyone is!";
12+
std::string policy = "\"A\" and \"B\"";
13+
auto cipherText = ctx.cpAbeEncrypt(policy, plainText);
14+
15+
// Prepare decryption
16+
std::vector<std::string> attributes = {"A", "B"};
17+
auto actualPlainText = ctx.cpAbeDecrypt(attributes, cipherText);
18+
19+
// Compare
20+
std::string actualPlainTextStr;
21+
actualPlainTextStr.assign(reinterpret_cast<char*>(actualPlainText.data()), actualPlainText.size());
22+
if (plainText != actualPlainTextStr) {
23+
std::cerr << "Encryption/decryption test failed!" << std::endl;
24+
return -1;
25+
}
26+
27+
std::cout << "Encryption worked!" << std::endl;
28+
return 0;
29+
}

0 commit comments

Comments
 (0)