Skip to content

Commit ec32313

Browse files
authored
Merge pull request #8 from jonas/docker-compose
Configure docker-compose to build against different LLVM versions
2 parents dfd5933 + 22765df commit ec32313

File tree

6 files changed

+83
-23
lines changed

6 files changed

+83
-23
lines changed

.travis.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
language: cpp
2-
sudo: false
3-
compiler: clang
2+
sudo: required
3+
compiler: gcc
44

55
script:
6-
- mkdir -p target
7-
- cd target
8-
- cmake ..
9-
- make
10-
- ./scalaBindgen /usr/include/ctype.h -name ctype
6+
- docker-compose build ubuntu-16.04-llvm-$LLVM_VERSION
7+
- docker run --rm -ti scala-native-bindgen:ubuntu-16.04-llvm-$LLVM_VERSION /usr/include/ctype.h -name ctype --
8+
- docker run --rm -ti scala-native-bindgen:ubuntu-16.04-llvm-$LLVM_VERSION
9+
10+
matrix:
11+
include:
12+
- env: LLVM_VERSION=dev
13+
- env: LLVM_VERSION=6.0
14+
- env: LLVM_VERSION=5.0

CMakeLists.txt

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,13 @@ project(scala-native-bindgen)
33

44
# Locate $LLVM_PATH/lib/cmake/clang/ClangConfig.cmake
55
find_package(Clang REQUIRED CONFIG)
6+
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
7+
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
68

7-
# Read and set CXXFLAGS and LDFLAGS
8-
execute_process(COMMAND llvm-config --cxxflags
9-
OUTPUT_VARIABLE LLVM_CXX_FLAGS
10-
OUTPUT_STRIP_TRAILING_WHITESPACE
11-
)
12-
13-
execute_process(COMMAND llvm-config --ldflags
14-
OUTPUT_VARIABLE LLVM_LINKER_FLAGS
15-
OUTPUT_STRIP_TRAILING_WHITESPACE
16-
)
17-
18-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLVM_CXX_FLAGS}")
19-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LLVM_LINKER_FLAGS}")
9+
include_directories(${LLVM_INCLUDE_DIRS})
10+
add_definitions(${LLVM_DEFINITIONS})
2011

21-
add_compile_options(-fexceptions)
12+
add_compile_options(-fexceptions -std=c++11)
2213

2314
add_executable(scalaBindgen
2415
Main.cpp

Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
ARG UBUNTU_VERSION=16.04
2+
FROM ubuntu:$UBUNTU_VERSION
3+
4+
RUN set -x \
5+
&& apt update \
6+
&& apt install -y curl build-essential \
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
WORKDIR /cmake
10+
ARG CMAKE_ARCHIVE=cmake-3.11.2-Linux-x86_64
11+
RUN curl https://cmake.org/files/v3.11/$CMAKE_ARCHIVE.tar.gz | tar zxf - \
12+
&& for i in bin share; do \
13+
cp -r /cmake/$CMAKE_ARCHIVE/$i/* /usr/$i/; \
14+
done \
15+
&& rm -rf /cmake
16+
17+
ARG LLVM_VERSION=6.0
18+
# LLVM dev versions do not have a "-x.y" version suffix.
19+
ARG LLVM_DEB_COMPONENT=-$LLVM_VERSION
20+
RUN set -x \
21+
&& curl https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - \
22+
&& . /etc/lsb-release \
23+
&& echo "deb http://apt.llvm.org/$DISTRIB_CODENAME/ llvm-toolchain-$DISTRIB_CODENAME$LLVM_DEB_COMPONENT main" > /etc/apt/sources.list.d/llvm.list \
24+
&& apt update \
25+
&& apt install -y clang-$LLVM_VERSION libclang-$LLVM_VERSION-dev make \
26+
&& rm -rf /var/lib/apt/lists/*
27+
28+
WORKDIR /src/target
29+
COPY . /src
30+
RUN cmake .. && make VERBOSE=1
31+
32+
ENTRYPOINT ["/src/target/scalaBindgen"]

SimpleTypeTests.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,13 @@ TEST_CASE("native types", "[Type]" ) {
4747
for(const auto& kv: types){
4848
std::string code = "#include<uchar.h>\n#include<stddef.h>\ntypedef " + kv.first + " a;\n";
4949
std::string answer = "\ttype a = " + kv.second + "\n";
50+
std::string translated = Translate(code);
51+
std::string::size_type last_line_pos = translated.rfind("\t");
52+
// FIXME(jonas): Only test against the last line until we prune
53+
// type aliases according to referenced output types.
54+
std::string last_line = translated.substr(last_line_pos);
5055

51-
REQUIRE(answer == Translate(code));
56+
REQUIRE(answer == last_line);
5257
}
5358
}
5459

TreeVisitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ bool TreeVisitor::VisitFunctionDecl(clang::FunctionDecl *func) {
3737
}
3838

3939
//Note the C Iso require at least one argument in a variadic function, so the comma is fine
40-
std::string variad = func->isVariadic() ? ", varArgs: native.CVararg" : "";
40+
std::string variad = func->isVariadic() ? ", varArgs: native.CVararg*" : "";
4141

4242
declarations += "\tdef " + funcName + "(" + params + variad + "): " + retType + " = native.extern\n";
4343
return true;

docker-compose.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: '3'
2+
3+
services:
4+
ubuntu-16.04-llvm-dev:
5+
image: scala-native-bindgen:ubuntu-16.04-llvm-dev
6+
build:
7+
context: .
8+
args:
9+
- UBUNTU_VERSION=16.04
10+
- LLVM_VERSION=7
11+
- LLVM_DEB_COMPONENT=
12+
13+
ubuntu-16.04-llvm-6.0:
14+
image: scala-native-bindgen:ubuntu-16.04-llvm-6.0
15+
build:
16+
context: .
17+
args:
18+
- UBUNTU_VERSION=16.04
19+
- LLVM_VERSION=6.0
20+
21+
ubuntu-16.04-llvm-5.0:
22+
image: scala-native-bindgen:ubuntu-16.04-llvm-5.0
23+
build:
24+
context: .
25+
args:
26+
- UBUNTU_VERSION=16.04
27+
- LLVM_VERSION=5.0
28+

0 commit comments

Comments
 (0)