Skip to content

Commit c19b032

Browse files
committed
Reorganize the documentation
1 parent b4e14e3 commit c19b032

File tree

20 files changed

+182
-191
lines changed

20 files changed

+182
-191
lines changed

CONTRIBUTING.md

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ cd tests
3030
sbt ~test
3131
```
3232

33+
To run the same tests as is run by Travis CI use the `test.sh` script, which will both build the executable and run `sbt verify`:
34+
35+
```sh
36+
./scripts/test.sh
37+
```
38+
3339
## Coding Guidelines
3440

3541
Code should be formatted with `./scripts/scalafmt` and `./scripts/clangfmt`.

build.sbt

+3
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,17 @@ lazy val docs = project("docs")
168168
.enablePlugins(GhpagesPlugin, ParadoxSitePlugin, ParadoxMaterialThemePlugin)
169169
.settings(
170170
publish / skip := true,
171+
scalaVersion := Versions.scala211,
171172
Paradox / paradoxProperties ++= Map(
172173
"github.base_url" -> scmInfo.value.get.browseUrl.toString
173174
),
174175
ParadoxMaterialThemePlugin.paradoxMaterialThemeSettings(Paradox),
175176
Paradox / paradoxMaterialTheme := {
177+
val licenseUrl = scmInfo.value.get.browseUrl.toString + "blob/master/LICENSE.txt"
176178
(Paradox / paradoxMaterialTheme).value
177179
.withRepository(scmInfo.value.get.browseUrl.toURI)
178180
.withColor("indigo", "indigo")
181+
.withCopyright(s"Copyright © Liudmila Kornilova, distributed under the <a href='$licenseUrl'>Scala license</a>.")
179182
}
180183
)
181184

docs/src/paradox/cli.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Generating Bindings with the CLI
2+
3+
Statically linked executables are provided with each release for Linux and macOS. Head over to the [releases page] to download the latest version for your platform.
4+
5+
[releases page]: https://github.com/kornilova-l/scala-native-bindgen/releases
6+
7+
@@@ note
8+
9+
In the following we assume you have renamed the downloaded `scala-native-bindgen-$PLATFORM` file to `scala-native-bindgen`.
10+
11+
@@@
12+
13+
## Command Line Usage
14+
15+
When generating bindings with the CLI, you need to specify the header file and provide the name of the created bindings using the `--name` option:
16+
17+
```sh
18+
scala-native-bindgen --name fnmatch /usr/include/fnmatch.h --
19+
```
20+
21+
When running the CLI it will also yield warnings along with the translation. To keep only the bindings please redirect the output to a file like this:
22+
23+
```sh
24+
scala-native-bindgen --name fnmatch /usr/include/fnmatch.h -- > fnmatch.scala
25+
```
26+
27+
By default it is assumed that you want to link with a library based on the name option.
28+
In case the name of the library to link with is different from the binding name provide the library name using `--link`:
29+
30+
```sh
31+
scala-native-bindgen --name zlib --link z /usr/include/zlib.h --
32+
```
33+
34+
If the binding does not require any linking, pass `--no-link`:
35+
36+
```sh
37+
scala-native-bindgen --name fnmatch --no-link /usr/include/fnmatch.h --
38+
```
39+
40+
For libraries that require linking you m
41+
42+
## Options
43+
44+
The generated bindings can be configured using the different options and it is also possible to pass arguments directly to the Clang compiler using the `--extra-arg*` options.
45+
46+
| Option | Description
47+
|----------------------|---------------------------------------------------------------------------------|
48+
| `--link` | Library to link with, e.g. `--link` uv for libuv.
49+
| `--no-link` | Library does not require linking.
50+
| `--name` | Scala object name that contains bindings. Default value set to library name.
51+
| `--package` | Package name of generated Scala file.
52+
| `--exclude-prefix` | Functions and unused typedefs will be removed if their names have given prefix.
53+
| `--binding-config` | Path to a config file that contains the information about bindings that should be reused. See @ref:[Integrating Bindings](integrating-bindings.md) for more information.
54+
| `--extra-arg` | Additional argument to append to the compiler command line.
55+
| `--extra-arg-before` | Additional argument to prepend to the compiler command line.

docs/src/paradox/command-line-usage/index.md

-26
This file was deleted.

docs/src/paradox/obtaining-bindgen/cmake.md renamed to docs/src/paradox/contrib/cmake.md

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Building with `CMake`
1+
# Building the executable with `CMake`
22

33
Building `scala-native-bindgen` requires the following tools and libraries:
44

@@ -40,16 +40,6 @@ equivalent, e.g. to compile with debug symbols the following are the same:
4040
```sh
4141
cmake -DCMAKE_CXX_FLAGS=-g ..
4242
CXXFLAGS=-g cmake ..
43-
```
44-
45-
## Testing
46-
47-
The tests assume that the above instructions for building `scala-native-bindgen` from source
48-
has been followed.
49-
50-
```sh
51-
cd tests
52-
sbt test
5343
```
5444

5545
[CMake]: https://cmake.org/

docs/src/paradox/obtaining-bindgen/docker-compose.md renamed to docs/src/paradox/contrib/docker-compose.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Building with `docker-compose`
1+
# Building the executable with `docker-compose`
22

33
You can use [docker-compose] to build and test the program:
44

@@ -11,4 +11,5 @@ docker-compose run --rm ubuntu-18.04-llvm-6.0 ./script/test.sh
1111
docker-compose run --rm ubuntu-18.04-llvm-6.0 \
1212
bindgen/target/scala-native-bindgen --name union tests/samples/Union.h --
1313
```
14+
1415
[docker-compose]: https://docs.docker.com/compose/
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../CONTRIBUTING.md

