Skip to content

Commit

Permalink
Update dependencies and migrate to Mill (#6)
Browse files Browse the repository at this point in the history
* start porting to sn 0.4.0

* libui

* fix pointer conversion errors

* build.sbt

* libui

* fix 'requirement failed' exception

* [cosmetic] type annotations for unit definitions and public members, unnecessary brackets

* update C types to the corresponding Scala Native 0.4.0 types

* Migrate to Mill and other improvements

* Other fixes

* Add Mill script

Co-authored-by: Edward A Maxedon, Sr <[email protected]>
  • Loading branch information
lolgab and edadma authored Apr 29, 2022
1 parent f0501c5 commit b17fd9d
Show file tree
Hide file tree
Showing 81 changed files with 620 additions and 461 deletions.
100 changes: 100 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: ci

on:
push

jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Mill cache
uses: actions/cache@v2
with:
path: ~/.mill
key: mill-${{ hashFiles('.mill-version') }}
- name: Ivy cache
uses: actions/cache@v2
with:
path: ~/.cache/coursier
key: ivy-${{ hashFiles('build.sc') }}
restore-keys: |
ivy-${{ hashFiles('build.sc') }}
ivy
- name: Compilation cache
uses: actions/cache@v2
with:
path: ./out
key: out
- name: Install Dependencies
run: |
# TODO
- uses: actions/setup-java@v1
with:
java-version: '8'
architecture: x64
- name: Check formatting
run:
./mill -i --disable-ticker -j 0 mill.scalalib.scalafmt.ScalafmtModule/checkFormatAll __.sources
# ./mill -j 0 mill.scalalib.scalafmt.ScalafmtModule/checkFormatAll --sources buildSources
# - name: Check scalafix
# run:
# ./mill -i --disable-ticker -j 0 __.fix --check
- name: Compile
run:
./mill -i --disable-ticker -j 0 __.compile
# - name: Integration Test
# run: |
# sudo systemctl stop unit.service
# ./mill -i --disable-ticker -j 0 integration.test
publish-sonatype:
if: github.repository == 'lolgab/scalaui' && contains(github.ref, 'refs/tags/')
needs: build
runs-on: ubuntu-18.04
env:
SONATYPE_PGP_PRIVATE_KEY: ${{ secrets.SONATYPE_PGP_PRIVATE_KEY }}
SONATYPE_PGP_PRIVATE_KEY_PASSWORD: ${{ secrets.SONATYPE_PGP_PRIVATE_KEY_PASSWORD }}
SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
LANG: "en_US.UTF-8"
LC_MESSAGES: "en_US.UTF-8"
LC_ALL: "en_US.UTF-8"
steps:
- uses: actions/checkout@v2
- name: Mill cache
uses: actions/cache@v2
with:
path: ~/.mill
key: mill-${{ hashFiles('.mill-version') }}
- name: Ivy cache
uses: actions/cache@v2
with:
path: ~/.cache/coursier
key: ivy-${{ hashFiles('build.sc') }}
restore-keys: |
ivy-${{ hashFiles('build.sc') }}
ivy
- name: Compilation cache
uses: actions/cache@v2
with:
path: ./out
key: out
- uses: actions/setup-java@v1
with:
java-version: '8'
architecture: x64
- name: Publish to Maven Central
run: |
if [[ $(git tag --points-at HEAD) != '' ]]; then
echo $SONATYPE_PGP_PRIVATE_KEY | base64 --decode > gpg_key
gpg --import --no-tty --batch --yes gpg_key
rm gpg_key
./mill -i --disable-ticker mill.scalalib.PublishModule/publishAll \
--sonatypeCreds $SONATYPE_USER:$SONATYPE_PASSWORD \
--gpgArgs --passphrase=$SONATYPE_PGP_PRIVATE_KEY_PASSWORD,--no-tty,--pinentry-mode,loopback,--batch,--yes,-a,-b \
--publishArtifacts __.publishArtifacts \
--readTimeout 600000 \
--awaitTimeout 600000 \
--release true \
--signed true
fi
16 changes: 2 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,2 @@
.ensime
.ensime_cache
.gitignore
.idea/
project/target
src/main/scala-2.11
src/main/java
src/test/scala-2.11
src/test/java
target
ensime-langeserver.log
pc.stdout.log
*.class
*.log
/out
/.bsp
1 change: 1 addition & 0 deletions .mill-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.10.3
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

11 changes: 0 additions & 11 deletions build.sbt

This file was deleted.

61 changes: 61 additions & 0 deletions build.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import mill._
import mill.scalalib._
import mill.scalanativelib._
import mill.scalalib.publish._
import $ivy.`com.goyeau::mill-scalafix::0.2.8`
import com.goyeau.mill.scalafix.ScalafixModule
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.1.4`
import de.tobiasroeser.mill.vcs.version.VcsVersion

trait Common extends ScalaNativeModule {
def scalaVersion = "2.13.8"
def scalaNativeVersion = "0.4.4"
}

trait Publish extends PublishModule {
def pomSettings =
PomSettings(
description = "Scala Native GUI library based on libui",
organization = "com.github.lolgab",
url = "https://github.com/lolgab/scalaui",
licenses = Seq(License.MIT),
versionControl = VersionControl.github(owner = "lolgab", repo = "scalaui"),
developers = Seq(
Developer("lolgab", "Lorenzo Gabriele", "https://github.com/lolgab")
)
)
def publishVersion = VcsVersion.vcsState().format()
}

object scalaui extends Common with Publish
object integration extends Module {
object tests extends Module {
object `border-panel` extends Common {
def moduleDeps = Seq(scalaui)
}
object `content-size` extends Common {
def moduleDeps = Seq(scalaui)
}
object `font` extends Common {
def moduleDeps = Seq(scalaui)
}
object `hello-world` extends Common {
def moduleDeps = Seq(scalaui)
}
object `multiple-windows` extends Common {
def moduleDeps = Seq(scalaui)
}
object `on-closing` extends Common {
def moduleDeps = Seq(scalaui)
}
object paint extends Common {
def moduleDeps = Seq(scalaui)
}
object complex extends Common {
def moduleDeps = Seq(scalaui)
}
object `write-on-screen` extends Common {
def moduleDeps = Seq(scalaui)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ object ScalauiExample {
menus = menus
)

def main(args: Array[String]) = {
def main(args: Array[String]): Unit = {
render(w)
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import scalaui._

object MultipleWindows {
var i = 0
def newW = {
def newW: Window = {
def onClosing(): Boolean = { println("closing window"); true }
val w = new Window(
s"Window n° $i",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package examples
import scala.collection.mutable
import scalaui._

import scala.collection.mutable.ListBuffer

object PaintExample {
val points = mutable.ListBuffer[Point]()
val points: ListBuffer[Point] = mutable.ListBuffer[Point]()

val width, height = 500

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import scalaui._

object WriteOnScreenExample {
var typing = false
var texts = List[(String, Font, Point)]()
var texts: List[(String, Font, Point)] = List[(String, Font, Point)]()

object callbacks extends AreaCallbacks {
val whiteBrush = new SolidBrush(Color.White)
Expand Down Expand Up @@ -48,10 +48,9 @@ object WriteOnScreenExample {

override def onKeyEvent(ha: AreaHandler, a: Area, e: KeyEvent): Boolean = {
if (typing) e.key match {
case Key.Down(Key.Coded(8)) => {
case Key.Down(Key.Coded(8)) =>
val s = texts.head._1
if (s != "") texts = texts.head.copy(_1 = s.init) :: texts.tail
}
case Key.Down(Key.Coded(key)) =>
val k = if (key >= 'a' && key <= 'z' && e.shiftDown) key - 32 else key
texts = texts.head.copy(_1 = texts.head._1 + k.toChar) :: texts.tail
Expand Down
49 changes: 49 additions & 0 deletions mill
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env sh

# This is a wrapper script, that automatically download mill from GitHub release pages
# You can give the required mill version with MILL_VERSION env variable
# If no version is given, it falls back to the value of DEFAULT_MILL_VERSION
DEFAULT_MILL_VERSION=0.10.3

set -e

if [ -z "$MILL_VERSION" ] ; then
if [ -f ".mill-version" ] ; then
MILL_VERSION="$(head -n 1 .mill-version 2> /dev/null)"
elif [ -f "mill" ] && [ "$0" != "mill" ] ; then
MILL_VERSION=$(grep -F "DEFAULT_MILL_VERSION=" "mill" | head -n 1 | cut -d= -f2)
else
MILL_VERSION=$DEFAULT_MILL_VERSION
fi
fi

if [ "x${XDG_CACHE_HOME}" != "x" ] ; then
MILL_DOWNLOAD_PATH="${XDG_CACHE_HOME}/mill/download"
else
MILL_DOWNLOAD_PATH="${HOME}/.cache/mill/download"
fi
MILL_EXEC_PATH="${MILL_DOWNLOAD_PATH}/${MILL_VERSION}"

version_remainder="$MILL_VERSION"
MILL_MAJOR_VERSION="${version_remainder%%.*}"; version_remainder="${version_remainder#*.}"
MILL_MINOR_VERSION="${version_remainder%%.*}"; version_remainder="${version_remainder#*.}"

if [ ! -s "$MILL_EXEC_PATH" ] ; then
mkdir -p "$MILL_DOWNLOAD_PATH"
if [ "$MILL_MAJOR_VERSION" -gt 0 ] || [ "$MILL_MINOR_VERSION" -ge 5 ] ; then
ASSEMBLY="-assembly"
fi
DOWNLOAD_FILE=$MILL_EXEC_PATH-tmp-download
MILL_VERSION_TAG=$(echo $MILL_VERSION | sed -E 's/([^-]+)(-M[0-9]+)?(-.*)?/\1\2/')
MILL_DOWNLOAD_URL="https://github.com/lihaoyi/mill/releases/download/${MILL_VERSION_TAG}/$MILL_VERSION${ASSEMBLY}"
curl --fail -L -o "$DOWNLOAD_FILE" "$MILL_DOWNLOAD_URL"
chmod +x "$DOWNLOAD_FILE"
mv "$DOWNLOAD_FILE" "$MILL_EXEC_PATH"
unset DOWNLOAD_FILE
unset MILL_DOWNLOAD_URL
fi

unset MILL_DOWNLOAD_PATH
unset MILL_VERSION

exec $MILL_EXEC_PATH "$@"
1 change: 0 additions & 1 deletion project/build.properties

This file was deleted.

2 changes: 0 additions & 2 deletions project/plugins.sbt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package scalaui

import scala.scalanative.native.CFunctionPtr0
import scala.scalanative.unsafe.CFuncPtr0
import ui._

class AboutMenuItem(onClick: CFunctionPtr0[Unit]) extends AbstractMenuItem {
class AboutMenuItem(onClick: CFuncPtr0[Unit]) extends AbstractMenuItem {
private[scalaui] def build(): Unit = {
uiMenuItemOnClicked(control, onClick, null)
}
Expand Down
24 changes: 24 additions & 0 deletions scalaui/src/scalaui/AbstractArea.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package scalaui

import scala.scalanative.unsafe._
import scala.scalanative.runtime._
import scala.scalanative.libc.stdlib.malloc
import ui._
import uiOps._

abstract class AbstractArea(
draw: DrawCallback,
onMouseEvent: MouseEventCallback,
onMouseCrossed: MouseCrossedCallback,
onKeyEvent: KeyEventCallback,
onDragBroken: DragBrokenCallback = doNothingOnDragBroken _
) extends Component {
private val handlerArray = ByteArray.alloc(sizeof[uiAreaHandler].toInt)
val handler: Ptr[uiAreaHandler] =
handlerArray.at(0).asInstanceOf[Ptr[uiAreaHandler]]
handler.Draw = draw
handler.MouseEvent = onMouseEvent
handler.MouseCrossed = onMouseCrossed.asInstanceOf[uiMouseCrossedCallback]
handler.DragBroken = onDragBroken
handler.KeyEvent = onKeyEvent.asInstanceOf[uiKeyEventCallback]
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package scalaui

import scala.scalanative.native.{Zone, fromCString, toCString}
import scala.scalanative.unsafe.{Zone, fromCString, toCString}
import ui._

trait AbstractTextArea extends Component {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit b17fd9d

Please sign in to comment.