Skip to content

Commit ca580ff

Browse files
authored
Merge pull request #187 from scala-native/more-binding-doc-improvements
More binding doc improvements
2 parents c42019e + a16068f commit ca580ff

File tree

8 files changed

+50
-18
lines changed

8 files changed

+50
-18
lines changed

bindings/posix/src/main/scala/org/scalanative/bindgen/bindings/posix/regex.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ object regex {
5454
def rm_eo: regoff_t = !p._2
5555
def rm_eo_=(value: regoff_t): Unit = !p._2 = value
5656
}
57-
def struct_regmatch_t()(implicit z: native.Zone): native.Ptr[struct_regmatch_t] = native.alloc[struct_regmatch_t]
57+
}
58+
59+
object struct_regmatch_t {
60+
import implicits._
61+
def apply()(implicit z: native.Zone): native.Ptr[struct_regmatch_t] = native.alloc[struct_regmatch_t]
62+
def apply(rm_so: regoff_t, rm_eo: regoff_t)(implicit z: native.Zone): native.Ptr[struct_regmatch_t] = {
63+
val ptr = native.alloc[struct_regmatch_t]
64+
ptr.rm_so = rm_so
65+
ptr.rm_eo = rm_eo
66+
ptr
67+
}
5868
}
5969
}

build.sbt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,23 +215,30 @@ lazy val bindings = project("bindings")
215215
lazy val libiconv = bindingProject("iconv")
216216
.configure(binding("iconv.h"))
217217
.settings(
218-
Test / nativeLinkingOptions ++= {
219-
// Link with libiconv on macOS.
218+
//#sbt-iconv-linking-options
219+
Compile / nativeLinkingOptions ++= {
220220
Option(System.getProperty("os.name")) match {
221221
case Some("Mac OS X") => Seq("-liconv")
222222
case _ => Seq.empty
223223
}
224224
}
225+
//#sbt-iconv-linking-options
226+
,
227+
Test / nativeLinkingOptions ++= {
228+
(Compile / nativeLinkingOptions).value
229+
}
225230
)
226231

227-
//#sbt-binding-project
232+
//#sbt-binding-project-multi-header
228233
lazy val libposix = bindingProject("posix")
229234
.configure(binding("fnmatch.h"))
230235
.configure(binding("regex.h"))
231-
//#sbt-binding-project
236+
//#sbt-binding-project-multi-header
232237

238+
//#sbt-binding-project
233239
lazy val libutf8proc = bindingProject("utf8proc")
234240
.configure(binding("utf8proc.h", Some("utf8proc")))
241+
//#sbt-binding-project
235242

236243
def project(name: String, plugged: AutoPlugin*) = {
237244
val unplugged = Seq(ScriptedPlugin).filterNot(plugged.toSet)

docs/src/paradox/bindings/iconv.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
# Iconv - Character set conversion
1+
# iconv
2+
3+
The [`iconv.h`] binding allows to convert text between different character sets, for example convert text from UTF-8 to ISO-8859-1.
24

35
To use this binding add the following resolver and the dependency:
46

57
@@binding[iconv]
68

7-
The [`iconv.h`] header allows to convert text between different character sets, for example UTF-8 to ISO-8859-1.
9+
You also need to configure your build tool to link with the iconv library on macOS.
10+
For sbt, you can use the following code:
11+
12+
@@snip[sbt-iconv](../../../../build.sbt) { #sbt-iconv-linking-options }
813

914
## Example
1015

docs/src/paradox/bindings/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
The following bindings have been generated with bindgen.
44

5+
If you would like to contribute a binding see the @ref:[Contributing Bindings] page.
6+
57
@@ toc { depth=1 }
68

79
@@@ index
@@ -10,4 +12,6 @@ The following bindings have been generated with bindgen.
1012
* [iconv](iconv.md)
1113
* [utf8proc](utf8proc.md)
1214

13-
@@@
15+
@@@
16+
17+
[Contributing Bindings]: ../contrib/bindings.md

docs/src/paradox/bindings/posix.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# POSIX
22

3-
An addition to Scala Native's [POSIX](http://www.scala-native.org/en/latest/lib/posixlib.html) bindings. To use one of the POSIX bindings you must add the resolver and the dependency:
3+
An addition to Scala Native's [POSIX](http://www.scala-native.org/en/latest/lib/posixlib.html) bindings.
4+
5+
To use this binding add the following resolver and dependency:
46

57
@@binding[posix]
68

docs/src/paradox/bindings/utf8proc.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# Utf8proc - UTF-8 text processing
1+
# utf8proc
22

3-
This binding for [`utf8proc.h`] provides Unicode normalization, case-folding, and other operations for strings in the UTF-8 encoding.
3+
The [utf8proc] binding provides Unicode normalization, case-folding, and other operations for strings in the UTF-8 encoding.
44

5-
To use it add the following resolver and the dependency:
5+
To use this binding add the following resolver and dependency:
66

77
@@binding[utf8proc]
88

99
## Example
1010

1111
@@snip [iconv](../../../../bindings/utf8proc/src/test/scala/org/scalanative/bindgen/bindings/tests/Utf8procSpec.scala) { #usage-example }
1212

13-
[`utf8proc.h`]: https://juliastrings.github.io/utf8proc/doc/
13+
[utf8proc]: https://juliastrings.github.io/utf8proc/doc/

docs/src/paradox/contrib/bindings.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
## Adding a new Bindings
44

5-
To add a new binding add a new project in `build.sbt` with the name of the artifact as well as a binding configuration for each header file and optionally the library to link with. The following example shows how it is possible to generate multiple bindings per project. For most libraries a single binding should be sufficient.
5+
To add a new binding, add a new project in `build.sbt` with the name of the artifact as well as a binding configuration for each header file and optionally the library to link with.
66

77
@@snip [build.sbt](../../../../build.sbt) { #sbt-binding-project }
88

9+
It is also possible to generate multiple bindings per project. For most libraries a single binding should be sufficient.
10+
11+
@@snip [build.sbt](../../../../build.sbt) { #sbt-binding-project-multi-header }
12+
913
The new sbt project should also be added to the `bindings` project's list of aggregated projects.
1014

1115
Optionally update the top-level `Dockerfile` to install the binding library's `-dev` package.
@@ -22,16 +26,16 @@ Next, run `nativeBindgen` to generate the bindings. Note, to ensure consistency
2226
This can be done by running:
2327

2428
```sh
25-
docker-compose run --rm ubuntu-18.04-llvm-6.0 sbt bindings/$BINDING/nativeBindgen
29+
docker-compose run --rm ubuntu-18.04-llvm-6.0 sbt lib$BINDING/nativeBindgen
2630
```
2731

2832
Then write tests for the generated bindings. The test class should be in the `org.scalanative.bindgen.bindings.tests` package to make it easier to write examples for the binding documentation. Verify that the tests pass:
2933

3034
```sh
31-
docker-compose run --rm ubuntu-18.04-llvm-6.0 sbt bindings/$BINDING/test
35+
docker-compose run --rm ubuntu-18.04-llvm-6.0 sbt lib$BINDING/test
3236
```
3337

34-
Finally, add a page in the `bindings` folder and document the binding, ideally with an example or two of how to use it.
38+
Finally, add a Markdown file in the `bindings` folder and document the binding, ideally with an example or two of how to use it. Remember to add the new file to the index in `bindings/index.md`.
3539

3640
## Update all Bindings
3741

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0")
99

1010
libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
1111

12-
val VERSION = "0.3.0"
12+
val VERSION = "0.3.1"
1313

1414
//#sbt-plugin-example
1515
addSbtPlugin("org.scala-native.bindgen" % "sbt-scala-native-bindgen" % VERSION)

0 commit comments

Comments
 (0)