Skip to content

Commit 088b314

Browse files
authored
LLVM 13 (#106)
* gh: bump code version * llvm: add task to build llvm using env. variables * docker: install python in llvm image and bump llvm version * docker: fixes for llvm 13 * docker: set env. variable for right venv creation * llvm: fix typo in makefile * docker: bump cpp-sysroot image * python: update task to build llvm * faasmtools: export stack_pointer and mutable globals * update remaining references to clang-10 * gha: fix libc step * deps: bump faabric-base to 0.4.0 * libc: not re-build in the tests * docker: update llvm dockerfile to install toolchain and re-build to use cflags without simd * gh: remove libc build * nits: minor formatting changes * gh: bump faabric submodule and point clapack to the faasm branch * makefile: add exe ldflags * makefile: undo change * build: re-introduce simd * revert simd and pin wasi-libc to latest commit * faasmtools: enable simd * docker: remove comment * ffi: add extra import to build ctypes statically in cpython * faabric: bump submodule after merge
1 parent 3aa892b commit 088b314

21 files changed

+165
-110
lines changed

.env

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
SYSROOT_VERSION=0.1.12
2-
SYSROOT_CLI_IMAGE=faasm/cpp-sysroot:0.1.12
1+
SYSROOT_VERSION=0.2.0
2+
SYSROOT_CLI_IMAGE=faasm/cpp-sysroot:0.2.0
33
COMPOSE_PROJECT_NAME=cpp-dev

.github/workflows/tests.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
if: github.event.pull_request.draft == false
2020
runs-on: ubuntu-20.04
2121
container:
22-
image: faasm/cpp-sysroot:0.1.12
22+
image: faasm/cpp-sysroot:0.2.0
2323
steps:
2424
# --- Update code ---
2525
- name: "Checkout code"
@@ -30,8 +30,6 @@ jobs:
3030
- name: "Set the GH workspace as a safe git directory"
3131
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
3232
# --- Build libraries to wasm ---
33-
- name: "Build libc"
34-
run: ./bin/inv_wrapper.sh libc
3533
- name: "Build libfaasm"
3634
run: ./bin/inv_wrapper.sh libfaasm
3735
- name: "Build libfaasmp"

.gitmodules

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
[submodule "third-party/faasm-clapack"]
1414
path = third-party/faasm-clapack
1515
url = https://github.com/faasm/faasm-clapack
16+
branch = faasm
1617
[submodule "third-party/faabric"]
1718
path = third-party/faabric
1819
url = https://github.com/faasm/faabric.git

Makefile renamed to LLVM.makefile

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# Project directories
2-
PROJ_ROOT=${CURDIR}
3-
LLVM_PROJ_DIR=$(PROJ_ROOT)/third-party/llvm-project
2+
LLVM_PROJ_DIR=${FAASM_LLVM_DIR}
43

5-
TOOLCHAIN_DIR=$(PROJ_ROOT)
4+
TOOLCHAIN_DIR=${FAASM_CPP_PROJ_ROOT}
65
TOOLCHAIN_FILE=$(TOOLCHAIN_DIR)/WasiToolchain.cmake
76

87
# Install dirs
9-
FAASM_LOCAL_DIR=/usr/local/faasm
8+
FAASM_LOCAL_DIR=${FAASM_LOCAL_DIR_ENV}
109
PREFIX=$(FAASM_LOCAL_DIR)/toolchain
11-
FAASM_SYSROOT=/usr/local/faasm/llvm-sysroot
10+
FAASM_SYSROOT=$(FAASM_LOCAL_DIR)/llvm-sysroot
1211

13-
CLANG_VERSION=10.0.1
12+
CLANG_VERSION=${FAASM_LLVM_VERSION}
13+
CLANG_VERSION_MAJOR := $(shell echo $(CLANG_VERSION) | cut -f1 -d.)
1414

15-
BUILD_DIR=$(LLVM_PROJ_DIR)/build
15+
BUILD_DIR=${FAASM_LLVM_BUILD_DIR}
1616
LLVM_CONFIG=$(BUILD_DIR)/llvm/bin/llvm-config
1717
AR=$(BUILD_DIR)/llvm/bin/llvm-ar
1818

19-
WASI_LIBC_DIR=$(PROJ_ROOT)/third-party/wasi-libc
19+
WASI_LIBC_DIR=${FAASM_WASI_LIBC_DIR}
2020

2121
# -------------------------------------------
2222
# This is adapted from the wasi-sdk Makefile found here:
@@ -42,8 +42,8 @@ clean-all:
4242
$(BUILD_DIR)/llvm.BUILT:
4343
mkdir -p $(BUILD_DIR)/llvm
4444
cd $(BUILD_DIR)/llvm; cmake -G Ninja \
45-
-DCMAKE_C_COMPILER=/usr/bin/clang-10 \
46-
-DCMAKE_CXX_COMPILER=/usr/bin/clang++-10 \
45+
-DCMAKE_C_COMPILER=/usr/bin/clang-$(CLANG_VERSION_MAJOR) \
46+
-DCMAKE_CXX_COMPILER=/usr/bin/clang++-$(CLANG_VERSION_MAJOR) \
4747
-DCMAKE_BUILD_TYPE=MinSizeRel \
4848
-DCMAKE_INSTALL_PREFIX=$(PREFIX) \
4949
-DLLVM_TARGETS_TO_BUILD=WebAssembly \
@@ -69,6 +69,7 @@ $(BUILD_DIR)/llvm.BUILT:
6969

7070
# WASI libc
7171
$(BUILD_DIR)/libc.BUILT: $(BUILD_DIR)/llvm.BUILT
72+
mkdir -p $(WASI_LIBC_DIR)/build
7273
cd $(WASI_LIBC_DIR); $(MAKE) \
7374
THREAD_MODEL=faasm \
7475
WASM_CC=$(PREFIX)/bin/clang \
@@ -86,6 +87,7 @@ $(BUILD_DIR)/compiler-rt.BUILT: $(BUILD_DIR)/libc.BUILT
8687
-DCOMPILER_RT_BUILD_XRAY=OFF \
8788
-DCOMPILER_RT_INCLUDE_TESTS=OFF \
8889
-DCOMPILER_RT_HAS_FPIC_FLAG=OFF \
90+
-DCOMPILER_RT_ENABLE_IOS=OFF \
8991
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
9092
-DLLVM_CONFIG_PATH=$(LLVM_CONFIG) \
9193
-DCMAKE_INSTALL_PREFIX=$(PREFIX)/lib/clang/$(CLANG_VERSION)/ \
@@ -102,7 +104,7 @@ $(BUILD_DIR)/libcxx.BUILT: $(BUILD_DIR)/compiler-rt.BUILT
102104
-DCMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN_FILE) \
103105
-DCMAKE_BUILD_TYPE=RelWithDebugInfo \
104106
-DCMAKE_CXX_COMPILER_WORKS=ON \
105-
-DCMAKE_C_COMPILER_WORKS=ON \
107+
-DCMAKE_C_COMPILER_WORKS=ON \
106108
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
107109
-DCMAKE_INSTALL_PREFIX=$(FAASM_SYSROOT) \
108110
-DLLVM_COMPILER_CHECKED=ON \

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.12
1+
0.2.0

