-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
198 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Command Line Usage | ||
|
||
Calling the tool is pretty easy, you need to specify the file(s) and the name of the created bindings. | ||
|
||
```sh | ||
scala-native-bindgen --name uv /usr/include/uv.h -- | ||
``` | ||
|
||
Running 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: | ||
|
||
```sh | ||
scala-native-bindgen --name uv /usr/include/uv.h -- > uv.scala | ||
``` | ||
|
||
## Bindgen Options | ||
|
||
| Option | Description | | ||
|----------------------|--------------------------------------------------------------------------------------------------------------| | ||
| `--link` | Library to link with, e.g. `--link` uv for libuv. | | ||
| `--no-link` | Library is static and does not require linking. | | ||
| `--name` | Scala object name that contains bindings. If `--no-link` is specified then `name` should match library name. | | ||
| `--package` | Package name of generated Scala file. | | ||
| `--exclude-prefix` | Functions and unused typedefs will be removed if their names have given prefix. | | ||
| `--extra-arg` | Additional argument to append to the compiler command line. | | ||
| `--extra-arg-before` | Additional argument to prepend to the compiler command line. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Scala Native Bindgen | ||
|
||
@@@ index | ||
|
||
* [Obtaining bindgen](obtaining-bindgen/index.md) | ||
* [Usage](command-line-usage/index.md) | ||
* [Limitations](limitations/index.md) | ||
|
||
@@@ | ||
|
||
This tool generates Scala Native bindings from C headers. | ||
It's built upon clang and [LibTooling] and thus respects the conventions of clang-tools. | ||
|
||
## License | ||
|
||
This project is distributed under the Scala license. | ||
@github[See LICENSE.txt for details](/LICENSE.txt) | ||
|
||
[LibTooling]: https://clang.llvm.org/docs/LibTooling.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
## Limitations | ||
|
||
There are multiple unsupported cases that should be considered when generating bindings: | ||
|
||
1. Currently bindgen does not support passing structs by value. | ||
For example, it will not be possible to call these two functions from Scala Native code: | ||
|
||
```c | ||
struct MyStruct { | ||
int a; | ||
}; | ||
|
||
struct MyStruct returnStruct(); | ||
|
||
void handleStruct(struct MyStruct mystr); | ||
``` | ||
To support such cases one should generate bindings for C wrapper functions that use pointers to structs instead of actual structs. | ||
2. `#define`s for literals and variables are supported. For other types of `#define`s, | ||
write wrapper functions that return defined values. | ||
|
||
```c | ||
// Supported | ||
#define ESC 0x1b /* Defines for numerical and string literals. */ | ||
extern const int pi_const; | ||
#define PI pi_const /* Defines aliasing extern variables. */ | ||
|
||
// Not supported (non-exhaustive list) | ||
#define COLS (getenv("COLS") ? atoi(getenv("COLS")) : 80) | ||
#define MAX(a, b) (a > b ? a : b) | ||
``` | ||
|
||
3. There is no way to reuse already generated bindings. | ||
Bindgen outputs bindings also for headers that were included in a given header. See @github[#2](#2). | ||
4. Type qualifiers `const`, `volatile` and `restrict` are not supported. | ||
5. Extern variables are read-only. See @github[scala-native/scala-native#202](scala-native/scala-native#202). |
Oops, something went wrong.