Skip to content

Commit fb8d193

Browse files
committed
Add emulator and tests
1 parent 5b3ca7c commit fb8d193

31 files changed

+887
-183
lines changed

.dockerignore

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
# Ignore local builds
2-
third-party/llvm-project/build
3-
third-party/wasi-libc/build
1+
.git
2+
3+
build/
4+
5+
# Ignore big third party deps
6+
third-party/llvm-project/
7+
third-party/wasi-libc/build/

.github/workflows/build.yml

-46
This file was deleted.

.github/workflows/release.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ jobs:
2626
with:
2727
username: ${{ secrets.DOCKER_USERNAME }}
2828
password: ${{ secrets.DOCKER_PASSWORD }}
29-
- name: "Build and push sysroot container"
29+
- name: "Build and push cpp-sysroot container"
3030
id: docker_build
3131
uses: docker/build-push-action@v2
3232
with:
3333
push: true
34-
file: docker/sysroot.dockerfile
34+
file: docker/cpp-sysroot.dockerfile
3535
context: .
36-
tags: faasm/sysroot:${{ env.TAG_VERSION }}
36+
tags: faasm/cpp-sysroot:${{ env.TAG_VERSION }}

.github/workflows/tests.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
formatting:
11+
if: github.event.pull_request.draft == false
12+
runs-on: ubuntu-20.04
13+
steps:
14+
- name: "Get the latest code"
15+
uses: actions/checkout@v2
16+
- name: "Install requirements"
17+
run: "pip3 install -r requirements.txt"
18+
- name: "Run Black"
19+
run: "python3 -m black --check $(git ls-files '*.py')"
20+
- name: "Run C/C++ formatting"
21+
run: ./bin/run_clang_format.sh
22+
- name: "Check no formatting changes"
23+
run: git diff --exit-code
24+
25+
tests:
26+
if: github.event.pull_request.draft == false
27+
runs-on: ubuntu-20.04
28+
env:
29+
HOST_TYPE: ci
30+
REDIS_QUEUE_HOST: redis
31+
REDIS_STATE_HOST: redis
32+
container:
33+
image: faasm/cpp-sysroot:0.0.11
34+
defaults:
35+
run:
36+
working-directory: /code/faasm-toolchain
37+
services:
38+
redis:
39+
image: redis
40+
steps:
41+
- name: "Fetch ref"
42+
run: git fetch origin ${GITHUB_REF}:ci-branch
43+
- name: "Check out branch"
44+
run: git checkout --force ci-branch
45+
- name: "Update Faabric submodule"
46+
run: "git submodule update --init -f third-party/faabric"
47+
- name: "Update CMake build"
48+
run: "inv dev.cmake"
49+
- name: "Build the tests"
50+
run: "inv dev.cc tests"
51+
- name: "Run the tests"
52+
run: "/build/faasm-toolchain/bin/tests"

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@
1717
[submodule "third-party/faasm-clapack"]
1818
path = third-party/faasm-clapack
1919
url = https://github.com/faasm/faasm-clapack
20+
[submodule "third-party/faabric"]
21+
path = third-party/faabric
22+
url = https://github.com/faasm/faabric/

CMakeLists.txt

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
cmake_minimum_required(VERSION 3.13.0)
2+
project(faasm-cpp)
3+
4+
# Top-level CMake config
5+
set(CMAKE_CXX_FLAGS "-Wall")
6+
set(CMAKE_CXX_FLAGS_DEBUG "-g")
7+
set(CMAKE_CXX_STANDARD 17)
8+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
9+
set(CMAKE_CXX_EXTENSIONS OFF)
10+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
11+
12+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
13+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
14+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
15+
16+
# Add Faabric dependency
17+
add_subdirectory(third-party/faabric)
18+
19+
# Generated protobuf headers
20+
include_directories(${CMAKE_CURRENT_BINARY_DIR}/third-party/faabric/src)
21+
22+
add_subdirectory(libfaasm)
23+
add_subdirectory(emulator)
24+
add_subdirectory(tests)