docker/cpp-sysroot.dockerfile

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
FROM faasm/llvm:10.0.1 as llvm
1+
FROM faasm/llvm:13.0.1 as llvm
22

33
# faabric-base image is not re-built often, so tag may be behind
4-
FROM faasm/faabric-base:0.3.5
4+
FROM faasm/faabric-base:0.4.0
55
SHELL ["/bin/bash", "-c"]
66
ENV CPP_DOCKER="on"
77

@@ -17,7 +17,7 @@ RUN mkdir -p /code \
1717
https://github.com/faasm/cpp \
1818
/code/cpp \
1919
&& cd /code/cpp \
20-
# Update submodules (not LLVM)
20+
&& git submodule update --init -f third-party/llvm-project \
2121
&& git submodule update --init -f third-party/faabric \
2222
&& git submodule update --init -f third-party/faasm-clapack \
2323
&& git submodule update --init -f third-party/libffi \
@@ -44,6 +44,8 @@ RUN cd /code/cpp \
4444
libfaasmpi --native --shared \
4545
# Install toolchain files
4646
&& inv install \
47+
# First build libc
48+
&& inv llvm.libc \
4749
# Build Faasm WASM libraries
4850
&& inv \
4951
libemscripten \
@@ -52,7 +54,6 @@ RUN cd /code/cpp \
5254
libfaasmpi \
5355
# Lastly, build the libraries that populate the sysroot
5456
&& inv \
55-
libc \
5657
clapack \
5758
clapack --clean --shared \
5859
libffi \

