Skip to content

Commit 3555d85

Browse files
committed
Builder API
1 parent 4d30963 commit 3555d85

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

build.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,5 @@ lazy val samples = project
8585
(Test / compile).value
8686
}
8787
)
88+
89+
lazy val tools = project in file("tools")
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.scalanative.bindgen
2+
3+
import java.io.{File, PrintWriter}
4+
5+
class Bindings(private val bindings: String) {
6+
def writeToFile(pathToFile: String): Unit = {
7+
val pw = new PrintWriter(new File(pathToFile))
8+
try {
9+
pw.write(bindings)
10+
} finally {
11+
pw.close()
12+
}
13+
}
14+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package org.scalanative.bindgen
2+
3+
import scala.collection.mutable
4+
5+
class Builder {
6+
private var library: String = _
7+
private var pathToHeader: String = _
8+
private var packageName: String = _
9+
private var excludePrefix: String = _
10+
private var extraArg: mutable.Seq[String] = mutable.Seq()
11+
private var extraArgBefore: mutable.Seq[String] = mutable.Seq()
12+
13+
/**
14+
* Set header file for which bindings will be generated
15+
*/
16+
def header(pathToHeader: String): Unit = {
17+
this.pathToHeader = pathToHeader
18+
}
19+
20+
/**
21+
* Library to link with, e.g. -luv for libuv
22+
*/
23+
def link(library: String): Unit = {
24+
this.library = library
25+
}
26+
27+
/**
28+
* Package name of generated Scala file
29+
*/
30+
def packageName(packageName: String): Unit = {
31+
this.packageName = packageName
32+
}
33+
34+
/**
35+
* Declarations will be removed if their names
36+
* contain given prefix
37+
*/
38+
def excludePrefix(prefix: String): Unit = {
39+
if (!prefix.isEmpty) {
40+
excludePrefix = prefix
41+
}
42+
}
43+
44+
/**
45+
* Additional argument to append to the compiler command line
46+
*/
47+
def extraArg(arg: String): Unit = {
48+
if (!arg.isEmpty) {
49+
extraArg += arg
50+
}
51+
}
52+
53+
/**
54+
* Additional argument to append to the compiler command line
55+
*/
56+
def extraArgBefore(arg: String): Unit = {
57+
if (!arg.isEmpty) {
58+
extraArgBefore += arg
59+
}
60+
}
61+
62+
/**
63+
* Run binding generator
64+
*/
65+
def generate(): Bindings = {
66+
// TODO: generate bindings
67+
new Bindings("")
68+
}
69+
}
70+
71+
object Builder {
72+
def apply(): Builder = new Builder()
73+
}

0 commit comments

Comments
 (0)