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

Avoid using uname except on ARM #32

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ target in nativeCompile := target.value / "native" / (nativePlatform).value,
|--------------------------------|---------------|
| automatic, when JniNative enabled | [JniPackage.scala](plugin/src/main/scala/ch/jodersky/sbt/jni/plugins/JniPackage.scala) |

This plugin packages native libraries produced by JniNative in a way that they can be transparently loaded with JniLoad. It uses the notion of a native "platform", defined as the architecture-kernel values returned by `uname -sm`. A native binary of a given platform is assumed to be executable on any machines of the same platform.
This plugin packages native libraries produced by JniNative in a way that they can be transparently loaded with JniLoad. It uses the notion of a native "platform", defined as the architecture-kernel values returned by `sys.props("os.arch")` and `sys.props("os.name')`. On ARM-based platforms, where the former fails to provide sufficient granularity, the output of `uname -sm` is used instead. A native binary of a given platform is assumed to be executable on any machines of the same platform.

## Canonical Use

Expand Down Expand Up @@ -183,7 +183,7 @@ Real-world use-cases of sbt-jni include:
## Requirements and Dependencies

- projects using `JniLoad` must use Scala versions 2.10, 2.11 or 2.12
- only POSIX platforms are supported (actually, any platform that has the `uname` command available)
- all platforms are supported (on ARM, the `uname` command is assumed to be available)

The goal of sbt-jni is to be the least intrusive possible. No transitive dependencies are added to projects using any plugin (some dependencies are added to the `provided` configuration, however these do not affect any downstream projects).

Expand Down
28 changes: 16 additions & 12 deletions macros/src/main/scala/ch/jodersky/jni/annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,23 @@ class nativeLoaderMacro(val c: Context) {

val tmp: Path = Files.createTempDirectory("jni-")
val plat: String = {
val line = try {
scala.sys.process.Process("uname -sm").lines.head
} catch {
case ex: Exception => sys.error("Error running `uname` command")
}
val parts = line.split(" ")
if (parts.length != 2) {
sys.error("Could not determine platform: 'uname -sm' returned unexpected string: " + line)
} else {
val arch = parts(1).toLowerCase.replaceAll("\\s", "")
val kernel = parts(0).toLowerCase.replaceAll("\\s", "")
arch + "-" + kernel
val osarch = sys.props("os.arch").toLowerCase.replaceAll("\\s", "")
if ("arm" == osarch) {
val line = try {
scala.sys.process.Process("uname -sm").lines.head
} catch {
case ex: Exception => sys.error("Error running `uname` command")
}
val parts = line.split(" ")
if (parts.length != 2) {
sys.error("Could not determine platform: 'uname -sm' returned unexpected string: " + line)
} else {
val arch = parts(1).toLowerCase.replaceAll("\\s", "")
val kernel = parts(0).toLowerCase.replaceAll("\\s", "")
arch + "-" + kernel
}
}
else osarch + "-" + sys.props("os.name").toLowerCase.replaceAll("\\s", "")
}

val resourcePath: String = "/native/" + plat + "/" + lib
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ object JniNative extends AutoPlugin {

// the value retruned must match that of `ch.jodersky.jni.PlatformMacros#current()` of project `macros`
nativePlatform := {
try {
val osarch = sys.props("os.arch").toLowerCase.replaceAll("\\s", "")
if ("arm" == osarch) try {
val lines = Process("uname -sm").lineStream
if (lines.length == 0) {
sys.error("Error occured trying to run `uname`")
Expand All @@ -56,7 +57,7 @@ object JniNative extends AutoPlugin {
sLog.value.error("Error trying to determine platform.")
sLog.value.warn("Cannot determine platform! It will be set to 'unknown'.")
"unknown-unknown"
}
} else osarch + "-" + sys.props("os.name").toLowerCase.replaceAll("\\s", "")
},

sourceDirectory in nativeCompile := sourceDirectory.value / "native",
Expand Down