docker/llvm.dockerfile

+20-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
FROM ubuntu:20.04
22

3+
SHELL ["/bin/bash", "-c"]
4+
ENV CPP_DOCKER="on"
5+
36
# Install APT dependencies
47
ARG DEBIAN_FRONTEND=noninteractive
58
RUN apt update \
9+
&& apt install -y \
10+
curl \
11+
gpg \
12+
software-properties-common \
13+
wget \
14+
&& wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - \
15+
&& add-apt-repository -y -n "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-13 main" \
16+
&& add-apt-repository -y -n ppa:ubuntu-toolchain-r/test \
17+
&& apt update \
618
&& apt upgrade -y \
719
&& apt install -y \
820
autoconf \
9-
clang-10 \
10-
curl \
21+
clang-13 \
1122
build-essential \
1223
git \
13-
gpg \
1424
ninja-build \
1525
pkg-config \
16-
software-properties-common \
17-
wget
26+
python3-dev \
27+
python3-pip \
28+
python3-venv
1829

1930
# Install up-to-date CMake
2031
RUN apt remove --purge --auto-remove cmake \
@@ -35,6 +46,9 @@ RUN mkdir -p /code \
3546
&& cd /code/cpp \
3647
&& git submodule update --init -f third-party/llvm-project \
3748
&& git submodule update --init -f third-party/wasi-libc \
38-
&& make \
49+
&& ./bin/create_venv.sh \
50+
&& source venv/bin/activate \
51+
&& inv install \
52+
&& inv llvm.build \
3953
&& /usr/local/faasm/toolchain/bin/clang --version \
4054
&& rm -rf /code

docs/upgrade-llvm.md

+11-15
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,46 @@
33
To upgrade the underlying LLVM version you need to:
44

55
- Update the _submodule_ in this project (see below)
6-
- Update the version in `docker/sysroot.dockerfile`
7-
- Update the version in `faasmtools`
8-
- Update `Makefile`
9-
- Grep the project for any other mentions of the LLVM version
10-
- Run the `inv container.toolchain` task
11-
- Test it out
12-
- Run the `inv container.push-toolchain` task
6+
- Update the version in `docker/cpp-sysroot.dockerfile`
7+
- Update the version in `faasmtools/env.py`
8+
- Tag and push the code
9+
- Re-build the LLVM container (will take some time): `inv docker.build -c llvm`
10+
- Re-build the cpp-sysroot container: `inv docker.build -c cpp-sysroot`
1311

1412
## Updating the LLVM submodule
1513

1614
Find the commit related to tag name for the desired release in
1715
[the LLVM repo](https://github.com/llvm/llvm-project/releases) (e.g.
18-
`llvmorg-10.0.1`), then:
16+
`llvmorg-13.0.1`), then:
1917

2018
```bash
2119
cd third-party/llvm-project
2220
git checkout main
2321
git fetch origin
24-
git checkout <tag-name>
22+
git checkout faasm
23+
git rebase <tag_name>
2524
```
2625

2726
# Rebuilding LLVM
2827

2928
To rebuild LLVM, there a couple of options. To rebuild just libc:
3029

3130
```bash
32-
make clean-libc
33-
make
31+
inv llvm.libc --clean
3432
```
3533

3634
To rebuilding all the libs, i.e. libc, libcxx, libcxxabi and
3735
compiler-rt:
3836

3937
```bash
40-
make clean-libs
41-
make
38+
inv llvm.libs --clean
4239
```
4340

4441
The final option is to rebuild _everything_, including Clang. This only
4542
necessary if you need to change the underlying LLVM or Clang configuration:
4643

4744
```bash
48-
make clean-all
49-
make
45+
inv llvm --clean
5046
```
5147

5248
## Troubleshooting the build

