blob: 7fa559e57dd5fea9766230b50d9844fc13d90088 [file] [log] [blame]
Devin Jeanpierrec503d332023-04-26 11:28:11 -07001// 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
7use once_cell::sync::Lazy;
8
9#[non_exhaustive]
10#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
11pub enum Platform {
12 X86Linux,
13 ArmLinux,
14}
15
16impl 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.
27pub fn test_platform() -> Platform {
28 *TEST_PLATFORM.as_ref().unwrap()
29}
30
31static 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});