Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vcpkg native plugin #92

Merged
merged 13 commits into from
Feb 25, 2023
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ jobs:

- name: Run example
env:
LLVM_BIN: /usr/local/opt/llvm/bin
LLVM_BIN: /usr/local/opt/llvm@14/bin
if: startsWith(matrix.os, 'macos-')
run: |
set -e
brew install llvm
brew install llvm@14
cd example
SBT_VCPKG_VERSION=$(cat ../version) sbt example/run

Expand All @@ -62,10 +62,12 @@ jobs:
curl -fLo cs https://github.com/coursier/launchers/raw/master/coursier &&
chmod +x cs

./cs launch com.indoorvivants.vcpkg:scala-vcpkg_3:$(cat version) -- install -v libpq s2n
./cs launch com.indoorvivants.vcpkg:sn-vcpkg_3:$(cat version) -- install -v libpq s2n

echo '{"name": "my-application","version": "0.15.2","dependencies": ["sqlite3"]}' > test-vcpkg.json
./cs launch com.indoorvivants.vcpkg:scala-vcpkg_3:$(cat version) -- install-manifest -v test-vcpkg.json
./cs launch com.indoorvivants.vcpkg:sn-vcpkg_3:$(cat version) -- install-manifest -v test-vcpkg.json

./cs launch com.indoorvivants.vcpkg:sn-vcpkg_3:$(cat version) -- install -q -c -l libpq s2n


windows_build:
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ RUN apt update && apt install -y curl && \
curl -Lo llvm.sh https://apt.llvm.org/llvm.sh && \
chmod +x llvm.sh && \
apt install -y lsb-release wget software-properties-common gnupg && \
./llvm.sh 13 && \
./llvm.sh 14 && \
apt update && \
apt install -y zip unzip tar make cmake autoconf pkg-config libclang-13-dev
apt install -y zip unzip tar make cmake autoconf pkg-config

COPY . /sources

RUN apt install -y git

ENV LLVM_BIN "/usr/lib/llvm-13/bin"
ENV CC "/usr/lib/llvm-13/bin/clang"
ENV LLVM_BIN "/usr/lib/llvm-14/bin"
ENV CC "/usr/lib/llvm-14/bin/clang"
ENV PATH="${PATH}:/root/.local/share/coursier/bin"

ENV SBT_VCPKG_VERSION dev
Expand Down
66 changes: 52 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ val V = new {

val scribe = "3.11.1"

val scalaNative = "0.4.10"

val supportedScalaVersions = List(scala213, scala212, scala3)
}

