Skip to content

Commit

Permalink
Fix CI, add gobject fluent bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
keynmol committed Jan 11, 2025
1 parent 731362b commit bbe8e17
Show file tree
Hide file tree
Showing 37 changed files with 1,130 additions and 15 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,13 @@ jobs:
- name: Regenerate raw bindings in docker
run: sbt generateRawBindings && git diff


- name: Regenerate XSD schema
run: sbt generateIntrospectionSchema && git diff

- name: Regenerate XSD schema
run: sbt generateFluentBindings && git diff


mergify-build-checkpoint:
runs-on: ubuntu-24.04
needs: [ build, gen-check ]
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ ENV LLVM_BIN=/usr/lib/llvm-17/bin

WORKDIR /source/sn-bindgen
ENV SCALANATIVE_MODE=release-fast
ENV BINDGEN_REV=6068826558cd150ec3f3fc4a99ae1dbc5e2ec81b
ENV SN_BINDGEN_VERSION=0.2.0+1-60688265-SNAPSHOT
ENV BINDGEN_REV=v0.2.1
ENV SN_BINDGEN_VERSION=0.2.1
RUN git clone https://github.com/indoorvivants/sn-bindgen . && git checkout $BINDGEN_REV && sbt devPublish
RUN chmod +x /root/.ivy2/local/com.indoorvivants/bindgen_native0.5_3/$SN_BINDGEN_VERSION/jars/bindgen_native0.5_3-*.jar

Expand Down
11 changes: 7 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ lazy val gobject =
.withNoLocation(true)
.withMultiFile(true)
.addExcludedSystemPath(headerPath.toPath.getParent()),
}
},
girModuleName := "gobject-2.0",
withFluentBindings
)

lazy val pango =
Expand All @@ -229,8 +231,7 @@ lazy val pango =
.withMultiFile(true)
.addExcludedSystemPath(headerPath.toPath.getParent())
},
girModuleName := "pango-1.0"
// withFluentBindings
girModuleName := "pango-1.0",
)

lazy val gdkpixbuf =
Expand Down Expand Up @@ -342,7 +343,9 @@ lazy val harfbuzz =
.withNoLocation(true)
.withMultiFile(true)
.addExcludedSystemPath(headerPath.toPath.getParent())
}
},
girModuleName := "harfbuzz-0.0",
withFluentBindings
)

