Skip to content

Commit

Permalink
Fix LLVM target probe compilation (#639)
Browse files Browse the repository at this point in the history
The refactoring of the sbt plugin in commit 036de7e broke the
compilation to native code with clang-4.0/macOS 10.10.5 because the
compilation of the probe code was changed to use the common work
directory.

    [error] /opt/scala-native/sandbox/target/scala-2.11/native/target.ll:2:1: error: expected top-level entity
    [error] source_filename = "/opt/scala-native/sandbox/target/scala-2.11/native/target.c"
    [error] ^
    [error] 1 error generated.
  • Loading branch information
jonas authored and densh committed Apr 19, 2017
1 parent 38fb182 commit 1188a2d
Showing 1 changed file with 9 additions and 11 deletions.
Expand Up @@ -18,7 +18,7 @@ import KeyRanks.DTask
import scala.util.Try

import System.{lineSeparator => nl}
import java.io.File
import java.io.{File, ByteArrayInputStream}

object ScalaNativePluginInternal {

Expand Down Expand Up @@ -149,20 +149,18 @@ object ScalaNativePluginInternal {
libs
},
nativeTarget := {
val logger = nativeLogger.value
val cwd = nativeWorkdir.value
val clang = nativeClang.value
val targetcfile = cwd / "target.c"
val targetllfile = cwd / "target.ll"
val compilec = Seq(abs(clang), "-S", "-emit-llvm", abs(targetcfile))
val logger = nativeLogger.value
val cwd = nativeWorkdir.value
val clang = nativeClang.value
val compilec =
Seq(abs(clang), "-S", "-emit-llvm", "-x", "c", "-o", "-", "-")
val probe = new ByteArrayInputStream("int probe;".getBytes("UTF-8"))
def fail =
throw new MessageOnlyException("Failed to detect native target.")

IO.write(targetcfile, "int probe;")
logger.running(compilec)
val exit = Process(compilec, cwd) ! logger
if (exit != 0) fail
IO.readLines(targetllfile)
val lines = Process(compilec, cwd) #< probe lines_! logger
lines
.collectFirst {
case line if line.startsWith("target triple") =>
line.split("\"").apply(1)
Expand Down

0 comments on commit 1188a2d

Please sign in to comment.