diff --git a/programs/bpf/c/sdk/bpf.mk b/programs/bpf/c/sdk/bpf.mk index 06c565c29b1d97..ea4b7cf847784b 100644 --- a/programs/bpf/c/sdk/bpf.mk +++ b/programs/bpf/c/sdk/bpf.mk @@ -12,10 +12,14 @@ SRC_DIR ?= ./src TEST_DIR ?= ./test OUT_DIR ?= ./out +ifeq ($(DOCKER),1) +LLVM_DIR = $(LOCAL_PATH)llvm/llvm-docker +else OS=$(shell uname) ifeq ($(OS),Darwin) LLVM_DIR ?= $(shell brew --prefix llvm) endif +endif ifdef LLVM_DIR CC := $(LLVM_DIR)/bin/clang @@ -29,14 +33,14 @@ LLC := llc-7 OBJ_DUMP := llvm-objdump-7 endif -SYSTEM_INC_DIRS := -isystem $(LOCAL_PATH)inc +SYSTEM_INC_DIRS := $(LOCAL_PATH)inc C_FLAGS := \ -Werror \ -O2 \ -fno-builtin \ -std=c17 \ - $(SYSTEM_INC_DIRS) \ + $(addprefix -isystem,$(SYSTEM_INC_DIRS)) \ $(addprefix -I,$(INC_DIRS)) CXX_FLAGS := \ @@ -88,6 +92,7 @@ TEST_CXX_FLAGS := \ $(TESTFRAMEWORK_FLAGS) \ help: + @echo '' @echo 'BPF Program makefile' @echo '' @echo 'This makefile will build BPF Programs from C or C++ source files into ELFs' @@ -102,8 +107,11 @@ help: @echo '' @echo 'User settings' @echo ' - The following setting are overridable on the command line, default values shown:' - @echo ' - Show commands while building:' - @echo ' V=1' + @echo ' - Show commands while building: V=1' + @echo ' V=$(V)' + @echo ' - Use LLVM from docker: DOCKER=1' + @echo ' Docker image must be pulled first: docker pull solanalabs/llvm' + @echo ' DOCKER=$(DOCKER)' @echo ' - List of include directories:' @echo ' INC_DIRS=$(INC_DIRS)' @echo ' - List of system include directories:' @@ -119,7 +127,7 @@ help: @echo '' @echo 'Usage:' @echo ' - make help - This help message' - @echo ' - make all - Builds all the programs' + @echo ' - make all - Build all the programs' @echo ' - make test - Build and run all tests' @echo ' - make dump_ - Dumps the contents of the program to stdout' @echo ' - make - Build a single program by name' @@ -133,6 +141,7 @@ help: @echo ' - Assuming a programed named foo (src/foo.c)' @echo ' - make foo' @echo ' - make dump_foo' + @echo '' .PRECIOUS: $(OUT_DIR)/%.bc $(OUT_DIR)/%.bc: $(SRC_DIR)/%.c diff --git a/programs/bpf/c/sdk/llvm/llvm-docker/bin/clang b/programs/bpf/c/sdk/llvm/llvm-docker/bin/clang new file mode 100755 index 00000000000000..2aef38dba862ac --- /dev/null +++ b/programs/bpf/c/sdk/llvm/llvm-docker/bin/clang @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -ex +SDKPATH="$( cd "$(dirname "$0")" ; pwd -P )"/../../../.. +docker run --workdir /solana_sdk --volume $SDKPATH:/solana_sdk --rm solanalabs/llvm `basename "$0"` "$@" diff --git a/programs/bpf/c/sdk/llvm/llvm-docker/bin/clang++ b/programs/bpf/c/sdk/llvm/llvm-docker/bin/clang++ new file mode 100755 index 00000000000000..2aef38dba862ac --- /dev/null +++ b/programs/bpf/c/sdk/llvm/llvm-docker/bin/clang++ @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -ex +SDKPATH="$( cd "$(dirname "$0")" ; pwd -P )"/../../../.. +docker run --workdir /solana_sdk --volume $SDKPATH:/solana_sdk --rm solanalabs/llvm `basename "$0"` "$@" diff --git a/programs/bpf/c/sdk/llvm/llvm-docker/bin/llc b/programs/bpf/c/sdk/llvm/llvm-docker/bin/llc new file mode 100755 index 00000000000000..2aef38dba862ac --- /dev/null +++ b/programs/bpf/c/sdk/llvm/llvm-docker/bin/llc @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -ex +SDKPATH="$( cd "$(dirname "$0")" ; pwd -P )"/../../../.. +docker run --workdir /solana_sdk --volume $SDKPATH:/solana_sdk --rm solanalabs/llvm `basename "$0"` "$@" diff --git a/programs/bpf/c/sdk/llvm/llvm-docker/bin/llvm-objdump b/programs/bpf/c/sdk/llvm/llvm-docker/bin/llvm-objdump new file mode 100755 index 00000000000000..2aef38dba862ac --- /dev/null +++ b/programs/bpf/c/sdk/llvm/llvm-docker/bin/llvm-objdump @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -ex +SDKPATH="$( cd "$(dirname "$0")" ; pwd -P )"/../../../.. +docker run --workdir /solana_sdk --volume $SDKPATH:/solana_sdk --rm solanalabs/llvm `basename "$0"` "$@" diff --git a/programs/bpf/c/sdk/llvm/llvm-docker/generate.sh b/programs/bpf/c/sdk/llvm/llvm-docker/generate.sh new file mode 100755 index 00000000000000..55be032875b679 --- /dev/null +++ b/programs/bpf/c/sdk/llvm/llvm-docker/generate.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +read -r -d '' SCRIPT << 'EOM' +#!/usr/bin/env bash +set -ex +SDKPATH="$( cd "$(dirname "$0")" ; pwd -P )"/../../../.. +docker run --workdir /solana_sdk --volume $SDKPATH:/solana_sdk --rm solanalabs/llvm `basename "$0"` "$@" +EOM + +echo "$SCRIPT" > bin/clang +echo "$SCRIPT" > bin/clang++ +echo "$SCRIPT" > bin/llc +echo "$SCRIPT" > bin/llvm-objdump diff --git a/sdk/docker-llvm/Dockerfile b/sdk/docker-llvm/Dockerfile new file mode 100644 index 00000000000000..152aa1bbc9631d --- /dev/null +++ b/sdk/docker-llvm/Dockerfile @@ -0,0 +1,68 @@ +# This docker file is based on the llvm docker file example located here: +# https://github.com/llvm-mirror/llvm/blob/master/utils/docker/debian8/Dockerfile + +FROM launcher.gcr.io/google/debian8:latest as builder +LABEL maintainer "Solana Maintainers" + +# Install build dependencies of llvm. +# First, Update the apt's source list and include the sources of the packages. +RUN grep deb /etc/apt/sources.list | \ + sed 's/^deb/deb-src /g' >> /etc/apt/sources.list + +# Install compiler, python and subversion. +RUN apt-get update && \ + apt-get install -y \ + --no-install-recommends \ + ca-certificates gnupg \ + build-essential \ + python \ + wget \ + unzip \ + git \ + ssh && \ + rm -rf /var/lib/apt/lists/* + +# Install a newer ninja release. It seems the older version in the debian repos +# randomly crashes when compiling llvm. +RUN wget "https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-linux.zip" && \ + echo "d2fea9ff33b3ef353161ed906f260d565ca55b8ca0568fa07b1d2cab90a84a07 ninja-linux.zip" \ + | sha256sum -c && \ + unzip ninja-linux.zip -d /usr/local/bin && \ + rm ninja-linux.zip + +# Import public key required for verifying signature of cmake download. +RUN gpg --no-tty --keyserver hkp://pgp.mit.edu --recv 0x2D2CEF1034921684 + +# Download, verify and install cmake version that can compile clang into /usr/local. +# (Version in debian8 repos is too old) +RUN mkdir /tmp/cmake-install && cd /tmp/cmake-install && \ + wget "https://cmake.org/files/v3.7/cmake-3.7.2-SHA-256.txt.asc" && \ + wget "https://cmake.org/files/v3.7/cmake-3.7.2-SHA-256.txt" && \ + gpg --verify cmake-3.7.2-SHA-256.txt.asc cmake-3.7.2-SHA-256.txt && \ + wget "https://cmake.org/files/v3.7/cmake-3.7.2-Linux-x86_64.tar.gz" && \ + ( grep "cmake-3.7.2-Linux-x86_64.tar.gz" cmake-3.7.2-SHA-256.txt | \ + sha256sum -c - ) && \ + tar xzf cmake-3.7.2-Linux-x86_64.tar.gz -C /usr/local --strip-components=1 && \ + cd / && \ + rm -rf /tmp/cmake-install + +# ADD checksums /tmp/checksums +# ADD scripts /tmp/scripts + +# Checkout the source code +RUN git clone https://github.com/solana-labs/llvm.git && \ + git clone https://github.com/solana-labs/clang.git llvm/tools/clang && \ + git clone https://github.com/solana-labs/clang-tools-extra.git llvm/tools/clang/tools/extra && \ + git clone https://github.com/solana-labs/lld.git llvm/tools/lld && \ + git clone https://github.com/solana-labs/compiler-rt.git llvm/projects/compiler-rt + +RUN mkdir /llvm/build && \ + cd /llvm/build && \ + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_INSTALL_PREFIX=$HOME/local -G "Ninja" .. && \ + ninja -j6 && \ + ninja install + +# Produce stage 2 docker with just the peices needed +FROM launcher.gcr.io/google/debian8:latest +LABEL maintainer "Solana Maintainers" +COPY --from=builder root/local/bin /usr/local/bin diff --git a/sdk/docker-llvm/README.md b/sdk/docker-llvm/README.md new file mode 100644 index 00000000000000..e607e02d936e2d --- /dev/null +++ b/sdk/docker-llvm/README.md @@ -0,0 +1,16 @@ +## Solana Customized LLVM + +This Docker contains LLVM binaries that incorporate customizations and fixes required +by Solana but not yet upstreamed into the LLVM mainline. + +https://hub.docker.com/r/solanalabs/llvm/ + +### Usage: + +This Docker is optionally used by the SDK BPF build system. + +For more information: + +```bash +$ make help +``` diff --git a/sdk/docker-llvm/build.sh b/sdk/docker-llvm/build.sh new file mode 100755 index 00000000000000..abc953acc0512b --- /dev/null +++ b/sdk/docker-llvm/build.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -ex + +cd "$(dirname "$0")" + +docker build -t solanalabs/llvm . +docker push solanalabs/llvm diff --git a/ci/docker-solana/.gitignore b/sdk/docker-solana/.gitignore similarity index 100% rename from ci/docker-solana/.gitignore rename to sdk/docker-solana/.gitignore diff --git a/ci/docker-solana/Dockerfile b/sdk/docker-solana/Dockerfile similarity index 100% rename from ci/docker-solana/Dockerfile rename to sdk/docker-solana/Dockerfile diff --git a/ci/docker-solana/README.md b/sdk/docker-solana/README.md similarity index 100% rename from ci/docker-solana/README.md rename to sdk/docker-solana/README.md diff --git a/ci/docker-solana/build.sh b/sdk/docker-solana/build.sh similarity index 84% rename from ci/docker-solana/build.sh rename to sdk/docker-solana/build.sh index ba5967200aa010..5942e06ff42154 100755 --- a/ci/docker-solana/build.sh +++ b/sdk/docker-solana/build.sh @@ -18,10 +18,10 @@ if [[ -z $CHANNEL ]]; then fi rm -rf usr/ -../docker-run.sh solanalabs/rust:1.30.1 bash -c " +../../ci/docker-run.sh solanalabs/rust:1.30.1 bash -c " set -ex - cargo install --path drone --root ci/docker-solana/usr - cargo install --path . --root ci/docker-solana/usr + cargo install --path drone --root sdk/docker-solana/usr + cargo install --path . --root sdk/docker-solana/usr " cp -f entrypoint.sh usr/bin/solana-entrypoint.sh ../../scripts/install-native-programs.sh usr/bin/ diff --git a/ci/docker-solana/entrypoint.sh b/sdk/docker-solana/entrypoint.sh similarity index 100% rename from ci/docker-solana/entrypoint.sh rename to sdk/docker-solana/entrypoint.sh