README.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Faasm Toolchain [![Toolchain tests](https://github.com/faasm/faasm-toolchain/workflows/Build/badge.svg?branch=master)](https://github.com/faasm/faasm-toolchain/actions) [![License](https://img.shields.io/github/license/faasm/faasm-toolchain.svg)](https://github.com/faasm/faasm-toolchain/blob/master/LICENSE.md)
1+
# Faasm C/C++ Support [![CPP tests](https://github.com/faasm/faasm-toolchain/workflows/Tests/badge.svg?branch=master)](https://github.com/faasm/faasm-toolchain/actions) [![License](https://img.shields.io/github/license/faasm/faasm-toolchain.svg)](https://github.com/faasm/faasm-toolchain/blob/master/LICENSE.md)
22

3-
This is the toolchain and sysroot used for building WebAssembly to run in
4-
[Faasm](https://github.com/faasm/faasm).
3+
This repo contains everything needed to build C/C++ applications for
4+
[Faasm](https://github.com/faasm/faasm):
55

66
Faasm aims to support a range of legacy applications, so requires a toolchain
77
capable of compiling large projects that may require threading, C++ exceptions
@@ -14,10 +14,13 @@ WebAssembly shared libraries outside of the Emscripten target. You can see these
1414
in [this fork](https://github.com/faasm/llvm-project) through [this
1515
diff](https://github.com/llvm/llvm-project/compare/llvmorg-10.0.1...faasm:faasm).
1616

17+
The repo also contains the C/C++ definition of the [Faasm host
18+
interface](https://github.com/faasm/faasm/blob/master/docs/host_interface.md)
19+
along with an emulator to compile and test native applications.
20+
1721
More detailed docs can be found in:
1822

19-
- [Usage](docs/usage.md)
20-
- [Building and Releasing](docs/release.md)
23+
- [Usage and Development](docs/usage.md)
24+
- [Releasing](docs/release.md)
2125
- [Upgrading LLVM](docs/upgrading-llvm.md)
22-
- [Python tooling](docs/python.md)
23-
26+
- [Python library](docs/python.md)

bin/cli.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
THIS_DIR=$(dirname $(readlink -f $0))
6+
PROJ_ROOT=${THIS_DIR}/..
7+
8+
pushd ${PROJ_ROOT} > /dev/null
9+
10+
if [[ -z "${SYSROOT_CLI_IMAGE}" ]]; then
11+
VERSION=$(cat VERSION)
12+
SYSROOT_CLI_IMAGE=faasm/cpp-sysroot:${VERSION}
13+
fi
14+
15+
INNER_SHELL=${SHELL:-"/bin/bash"}
16+
17+
docker-compose \
18+
up \
19+
--no-recreate \
20+
-d \
21+
cli
22+
23+
docker-compose \
24+
exec \
25+
cli \
26+
${INNER_SHELL}
27+
28+
popd > /dev/null

bin/here.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
def main():
99
version_file = join(PROJ_ROOT, "VERSION")
1010
with open(version_file) as fh:
11-
toolchain_ver = fh.read().strip()
11+
sysroot_ver = fh.read().strip()
12+
13+
image_tag = "faasm/cpp-sysroot:{}".format(sysroot_ver)
1214

1315
cwd = getcwd()
14-
print("Running toolchain at {}".format(cwd))
16+
print("Running {} at {}".format(image_tag, cwd))
1517

1618
docker_cmd = [
1719
'docker run --entrypoint="/bin/bash"',
@@ -20,7 +22,7 @@ def main():
2022
"-v {}:/work".format(cwd),
2123
"-w /work",
2224
"-it",
23-
"faasm/sysroot:{}".format(toolchain_ver),
25+
image_tag,
2426
]
2527

2628
docker_cmd = " ".join(docker_cmd)

docker-compose.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: "3"
2+
3+
services:
4+
redis:
5+
image: redis
6+
7+
cli:
8+
image: ${SYSROOT_CLI_IMAGE}
9+
volumes:
10+
- .:/code/faasm-toolchain
11+
- ./build:/build/faasm-toolchain
12+
working_dir: /code/faasm-toolchain
13+
stdin_open: true
14+
tty: true
15+
privileged: true
16+
environment:
17+
- LOG_LEVEL=debug
18+
- REDIS_STATE_HOST=redis
19+
- REDIS_QUEUE_HOST=redis
20+
depends_on:
21+
- redis

docker/cpp-sysroot.dockerfile

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
FROM faasm/llvm:10.0.1 as llvm
2+
3+
FROM faasm/grpc-root:0.0.12
4+
ARG SYSROOT_VERSION
5+
6+
# Copy the toolchain in from the LLVM container
7+
COPY --from=llvm /usr/local/faasm /usr/local/faasm
8+
9+
RUN apt install -y \
10+
autoconf \
11+
autotools-dev \
12+
libtool \
13+
python3-dev \
14+
python3-pip
15+
16+
# Get the code
17+
WORKDIR /code
18+
RUN git clone -b v${SYSROOT_VERSION} https://github.com/faasm/faasm-toolchain
19+
WORKDIR /code/faasm-toolchain
20+
21+
# Update submodules (not LLVM)
22+
RUN git submodule update --init -f third-party/eigen
23+
RUN git submodule update --init -f third-party/faabric
24+
RUN git submodule update --init -f third-party/faasm-clapack
25+
RUN git submodule update --init -f third-party/libffi
26+
RUN git submodule update --init -f third-party/wasi-libc
27+
28+
RUN pip3 install -r requirements.txt
29+
30+
# Install the faasmtools lib
31+
RUN pip3 install .
32+
33+
# -----------------------------
34+
# CPP EMULATOR
35+
# -----------------------------
36+
37+
RUN inv eigen --native
38+
39+
RUN inv dev.cmake
40+
RUN inv dev.cc emulator
41+
42+
# -----------------------------
43+
# WASM LIBRARIES
44+
# -----------------------------
45+
46+
# Install files
47+
RUN inv install
48+
49+
# Build libraries
50+
RUN inv libc
51+
52+
# Install eigen to wasm
53+
RUN inv eigen
54+
55+
# Install libffi
56+
RUN inv libffi
57+
58+
# Both static and shared clapack
59+
RUN inv clapack
60+
RUN inv clapack --clean --shared
61+
62+
# Install Faasm CPP wasm lib
63+
RUN inv libfaasm
File renamed without changes.

docker/sysroot.dockerfile

-38
This file was deleted.

0 commit comments

Comments
 (0)