@@ -8,13 +8,17 @@ This tool generates Scala Native bindings from C headers. It's built upon clang
88
99Calling the tool is pretty easy, you need to specify the file(s) and the name of the created bindings.
1010
11- ` ./scala-native-bindgen /usr/include/uv.h -name uv -- `
11+ ``` sh
12+ scala-native-bindgen --name uv /usr/include/uv.h --
13+ ```
1214
1315Running the previous command wild also yield warnings along with the translation. To keep only the bindings please redirect the output to a file like this:
1416
15- ` ./scala-native-bindgen /usr/include/uv.h -name uv -- > uv.scala `
17+ ``` sh
18+ scala-native-bindgen --name uv /usr/include/uv.h -- > uv.scala
19+ ```
1620
17- Run ` ./ scala-native-bindgen -help` to see all available options.
21+ Run ` scala-native-bindgen - -help ` to see all available options.
1822
1923## Obtaining bindgen
2024
@@ -53,17 +57,30 @@ each merge to the `master` branch.
5357 [ Docker ] : https://www.docker.com/
5458 [ docker-bindgen.sh ] : scripts/docker-bindgen.sh
5559
56- ### Building
60+ ## Building
61+
62+ Building ` scala-native-bindgen ` requires the following tools and libraries:
5763
58- Building this tool requires [ CMake] , [ LLVM] and [ Clang] . See the [ Scala
59- Native setup guide] for instructions on installing the dependencies.
64+ - [ CMake] version 3.9 or higher
65+ - [ LLVM] and [ Clang] version 5.0 or 6.0.
66+
67+ ``` sh
68+ # On apt-based systems
69+ apt install cmake clang-$LLVM_VERSION libclang-$LLVM_VERSION -dev llvm-$LLVM_VERSION -dev
70+
71+ # With `brew`
72+ brew install cmake llvm@6
73+ ```
74+
75+ To run the tests you also need the required Scala Native libraries.
76+ See the [ Scala Native setup guide] for instructions on installing the dependencies.
6077
6178``` sh
6279mkdir -p bindgen/target
6380cd bindgen/target
6481cmake ..
6582make
66- ./scala-native-bindgen /usr/include/ctype.h -name ctype --
83+ ./scala-native-bindgen --name ctype /usr/include/ctype.h --
6784```
6885
6986To build a statically linked executable pass ` -DSTATIC_LINKING=ON ` when invoking ` cmake ` :
@@ -72,15 +89,18 @@ To build a statically linked executable pass `-DSTATIC_LINKING=ON` when invoking
7289cmake -DSTATIC_LINKING=ON ..
7390```
7491
92+ ### Building with ` docker-compose `
93+
7594Alternatively, you can use [ docker-compose] to build and test the program:
7695
7796``` sh
7897# Build the docker image with LLVM version 6.0.
7998docker-compose build ubuntu-18.04-llvm-6.0
8099# Build the bindgen tool and run the tests.
81- docker-compose run --rm ubuntu-18.04-llvm-6.0
100+ docker-compose run --rm ubuntu-18.04-llvm-6.0 ./script/test.sh
82101# Run the bindgen tool inside the container.
83- docker-compose run --rm ubuntu-18.04-llvm-6.0 bindgen/target/scala-native-bindgen -name union tests/samples/Union.h --
102+ docker-compose run --rm ubuntu-18.04-llvm-6.0 \
103+ bindgen/target/scala-native-bindgen --name union tests/samples/Union.h --
84104```
85105
86106 [ CMake ] : https://cmake.org/
@@ -91,17 +111,19 @@ docker-compose run --rm ubuntu-18.04-llvm-6.0 bindgen/target/scala-native-bindge
91111
92112## Testing
93113
94- The tests assume that the above instructions for building has been
95- followed.
114+ The tests assume that the above instructions for building ` scala-native-bindgen ` from source
115+ has been followed.
96116
97117``` sh
98118cd tests
99119sbt test
100120```
101121
102- ## Current limitations
122+ ## Limitations
123+
103124There are multiple unsupported cases that should be considered when generating bindings:
104- 1 . Currently bindgen does not support passing structs by value.
125+
126+ 1 . Currently bindgen does not support passing structs by value.
105127 For example, it will not be possible to call these two functions from Scala Native code:
106128 ``` c
107129 struct MyStruct {
@@ -113,12 +135,26 @@ There are multiple unsupported cases that should be considered when generating b
113135 void handleStruct(struct MyStruct mystr);
114136 ```
115137 To support such cases one should generate bindings for C wrapper functions that use pointers to structs instead of actual structs.
116- 2 . Bindgen does not generate bindings for defines.
117- In order to use defines one should write wrapper functions that return defined values.
118- 3 . There is no way to reuse already generated bindings.
119- Bindgen outputs bindings also for headers that were included in a given header.
120- 4 . Type qualifiers ` const ` , ` volatile ` and ` restrict ` are not supported.
121- 5 . Extern variables are read-only.
138+ 2 . ` #define ` s for literals and variables are supported. For other types of ` #define ` s,
139+ write wrapper functions that return defined values.
140+ ``` c
141+ // Supported
142+ #define ESC 0x1b /* Defines for numerical and string literals. * /
143+ extern const int pi_const;
144+ #define PI pi_const /* Defines aliasing extern variables. * /
145+
146+ // Not supported (non-exhaustive list)
147+ #define COLS (getenv("COLS") ? atoi(getenv("COLS")) : 80)
148+ #define MAX (a, b ) (a > b ? a : b)
149+ ```
150+
151+ 3 . There is no way to reuse already generated bindings.
152+ Bindgen outputs bindings also for headers that were included in a given header. See [#2 ].
153+ 4 . Type qualifiers `const `, `volatile ` and `restrict ` are not supported.
154+ 5 . Extern variables are read-only. See [scala-native/scala-native#202 ].
155+
156+ [#2 ]: https:// github.com/kornilova-l/scala-native-bindgen/issues/2
157+ [scala-native/scala-native#202 ]: https:// github.com/scala-native/scala-native/issues/202
122158
123159## License
124160
0 commit comments