Devin Jeanpierre | c503d33 | 2023-04-26 11:28:11 -0700 | [diff] [blame] | 1 | // Part of the Crubit project, under the Apache License v2.0 with LLVM |
| 2 | // Exceptions. See /LICENSE for license information. |
| 3 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 4 | |
| 5 | //! Vocabulary library for multi-platform tests which use cross-compilation. |
| 6 | |
| 7 | use once_cell::sync::Lazy; |
| 8 | |
| 9 | #[non_exhaustive] |
| 10 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] |
| 11 | pub enum Platform { |
| 12 | X86Linux, |
| 13 | ArmLinux, |
| 14 | } |
| 15 | |
| 16 | impl Platform { |
| 17 | pub fn target_triple(self) -> &'static str { |
| 18 | match self { |
| 19 | Platform::X86Linux => "x86_64-grtev4-linux-gnu", |
| 20 | Platform::ArmLinux => "aarch64-grtev4-linux-gnu", |
| 21 | } |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | /// Returns the platform the current test is running for with |
| 26 | /// multiplatform_rust_test. |
| 27 | pub fn test_platform() -> Platform { |
| 28 | *TEST_PLATFORM.as_ref().unwrap() |
| 29 | } |
| 30 | |
| 31 | static TEST_PLATFORM: Lazy<Result<Platform, String>> = Lazy::new(|| { |
| 32 | let env = std::env::var("CRUBIT_TEST_PLATFORM") |
| 33 | .map_err(|_| "multiplatform tests must use `multiplatform_rust_test`.".to_string())?; |
| 34 | let platform = match env.as_str() { |
| 35 | "x86_linux" => Platform::X86Linux, |
| 36 | "arm_linux" => Platform::ArmLinux, |
| 37 | _ => return Err(format!("Unknown platform: {env}")), |
| 38 | }; |
| 39 | Ok(platform) |
| 40 | }); |