Skip to content

Commit 6fb4886

Browse files
authored
Merge branch 'master' into merge-upstream
2 parents d097887 + 98152cf commit 6fb4886

File tree

7 files changed

+108
-90
lines changed

7 files changed

+108
-90
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ compiler: gcc
55
script:
66
- docker-compose build ubuntu-16.04-llvm-$LLVM_VERSION
77
- 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
8+
- docker run --rm -ti --entrypoint /src/target/scalaBindgenTest scala-native-bindgen:ubuntu-16.04-llvm-$LLVM_VERSION
99

1010
matrix:
1111
include:

CMakeLists.txt

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ add_definitions(${LLVM_DEFINITIONS})
1111

1212
add_compile_options(-fexceptions -std=c++11)
1313

14-
add_executable(scalaBindgen
15-
Main.cpp
14+
add_library(scalaNativeBindgen
15+
STATIC
1616
ScalaFrontend.h
1717
TreeVisitor.h
1818
TreeVisitor.cpp
@@ -23,12 +23,27 @@ add_executable(scalaBindgen
2323
HeaderManager.cpp
2424
CycleDetection.h
2525
Utils.h
26-
catch/catch.hpp
27-
SimpleTypeTests.cpp
26+
)
27+
28+
add_executable(scalaBindgen
29+
Main.cpp
2830
)
2931

3032
target_link_libraries(scalaBindgen
3133
PRIVATE
34+
scalaNativeBindgen
35+
clangFrontend
36+
clangTooling
37+
)
38+
39+
add_executable(scalaBindgenTest
40+
SimpleTypeTests.cpp
41+
catch/catch.hpp
42+
)
43+
44+
target_link_libraries(scalaBindgenTest
45+
PRIVATE
46+
scalaNativeBindgen
3247
clangFrontend
3348
clangTooling
3449
)

LICENCE.txt

Lines changed: 0 additions & 27 deletions
This file was deleted.

LICENSE.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright (c) 2015-2018 EPFL
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without modification,
6+
are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright notice,
9+
this list of conditions and the following disclaimer.
10+
* Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
* Neither the name of the EPFL nor the names of its contributors
14+
may be used to endorse or promote products derived from this software
15+
without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Main.cpp

Lines changed: 46 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include "ScalaFrontend.h"
22
#include "Utils.h"
33

4-
#define CATCH_CONFIG_RUNNER
5-
#include "catch/catch.hpp"
64

75
static llvm::cl::OptionCategory Category("Binding Generator");
86
static llvm::cl::extrahelp CommonHelp(clang::tooling::CommonOptionsParser::HelpMessage);
@@ -13,72 +11,63 @@ static llvm::cl::opt<bool> PrintHeadersLocation ("location", llvm::cl::cat(Categ
1311

1412

1513
int main(int argc, char *argv[]) {
14+
clang::tooling::CommonOptionsParser op(argc, (const char**)argv, Category);
15+
clang::tooling::ClangTool Tool(op.getCompilations(), op.getSourcePathList());
1616

17-
if(argc <= 1 ){
17+
auto lib = LibName.getValue();
18+
if(lib == ""){
19+
llvm::errs() << "Error: Please specify the lib name using -name paramter\n";
20+
return -1;
21+
}
1822

19-
int result = Catch::Session().run( argc, argv );
20-
return result;
23+
auto stdhead = StdHeaders.getValue();
24+
if(stdhead != ""){
25+
headerMan.LoadConfig(stdhead);
26+
}
2127

22-
} else{
28+
declarations = "";
29+
enums = "";
30+
helpers = "";
31+
locations.clear();
2332

24-
clang::tooling::CommonOptionsParser op(argc, (const char**)argv, Category);
25-
clang::tooling::ClangTool Tool(op.getCompilations(), op.getSourcePathList());
33+
int result = Tool.run(clang::tooling::newFrontendActionFactory<ScalaFrontendAction>().get());
2634

27-
auto lib = LibName.getValue();
28-
if(lib == ""){
29-
llvm::errs() << "Error: Please specify the lib name using -name paramter\n";
30-
return -1;
31-
}
35+
auto printLoc = PrintHeadersLocation.getValue();
3236

33-
auto stdhead = StdHeaders.getValue();
34-
if(stdhead != ""){
35-
headerMan.LoadConfig(stdhead);
37+
if(printLoc){
38+
for(const auto& location: locations){
39+
llvm::outs() << location;
3640
}
3741

38-
declarations = "";
39-
enums = "";
40-
helpers = "";
41-
locations.clear();
42-
43-
int result = Tool.run(clang::tooling::newFrontendActionFactory<ScalaFrontendAction>().get());
44-
45-
auto printLoc = PrintHeadersLocation.getValue();
46-
47-
if(printLoc){
48-
for(const auto& location: locations){
49-
llvm::outs() << location;
50-
}
51-
52-
} else {
53-
if(declarations != "" || enums != "")
54-
llvm::outs() << "import scala.scalanative._\n"
55-
<< "import scala.scalanative.native._\n"
56-
<< "import scala.scalanative.native.Nat._\n\n";
57-
58-
if(declarations != ""){
59-
llvm::outs() << "@native.link(\"" << lib << "\")\n"
60-
<< "@native.extern\n"
61-
<< "object " << lib << " {\n"
62-
<< declarations
63-
<< "}\n\n";
64-
}
42+
} else {
43+
if(declarations != "" || enums != "")
44+
llvm::outs() << "import scala.scalanative._\n"
45+
<< "import scala.scalanative.native._\n"
46+
<< "import scala.scalanative.native.Nat._\n\n";
47+
48+
if(declarations != ""){
49+
llvm::outs() << "@native.link(\"" << lib << "\")\n"
50+
<< "@native.extern\n"
51+
<< "object " << lib << " {\n"
52+
<< declarations
53+
<< "}\n\n";
54+
}
6555

66-
if(enums != "" || helpers != ""){
67-
llvm::outs() << "import " + lib + "._\n\n";
68-
}
56+
if(enums != "" || helpers != ""){
57+
llvm::outs() << "import " + lib + "._\n\n";
58+
}
6959

70-
if(enums != ""){
71-
llvm::outs() << "object " << lib << "Enums {\n"
72-
<< enums
73-
<< "}\n\n";
74-
}
60+
if(enums != ""){
61+
llvm::outs() << "object " << lib << "Enums {\n"
62+
<< enums
63+
<< "}\n\n";
64+
}
7565

76-
if(helpers != ""){
77-
llvm::outs() << "object " << lib << "Helpers {\n"
78-
<< helpers
79-
<< "}\n\n";
80-
}
66+
if(helpers != ""){
67+
llvm::outs() << "object " << lib << "Helpers {\n"
68+
<< helpers
69+
<< "}\n\n";
8170
}
82-
return result;
8371
}
72+
return result;
8473
}

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Scala Native Binding generator
22

3-
This tool generate Scala Native bindings from C headers. It's build upon clang and Libtooling and thus respect the conventions of clang-tools.
3+
[![Build Status](https://travis-ci.com/kornilova-l/scala-native-bindgen.svg?branch=master)](https://travis-ci.com/kornilova-l/scala-native-bindgen)
4+
5+
This tool generate Scala Native bindings from C headers. It's built upon clang and Libtooling and thus respect the conventions of clang-tools.
46

57
## Usage
68

@@ -26,3 +28,8 @@ cmake ..
2628
make
2729
./scalaBindgen /usr/include/ctype.h -name ctype
2830
```
31+
32+
## License
33+
34+
This project is distributed under the Scala license.
35+
[See LICENSE.txt for details](LICENSE.txt)

SimpleTypeTests.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
#include "ScalaFrontend.h"
22

33
#include "clang/Tooling/Tooling.h"
4+
5+
#define CATCH_CONFIG_RUNNER
46
#include "catch/catch.hpp"
57

68
#include <iostream>
79

10+
int main(int argc, char *argv[]) {
11+
int result = Catch::Session().run( argc, argv );
12+
return result;
13+
}
14+
815
std::string Translate(std::string code){
916
declarations = "";
1017
enums = "";

0 commit comments

Comments
 (0)