Skip to content

Commit

Permalink
Reinstated here.py and added eigen
Browse files Browse the repository at this point in the history
  • Loading branch information
Shillaker committed Oct 13, 2020
1 parent 52ec70a commit bf72c92
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 11 deletions.
3 changes: 1 addition & 2 deletions WasiToolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ cmake_minimum_required(VERSION 3.4.0)
# -----------------------------------------
# A useful reference for this file is the wasi-sdk equivalent:
# https://github.com/WebAssembly/wasi-sdk/blob/master/wasi-sdk.cmake
# If anything breaks it's useful to compare the two.
#
# BUT there are lots of crucial modifications in here and it's
# used all over the place in this project, so be **very** careful
# if changing it.
# when changing it.
# -----------------------------------------

set(INSTALL_DIR /usr/local/faasm/toolchain/bin)
Expand Down
32 changes: 32 additions & 0 deletions bin/here.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from os.path import dirname, abspath, join
from os import getcwd
from subprocess import run
import yaml

PROJ_ROOT = dirname(dirname(abspath(__file__)))


def main():
version_file = join(PROJ_ROOT, "versions.yml")
with open(version_file) as fh:
toolchain_ver = yaml.load(fh, Loader=yaml.BaseLoader)["toolchain"]

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

docker_cmd = [
'docker run --entrypoint="/bin/bash"',
'--network="host"',
'-e "TERM=xterm-256color"',
"-v {}:/work".format(cwd),
"-w /work",
"-it",
"faasm/sysroot:v{}".format(toolchain_ver),
]

docker_cmd = " ".join(docker_cmd)
run(docker_cmd, shell=True, check=True, cwd=cwd)


if __name__ == "__main__":
main()
20 changes: 20 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Usage

## Running the `sysroot` container

The containers built from this repo aren't meant to be used directly, but to
debug and test builds, you _can_ run inside the `sysroot` container with
the `here.py` script.

This will mount your cwd into the sysroot container at `/work`, e.g.

```
# Go to some dir
cd <my work>
# Run the here script
python3 <this repo>/bin/here.py
# Now you should be in the container, so can run
/usr/local/faasm/toolchain/bin/clang --version
/usr/local/faasm/toolchain/bin/llc --version
```

## Shared libraries

For CMake projects, you should be able to add the following to your build:
Expand Down
5 changes: 5 additions & 0 deletions faasmtools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
from os.path import join
from subprocess import run

from .env import PROJ_ROOT

# Toolchain files
CMAKE_TOOLCHAIN_FILE = join(PROJ_ROOT, "WasiToolchain.cmake")

# Directories
WASM_SYSROOT = "/usr/local/faasm/llvm-sysroot"
WASM_LIB_INSTALL = "{}/lib/wasm32-wasi".format(WASM_SYSROOT)
Expand Down
1 change: 1 addition & 0 deletions faasmtools/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import yaml

PROJ_ROOT = dirname(dirname(abspath(__file__)))
THIRD_PARTY_DIR = join(PROJ_ROOT, "third-party")

VERSIONS_FILE = join(PROJ_ROOT, "versions.yml")

Expand Down
2 changes: 2 additions & 0 deletions tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from invoke import Collection

from . import container
from . import eigen
from . import git
from . import libc

ns = Collection(
container,
eigen,
git,
libc,
)
28 changes: 22 additions & 6 deletions tasks/eigen.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
from subprocess import run

@task
from os.path import join, exists
from os import makedirs
from shutil import rmtree

from invoke import task

from faasmtools.env import (
THIRD_PARTY_DIR,
)

from faasmtools.build import (
CMAKE_TOOLCHAIN_FILE,
WASM_SYSROOT,
)


@task(default=True)
def eigen(ctx, verbose=False):
"""
Compile and install Eigen
"""
work_dir = join(THIRD_PARTY_DIR, "eigen")
build_dir = join(PROJ_ROOT, "build", "eigen")
build_dir = join(work_dir, "build")

if exists(build_dir):
rmtree(build_dir)
Expand All @@ -16,10 +33,9 @@ def eigen(ctx, verbose=False):
cmd = [
verbose_string,
"cmake",
"-DFAASM_BUILD_TYPE=wasm",
"-DCMAKE_TOOLCHAIN_FILE={}".format(FAASM_TOOLCHAIN_FILE),
"-DCMAKE_BUILD_TYPE=Release",
"-DCMAKE_INSTALL_PREFIX={}".format(SYSROOT_INSTALL_PREFIX),
"-GNinja",
"-DCMAKE_TOOLCHAIN_FILE={}".format(CMAKE_TOOLCHAIN_FILE),
"-DCMAKE_INSTALL_PREFIX={}".format(WASM_SYSROOT),
work_dir,
]
cmd_string = " ".join(cmd)
Expand Down
4 changes: 2 additions & 2 deletions tasks/libc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from invoke import task

from faasmtools.env import (
PROJ_ROOT,
USABLE_CPUS,
THIRD_PARTY_DIR,
)

from faasmtools.build import (
Expand All @@ -22,7 +22,7 @@ def build(ctx, clean=False):
"""
Builds the wasi libc fork in this directory
"""
libc_dir = join(PROJ_ROOT, "third-party", "wasi-libc")
libc_dir = join(THIRD_PARTY_DIR, "wasi-libc")

if clean:
run("make clean", shell=True, check=True, cwd=libc_dir)
Expand Down
2 changes: 1 addition & 1 deletion third-party/eigen
Submodule eigen updated from b8a13f to 3a9196

0 comments on commit bf72c92

Please sign in to comment.