From 8af7386dd51f69fbda95c30fc0a81d11912f6834 Mon Sep 17 00:00:00 2001 From: Hugues de Valon Date: Tue, 6 Apr 2021 15:49:36 +0100 Subject: [PATCH] Modify handling of cross-compilation targets That way, hard float variants are accepted as well. Signed-off-by: Hugues de Valon --- tss-esapi-sys/Cargo.toml | 1 + tss-esapi-sys/build.rs | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/tss-esapi-sys/Cargo.toml b/tss-esapi-sys/Cargo.toml index 79bdedcc..7dd52263 100644 --- a/tss-esapi-sys/Cargo.toml +++ b/tss-esapi-sys/Cargo.toml @@ -15,6 +15,7 @@ links = "tss2-esys" [build-dependencies] bindgen = { version = "0.57.0", optional = true } pkg-config = "0.3.18" +target-lexicon = "0.12.0" [features] generate-bindings = ["bindgen"] diff --git a/tss-esapi-sys/build.rs b/tss-esapi-sys/build.rs index ad76acd2..b8b15b91 100644 --- a/tss-esapi-sys/build.rs +++ b/tss-esapi-sys/build.rs @@ -21,17 +21,18 @@ fn main() { #[cfg(not(feature = "generate-bindings"))] { - let supported_platforms = vec![ - String::from("x86_64-unknown-linux-gnu"), - String::from("aarch64-unknown-linux-gnu"), - String::from("armv7-unknown-linux-gnueabi"), - String::from("arm-unknown-linux-gnueabi"), - ]; - let target = std::env::var("TARGET").unwrap(); + use std::str::FromStr; + use target_lexicon::{Architecture, OperatingSystem, Triple}; - // check if target is in the list of supported ones or panic with nice message - if !supported_platforms.contains(&target) { - panic!(format!("Compilation target ({}) is not part of the supported targets ({:?}). Please compile with the \"generate-bindings\" feature or add support for your platform :)", target, supported_platforms)); + let target = Triple::from_str(&std::env::var("TARGET").unwrap()) + .expect("Failed to parse target triple"); + match (target.architecture, target.operating_system) { + (Architecture::Arm(_), OperatingSystem::Linux) => {} + (Architecture::Aarch64(_), OperatingSystem::Linux) => {} + (Architecture::X86_64, OperatingSystem::Linux) => {} + (arch, os) => { + panic!("Compilation target (architecture, OS) tuple ({}, {}) is not part of the supported tuples. Please compile with the \"generate-bindings\" feature or add support for your platform :)", arch, os); + } } pkg_config::Config::new()