@@ -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,28 +57,58 @@ 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
5761
58- Building this tool requires [ CMake] , [ LLVM] and [ Clang] . See the [ Scala
59- Native setup guide] for instructions on installing the dependencies.
62+ Building ` scala-native-bindgen ` requires the following tools and libraries:
63+
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
86+ To build a statically linked executable pass ` -DSTATIC_LINKING=ON ` when invoking ` cmake ` :
87+
88+ ``` sh
89+ cmake -DSTATIC_LINKING=ON ..
90+ ```
91+
92+ Additional compiler and linker flags may be passed as environment variable sor their CMake
93+ equivalent, e.g. to compile with debug symbols the following are the same:
94+
95+ ``` sh
96+ cmake -DCMAKE_CXX_FLAGS=-g ..
97+ CXXFLAGS=-g cmake ..
98+ ```
99+
100+ ### Building with ` docker-compose `
101+
69102Alternatively, you can use [ docker-compose] to build and test the program:
70103
71104``` sh
72105# Build the docker image with LLVM version 6.0.
73106docker-compose build ubuntu-18.04-llvm-6.0
74107# Build the bindgen tool and run the tests.
75- docker-compose run --rm ubuntu-18.04-llvm-6.0
108+ docker-compose run --rm ubuntu-18.04-llvm-6.0 ./script/test.sh
76109# Run the bindgen tool inside the container.
77- docker-compose run --rm ubuntu-18.04-llvm-6.0 bindgen/target/scala-native-bindgen -name union tests/samples/Union.h --
110+ docker-compose run --rm ubuntu-18.04-llvm-6.0 \
111+ bindgen/target/scala-native-bindgen --name union tests/samples/Union.h --
78112```
79113
80114 [ CMake ] : https://cmake.org/
@@ -85,17 +119,19 @@ docker-compose run --rm ubuntu-18.04-llvm-6.0 bindgen/target/scala-native-bindge
85119
86120## Testing
87121
88- The tests assume that the above instructions for building has been
89- followed.
122+ The tests assume that the above instructions for building ` scala-native-bindgen ` from source
123+ has been followed.
90124
91125``` sh
92126cd tests
93127sbt test
94128```
95129
96- ## Current limitations
130+ ## Limitations
131+
97132There are multiple unsupported cases that should be considered when generating bindings:
98- 1 . Currently bindgen does not support passing structs by value.
133+
134+ 1 . Currently bindgen does not support passing structs by value.
99135 For example, it will not be possible to call these two functions from Scala Native code:
100136 ``` c
101137 struct MyStruct {
@@ -107,12 +143,26 @@ There are multiple unsupported cases that should be considered when generating b
107143 void handleStruct(struct MyStruct mystr);
108144 ```
109145 To support such cases one should generate bindings for C wrapper functions that use pointers to structs instead of actual structs.
110- 2 . Bindgen does not generate bindings for defines.
111- In order to use defines one should write wrapper functions that return defined values.
112- 3 . There is no way to reuse already generated bindings.
113- Bindgen outputs bindings also for headers that were included in a given header.
114- 4 . Type qualifiers ` const ` , ` volatile ` and ` restrict ` are not supported.
115- 5 . Extern variables are read-only.
146+ 2 . ` #define ` s for literals and variables are supported. For other types of ` #define ` s,
147+ write wrapper functions that return defined values.
148+ ``` c
149+ // Supported
150+ #define ESC 0x1b /* Defines for numerical and string literals. * /
151+ extern const int pi_const;
152+ #define PI pi_const /* Defines aliasing extern variables. * /
153+
154+ // Not supported (non-exhaustive list)
155+ #define COLS (getenv("COLS") ? atoi(getenv("COLS")) : 80)
156+ #define MAX (a, b ) (a > b ? a : b)
157+ ```
158+
159+ 3 . There is no way to reuse already generated bindings.
160+ Bindgen outputs bindings also for headers that were included in a given header. See [#2 ].
161+ 4 . Type qualifiers `const `, `volatile ` and `restrict ` are not supported.
162+ 5 . Extern variables are read-only. See [scala-native/scala-native#202 ].
163+
164+ [#2 ]: https:// github.com/kornilova-l/scala-native-bindgen/issues/2
165+ [scala-native/scala-native#202 ]: https:// github.com/scala-native/scala-native/issues/202
116166
117167## License
118168
0 commit comments