Skip to content

Commit d3d288d

Browse files
committed
Reorganize the documentation
1 parent b4e14e3 commit d3d288d

File tree

29 files changed

+436
-377
lines changed

29 files changed

+436
-377
lines changed

.scalafmt.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ docstrings = JavaDoc
33
assumeStandardLibraryStripMargin = true
44
project.excludeFilters = [
55
tests/samples
6+
"docs/src/test/scala/org/example/.*[.]scala"
7+
"sbt-scala-native-bindgen/.*/expected/.*[.]scala"
68
]
79
project.git = true
810
runner.dialect = Scala211

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
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

Lines changed: 66 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import scala.sys.process._
2+
import org.scalanative.bindgen.sbt.ScalaNativeBindgenPlugin
23

3-
addCommandAlias("verify", "; ^test:compile ; ^test ; ^scripted ; docs/makeSite")
4+
addCommandAlias("verify",
5+
"; tests/test ; docs/test ; ^scripted ; docs/makeSite")
46

57
val Versions = new {
68
val scala210 = "2.10.6"
@@ -88,6 +90,7 @@ lazy val tests = project("tests")
8890
),
8991
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % Test
9092
)
93+
.aggregate(samples)
9194

9295
lazy val samples = project("samples")
9396
.in(file("tests/samples"))
@@ -98,47 +101,7 @@ lazy val samples = project("samples")
98101
libraryDependencies += "com.lihaoyi" %%% "utest" % "0.6.3" % "test",
99102
testFrameworks += new TestFramework("utest.runner.Framework"),
100103
nativeLinkStubs := true,
101-
Test / nativeLinkingOptions += {
102-
Seq("-L", (Test / target).value.getAbsoluteFile / "bindgen").mkString
103-
},
104-
Test / compile := {
105-
val log = streams.value.log
106-
val cwd = (Test / target).value / "bindgen"
107-
val compileOptions = (Test / nativeCompileOptions).value
108-
val cpaths = (baseDirectory.value.getAbsoluteFile * "*.c").get
109-
val clangPath = nativeClang.value.toPath.toAbsolutePath.toString
110-
111-
cwd.mkdirs()
112-
113-
def abs(path: File): String =
114-
path.getAbsolutePath
115-
116-
def run(command: Seq[String]): Int = {
117-
log.info("Running " + command.mkString(" "))
118-
Process(command, cwd) ! log
119-
}
120-
121-
val opaths = cpaths.map { cpath =>
122-
val opath = abs(cwd / s"${cpath.getName}.o")
123-
val command = Seq(clangPath) ++ compileOptions ++ Seq("-c",
124-
abs(cpath),
125-
"-o",
126-
opath)
127-
128-
if (run(command) != 0) {
129-
sys.error(s"Failed to compile $cpath")
130-
}
131-
opath
132-
}
133-
134-
val archivePath = cwd / "libbindgentests.a"
135-
val archive = Seq("ar", "cr", abs(archivePath)) ++ opaths
136-
if (run(archive) != 0) {
137-
sys.error(s"Failed to create archive $archivePath")
138-
}
139-
140-
(Test / compile).value
141-
}
104+
compileTask("bindgentests", baseDirectory)
142105
)
143106

144107
lazy val tools = project("tools")
@@ -166,16 +129,33 @@ lazy val sbtPlugin = project("sbt-scala-native-bindgen", ScriptedPlugin)
166129

167130
lazy val docs = project("docs")
168131
.enablePlugins(GhpagesPlugin, ParadoxSitePlugin, ParadoxMaterialThemePlugin)
132+
.enablePlugins(ScalaNativePlugin, ScalaNativeBindgenPlugin)
169133
.settings(
170134
publish / skip := true,
135+
scalaVersion := Versions.scala211,
136+
// FIXME: Remove when a version has been released with Test scope settings.
137+
ScalaNativeBindgenPlugin.nativeBindgenScopedSettings(Test),
138+
Test / nativeBindings += {
139+
NativeBinding((Test / resourceDirectory).value / "vector.h")
140+
.name("vector")
141+
.link("vector")
142+
.packageName("org.example")
143+
},
144+
Test / nativeBindgen / target := (Test / scalaSource).value / "org/example",
145+
nativeLinkStubs := true,
146+
compileTask("vector", Test / resourceDirectory),
147+
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.2.0-SNAP10" % Test,
171148
Paradox / paradoxProperties ++= Map(
172149
"github.base_url" -> scmInfo.value.get.browseUrl.toString
173150
),
174151
ParadoxMaterialThemePlugin.paradoxMaterialThemeSettings(Paradox),
175152
Paradox / paradoxMaterialTheme := {
153+
val licenseUrl = scmInfo.value.get.browseUrl.toString + "blob/master/LICENSE.txt"
176154
(Paradox / paradoxMaterialTheme).value
177155
.withRepository(scmInfo.value.get.browseUrl.toURI)
178156
.withColor("indigo", "indigo")
157+
.withCopyright(
158+
s"Copyright © Liudmila Kornilova, distributed under the <a href='$licenseUrl'>Scala license</a>.")
179159
}
180160
)
181161

@@ -209,3 +189,47 @@ def project(name: String, plugged: AutoPlugin*) = {
209189

210190
lazy val setReleaseVersions: String => State => State =
211191
v => _.put(ReleaseKeys.versions, (v, v))
192+
193+
def compileTask(libname: String, srcDirTask: SettingKey[File]) = Def.settings(
194+
Test / nativeLinkingOptions += {
195+
Seq("-L", (Test / target).value.getAbsoluteFile / "bindgen").mkString
196+
},
197+
Test / compile := {
198+
val log = streams.value.log
199+
val cwd = (Test / target).value / "bindgen"
200+
val compileOptions = (Test / nativeCompileOptions).value
201+
val cpaths = (srcDirTask.value.getAbsoluteFile * "*.c").get
202+
val clangPath = nativeClang.value.toPath.toAbsolutePath.toString
203+
204+
cwd.mkdirs()
205+
206+
def abs(path: File): String =
207+
path.getAbsolutePath
208+
209+
def run(command: Seq[String]): Int = {
210+
log.info("Running " + command.mkString(" "))
211+
Process(command, cwd) ! log
212+
}
213+
214+
val opaths = cpaths.map { cpath =>
215+
val opath = abs(cwd / s"${cpath.getName}.o")
216+
val command = Seq(clangPath) ++ compileOptions ++ Seq("-c",
217+
abs(cpath),
218+
"-o",
219+
opath)
220+
221+
if (run(command) != 0) {
222+
sys.error(s"Failed to compile $cpath")
223+
}
224+
opath
225+
}
226+
227+
val archivePath = cwd / s"lib$libname.a"
228+
val archive = Seq("ar", "cr", abs(archivePath)) ++ opaths
229+
if (run(archive) != 0) {
230+
sys.error(s"Failed to create archive $archivePath")
231+
}
232+
233+
(Test / compile).value
234+
}
235+
)

docs/src/paradox/cli.md

Lines changed: 55 additions & 0 deletions
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

Lines changed: 0 additions & 26 deletions
This file was deleted.

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

Lines changed: 1 addition & 11 deletions
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

Lines changed: 2 additions & 1 deletion
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/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../CONTRIBUTING.md

docs/src/paradox/contrib/index.md

Lines changed: 15 additions & 0 deletions
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

Lines changed: 21 additions & 0 deletions
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

Lines changed: 27 additions & 11 deletions
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+
@@@

0 commit comments

Comments
 (0)