From 76ba5429d75e2a09a5d725a81f49f071c223e50f Mon Sep 17 00:00:00 2001 From: ilammy Date: Sat, 1 Jan 2022 13:54:25 +0900 Subject: [PATCH] boring-sys: Disable alignment tests for iOS ARM64 targets As pointed out in the comment, bindgen generates tests that cause compiler warnings about misaligned references. bindgen people are aware of the issue, but we have to deal with our warnings that are treated as errors. For the time being, suppress alignment tests on platforms that are known to be triggering UB. I suspect that other non-x86 platforms are affected as well, but I can't get the tests to compile for those tests at the moment, so I'm not sure. Dealing with the issues one platform at a time. --- boring-sys/build.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/boring-sys/build.rs b/boring-sys/build.rs index 07d5bd35..5e0e6646 100644 --- a/boring-sys/build.rs +++ b/boring-sys/build.rs @@ -385,6 +385,22 @@ fn main() { .clang_args(get_extra_clang_args_for_bindgen()) .clang_args(&["-I", &include_path]); + let target = std::env::var("TARGET").unwrap(); + match target.as_ref() { + // bindgen produces alignment tests that cause undefined behavior [1] + // when applied to explicitly unaligned types like OSUnalignedU64. + // + // There is no way to disable these tests for only some types + // and it's not nice to suppress warnings for the entire crate, + // so let's disable all alignment tests and hope for the best. + // + // [1]: https://github.com/rust-lang/rust-bindgen/issues/1651 + "aarch64-apple-ios" | "aarch64-apple-ios-sim" => { + builder = builder.layout_tests(false); + } + _ => {} + } + let headers = [ "aes.h", "asn1_mac.h",