docs/src/paradox/contrib/index.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Contributor's Guide
2+
3+
Contributions to the project is very welcome. This section provides more
4+
information about how to build and contribute to the project.
5+
6+
@@ toc
7+
8+
@@@ index
9+
10+
* [guidelines](guidelines.md)
11+
* [cmake](cmake.md)
12+
* [docker-compose](docker-compose.md)
13+
* [releasing](releasing.md)
14+
15+
@@@

docs/src/paradox/contrib/releasing.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Release Workflow
2+
3+
First build the `scala-native-bindgen` executable for both macOS and
4+
Linux:
5+
6+
```sh
7+
scripts/prepare-release.sh
8+
```
9+
10+
You should now have `scala-native-bindgen-linux` and
11+
`scala-native-bindgen-darwin` if you ran the script on a macOS machine.
12+
13+
Then release version `x.y.z` by running:
14+
15+
```sh
16+
sbt -Dproject.version=x.y.z release
17+
```
18+
19+
Finally, upload the `scala-native-bindgen-linux` and
20+
`scala-native-bindgen-darwin` executables to the release page at:
21+
<https://github.com/kornilova-l/scala-native-bindgen/releases/tag/vx.y.z>

docs/src/paradox/index.md

+27-11
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
11
# Scala Native Bindgen
22

3-
@@@ index
4-
5-
* [Obtaining Bindgen](obtaining-bindgen/index.md)
6-
* [Command Line Usage](command-line-usage/index.md)
7-
* [Integrating Bindings](integrating-bindings/index.md)
8-
* [Limitations](limitations/index.md)
9-
* [Using Generated Bindings](using-generated-bindings/README.md)
3+
Scala Native Bindgen is a binding generator for Scala Native that uses [Clang] to
4+
parse C header files and generates Scala binding definitions.
105

11-
@@@
6+
## Features
127

13-
This tool generates Scala Native bindings from C headers.
14-
It's built upon clang and [LibTooling] and thus respects the conventions of clang-tools.
8+
* possibility to reuse types from existing bindings.
9+
* type casts that make recursive structs be valid Scala Native structs.
10+
* implicit classes for structs and unions that make fields access easier.
11+
* implicit classes that add setters and getters to structs with more than 22 fields (such structs in Scala
12+
Native are represented as arrays of bytes).
13+
* literal defines embedding `#define MY_CONSTANT 42``val MY_CONSTANT: native.CInt = 42`.
14+
* read-only bindings for extern variables (such variables cannot be updated due to Scala Native limitation).
15+
* declarations filtering by prefix.
1516

1617
## License
1718

