sgrif / pq-sys

Auto-generated rust bindings for libpq
Apache License 2.0
41 stars 32 forks source link

Tests fail on 32bit architectures #32

Closed ignatenkobrain closed 9 months ago

ignatenkobrain commented 4 years ago
---- bindgen_test_layout__PQconninfoOption stdout ----
thread 'bindgen_test_layout__PQconninfoOption' panicked at 'assertion failed: `(left == right)`
  left: `28`,
 right: `56`', src/lib.rs:292:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
---- bindgen_test_layout__PQprintOpt stdout ----
thread 'bindgen_test_layout__PQprintOpt' panicked at 'assertion failed: `(left == right)`
  left: `24`,
 right: `40`', src/lib.rs:272:5
---- bindgen_test_layout___sFILE stdout ----
thread 'bindgen_test_layout___sFILE' panicked at 'assertion failed: `(left == right)`
  left: `88`,
 right: `152`', src/lib.rs:95:5
---- bindgen_test_layout__bindgen_ty_8 stdout ----
thread 'bindgen_test_layout__bindgen_ty_8' panicked at 'assertion failed: `(left == right)`
  left: `4`,
 right: `8`', src/lib.rs:325:5
---- bindgen_test_layout___sbuf stdout ----
thread 'bindgen_test_layout___sbuf' panicked at 'assertion failed: `(left == right)`
  left: `8`,
 right: `16`', src/lib.rs:41:5
---- bindgen_test_layout__bindgen_ty_8__bindgen_ty_1 stdout ----
thread 'bindgen_test_layout__bindgen_ty_8__bindgen_ty_1' panicked at 'assertion failed: `(left == right)`
  left: `4`,
 right: `8`', src/lib.rs:316:5
---- bindgen_test_layout_pgNotify stdout ----
thread 'bindgen_test_layout_pgNotify' panicked at 'assertion failed: `(left == right)`
  left: `16`,
 right: `32`', src/lib.rs:239:5
---- bindgen_test_layout_pgresAttDesc stdout ----
thread 'bindgen_test_layout_pgresAttDesc' panicked at 'assertion failed: `(left == right)`
  left: `28`,
 right: `32`', src/lib.rs:344:5
failures:
    bindgen_test_layout__PQconninfoOption
    bindgen_test_layout__PQprintOpt
    bindgen_test_layout___sFILE
    bindgen_test_layout___sbuf
    bindgen_test_layout__bindgen_ty_8
    bindgen_test_layout__bindgen_ty_8__bindgen_ty_1
    bindgen_test_layout_pgNotify
    bindgen_test_layout_pgresAttDesc
decathorpe commented 2 years ago

It appears that these test failures happen because bindgen test cases are not generated at build-time, and hard-code struct sizes that are only valid on 64-bit architectures. Looking at the code, I think the failures are harmless.

Still, would it be possible to generate the bindings and tests with bindgen at build-time (i.e. in build.rs)? Looking at the generated code in src/lib.rs, I think there are no manual modifications of the source code that was generated by bindgen, so that should work, it would solve the problem of the broken bindgen tests, and you wouldn't need to actually commit the generated source code to git at all, but only the build script and a "wrapper" lib.rs file.

weiznich commented 2 years ago

Just using bindgen directly is not a good solution as this introduces quite a lot of heavy dependencies. bindgen links llvm internally, so that must be there at build time or build as part of the build process. We can talk about adding support for this behind a feature flag that is off by default, but I would postpone that at least till https://github.com/sgrif/pq-sys/issues/42 is solved.

decathorpe commented 2 years ago

Sure, it makes sense to make it optional behind a feature flag for such cases. I can submit a PR for that, once the prerequisites are done :)

werdahias commented 1 year ago

I ran into the same issue on debian while unblocking diesel. I skipped the failing test for now with this patch:

--- a/src/lib.rs
+++ b/src/lib.rs
@@ -37,6 +37,7 @@ pub struct __sbuf {
     pub _size: ::std::os::raw::c_int,
 }
 #[test]
+#[cfg(not(target_pointer_width = "32"))]
 fn bindgen_test_layout___sbuf() {
     assert_eq!(::std::mem::size_of::<__sbuf>() , 16usize);
     assert_eq!(::std::mem::align_of::<__sbuf>() , 8usize);
@@ -91,6 +92,7 @@ pub struct __sFILE {
     pub _offset: fpos_t,
 }
 #[test]
+#[cfg(not(target_pointer_width = "32"))]
 fn bindgen_test_layout___sFILE() {
     assert_eq!(::std::mem::size_of::<__sFILE>() , 152usize);
     assert_eq!(::std::mem::align_of::<__sFILE>() , 8usize);
@@ -235,6 +237,7 @@ pub struct pgNotify {
     pub next: *mut pgNotify,
 }
 #[test]
+#[cfg(not(target_pointer_width = "32"))]
 fn bindgen_test_layout_pgNotify() {
     assert_eq!(::std::mem::size_of::<pgNotify>() , 32usize);
     assert_eq!(::std::mem::align_of::<pgNotify>() , 8usize);
@@ -268,6 +271,7 @@ pub struct _PQprintOpt {
     pub fieldName: *mut *mut ::std::os::raw::c_char,
 }
 #[test]
+#[cfg(not(target_pointer_width = "32"))]
 fn bindgen_test_layout__PQprintOpt() {
     assert_eq!(::std::mem::size_of::<_PQprintOpt>() , 40usize);
     assert_eq!(::std::mem::align_of::<_PQprintOpt>() , 8usize);
@@ -288,6 +292,7 @@ pub struct _PQconninfoOption {
     pub dispsize: ::std::os::raw::c_int,
 }
 #[test]
+#[cfg(not(target_pointer_width = "32"))]
 fn bindgen_test_layout__PQconninfoOption() {
     assert_eq!(::std::mem::size_of::<_PQconninfoOption>() , 56usize);
     assert_eq!(::std::mem::align_of::<_PQconninfoOption>() , 8usize);
@@ -311,6 +316,7 @@ pub struct _bindgen_ty_8__bindgen_ty_1 {
     pub bindgen_union_field: u64,
 }
 #[test]
+#[cfg(not(target_arch = "x86"))]
 fn bindgen_test_layout__bindgen_ty_8__bindgen_ty_1() {
     assert_eq!(::std::mem::size_of::<_bindgen_ty_8__bindgen_ty_1>() , 8usize);
     assert_eq!(::std::mem::align_of::<_bindgen_ty_8__bindgen_ty_1>() ,
@@ -340,6 +346,7 @@ pub struct pgresAttDesc {
     pub atttypmod: ::std::os::raw::c_int,
 }
 #[test]
+#[cfg(not(target_pointer_width = "32"))]
 fn bindgen_test_layout_pgresAttDesc() {
     assert_eq!(::std::mem::size_of::<pgresAttDesc>() , 32usize);
     assert_eq!(::std::mem::align_of::<pgresAttDesc>() , 8usize);
weiznich commented 1 year ago

@werdahias Again, I'm happy to accept a PR that fixes these tests.

weiznich commented 9 months ago

Essentially fixed by https://github.com/sgrif/pq-sys/pull/47 which allows to build your own platform specific bindings. The bundled bindings are meant to support all targets that are tested on CI.