Expand All @@ -56,16 +58,18 @@ lazy val publishing = Seq(
lazy val root = project
.in(file("."))
.aggregate(core.projectRefs *)
.aggregate(`sbt-plugin`.projectRefs *)
.aggregate(`mill-plugin`.projectRefs *)
.aggregate(`sbt-vcpkg-plugin`.projectRefs *)
.aggregate(`sbt-vcpkg-native-plugin`.projectRefs *)
.aggregate(`mill-vcpkg-plugin`.projectRefs *)
.aggregate(`mill-vcpkg-native-plugin`.projectRefs *)
.aggregate(cli.projectRefs *)
.settings(
publish / skip := true
)

lazy val core = projectMatrix
.jvmPlatform(scalaVersions = V.supportedScalaVersions)
.in(file("core"))
.in(file("modules/core"))
.settings(publishing)
.settings(
name := "vcpkg-core",
Expand All @@ -85,23 +89,23 @@ lazy val cli = projectMatrix
.jvmPlatform(scalaVersions = Seq(V.scala3))
.defaultAxes(VirtualAxis.scalaABIVersion(V.scala3), VirtualAxis.jvm)
.dependsOn(core)
.in(file("cli"))
.in(file("modules/cli"))
.settings(publishing)
.settings(
name := "scala-vcpkg",
name := "sn-vcpkg",
testFrameworks += new TestFramework("weaver.framework.CatsEffect"),
libraryDependencies += "com.monovore" %% "decline" % V.decline,
libraryDependencies += "com.outr" %% "scribe" % V.scribe
)

lazy val `sbt-plugin` = projectMatrix
lazy val `sbt-vcpkg-plugin` = projectMatrix
.jvmPlatform(scalaVersions = Seq(V.scala212))
.in(file("sbt-plugin"))
.in(file("modules/sbt-vcpkg-plugin"))
.dependsOn(core)
.enablePlugins(ScriptedPlugin, SbtPlugin)
.settings(publishing)
.settings(
name := """sbt-vcpkg""",
name := "sbt-vcpkg",
sbtPlugin := true,
// set up 'scripted; sbt plugin for testing sbt plugins
scriptedLaunchOpts ++= Seq(
Expand All @@ -111,26 +115,60 @@ lazy val `sbt-plugin` = projectMatrix
scriptedBufferLog := false
)

lazy val `mill-plugin` = projectMatrix
lazy val `sbt-vcpkg-native-plugin` = projectMatrix
.jvmPlatform(scalaVersions = Seq(V.scala212))
.in(file("modules/sbt-vcpkg-native-plugin"))
.dependsOn(core, `sbt-vcpkg-plugin`)
.enablePlugins(ScriptedPlugin, SbtPlugin)
.settings(publishing)
.settings(
name := """sbt-vcpkg-native""",
sbtPlugin := true,
// set up 'scripted; sbt plugin for testing sbt plugins
scriptedLaunchOpts ++= Seq(
"-Xmx1024M",
"-Dplugin.version=" + version.value
),
addSbtPlugin("org.scala-native" % "sbt-scala-native" % V.scalaNative),
scriptedBufferLog := false
)

lazy val `mill-vcpkg-plugin` = projectMatrix
.jvmPlatform(scalaVersions = Seq(V.scala213))
.in(file("mill-plugin"))
.in(file("modules/mill-vcpkg-plugin"))
.dependsOn(core)
.settings(publishing)
.settings(
name := """mill-vcpkg""",
name := "mill-vcpkg",
libraryDependencies += "com.lihaoyi" %% "mill-scalalib" % V.mill,
libraryDependencies += "com.lihaoyi" %% "utest" % V.utest % Test,
testFrameworks += new TestFramework("utest.runner.Framework"),
Test / fork := true,
Test / envVars := Map(
"MILL_VCPKG_ROOT" -> ((ThisBuild / baseDirectory).value / "mill-plugin" / "src" / "test").toString
Test / envVars += (
"MILL_VCPKG_ROOT" -> ((ThisBuild / baseDirectory).value / "modules" / "mill-vcpkg-plugin" / "src" / "test").toString
)
)

lazy val `mill-vcpkg-native-plugin` = projectMatrix
.jvmPlatform(scalaVersions = Seq(V.scala213))
.in(file("modules/mill-vcpkg-native-plugin"))
.dependsOn(core, `mill-vcpkg-plugin` % "test->test;compile->compile")
.settings(publishing)
.settings(
name := "mill-vcpkg",
libraryDependencies += "com.lihaoyi" %% "mill-scalanativelib" % V.mill,
libraryDependencies += "com.lihaoyi" %% "utest" % V.utest % Test,
testFrameworks += new TestFramework("utest.runner.Framework"),
Test / fork := true,
Test / envVars += (
"MILL_VCPKG_ROOT" -> ((ThisBuild / baseDirectory).value / "modules" / "mill-vcpkg-native-plugin" / "src" / "test").toString
)
)

Global / onChangedBuildSource := ReloadOnSourceChanges

lazy val versionDump =
taskKey[Unit]("Dumps the version in a file named version")
taskKey[Unit]("Dumps the version in a file named `version`")

versionDump := {
val file = (ThisBuild / baseDirectory).value / "version"
Expand Down
111 changes: 29 additions & 82 deletions example/build.sbt
Original file line number Diff line number Diff line change
@@ -1,97 +1,44 @@
enablePlugins(VcpkgPlugin, ScalaNativePlugin, BindgenPlugin)
enablePlugins(VcpkgNativePlugin, ScalaNativePlugin, BindgenPlugin)

vcpkgDependencies := Set("libuv", "czmq", "cjson", "zeromq")

resolvers += Resolver.sonatypeRepo("snapshots")

scalaVersion := "3.2.0"
scalaVersion := "3.2.2"

import bindgen.interface.Binding

bindgenBindings := {
val configurator = vcpkgConfigurator.value
Seq(
Binding(
configurator.includes("cjson") / "cjson" / "cJSON.h",
"cjson",
cImports = List("cJSON.h")
),
Binding(
configurator.includes("libuv") / "uv.h",
"libuv",
cImports = List("uv.h"),
clangFlags = List("-I" + configurator.includes("libuv").toString)
),
Binding(
configurator.includes("czmq") / "czmq.h",
"czmq",
cImports = List("czmq.h"),
clangFlags = List(
"-I" + configurator.includes("czmq").toString,
"-I" + configurator.includes("zeromq").toString
)
)
vcpkgNativeConfig ~= {
_.withRenamedLibraries(
Map("zeromq" -> "libzmq", "czmq" -> "libczmq", "cjson" -> "libcjson")
)
}

nativeConfig := {
import com.indoorvivants.detective.Platform
bindgenBindings := {
val configurator = vcpkgConfigurator.value
val pkgConfig = configurator.pkgConfig
val conf = nativeConfig.value
val deps = vcpkgDependencies.value.toSeq

val files = deps.map(d => configurator.files(d))

val compileArgsApprox = files.flatMap { f =>
List("-I" + f.includeDir.toString)
}
val linkingArgsApprox = files.flatMap { f =>
List("-L" + f.libDir) ++ f.staticLibraries.map(_.toString)
}

import scala.util.control.NonFatal

def updateLinkingFlags(current: Seq[String], deps: String*) =
try {
pkgConfig.updateLinkingFlags(
current,
deps *
)
} catch {
case NonFatal(exc) =>
linkingArgsApprox
}

def updateCompilationFlags(current: Seq[String], deps: String*) =
try {
pkgConfig.updateCompilationFlags(
current,
deps *
)
} catch {
case NonFatal(exc) =>
compileArgsApprox
}

val arch64 =
if (
Platform.arch == Platform.Arch.Arm && Platform.bits == Platform.Bits.x64
)
List("-arch", "arm64")
else Nil

conf
.withLinkingOptions(
updateLinkingFlags(
conf.linkingOptions ++ arch64,
deps *
Seq(
Binding
.builder(configurator.includes("cjson") / "cjson" / "cJSON.h", "cjson")
.withCImports(List("cJSON.h"))
.build,
Binding
.builder(configurator.includes("libuv") / "uv.h", "libuv")
.withCImports(List("uv.h"))
.withClangFlags(
List(
"-I" + configurator.includes("libuv").toString
)
)
)
.withCompileOptions(
updateCompilationFlags(
conf.compileOptions ++ arch64,
deps *
.build,
Binding
.builder(configurator.includes("czmq") / "czmq.h", "czmq")
.withCImports(List("czmq.h"))
.withClangFlags(
List(
"-I" + configurator.includes("czmq").toString,
"-I" + configurator.includes("zeromq").toString
)
)
)
.build
)
}
6 changes: 3 additions & 3 deletions example/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
val BindgenVersion =
sys.env.getOrElse("SN_BINDGEN_VERSION", "0.0.14")
sys.env.getOrElse("SN_BINDGEN_VERSION", "0.0.16")

val VcpkgVersion =
sys.env.getOrElse("SBT_VCPKG_VERSION", "0.0.7")
sys.env.getOrElse("SBT_VCPKG_VERSION", "0.0.9")

addSbtPlugin("com.indoorvivants" % "bindgen-sbt-plugin" % BindgenVersion)
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.7")
addSbtPlugin("com.indoorvivants.vcpkg" % "sbt-vcpkg" % VcpkgVersion)
addSbtPlugin("com.indoorvivants.vcpkg" % "sbt-vcpkg-native" % VcpkgVersion)

resolvers += Resolver.sonatypeRepo("snapshots")
Loading