Skip to content

Commit

Permalink
Add emulator and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Shillaker committed Nov 25, 2020
1 parent 5b3ca7c commit fb8d193
Show file tree
Hide file tree
Showing 31 changed files with 887 additions and 183 deletions.
10 changes: 7 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Ignore local builds
third-party/llvm-project/build
third-party/wasi-libc/build
.git

build/

# Ignore big third party deps
third-party/llvm-project/
third-party/wasi-libc/build/
46 changes: 0 additions & 46 deletions .github/workflows/build.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ jobs:
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: "Build and push sysroot container"
- name: "Build and push cpp-sysroot container"
id: docker_build
uses: docker/build-push-action@v2
with:
push: true
file: docker/sysroot.dockerfile
file: docker/cpp-sysroot.dockerfile
context: .
tags: faasm/sysroot:${{ env.TAG_VERSION }}
tags: faasm/cpp-sysroot:${{ env.TAG_VERSION }}
52 changes: 52 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Tests

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
formatting:
if: github.event.pull_request.draft == false
runs-on: ubuntu-20.04
steps:
- name: "Get the latest code"
uses: actions/checkout@v2
- name: "Install requirements"
run: "pip3 install -r requirements.txt"
- name: "Run Black"
run: "python3 -m black --check $(git ls-files '*.py')"
- name: "Run C/C++ formatting"
run: ./bin/run_clang_format.sh
- name: "Check no formatting changes"
run: git diff --exit-code

tests:
if: github.event.pull_request.draft == false
runs-on: ubuntu-20.04
env:
HOST_TYPE: ci
REDIS_QUEUE_HOST: redis
REDIS_STATE_HOST: redis
container:
image: faasm/cpp-sysroot:0.0.11
defaults:
run:
working-directory: /code/faasm-toolchain
services:
redis:
image: redis
steps:
- name: "Fetch ref"
run: git fetch origin ${GITHUB_REF}:ci-branch
- name: "Check out branch"
run: git checkout --force ci-branch
- name: "Update Faabric submodule"
run: "git submodule update --init -f third-party/faabric"
- name: "Update CMake build"
run: "inv dev.cmake"
- name: "Build the tests"
run: "inv dev.cc tests"
- name: "Run the tests"
run: "/build/faasm-toolchain/bin/tests"
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@
[submodule "third-party/faasm-clapack"]
path = third-party/faasm-clapack
url = https://github.com/faasm/faasm-clapack
[submodule "third-party/faabric"]
path = third-party/faabric
url = https://github.com/faasm/faabric/
24 changes: 24 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.13.0)
project(faasm-cpp)

# Top-level CMake config
set(CMAKE_CXX_FLAGS "-Wall")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# Add Faabric dependency
add_subdirectory(third-party/faabric)

# Generated protobuf headers
include_directories(${CMAKE_CURRENT_BINARY_DIR}/third-party/faabric/src)

add_subdirectory(libfaasm)
add_subdirectory(emulator)
add_subdirectory(tests)
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 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)
# 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)

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

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

The repo also contains the C/C++ definition of the [Faasm host
interface](https://github.com/faasm/faasm/blob/master/docs/host_interface.md)
along with an emulator to compile and test native applications.

More detailed docs can be found in:

- [Usage](docs/usage.md)
- [Building and Releasing](docs/release.md)
- [Usage and Development](docs/usage.md)
- [Releasing](docs/release.md)
- [Upgrading LLVM](docs/upgrading-llvm.md)
- [Python tooling](docs/python.md)

- [Python library](docs/python.md)
28 changes: 28 additions & 0 deletions bin/cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -e

THIS_DIR=$(dirname $(readlink -f $0))
PROJ_ROOT=${THIS_DIR}/..

pushd ${PROJ_ROOT} > /dev/null

if [[ -z "${SYSROOT_CLI_IMAGE}" ]]; then
VERSION=$(cat VERSION)
SYSROOT_CLI_IMAGE=faasm/cpp-sysroot:${VERSION}
fi

INNER_SHELL=${SHELL:-"/bin/bash"}

docker-compose \
up \
--no-recreate \
-d \
cli

docker-compose \
exec \
cli \
${INNER_SHELL}

popd > /dev/null
8 changes: 5 additions & 3 deletions bin/here.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
def main():
version_file = join(PROJ_ROOT, "VERSION")
with open(version_file) as fh:
toolchain_ver = fh.read().strip()
sysroot_ver = fh.read().strip()

image_tag = "faasm/cpp-sysroot:{}".format(sysroot_ver)

cwd = getcwd()
print("Running toolchain at {}".format(cwd))
print("Running {} at {}".format(image_tag, cwd))

docker_cmd = [
'docker run --entrypoint="/bin/bash"',
Expand All @@ -20,7 +22,7 @@ def main():
"-v {}:/work".format(cwd),
"-w /work",
"-it",
"faasm/sysroot:{}".format(toolchain_ver),
image_tag,
]

docker_cmd = " ".join(docker_cmd)
Expand Down
21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: "3"

services:
redis:
image: redis

cli:
image: ${SYSROOT_CLI_IMAGE}
volumes:
- .:/code/faasm-toolchain
- ./build:/build/faasm-toolchain
working_dir: /code/faasm-toolchain
stdin_open: true
tty: true
privileged: true
environment:
- LOG_LEVEL=debug
- REDIS_STATE_HOST=redis
- REDIS_QUEUE_HOST=redis
depends_on:
- redis
63 changes: 63 additions & 0 deletions docker/cpp-sysroot.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
FROM faasm/llvm:10.0.1 as llvm

FROM faasm/grpc-root:0.0.12
ARG SYSROOT_VERSION

# Copy the toolchain in from the LLVM container
COPY --from=llvm /usr/local/faasm /usr/local/faasm

RUN apt install -y \
autoconf \
autotools-dev \
libtool \
python3-dev \
python3-pip

# Get the code
WORKDIR /code
RUN git clone -b v${SYSROOT_VERSION} https://github.com/faasm/faasm-toolchain
WORKDIR /code/faasm-toolchain

# Update submodules (not LLVM)
RUN git submodule update --init -f third-party/eigen
RUN git submodule update --init -f third-party/faabric
RUN git submodule update --init -f third-party/faasm-clapack
RUN git submodule update --init -f third-party/libffi
RUN git submodule update --init -f third-party/wasi-libc

RUN pip3 install -r requirements.txt

# Install the faasmtools lib
RUN pip3 install .

# -----------------------------
# CPP EMULATOR
# -----------------------------

RUN inv eigen --native

RUN inv dev.cmake
RUN inv dev.cc emulator

# -----------------------------
# WASM LIBRARIES
# -----------------------------

# Install files
RUN inv install

# Build libraries
RUN inv libc

# Install eigen to wasm
RUN inv eigen

# Install libffi
RUN inv libffi

# Both static and shared clapack
RUN inv clapack
RUN inv clapack --clean --shared

# Install Faasm CPP wasm lib
RUN inv libfaasm
File renamed without changes.
38 changes: 0 additions & 38 deletions docker/sysroot.dockerfile

This file was deleted.

Loading

0 comments on commit fb8d193

Please sign in to comment.