|
| 1 | +use std::process::Command; |
| 2 | + |
1 | 3 | fn main() { |
2 | 4 | use std::env; |
3 | 5 | let opt_level = env::var("OPT_LEVEL") |
@@ -48,34 +50,43 @@ fn main() { |
48 | 50 | .skip_roundtrip(|_| true) |
49 | 51 | .generate("src/t2.rs", "t2gen.rs"); |
50 | 52 |
|
51 | | - ctest::TestGenerator::new() |
52 | | - .header("t1.h") |
53 | | - .language(ctest::Lang::CXX) |
54 | | - .include("src") |
55 | | - .fn_cname(|a, b| b.unwrap_or(a).to_string()) |
56 | | - .type_name(move |ty, is_struct, is_union| match ty { |
57 | | - "T1Union" => ty.to_string(), |
58 | | - "Transparent" => ty.to_string(), |
59 | | - t if is_struct => format!("struct {}", t), |
60 | | - t if is_union => format!("union {}", t), |
61 | | - t => t.to_string(), |
62 | | - }) |
63 | | - .volatile_item(t1_volatile) |
64 | | - .array_arg(t1_arrays) |
65 | | - .skip_roundtrip(|n| n == "Arr") |
66 | | - .generate("src/t1.rs", "t1gen_cxx.rs"); |
67 | | - ctest::TestGenerator::new() |
68 | | - .header("t2.h") |
69 | | - .language(ctest::Lang::CXX) |
70 | | - .include("src") |
71 | | - .type_name(move |ty, is_struct, is_union| match ty { |
72 | | - "T2Union" => ty.to_string(), |
73 | | - t if is_struct => format!("struct {}", t), |
74 | | - t if is_union => format!("union {}", t), |
75 | | - t => t.to_string(), |
76 | | - }) |
77 | | - .skip_roundtrip(|_| true) |
78 | | - .generate("src/t2.rs", "t2gen_cxx.rs"); |
| 53 | + println!("cargo::rustc-check-cfg=cfg(has_cxx)"); |
| 54 | + if !cfg!(unix) || Command::new("c++").arg("v").output().is_ok() { |
| 55 | + // A C compiler is always available, but these are only run if a C++ compiler is |
| 56 | + // also available. |
| 57 | + println!("cargo::rustc-cfg=has_cxx"); |
| 58 | + |
| 59 | + ctest::TestGenerator::new() |
| 60 | + .header("t1.h") |
| 61 | + .language(ctest::Lang::CXX) |
| 62 | + .include("src") |
| 63 | + .fn_cname(|a, b| b.unwrap_or(a).to_string()) |
| 64 | + .type_name(move |ty, is_struct, is_union| match ty { |
| 65 | + "T1Union" => ty.to_string(), |
| 66 | + "Transparent" => ty.to_string(), |
| 67 | + t if is_struct => format!("struct {}", t), |
| 68 | + t if is_union => format!("union {}", t), |
| 69 | + t => t.to_string(), |
| 70 | + }) |
| 71 | + .volatile_item(t1_volatile) |
| 72 | + .array_arg(t1_arrays) |
| 73 | + .skip_roundtrip(|n| n == "Arr") |
| 74 | + .generate("src/t1.rs", "t1gen_cxx.rs"); |
| 75 | + ctest::TestGenerator::new() |
| 76 | + .header("t2.h") |
| 77 | + .language(ctest::Lang::CXX) |
| 78 | + .include("src") |
| 79 | + .type_name(move |ty, is_struct, is_union| match ty { |
| 80 | + "T2Union" => ty.to_string(), |
| 81 | + t if is_struct => format!("struct {}", t), |
| 82 | + t if is_union => format!("union {}", t), |
| 83 | + t => t.to_string(), |
| 84 | + }) |
| 85 | + .skip_roundtrip(|_| true) |
| 86 | + .generate("src/t2.rs", "t2gen_cxx.rs"); |
| 87 | + } else { |
| 88 | + println!("cargo::warning=skipping C++ tests"); |
| 89 | + } |
79 | 90 | } |
80 | 91 |
|
81 | 92 | fn t1_volatile(i: ctest::VolatileItemKind) -> bool { |
|
0 commit comments