|
| 1 | +# Obtaining bindgen |
| 2 | + |
| 3 | +There are 2 ways to obtain bindgen: |
| 4 | + * [Use docker container](#docker-container) |
| 5 | + * [Build binary with CMake](#building-with-cmake) |
| 6 | + * [Build binary with docker-compose](#building-with-docker-compose) |
| 7 | + |
| 8 | +## Docker container |
| 9 | + |
| 10 | +This option requires [Docker]. |
| 11 | + |
| 12 | +Download docker image with the binary: |
| 13 | + |
| 14 | +```sh |
| 15 | +docker pull scalabindgen/scala-native-bindgen |
| 16 | +``` |
| 17 | + |
| 18 | +Mount directories with required header files and run bindgen: |
| 19 | + |
| 20 | +```sh |
| 21 | +docker run -v "$(pwd)":/src -v /usr/include:/usr/include \ |
| 22 | + --rm scalabindgen/scala-native-bindgen \ |
| 23 | + relative/path/to/my_header.h --name my_header -- |
| 24 | +``` |
| 25 | + |
| 26 | +The docker image does not contain standard headers so it is important to |
| 27 | +mount all system include directories that are used by the header file |
| 28 | +passed to `scala-native-bindgen`. See the [docker-bindgen.sh] script for |
| 29 | +how to wrap the dockerized program. The `$CWD` of the container is |
| 30 | +`/src` which should be mounted from `$(pwd)` in case relative paths are |
| 31 | +used. |
| 32 | + |
| 33 | +Note, the `scalabindgen/scala-native-bindgen:latest` image is updated on |
| 34 | +each merge to the `master` branch. |
| 35 | + |
| 36 | + [Docker]: https://www.docker.com/ |
| 37 | + [docker-bindgen.sh]: scripts/docker-bindgen.sh |
| 38 | + |
| 39 | +## Building with `CMake` |
| 40 | + |
| 41 | +Building `scala-native-bindgen` requires the following tools and libraries: |
| 42 | + |
| 43 | + - [CMake] version 3.9 or higher |
| 44 | + - [LLVM] and [Clang] version 5.0 or 6.0. |
| 45 | + |
| 46 | +```sh |
| 47 | +# On apt-based systems |
| 48 | +apt install cmake clang-$LLVM_VERSION libclang-$LLVM_VERSION-dev llvm-$LLVM_VERSION-dev |
| 49 | + |
| 50 | +# With `brew` |
| 51 | +brew install cmake llvm@6 |
| 52 | +``` |
| 53 | + |
| 54 | +To run the tests you also need the required Scala Native libraries. |
| 55 | +See the [Scala Native setup guide] for instructions on installing the dependencies. |
| 56 | + |
| 57 | +```sh |
| 58 | +mkdir -p bindgen/target |
| 59 | +cd bindgen/target |
| 60 | +cmake .. |
| 61 | +make |
| 62 | +./scala-native-bindgen --name ctype /usr/include/ctype.h -- |
| 63 | +``` |
| 64 | + |
| 65 | +To build a statically linked executable pass `-DSTATIC_LINKING=ON` when invoking `cmake`: |
| 66 | + |
| 67 | +```sh |
| 68 | +cmake -DSTATIC_LINKING=ON .. |
| 69 | +``` |
| 70 | + |
| 71 | +Additional compiler and linker flags may be passed as environment variable sor their CMake |
| 72 | +equivalent, e.g. to compile with debug symbols the following are the same: |
| 73 | + |
| 74 | +```sh |
| 75 | +cmake -DCMAKE_CXX_FLAGS=-g .. |
| 76 | +CXXFLAGS=-g cmake .. |
| 77 | +``` |
| 78 | + |
| 79 | +## Building with `docker-compose` |
| 80 | + |
| 81 | +Alternatively, you can use [docker-compose] to build and test the program: |
| 82 | + |
| 83 | +```sh |
| 84 | +# Build the docker image with LLVM version 6.0. |
| 85 | +docker-compose build ubuntu-18.04-llvm-6.0 |
| 86 | +# Build the bindgen tool and run the tests. |
| 87 | +docker-compose run --rm ubuntu-18.04-llvm-6.0 ./script/test.sh |
| 88 | +# Run the bindgen tool inside the container. |
| 89 | +docker-compose run --rm ubuntu-18.04-llvm-6.0 \ |
| 90 | + bindgen/target/scala-native-bindgen --name union tests/samples/Union.h -- |
| 91 | +``` |
| 92 | + |
| 93 | + [CMake]: https://cmake.org/ |
| 94 | + [LLVM]: https://llvm.org/ |
| 95 | + [Clang]: https://clang.llvm.org/ |
| 96 | + [Scala Native setup guide]: http://www.scala-native.org/en/latest/user/setup.html |
| 97 | + [docker-compose]: https://docs.docker.com/compose/ |
| 98 | + |
| 99 | +## Testing |
| 100 | + |
| 101 | +The tests assume that the above instructions for building `scala-native-bindgen` from source |
| 102 | +has been followed. |
| 103 | + |
| 104 | +```sh |
| 105 | +cd tests |
| 106 | +sbt test |
| 107 | +``` |
0 commit comments