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 | """Supporting macro for multiplatform code.""" |
| 5 | |
Jing Lu | 4e940f9 | 2023-08-25 09:21:40 -0700 | [diff] [blame] | 6 | load("//common:crubit_wrapper_macros_oss.bzl", "crubit_rust_test") |
Devin Jeanpierre | c503d33 | 2023-04-26 11:28:11 -0700 | [diff] [blame] | 7 | |
| 8 | _PLATFORMS = [ |
| 9 | "x86_linux", |
| 10 | "arm_linux", |
| 11 | ] |
| 12 | |
| 13 | def multiplatform_rust_test(name, **kwargs): |
| 14 | """Macro to parameterize a test target by target platform.""" |
| 15 | |
| 16 | # TODO(jeanpierreda): Ideally we'd use `.`, not `-`, but this breaks for non-crate= rust_test targets |
| 17 | # because they create a crate with `.` in the name. That's illegal. |
| 18 | native.test_suite( |
| 19 | name = name, |
| 20 | tests = [name + "-" + platform for platform in _PLATFORMS], |
| 21 | ) |
| 22 | rustc_env = kwargs.setdefault("env", {}) |
| 23 | for platform in _PLATFORMS: |
| 24 | rustc_env["CRUBIT_TEST_PLATFORM"] = platform |
| 25 | test_name = name + "-" + platform |
Jing Lu | 6c8b8a8 | 2023-08-25 06:42:35 -0700 | [diff] [blame] | 26 | crubit_rust_test( |
Devin Jeanpierre | c503d33 | 2023-04-26 11:28:11 -0700 | [diff] [blame] | 27 | name = test_name, |
| 28 | **kwargs |
| 29 | ) |