faasmtools/build.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@
7272
# introduced them upstream. Use of atomics means we can't link things together:
7373
# https://reviews.llvm.org/D59281
7474
WASM_CFLAGS = [
75-
"-O3 -mno-atomics",
75+
"-O3",
76+
"-mno-atomics",
77+
"-msimd128",
7678
"--sysroot={}".format(WASM_SYSROOT),
7779
"-m32",
7880
"-DANSI",
@@ -116,7 +118,9 @@
116118
"-Xlinker --export=__heap_base",
117119
"-Xlinker --export=__data_end",
118120
"-Xlinker --export={}".format(FAASM_WASM_CTORS_FUNC_NAME),
121+
"-Xlinker --export=__stack_pointer",
119122
"-Xlinker --max-memory={}".format(FAASM_WASM_MAX_MEMORY),
123+
"-Xlinker --features=mutable-globals,simd128",
120124
"-Wl,-z,stack-size={} -Wl".format(FAASM_WASM_STACK_SIZE),
121125
"-Wl,--initial-memory={}".format(FAASM_WASM_INITIAL_MEMORY_SIZE),
122126
]

faasmtools/env.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111

1212
# Versioning
1313
VERSION_FILE = join(PROJ_ROOT, "VERSION")
14-
LLVM_VERSION = "10.0.1"
14+
15+
# LLVM variables
16+
LLVM_VERSION = "13.0.1"
17+
LLVM_DIR = join(THIRD_PARTY_DIR, "llvm-project")
18+
LLVM_MAKEFILE = join(PROJ_ROOT, "LLVM.makefile")
19+
WASI_LIBC_DIR = join(THIRD_PARTY_DIR, "wasi-libc")
1520

1621

1722
def get_version():

func/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Wasm")
2020
set(CMAKE_EXECUTABLE_SUFFIX ".wasm")
2121
endif ()
2222

23-
2423
if (CMAKE_SYSTEM_NAME STREQUAL "Wasm")
2524
# ----------------------
2625
# Wasm build

native_clang.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

3-
export CXX=/usr/bin/clang++-10
4-
export CC=/usr/bin/clang-10
5-
export CPP=/usr/bin/clang-cpp-10
6-
export LINK=/usr/bin/clang++-10
3+
export CXX=/usr/bin/clang++-13
4+
export CC=/usr/bin/clang-13
5+
export CPP=/usr/bin/clang-cpp-13
6+
export LINK=/usr/bin/clang++-13
77

sysroot_extras/libffi.imports

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
ffi_call
2+
ffi_prep_closure_loc

tasks/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
from . import func
77
from . import git
88
from . import install
9-
from . import libc
109
from . import libemscripten
1110
from . import libfaasm
1211
from . import libfaasmp
1312
from . import libfaasmpi
1413
from . import libfake
1514
from . import libffi
15+
from . import llvm
1616
from . import zlib
1717

1818
ns = Collection(
@@ -22,12 +22,12 @@
2222
func,
2323
git,
2424
install,
25-
libc,
2625
libemscripten,
2726
libfaasm,
2827
libfaasmp,
2928
libfaasmpi,
3029
libfake,
3130
libffi,
31+
llvm,
3232
zlib,
3333
)

tasks/format_code.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def format(ctx, check=False):
3131

3232
flake8_cmd = [
3333
"python3 -m flake8",
34-
"{}".format("--format" if not check else ""),
3534
" ".join(files_to_check),
3635
]
3736
flake8_cmd = " ".join(flake8_cmd)
@@ -52,7 +51,7 @@ def format(ctx, check=False):
5251
)
5352

5453
clang_cmd = [
55-
"clang-format-10",
54+
"clang-format-13",
5655
"--dry-run --Werror" if check else "-i",
5756
" ".join(files_to_check),
5857
]

tasks/lib.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
FAASM_NATIVE_DIR,
55
WASM_SYSROOT,
66
)
7-
from faasmtools.env import PROJ_ROOT
7+
from faasmtools.env import LLVM_VERSION, PROJ_ROOT
88
from os.path import exists, join
99
from os import environ, makedirs
1010
from shutil import rmtree
@@ -33,9 +33,10 @@ def build_faasm_lib(subdir, clean=False, native=False, shared=False):
3333
makedirs(build_dir, exist_ok=True)
3434

3535
if native:
36+
llvm_major = LLVM_VERSION.split(".")[0]
3637
extras = [
37-
"-DCMAKE_C_COMPILER=/usr/bin/clang-10",
38-
"-DCMAKE_CXX_COMPILER=/usr/bin/clang++-10",
38+
"-DCMAKE_C_COMPILER=/usr/bin/clang-{}".format(llvm_major),
39+
"-DCMAKE_CXX_COMPILER=/usr/bin/clang++-{}".format(llvm_major),
3940
]
4041
else:
4142
extras = [

0 commit comments

Comments
 (0)