From c4fdff85a841ed6459b7b611f129a74b0728a376 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Thu, 20 Jul 2017 10:43:26 +1000 Subject: [PATCH 1/3] Have tests targetting Linux by default on Windows --- tests/tests.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/tests.rs b/tests/tests.rs index 6950026817..05a39fad1b 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -137,6 +137,20 @@ fn create_bindgen_builder(header: &PathBuf) -> Result, Error> { } } + // Windows platform has various different conventions than *nix platforms, + // e.g. default enum underlying type, struct padding, mangling. Most tests + // were written and checked on Linux and macOS, and thus they could fail on + // Windows. We just make those tests targetting Linux instead as far as one + // isn't annotated for a specific target. + if cfg!(target_os = "windows") { + if flags.iter().all(|flag| !flag.starts_with("--target=")) { + if !flags.iter().any(|flag| flag == "--") { + flags.push("--".into()); + } + flags.push("--target=x86_64-unknown-linux".into()); + } + } + // Fool builder_from_flags() into believing it has real env::args_os... // - add "bindgen" as executable name 0th element // - add header filename as 1st element From c6cf648b6cd9a5d6a85336ab7dc47388c346e27c Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Thu, 20 Jul 2017 10:44:15 +1000 Subject: [PATCH 2/3] Skip no_system_header_includes test for Windows --- tests/tests.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/tests.rs b/tests/tests.rs index 05a39fad1b..41e8d85861 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -7,7 +7,6 @@ use bindgen::{Builder, builder, clang_version}; use std::fs; use std::io::{BufRead, BufReader, Error, ErrorKind, Read, Write}; use std::path::PathBuf; -use std::process::Command; #[path="../src/options.rs"] mod options; @@ -243,7 +242,11 @@ fn test_multiple_header_calls_in_builder() { } #[test] +// Doesn't support executing sh file on Windows. +// We may want to implement it in Rust so that we support all systems. +#[cfg(not(target_os = "windows"))] fn no_system_header_includes() { + use std::process::Command; assert!(Command::new("./ci/no-includes.sh") .current_dir(env!("CARGO_MANIFEST_DIR")) .spawn() From 294483487aa41a1a12deea4c9ecde1ba79c0976f Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Thu, 20 Jul 2017 10:44:53 +1000 Subject: [PATCH 3/3] Use a platform-neutral header for test_multiple_header_calls_in_builder --- .../test_multiple_header_calls_in_builder.rs | 95 +++++++++++++++++-- tests/tests.rs | 2 +- 2 files changed, 90 insertions(+), 7 deletions(-) diff --git a/tests/expectations/tests/test_multiple_header_calls_in_builder.rs b/tests/expectations/tests/test_multiple_header_calls_in_builder.rs index 58ec6fff09..5f009f85fb 100644 --- a/tests/expectations/tests/test_multiple_header_calls_in_builder.rs +++ b/tests/expectations/tests/test_multiple_header_calls_in_builder.rs @@ -9,9 +9,92 @@ extern "C" { ::std::os::raw::c_int) -> ::std::os::raw::c_int>; } -#[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum Foo { Bar = 0, Qux = 1, } -#[repr(i32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum Neg { MinusOne = -1, One = 1, } +pub type Char = ::std::os::raw::c_char; +pub type SChar = ::std::os::raw::c_schar; +pub type UChar = ::std::os::raw::c_uchar; +#[repr(C)] +#[derive(Debug, Copy)] +pub struct Test { + pub ch: ::std::os::raw::c_char, + pub u: ::std::os::raw::c_uchar, + pub d: ::std::os::raw::c_schar, + pub cch: ::std::os::raw::c_char, + pub cu: ::std::os::raw::c_uchar, + pub cd: ::std::os::raw::c_schar, + pub Cch: Char, + pub Cu: UChar, + pub Cd: SChar, + pub Ccch: Char, + pub Ccu: UChar, + pub Ccd: SChar, +} +#[test] +fn bindgen_test_layout_Test() { + assert_eq!(::std::mem::size_of::() , 12usize , concat ! ( + "Size of: " , stringify ! ( Test ) )); + assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Test ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Test ) ) . ch as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Test ) , "::" , + stringify ! ( ch ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Test ) ) . u as * const _ as usize } , + 1usize , concat ! ( + "Alignment of field: " , stringify ! ( Test ) , "::" , + stringify ! ( u ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Test ) ) . d as * const _ as usize } , + 2usize , concat ! ( + "Alignment of field: " , stringify ! ( Test ) , "::" , + stringify ! ( d ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Test ) ) . cch as * const _ as usize } , + 3usize , concat ! ( + "Alignment of field: " , stringify ! ( Test ) , "::" , + stringify ! ( cch ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Test ) ) . cu as * const _ as usize } , + 4usize , concat ! ( + "Alignment of field: " , stringify ! ( Test ) , "::" , + stringify ! ( cu ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Test ) ) . cd as * const _ as usize } , + 5usize , concat ! ( + "Alignment of field: " , stringify ! ( Test ) , "::" , + stringify ! ( cd ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Test ) ) . Cch as * const _ as usize } , + 6usize , concat ! ( + "Alignment of field: " , stringify ! ( Test ) , "::" , + stringify ! ( Cch ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Test ) ) . Cu as * const _ as usize } , + 7usize , concat ! ( + "Alignment of field: " , stringify ! ( Test ) , "::" , + stringify ! ( Cu ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Test ) ) . Cd as * const _ as usize } , + 8usize , concat ! ( + "Alignment of field: " , stringify ! ( Test ) , "::" , + stringify ! ( Cd ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Test ) ) . Ccch as * const _ as usize } , + 9usize , concat ! ( + "Alignment of field: " , stringify ! ( Test ) , "::" , + stringify ! ( Ccch ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Test ) ) . Ccu as * const _ as usize } , + 10usize , concat ! ( + "Alignment of field: " , stringify ! ( Test ) , "::" , + stringify ! ( Ccu ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Test ) ) . Ccd as * const _ as usize } , + 11usize , concat ! ( + "Alignment of field: " , stringify ! ( Test ) , "::" , + stringify ! ( Ccd ) )); +} +impl Clone for Test { + fn clone(&self) -> Self { *self } +} diff --git a/tests/tests.rs b/tests/tests.rs index 41e8d85861..cf04af5077 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -219,7 +219,7 @@ extern \"C\" { fn test_multiple_header_calls_in_builder() { let actual = builder() .header(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/headers/func_ptr.h")) - .header(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/headers/enum.h")) + .header(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/headers/char.h")) .generate() .unwrap() .to_string();