From 4932d2376cc03c64eb82972824be673cdc2e0741 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 22 Sep 2020 18:26:53 +0200 Subject: Do not include layout tests in generated bindings We are generating the Rust bindings in src/ffi.rs using bindgen once for all platforms on an amd64 machine. These bindings previously included layout tests. But these tests fail on some 32-bit architecture. See this discussion for more information: https://lists.sr.ht/~ireas/nitrokey-rs-dev/%3C20200919182408.GA1513%40ireas.org%3E With this patch, we remove the layout tests from the generated bindings. Instead, we will add the option to re-generate the bindings, including the layout tests, during the build in the next patch. --- CHANGELOG.md | 1 + Makefile | 1 + patches/deprecated.diff | 8 +- src/ffi.rs | 689 ------------------------------------------------ 4 files changed, 6 insertions(+), 693 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af7fb18..8efd48c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Derive `Debug` for all structs generated by `bindgen`. - Implement `std::fmt::Display` instead of `std::string::ToString` for the `Version` enum in `build.rs`. +- Do not include layout tests in the generated bindings. - Update to libnitrokey 3.6, causing all following changes. - New constants: - `NK_device_model_NK_LIBREM` (`NK_device_model` enum) diff --git a/Makefile b/Makefile index 3e48cf8..b5fec75 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ src/ffi.rs: ${LIBNITROKEY}/NK_C_API.h --whitelist-var "NK_.*" \ --whitelist-var "MAXIMUM_STR_REPLY_LENGTH" \ --with-derive-default \ + --no-layout-tests \ --output "$@" \ "$<" \ -- "-I${LIBNITROKEY}/libnitrokey" diff --git a/patches/deprecated.diff b/patches/deprecated.diff index 79fe5ba..e13f90f 100644 --- a/patches/deprecated.diff +++ b/patches/deprecated.diff @@ -6,7 +6,7 @@ Index: nitrokey-sys-rs/src/ffi.rs =================================================================== --- nitrokey-sys-rs.orig/src/ffi.rs +++ nitrokey-sys-rs/src/ffi.rs -@@ -848,6 +848,7 @@ extern "C" { +@@ -212,6 +212,7 @@ extern "C" { #[doc = " deprecated in favor of NK_get_status_as_string."] #[doc = " @return string representation of the status or an empty string"] #[doc = " if the command failed"] @@ -14,7 +14,7 @@ Index: nitrokey-sys-rs/src/ffi.rs pub fn NK_status() -> *mut ::std::os::raw::c_char; } extern "C" { -@@ -1134,6 +1135,7 @@ extern "C" { +@@ -498,6 +499,7 @@ extern "C" { pub fn NK_totp_set_time_soft(time: u64) -> ::std::os::raw::c_int; } extern "C" { @@ -22,7 +22,7 @@ Index: nitrokey-sys-rs/src/ffi.rs pub fn NK_totp_get_time() -> ::std::os::raw::c_int; } extern "C" { -@@ -1309,6 +1311,7 @@ extern "C" { +@@ -673,6 +675,7 @@ extern "C" { #[doc = " Storage only"] #[doc = " @param user_pin 20 characters User PIN"] #[doc = " @return command processing error code"] @@ -30,7 +30,7 @@ Index: nitrokey-sys-rs/src/ffi.rs pub fn NK_set_unencrypted_read_only( user_pin: *const ::std::os::raw::c_char, ) -> ::std::os::raw::c_int; -@@ -1322,6 +1325,7 @@ extern "C" { +@@ -686,6 +689,7 @@ extern "C" { #[doc = " Storage only"] #[doc = " @param user_pin 20 characters User PIN"] #[doc = " @return command processing error code"] diff --git a/src/ffi.rs b/src/ffi.rs index d335280..94ac5ae 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -28,59 +28,6 @@ pub struct NK_device_info { #[doc = " if this is the last element in the list."] pub next: *mut NK_device_info, } -#[test] -fn bindgen_test_layout_NK_device_info() { - assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(NK_device_info)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(NK_device_info)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).model as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NK_device_info), - "::", - stringify!(model) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).path as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(NK_device_info), - "::", - stringify!(path) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).serial_number as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(NK_device_info), - "::", - stringify!(serial_number) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).next as *const _ as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(NK_device_info), - "::", - stringify!(next) - ) - ); -} impl Default for NK_device_info { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -112,95 +59,6 @@ pub struct NK_status { #[doc = " an OTP value."] pub otp_user_password: bool, } -#[test] -fn bindgen_test_layout_NK_status() { - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(NK_status)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NK_status)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).firmware_version_major as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NK_status), - "::", - stringify!(firmware_version_major) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).firmware_version_minor as *const _ as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(NK_status), - "::", - stringify!(firmware_version_minor) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).serial_number_smart_card as *const _ as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(NK_status), - "::", - stringify!(serial_number_smart_card) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).config_numlock as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(NK_status), - "::", - stringify!(config_numlock) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).config_capslock as *const _ as usize }, - 9usize, - concat!( - "Offset of field: ", - stringify!(NK_status), - "::", - stringify!(config_capslock) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).config_scrolllock as *const _ as usize }, - 10usize, - concat!( - "Offset of field: ", - stringify!(NK_status), - "::", - stringify!(config_scrolllock) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).otp_user_password as *const _ as usize }, - 11usize, - concat!( - "Offset of field: ", - stringify!(NK_status), - "::", - stringify!(otp_user_password) - ) - ); -} #[doc = " Stores the status of a Storage device."] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -239,219 +97,6 @@ pub struct NK_storage_status { #[doc = " the AES keys."] pub stick_initialized: bool, } -#[test] -fn bindgen_test_layout_NK_storage_status() { - assert_eq!( - ::std::mem::size_of::(), - 28usize, - concat!("Size of: ", stringify!(NK_storage_status)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NK_storage_status)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).unencrypted_volume_read_only as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(unencrypted_volume_read_only) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).unencrypted_volume_active as *const _ - as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(unencrypted_volume_active) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).encrypted_volume_read_only as *const _ - as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(encrypted_volume_read_only) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).encrypted_volume_active as *const _ - as usize - }, - 3usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(encrypted_volume_active) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).hidden_volume_read_only as *const _ - as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(hidden_volume_read_only) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).hidden_volume_active as *const _ as usize - }, - 5usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(hidden_volume_active) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).firmware_version_major as *const _ - as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(firmware_version_major) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).firmware_version_minor as *const _ - as usize - }, - 7usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(firmware_version_minor) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).firmware_locked as *const _ as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(firmware_locked) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).serial_number_sd_card as *const _ as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(serial_number_sd_card) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).serial_number_smart_card as *const _ - as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(serial_number_smart_card) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).user_retry_count as *const _ as usize - }, - 20usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(user_retry_count) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).admin_retry_count as *const _ as usize - }, - 21usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(admin_retry_count) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).new_sd_card_found as *const _ as usize - }, - 22usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(new_sd_card_found) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).filled_with_random as *const _ as usize - }, - 23usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(filled_with_random) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).stick_initialized as *const _ as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(stick_initialized) - ) - ); -} #[doc = " Data about the usage of the SD card."] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -463,43 +108,6 @@ pub struct NK_SD_usage_data { #[doc = " size."] pub write_level_max: u8, } -#[test] -fn bindgen_test_layout_NK_SD_usage_data() { - assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(NK_SD_usage_data)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(NK_SD_usage_data)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).write_level_min as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NK_SD_usage_data), - "::", - stringify!(write_level_min) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).write_level_max as *const _ as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(NK_SD_usage_data), - "::", - stringify!(write_level_max) - ) - ); -} #[doc = " The general configuration of a Nitrokey device."] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -516,69 +124,6 @@ pub struct NK_config { #[doc = " Unused."] pub disable_user_password: bool, } -#[test] -fn bindgen_test_layout_NK_config() { - assert_eq!( - ::std::mem::size_of::(), - 5usize, - concat!("Size of: ", stringify!(NK_config)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(NK_config)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).numlock as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NK_config), - "::", - stringify!(numlock) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).capslock as *const _ as usize }, - 1usize, - concat!( - "Offset of field: ", - stringify!(NK_config), - "::", - stringify!(capslock) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).scrolllock as *const _ as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(NK_config), - "::", - stringify!(scrolllock) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).enable_user_password as *const _ as usize }, - 3usize, - concat!( - "Offset of field: ", - stringify!(NK_config), - "::", - stringify!(enable_user_password) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).disable_user_password as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(NK_config), - "::", - stringify!(disable_user_password) - ) - ); -} #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct NK_storage_ProductionTest { @@ -596,187 +141,6 @@ pub struct NK_storage_ProductionTest { pub SD_WriteSpeed_u16: u16, pub SD_Card_Manufacturer_u8: u8, } -#[test] -fn bindgen_test_layout_NK_storage_ProductionTest() { - assert_eq!( - ::std::mem::size_of::(), - 28usize, - concat!("Size of: ", stringify!(NK_storage_ProductionTest)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NK_storage_ProductionTest)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).FirmwareVersion_au8 as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(FirmwareVersion_au8) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).FirmwareVersionInternal_u8 - as *const _ as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(FirmwareVersionInternal_u8) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).SD_Card_Size_u8 as *const _ - as usize - }, - 3usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SD_Card_Size_u8) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).CPU_CardID_u32 as *const _ - as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(CPU_CardID_u32) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).SmartCardID_u32 as *const _ - as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SmartCardID_u32) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).SD_CardID_u32 as *const _ as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SD_CardID_u32) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).SC_UserPwRetryCount as *const _ - as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SC_UserPwRetryCount) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).SC_AdminPwRetryCount as *const _ - as usize - }, - 17usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SC_AdminPwRetryCount) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).SD_Card_ManufacturingYear_u8 - as *const _ as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SD_Card_ManufacturingYear_u8) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).SD_Card_ManufacturingMonth_u8 - as *const _ as usize - }, - 19usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SD_Card_ManufacturingMonth_u8) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).SD_Card_OEM_u16 as *const _ - as usize - }, - 20usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SD_Card_OEM_u16) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).SD_WriteSpeed_u16 as *const _ - as usize - }, - 22usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SD_WriteSpeed_u16) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).SD_Card_Manufacturer_u8 - as *const _ as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SD_Card_Manufacturer_u8) - ) - ); -} extern "C" { pub fn NK_get_storage_production_info( out: *mut NK_storage_ProductionTest, @@ -1548,59 +912,6 @@ pub struct ReadSlot_t { pub slot_token_id: [u8; 13usize], pub slot_counter: u64, } -#[test] -fn bindgen_test_layout_ReadSlot_t() { - assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(ReadSlot_t)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ReadSlot_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).slot_name as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ReadSlot_t), - "::", - stringify!(slot_name) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::()))._slot_config as *const _ as usize }, - 15usize, - concat!( - "Offset of field: ", - stringify!(ReadSlot_t), - "::", - stringify!(_slot_config) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).slot_token_id as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(ReadSlot_t), - "::", - stringify!(slot_token_id) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).slot_counter as *const _ as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(ReadSlot_t), - "::", - stringify!(slot_counter) - ) - ); -} extern "C" { pub fn NK_read_HOTP_slot(slot_num: u8, out: *mut ReadSlot_t) -> ::std::os::raw::c_int; } -- cgit v1.2.1