1819
This project is distributed under the Scala license.
1920
@github[See LICENSE.txt for details](/LICENSE.txt)
2021

21-
[LibTooling]: https://clang.llvm.org/docs/LibTooling.html
22+
[Clang]: https://clang.llvm.org/
23+
24+
## Table of Contents
25+
26+
@@ toc
27+
28+
@@@ index
29+
30+
* [sbt](sbt.md)
31+
* [cli](cli.md)
32+
* [Using Generated Bindings](using-generated-bindings.md)
33+
* [Integrating Bindings](integrating-bindings.md)
34+
* [Limitations](limitations.md)
35+
* [Contributor's Guide](contrib/index.md)
36+
37+
@@@

docs/src/paradox/integrating-bindings/index.md renamed to docs/src/paradox/integrating-bindings.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Integrating Bindings
22

33
To reuse already generated bindings create a `config.json` file that defines which headers correspond to which Scala objects:
4+
45
```json
56
{
67
"_stdio.h": "scala.scalanative.native.stdio",
@@ -10,6 +11,7 @@ To reuse already generated bindings create a `config.json` file that defines whi
1011

1112
Bindgen assumes that type names in header files match type names in generated binding (spaces in struct, union and enum
1213
names are replaces with underscores), but it is possible to specify custom names mapping:
14+
1315
```json
1416
{
1517
"hiredis.h": {
@@ -22,4 +24,4 @@ names are replaces with underscores), but it is possible to specify custom names
2224
```
2325

2426
Provide a path to `config.json` to bindgen using `--binding-config` command-line option or `NativeBinding.bindingConfig`
25-
sbt plugin option (see @ref:[Using the sbt plugin](../obtaining-bindgen/sbt-plugin.md)).
27+
sbt plugin option (see @ref:[Using the sbt plugin](sbt.md)).

docs/src/paradox/limitations/index.md renamed to docs/src/paradox/limitations.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
There are multiple unsupported cases that should be considered when generating bindings.
44

5+
@@ toc
6+
57
## Passing structs by value
68

79
Scala Native does not support passing structs by value, bindgen skips such functions.

docs/src/paradox/obtaining-bindgen/docker-container.md

-32
This file was deleted.

docs/src/paradox/obtaining-bindgen/index.md

-20
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Using the sbt plugin
1+
# Generating Bindings with sbt
22

33
To add the sbt plugin to your project add the following lines in `project/plugins.sbt`:
44

@@ -27,31 +27,12 @@ nativeBindgenPath := file("/path/to/scala-native-bindgen")
2727

2828
Example settings:
2929

30-
```sbt
31-
enablePlugins(ScalaNativeBindgenPlugin)
32-
inConfig(Compile)(
33-
Def.settings(
34-
nativeBindings += {
35-
NativeBinding((resourceDirectory in Compile).value / "header.h")
36-
.name("MyLib")
37-
.packageName("org.example.mylib")
38-
.link("mylib"), // Will pass `-lmylib` to the linker
39-
.excludePrefix("__")
40-
}
41-
))
42-
```
30+
@@snip [sbt] (../../../sbt-scala-native-bindgen/src/sbt-test/bindgen/generate/build.sbt) { #example }
4331

44-
Running `nativeBindgen` will generate a file named `target/scala-2.x/src_managed/main/sbt-scala-native-bindgen/MyLib.scala` containing something along the following lines:
32+
Given that the `stdlib.h` header file contains:
4533

46-
```scala
47-
package org.example.mylib
34+
@@snip [sbt] (../../../sbt-scala-native-bindgen/src/sbt-test/bindgen/generate/src/main/resources/stdlib.h)
4835

49-
import scala.scalanative._
50-
import scala.scalanative.native._
36+
Running `nativeBindgen` will generate a file named `target/scala-2.11/src_managed/main/sbt-scala-native-bindgen/stdlib.scala` containing something along the following lines:
5137

52-
@native.link("mylib")
53-
@native.extern
54-
object MyLib {
55-
// ... left out for brevity ...
56-
}
57-
```
38+
@@snip [sbt] (../../../sbt-scala-native-bindgen/src/sbt-test/bindgen/generate/expected/stdlib.scala)

0 commit comments

Comments
 (0)