Skip to content

Commit

Permalink
fix(build): Support glibc qualifiers for Rust targets (#1858)
Browse files Browse the repository at this point in the history
If you're targetting an older Linux distro the default glibc version
being linked against may be too high to produce runnable images.

cargo zigbuild supports specifying a specific glibc version to use
for a link target by appending ".<version>" to the target triple.  For
example, "x86_64-unknown-linux-gnu.2.17" will target v2.17.

For the most part this just works but we need to strip this suffix when
looking for output binaries.  This fix adds that logic.
  • Loading branch information
rfairfax authored Sep 27, 2024
1 parent 6fe42cc commit e310445
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions project/RustPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,18 @@ object RustPlugin extends AutoPlugin {

// For each architecture find artifacts
for (archTarget <- rustArchitectures.value) {
val normalizedArch = normalizeRustTarget(archTarget)

// Special case - host
val archFolder = if (archTarget == "host") {
val archFolder = if (normalizedArch == "host") {
targetFolder / releaseDir
} else {
// General case
targetFolder / archTarget / releaseDir
targetFolder / normalizedArch / releaseDir
}

// get os arch / kernel, build path
val resourceArchTarget = mapRustTargetToJVMTarget(archTarget)
val resourceArchTarget = mapRustTargetToJVMTarget(normalizedArch)

// Find library files in folder
// We place every produced library in a resource path like
Expand Down Expand Up @@ -207,6 +209,23 @@ object RustPlugin extends AutoPlugin {
}
}

// Normalize a target string by stripping excess info, like GLIBC version
private def normalizeRustTarget(target: String): String = {
// Handle strings like x86_64-unknown-linux-gnu.2.17,
// which contain a GLIBC version suffix
//
// We want to drop the suffix to get x86_64-unknown-linux-gnu
val RustPattern = "([^-]+)-([^-]+)-([^.]+).*".r

target match {
// Valid inputs
case "host" => target
case RustPattern(arch, vendor, kernel) => s"$arch-$vendor-$kernel"
// Not matched
case x => sys.error(s"Unsupported target $x")
}
}

// Get normalized host kernel name
private def getHostKernel: String = {
if (SystemUtils.IS_OS_LINUX) {
Expand Down

0 comments on commit e310445

Please sign in to comment.