Skip to content

Commit

Permalink
Get the JNI examples working with modern versions of the tools.
Browse files Browse the repository at this point in the history
* Try and debug native builds some more

* Slightly adjust CMakeLists.txt and build.sbt

* Enable fortran because life is sad.

* JDK11+ seems reasonable for "high performance"

Fix the library we are loading.

---------

Co-authored-by: Grigory Pomadchin <[email protected]>
  • Loading branch information
holdenk and pomadchin authored Aug 27, 2023
1 parent 8ced692 commit 7ba42b2
Show file tree
Hide file tree
Showing 96 changed files with 115 additions and 127 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ jobs:
include:
- java: 17
- java: 11
- java: 8
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ lib_managed/
src_managed/
project/boot/
project/plugins/project/
.bsp

# Scala-IDE specific
.scala_dependencies
Expand All @@ -23,6 +24,15 @@ project/plugins/project/
*~
sbt/*launch*.jar

# VSCode specific
.vscode
.history

# Metals
.metals
.bloop
metals.sbt

# python
*.pyc
.tox
Expand Down
107 changes: 55 additions & 52 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
lazy val root = (project in file("."))
.aggregate(core, native)


organization := "com.highperformancespark"

//tag::addSparkScalaFix[]
Expand All @@ -22,14 +26,20 @@ name := "examples"
publishMavenStyle := true

version := "0.0.1"
resolvers ++= Seq(
"JBoss Repository" at "https://repository.jboss.org/nexus/content/repositories/releases/",
"Cloudera Repository" at "https://repository.cloudera.com/artifactory/cloudera-repos/",
"Apache HBase" at "https://repository.apache.org/content/repositories/releases",
"Twitter Maven Repo" at "https://maven.twttr.com/",
"scala-tools" at "https://oss.sonatype.org/content/groups/scala-tools",
"sonatype-releases" at "https://oss.sonatype.org/content/repositories/releases/",
"Typesafe repository" at "https://repo.typesafe.com/typesafe/releases/",
"Second Typesafe repo" at "https://repo.typesafe.com/typesafe/maven-releases/",
"Mesosphere Public Repository" at "https://downloads.mesosphere.io/maven",
Resolver.sonatypeRepo("public")
)

javacOptions ++= Seq("-source", "1.8", "-target", "1.8")

parallelExecution in Test := false

fork := true

javaOptions ++= Seq("-Xms512M", "-Xmx2048M", "-Djna.nosys=true")
licenses := Seq("Apache License 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.html"))

def specialOptions = {
// We only need these extra props for JRE>17
Expand All @@ -45,56 +55,49 @@ def specialOptions = {
}
}

Test / javaOptions ++= specialOptions

val sparkVersion = settingKey[String]("Spark version")
val sparkTestingVersion = settingKey[String]("Spark testing base version without Spark version part")

// 2.4.5 is the highest version we have with the old spark-testing-base deps
sparkVersion := System.getProperty("sparkVersion", "3.3.0")
sparkTestingVersion := "1.4.0"

// additional libraries
libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-core" % sparkVersion.value,
"org.apache.spark" %% "spark-streaming" % sparkVersion.value,
"org.apache.spark" %% "spark-sql" % sparkVersion.value,
"org.apache.spark" %% "spark-hive" % sparkVersion.value,
"org.apache.spark" %% "spark-hive-thriftserver" % sparkVersion.value,
"org.apache.spark" %% "spark-catalyst" % sparkVersion.value,
"org.apache.spark" %% "spark-yarn" % sparkVersion.value,
"org.apache.spark" %% "spark-mllib" % sparkVersion.value,
"com.holdenkarau" %% "spark-testing-base" % s"${sparkVersion.value}_${sparkTestingVersion.value}",
//tag::scalaLogging[]
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.4",
//end::scalaLogging[]
"net.java.dev.jna" % "jna" % "5.12.1")


scalacOptions ++= Seq("-deprecation", "-unchecked")

pomIncludeRepository := { x => false }

resolvers ++= Seq(
"JBoss Repository" at "https://repository.jboss.org/nexus/content/repositories/releases/",
"Cloudera Repository" at "https://repository.cloudera.com/artifactory/cloudera-repos/",
"Apache HBase" at "https://repository.apache.org/content/repositories/releases",
"Twitter Maven Repo" at "https://maven.twttr.com/",
"scala-tools" at "https://oss.sonatype.org/content/groups/scala-tools",
"sonatype-releases" at "https://oss.sonatype.org/content/repositories/releases/",
"Typesafe repository" at "https://repo.typesafe.com/typesafe/releases/",
"Second Typesafe repo" at "https://repo.typesafe.com/typesafe/maven-releases/",
"Mesosphere Public Repository" at "https://downloads.mesosphere.io/maven",
Resolver.sonatypeRepo("public")
)

licenses := Seq("Apache License 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.html"))

// JNI

enablePlugins(JniNative)

sourceDirectory in nativeCompile := sourceDirectory.value
// Core (non-JNI bits)

lazy val core = (project in file("core")) // regular scala code with @native methods
.dependsOn(native % Runtime)
.settings(javah / target := (native / nativeCompile / sourceDirectory).value / "include")
.settings(sbtJniCoreScope := Compile)
.settings(
javacOptions ++= Seq("-source", "1.8", "-target", "1.8"),
parallelExecution in Test := false,
fork := true,
javaOptions ++= Seq("-Xms512M", "-Xmx2048M", "-Djna.nosys=true"),
Test / javaOptions ++= specialOptions,
// 2.4.5 is the highest version we have with the old spark-testing-base deps
sparkVersion := System.getProperty("sparkVersion", "3.3.0"),
sparkTestingVersion := "1.4.0",
// additional libraries
libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-core" % sparkVersion.value,
"org.apache.spark" %% "spark-streaming" % sparkVersion.value,
"org.apache.spark" %% "spark-sql" % sparkVersion.value,
"org.apache.spark" %% "spark-hive" % sparkVersion.value,
"org.apache.spark" %% "spark-hive-thriftserver" % sparkVersion.value,
"org.apache.spark" %% "spark-catalyst" % sparkVersion.value,
"org.apache.spark" %% "spark-yarn" % sparkVersion.value,
"org.apache.spark" %% "spark-mllib" % sparkVersion.value,
"com.holdenkarau" %% "spark-testing-base" % s"${sparkVersion.value}_${sparkTestingVersion.value}",
//tag::scalaLogging[]
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.4",
//end::scalaLogging[]
"net.java.dev.jna" % "jna" % "5.12.1"),
scalacOptions ++= Seq("-deprecation", "-unchecked"),
pomIncludeRepository := { x => false },
)

// JNI Magic!
lazy val native = (project in file("native")) // native code and build script
.settings(nativeCompile / sourceDirectory := sourceDirectory.value)
.enablePlugins(JniNative) // JniNative needs to be explicitly enabled

//tag::xmlVersionConflict[]
// See https://github.com/scala/bug/issues/12632
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
50 changes: 50 additions & 0 deletions native/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
################################################################
# A minimal CMake file that is compatible with sbt-jni #
# #
# All settings required by sbt-jni have been marked so, please #
# add/modify/remove settings to build your specific library. #
################################################################

cmake_minimum_required(VERSION 3.12)

option(SBT "Set if invoked from sbt-jni" OFF)

# Define project and related variables
# (required by sbt-jni) please use semantic versioning
#
project (high-performance-spark)
enable_language(Fortran)
set(PROJECT_VERSION_MAJOR 0)
set(PROJECT_VERSION_MINOR 0)
set(PROJECT_VERSION_PATCH 0)

# Setup JNI
find_package(JNI REQUIRED)
if (JNI_FOUND)
message (STATUS "JNI include directories: ${JNI_INCLUDE_DIRS}")
endif()

# Include directories
include_directories(.)
include_directories(include)
include_directories(${JNI_INCLUDE_DIRS})

# Sources
file(GLOB LIB_SRC
"*.c"
"*.f95"
"*.f*"
"*.cc"
"*.cpp"
"./c/*.c"
"./c/*.cpp"
"./fortran/*.f95"
"./fortran/*.f*"
)

# Setup installation targets
# (required by sbt-jni) major version should always be appended to library name
#
set (LIB_NAME ${PROJECT_NAME}${PROJECT_VERSION_MAJOR})
add_library(${LIB_NAME} SHARED ${LIB_SRC})
install(TARGETS ${LIB_NAME} LIBRARY DESTINATION .)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
74 changes: 0 additions & 74 deletions src/CMakeLists.txt

This file was deleted.

0 comments on commit 7ba42b2

Please sign in to comment.