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

fix(build): Support glibc qualifiers for Rust targets #1858

Merged
merged 1 commit into from
Sep 27, 2024
Merged
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
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
Loading