Skip to content

Commit

Permalink
improvement [toolchain]: Respect LLVM_BIN when invoking llvm-config (#…
Browse files Browse the repository at this point in the history
…3908)

This prevents polluting compilation/linking flags with whatever
different LLVM you have installed globally
  • Loading branch information
keynmol committed May 10, 2024
1 parent 8302845 commit 1a42105
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tools/src/main/scala/scala/scalanative/build/Discover.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,20 @@ object Discover {
path
}

/** Use llvm-config binary on the path or via LLVM_BIN env var */
private lazy val llvmConfigCLI: String =
tryDiscover("llvm-config", "LLVM_BIN")
.map(_.toAbsolutePath.toString)
.getOrElse("llvm-config")

private def filterExisting(paths: Seq[String]): Seq[String] =
paths.filter(new File(_).exists())

/** Find default clang compilation options. */
def compileOptions(): Seq[String] = {
val includes = {
val llvmIncludeDir =
Try(Process("llvm-config --includedir").lineStream_!.toSeq)
Try(Process(s"$llvmConfigCLI --includedir").lineStream_!.toSeq)
.getOrElse(Seq.empty)
// dirs: standard, macports, brew M1 arm
val includeDirs =
Expand All @@ -75,7 +81,7 @@ object Discover {
def linkingOptions(): Seq[String] = {
val libs = {
val llvmLibDir =
Try(Process("llvm-config --libdir").lineStream_!.toSeq)
Try(Process(s"$llvmConfigCLI --libdir").lineStream_!.toSeq)
.getOrElse(Seq.empty)

val libDirs =
Expand Down

0 comments on commit 1a42105

Please sign in to comment.