def generateXsd(
Expand Down
14 changes: 7 additions & 7 deletions fluent-generator/src/main/scala/FilterDefinitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ def filterDefinitions(
method: Option[Method] = None,
constructor: Option[Constructor] = None
): Option[String] =
val isiFltered = cls
.map(_.name)
.collect:
case "Application" => None
case other => Some(s"skipping $other")
.flatten
// val isiFltered = cls
// .map(_.name)
// .collect:
// case "Application" => None
// case other => Some(s"skipping $other")
// .flatten

return isiFltered
// return isiFltered

def isNamespace(name: String) =
namespace.exists(_.name.exists(n => n.equalsIgnoreCase(name)))
Expand Down
9 changes: 8 additions & 1 deletion fluent-generator/src/main/scala/main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ end config
case Right(value) =>
val root = os.Path(value.girFiles.toAbsolutePath())
val target = os.Path(value.out.toAbsolutePath())
os.makeDir.all(target)
val includeResolver = IncludeResolver(root.toNIO)
val reader = Reader(includeResolver)

Expand All @@ -69,12 +68,20 @@ end config

val nonEmptyFiles = List.newBuilder[os.Path]

val createTarget =
var created = false
() =>
if !created then
os.makeDir.all(target)
created = true

streams
.renderMapping()
.foreach: (relative, contents) =>
val filePath = target / relative
if contents.trim.nonEmpty then
scribe.debug(s"Rendering ${relative}")
createTarget()
os.write.over(filePath, contents)
nonEmptyFiles += filePath
else scribe.warn(s"Filepath $filePath was empty, not writing to disk")
Expand Down
28 changes: 28 additions & 0 deletions glib/src/main/scala/fluent/GResult.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package sn.gnome.glib.fluent

import sn.gnome.glib.internal.{GQuark, GError, g_error_free}
import scala.scalanative.unsafe.*

enum GResult[+A]:
case Error(domain: GQuark, code: Int, message: String)
case Ok(value: A)

object GResult:
inline def wrap[A](inline f: Ptr[Ptr[GError]] => A): GResult[A] =
val st = stackalloc[Ptr[GError]]()
val raw = f(st)
val errorPtr = !st

if errorPtr != null then
val err = !errorPtr
val result = GResult.Error(
err.domain,
err.code.value,
fromCString(err.message.asInstanceOf[CString])
)
g_error_free(errorPtr)
result
else Ok(raw)
end if
end wrap
end GResult
43 changes: 43 additions & 0 deletions gobject/src/main/scala/generated/fluent/Binding.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package sn.gnome.gobject.fluent

import _root_.sn.gnome.gobject.internal.*

import _root_.scala.scalanative.unsafe.*

import sn.gnome.glib.internal.gchar
import sn.gnome.gobject.fluent.Object
import sn.gnome.gobject.internal.GBinding
import sn.gnome.gobject.internal.GBindingFlags

class Binding(raw: Ptr[GBinding]) extends Object(raw.asInstanceOf):
override def getUnsafeRawPointer(): Ptr[Byte] = this.raw.asInstanceOf

def dupSource(): Object = new Object(
g_binding_dup_source(this.raw.asInstanceOf).asInstanceOf
)

def dupTarget(): Object = new Object(
g_binding_dup_target(this.raw.asInstanceOf).asInstanceOf
)

def getFlags(): GBindingFlags = g_binding_get_flags(this.raw.asInstanceOf)

def getSource(): Object = new Object(
g_binding_get_source(this.raw.asInstanceOf).asInstanceOf
)

def getSourceProperty()(using Zone): String = fromCString(
g_binding_get_source_property(this.raw.asInstanceOf).asInstanceOf
)

def getTarget(): Object = new Object(
g_binding_get_target(this.raw.asInstanceOf).asInstanceOf
)

def getTargetProperty()(using Zone): String = fromCString(
g_binding_get_target_property(this.raw.asInstanceOf).asInstanceOf
)

def unbind(): Unit = g_binding_unbind(this.raw.asInstanceOf)

end Binding
93 changes: 93 additions & 0 deletions gobject/src/main/scala/generated/fluent/BindingGroup.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package sn.gnome.gobject.fluent

import _root_.sn.gnome.gobject.internal.*

import _root_.scala.scalanative.unsafe.*

import sn.gnome.glib.internal.GDestroyNotify
import sn.gnome.glib.internal.gchar
import sn.gnome.glib.internal.gpointer
import sn.gnome.gobject.fluent.Object
import sn.gnome.gobject.internal.GBindingFlags
import sn.gnome.gobject.internal.GBindingGroup
import sn.gnome.gobject.internal.GBindingTransformFunc
import sn.gnome.gobject.internal.GClosure

class BindingGroup(raw: Ptr[GBindingGroup]) extends Object(raw.asInstanceOf):
override def getUnsafeRawPointer(): Ptr[Byte] = this.raw.asInstanceOf

def bind(
source_property: String | CString,
target: Object,
target_property: String | CString,
flags: GBindingFlags
)(using Zone): Unit = g_binding_group_bind(
this.raw.asInstanceOf,
__sn_extract_string(source_property).asInstanceOf[Ptr[gchar]],
gpointer(target.getUnsafeRawPointer().asInstanceOf.asInstanceOf[Ptr[Byte]]),
__sn_extract_string(target_property).asInstanceOf[Ptr[gchar]],
flags
)

def bindFull(
source_property: String | CString,
target: Object,
target_property: String | CString,
flags: GBindingFlags,
transform_to: GBindingTransformFunc,
transform_from: GBindingTransformFunc,
user_data: Ptr[Byte],
user_data_destroy: GDestroyNotify
)(using Zone): Unit = g_binding_group_bind_full(
this.raw.asInstanceOf,
__sn_extract_string(source_property).asInstanceOf[Ptr[gchar]],
gpointer(target.getUnsafeRawPointer().asInstanceOf.asInstanceOf[Ptr[Byte]]),
__sn_extract_string(target_property).asInstanceOf[Ptr[gchar]],
flags,
transform_to,
transform_from,
gpointer(user_data),
user_data_destroy
)

def bindWithClosures(
source_property: String | CString,
target: Object,
target_property: String | CString,
flags: GBindingFlags,
transform_to: Ptr[GClosure],
transform_from: Ptr[GClosure]
)(using Zone): Unit = g_binding_group_bind_with_closures(
this.raw.asInstanceOf,
__sn_extract_string(source_property).asInstanceOf[Ptr[gchar]],
gpointer(target.getUnsafeRawPointer().asInstanceOf.asInstanceOf[Ptr[Byte]]),
__sn_extract_string(target_property).asInstanceOf[Ptr[gchar]],
flags,
transform_to,
transform_from
)

def dupSource(): Object = new Object(
g_binding_group_dup_source(this.raw.asInstanceOf).asInstanceOf
)

def setSource(source: Object): Unit = g_binding_group_set_source(
this.raw.asInstanceOf,
gpointer(source.getUnsafeRawPointer().asInstanceOf.asInstanceOf[Ptr[Byte]])
)

private inline def __sn_extract_string(str: String | CString)(using
Zone
): CString =
str match
case s: String => toCString(s)
case s: CString => s
end match
end __sn_extract_string
end BindingGroup

object BindingGroup:
def apply(): BindingGroup = new BindingGroup(
g_binding_group_new().asInstanceOf
)
end BindingGroup
14 changes: 14 additions & 0 deletions gobject/src/main/scala/generated/fluent/InitiallyUnowned.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package sn.gnome.gobject.fluent

import _root_.sn.gnome.gobject.internal.*

import _root_.scala.scalanative.unsafe.*

import sn.gnome.gobject.fluent.Object
import sn.gnome.gobject.internal.GInitiallyUnowned

class InitiallyUnowned(raw: Ptr[GInitiallyUnowned])
extends Object(raw.asInstanceOf):
override def getUnsafeRawPointer(): Ptr[Byte] = this.raw.asInstanceOf

end InitiallyUnowned
Loading

0 comments on commit bbe8e17

Please sign in to comment.