Skip to content

Commit eca8253

Browse files
dfranklandvtjnash
authored andcommitted
Add Docker image and example using docker-compose (#32)
* Create Dockerfile This follows all the intructions for llvm and makes it possilble to start making reproducible builds * Create docker-compose.yml to compile and run an example project * Simplify example so that it can be run without user input * Copy files from repo into container This makes it nice for building an image based on the current repo, not the latest HEAD * Link llvm-cbe so it's in PATH * Improve hello_world test example * Improve build time using Ninja and curling sources / prebuilt binaries * Update Dockerfile to install ninja and cmake using apt
1 parent de2610b commit eca8253

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

Dockerfile

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM buildpack-deps:stretch
2+
3+
RUN \
4+
set -e; \
5+
apt update && apt install -y \
6+
clang \
7+
ninja-build \
8+
cmake; \
9+
cd /root; \
10+
curl -fL http://releases.llvm.org/7.0.1/llvm-7.0.1.src.tar.xz \
11+
| tar xJf -; \
12+
mv /root/llvm-7.0.1.src /root/llvm; \
13+
mkdir -p /root/llvm/build;
14+
15+
COPY . /root/llvm/projects/llvm-cbe/
16+
17+
RUN \
18+
set -e; \
19+
mkdir -p /root/llvm/build; \
20+
cd /root/llvm/build; \
21+
cmake -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..; \
22+
ninja llvm-cbe; \
23+
ninja lli; \
24+
ninja CBEUnitTests; \
25+
/root/llvm/build/projects/llvm-cbe/unittests/CWriterTest; \
26+
ln -s /root/llvm/build/bin/llvm-cbe /bin/llvm-cbe;

docker-compose.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
version: "3"
2+
3+
services:
4+
llvm-cbe:
5+
build: .
6+
working_dir: /root
7+
volumes:
8+
- ./test:/test
9+
command: |
10+
bash -c "
11+
set -e;
12+
13+
# Navigate to test folder
14+
cd /test/hello_world;
15+
16+
# Compile main.c to llvm IR
17+
clang -S -emit-llvm main.c;
18+
19+
# Compile llvm IR back to C
20+
llvm-cbe main.ll;
21+
22+
# Compile llvm-cbe generated C code
23+
gcc -g -o main.cbe main.cbe.c;
24+
25+
# Run it
26+
./main.cbe;
27+
"

test/hello_world/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*
2+
!.gitignore
3+
!main.c

test/hello_world/main.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
printf("Hello, World!\n");
5+
return 0;
6+
}

0 commit comments

Comments
 (0)