Skip to content

Commit

Permalink
Improve nixos support for recent protoc versions
Browse files Browse the repository at this point in the history
  • Loading branch information
thesamet committed Nov 23, 2023
1 parent cf8decf commit cbbb48e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
11 changes: 10 additions & 1 deletion bridge/src/main/scala/protocbridge/ProtocRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,19 @@ object ProtocRunner {
None
}

// This version of maybeNixDynamicLinker() finds ld-linux and also uses it
// to verify that the executable is dynamic. Newer version (>=3.23.0) of
// protoc are static, and thus do not load with ld-linux.
def maybeNixDynamicLinker(executable: String): Option[String] =
maybeNixDynamicLinker().filter { linker =>
Process(command = Seq(linker, "--verify", executable)).! == 0
}

def apply(executable: String): ProtocRunner[Int] = ProtocRunner.fromFunction {
case (args, extraEnv) =>
Process(
command = (maybeNixDynamicLinker().toSeq :+ executable) ++ args,
command =
(maybeNixDynamicLinker(executable).toSeq :+ executable) ++ args,
cwd = None,
extraEnv: _*
).!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import java.io.File
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Await
import scala.concurrent.duration.Duration
import scala.io.Source
import coursier._
import coursier.core.Extension

Expand All @@ -23,13 +22,10 @@ object CoursierProtocCache {
): Int = {
import sys.process._

val maybeNixDynamicLinker: Option[String] =
sys.env.get("NIX_CC").map { nixCC =>
Source.fromFile(nixCC + "/nix-support/dynamic-linker").mkString.trim()
}
val protoc = getProtoc(version).getAbsolutePath()

val cmd = (maybeNixDynamicLinker.toSeq :+ getProtoc(version)
.getAbsolutePath()) ++ args
val cmd =
(ProtocRunner.maybeNixDynamicLinker(protoc).toSeq :+ protoc) ++ args
Process(command = cmd, cwd = None, extraEnv: _*).!
}

Expand Down

0 comments on commit cbbb48e

Please sign in to comment.