Skip to content

prebuilt bindings for win + mac + linux #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ signalbool = { version = "0.2.0", optional = true }
[features]
default = ["log"]
binaries = ["byteorder", "getopts", "signalbool"]
build_bindings = ["soapysdr-sys/build_bindings"]

[[bin]]
name = "soapy-sdr-info"
Expand Down
3 changes: 3 additions & 0 deletions soapysdr-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ repository = "https://github.com/kevinmehall/rust-soapysdr"
bindgen = { version = "0.66.1", default-features = false, features = ["runtime"] }
cc = "1.0"
pkg-config = "0.3.9"

[features]
build_bindings = []
1,486 changes: 1,486 additions & 0 deletions soapysdr-sys/bindings/bindings.rs

Large diffs are not rendered by default.

131 changes: 131 additions & 0 deletions soapysdr-sys/bindings/bindings_linux.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// linux tests + data structures

#[doc = "! Possible data types for argument info"]
pub type SoapySDRArgInfoType = ::std::os::raw::c_uint;

#[doc = " The available priority levels for log messages.\n\n The default log level threshold is SOAPY_SDR_INFO.\n Log messages with lower priorities are dropped.\n\n The default threshold can be set via the\n SOAPY_SDR_LOG_LEVEL environment variable.\n Set SOAPY_SDR_LOG_LEVEL to the string value:\n \"WARNING\", \"ERROR\", \"DEBUG\", etc...\n or set it to the equivalent integer value."]
pub type SoapySDRLogLevel = ::std::os::raw::c_uint;

Comment on lines +3 to +8
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the same on all platforms?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On windows they are signed, oddly (c_int vs c_uint). If they're the same width, then it seems it would generally be the same with a potential footgun that might eventually be triggered. I'm not sure it's worth preserving this discrepancy but I figured I'd at least surface it in this PR.

extern "C" {
#[doc = " Send a message to the registered logger.\n \\param logLevel a possible logging level\n \\param format a printf style format string\n \\param argList an argument list for the formatter"]
pub fn SoapySDR_vlogf(
logLevel: SoapySDRLogLevel,
format: *const ::std::os::raw::c_char,
argList: *mut __va_list_tag,
);
}

pub type va_list = __builtin_va_list;
pub type __builtin_va_list = [__va_list_tag; 1usize];
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct __va_list_tag {
pub gp_offset: ::std::os::raw::c_uint,
pub fp_offset: ::std::os::raw::c_uint,
pub overflow_arg_area: *mut ::std::os::raw::c_void,
pub reg_save_area: *mut ::std::os::raw::c_void,
}
#[test]
fn bindgen_test_layout___va_list_tag() {
const UNINIT: ::std::mem::MaybeUninit<__va_list_tag> = ::std::mem::MaybeUninit::uninit();
let ptr = UNINIT.as_ptr();
assert_eq!(
::std::mem::size_of::<__va_list_tag>(),
24usize,
concat!("Size of: ", stringify!(__va_list_tag))
);
assert_eq!(
::std::mem::align_of::<__va_list_tag>(),
8usize,
concat!("Alignment of ", stringify!(__va_list_tag))
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).gp_offset) as usize - ptr as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(__va_list_tag),
"::",
stringify!(gp_offset)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).fp_offset) as usize - ptr as usize },
4usize,
concat!(
"Offset of field: ",
stringify!(__va_list_tag),
"::",
stringify!(fp_offset)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).overflow_arg_area) as usize - ptr as usize },
8usize,
concat!(
"Offset of field: ",
stringify!(__va_list_tag),
"::",
stringify!(overflow_arg_area)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).reg_save_area) as usize - ptr as usize },
16usize,
concat!(
"Offset of field: ",
stringify!(__va_list_tag),
"::",
stringify!(reg_save_area)
)
);
}

// preserve any bindgen tests for all platforms out of an abundance of caution
// these get run as part of `cargo test`

#[repr(C)]
#[repr(align(16))]
#[derive(Debug, Copy, Clone)]
pub struct max_align_t {
pub __clang_max_align_nonce1: ::std::os::raw::c_longlong,
pub __bindgen_padding_0: u64,
pub __clang_max_align_nonce2: u128,
}

#[test]
fn bindgen_test_layout_max_align_t() {
const UNINIT: ::std::mem::MaybeUninit<max_align_t> = ::std::mem::MaybeUninit::uninit();
let ptr = UNINIT.as_ptr();
assert_eq!(
::std::mem::size_of::<max_align_t>(),
32usize,
concat!("Size of: ", stringify!(max_align_t))
);
assert_eq!(
::std::mem::align_of::<max_align_t>(),
16usize,
concat!("Alignment of ", stringify!(max_align_t))
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce1) as usize - ptr as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(max_align_t),
"::",
stringify!(__clang_max_align_nonce1)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce2) as usize - ptr as usize },
16usize,
concat!(
"Offset of field: ",
stringify!(max_align_t),
"::",
stringify!(__clang_max_align_nonce2)
)
);
}

Comment on lines +9 to +131
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think a bindgen-translated definition of va_list is going to be usable from Rust. There's an unstable type and a crate but both appear to only support a Rust function receiving a va_list from C to Rust, not the other way around.

So SoapySDR_vlogf should probably just be removed pending support for that.

19 changes: 19 additions & 0 deletions soapysdr-sys/bindings/bindings_macos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// macos tests + data structures

#[doc = "! Possible data types for argument info"]
pub type SoapySDRArgInfoType = ::std::os::raw::c_uint;

#[doc = " The available priority levels for log messages.\n\n The default log level threshold is SOAPY_SDR_INFO.\n Log messages with lower priorities are dropped.\n\n The default threshold can be set via the\n SOAPY_SDR_LOG_LEVEL environment variable.\n Set SOAPY_SDR_LOG_LEVEL to the string value:\n \"WARNING\", \"ERROR\", \"DEBUG\", etc...\n or set it to the equivalent integer value."]
pub type SoapySDRLogLevel = ::std::os::raw::c_uint;

extern "C" {
#[doc = " Send a message to the registered logger.\n \\param logLevel a possible logging level\n \\param format a printf style format string\n \\param argList an argument list for the formatter"]
pub fn SoapySDR_vlogf(
logLevel: SoapySDRLogLevel,
format: *const ::std::os::raw::c_char,
argList: va_list,
);
}

pub type va_list = __builtin_va_list;
pub type __builtin_va_list = *mut ::std::os::raw::c_char;
190 changes: 190 additions & 0 deletions soapysdr-sys/bindings/bindings_windows.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
// windows tests + data structures
#[doc = "! Possible data types for argument info"]
pub type SoapySDRArgInfoType = ::std::os::raw::c_int;

#[doc = " The available priority levels for log messages.\n\n The default log level threshold is SOAPY_SDR_INFO.\n Log messages with lower priorities are dropped.\n\n The default threshold can be set via the\n SOAPY_SDR_LOG_LEVEL environment variable.\n Set SOAPY_SDR_LOG_LEVEL to the string value:\n \"WARNING\", \"ERROR\", \"DEBUG\", etc...\n or set it to the equivalent integer value."]
pub type SoapySDRLogLevel = ::std::os::raw::c_int;

pub type va_list = *mut ::std::os::raw::c_char;

extern "C" {
#[doc = " Send a message to the registered logger.\n \\param logLevel a possible logging level\n \\param format a printf style format string\n \\param argList an argument list for the formatter"]
pub fn SoapySDR_vlogf(
logLevel: SoapySDRLogLevel,
format: *const ::std::os::raw::c_char,
argList: va_list,
);
}

// preserve any bindgen tests for all platforms out of an abundance of caution
// these get run as part of `cargo test`

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct __crt_locale_data_public {
pub _locale_pctype: *const ::std::os::raw::c_ushort,
pub _locale_mb_cur_max: ::std::os::raw::c_int,
pub _locale_lc_codepage: ::std::os::raw::c_uint,
}

#[test]
fn bindgen_test_layout___crt_locale_data_public() {
const UNINIT: ::std::mem::MaybeUninit<__crt_locale_data_public> =
::std::mem::MaybeUninit::uninit();
let ptr = UNINIT.as_ptr();
assert_eq!(
::std::mem::size_of::<__crt_locale_data_public>(),
16usize,
concat!("Size of: ", stringify!(__crt_locale_data_public))
);
assert_eq!(
::std::mem::align_of::<__crt_locale_data_public>(),
8usize,
concat!("Alignment of ", stringify!(__crt_locale_data_public))
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr)._locale_pctype) as usize - ptr as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(__crt_locale_data_public),
"::",
stringify!(_locale_pctype)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr)._locale_mb_cur_max) as usize - ptr as usize },
8usize,
concat!(
"Offset of field: ",
stringify!(__crt_locale_data_public),
"::",
stringify!(_locale_mb_cur_max)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr)._locale_lc_codepage) as usize - ptr as usize },
12usize,
concat!(
"Offset of field: ",
stringify!(__crt_locale_data_public),
"::",
stringify!(_locale_lc_codepage)
)
);
}


#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct __crt_locale_pointers {
pub locinfo: *mut __crt_locale_data,
pub mbcinfo: *mut __crt_multibyte_data,
}

#[test]
fn bindgen_test_layout___crt_locale_pointers() {
const UNINIT: ::std::mem::MaybeUninit<__crt_locale_pointers> =
::std::mem::MaybeUninit::uninit();
let ptr = UNINIT.as_ptr();
assert_eq!(
::std::mem::size_of::<__crt_locale_pointers>(),
16usize,
concat!("Size of: ", stringify!(__crt_locale_pointers))
);
assert_eq!(
::std::mem::align_of::<__crt_locale_pointers>(),
8usize,
concat!("Alignment of ", stringify!(__crt_locale_pointers))
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).locinfo) as usize - ptr as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(__crt_locale_pointers),
"::",
stringify!(locinfo)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr).mbcinfo) as usize - ptr as usize },
8usize,
concat!(
"Offset of field: ",
stringify!(__crt_locale_pointers),
"::",
stringify!(mbcinfo)
)
);
}

pub type _locale_t = *mut __crt_locale_pointers;

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _Mbstatet {
pub _Wchar: ::std::os::raw::c_ulong,
pub _Byte: ::std::os::raw::c_ushort,
pub _State: ::std::os::raw::c_ushort,
}

#[test]
fn bindgen_test_layout__Mbstatet() {
const UNINIT: ::std::mem::MaybeUninit<_Mbstatet> = ::std::mem::MaybeUninit::uninit();
let ptr = UNINIT.as_ptr();
assert_eq!(
::std::mem::size_of::<_Mbstatet>(),
8usize,
concat!("Size of: ", stringify!(_Mbstatet))
);
assert_eq!(
::std::mem::align_of::<_Mbstatet>(),
4usize,
concat!("Alignment of ", stringify!(_Mbstatet))
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr)._Wchar) as usize - ptr as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(_Mbstatet),
"::",
stringify!(_Wchar)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr)._Byte) as usize - ptr as usize },
4usize,
concat!(
"Offset of field: ",
stringify!(_Mbstatet),
"::",
stringify!(_Byte)
)
);
assert_eq!(
unsafe { ::std::ptr::addr_of!((*ptr)._State) as usize - ptr as usize },
6usize,
concat!(
"Offset of field: ",
stringify!(_Mbstatet),
"::",
stringify!(_State)
)
);
}

pub type mbstate_t = _Mbstatet;

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct __crt_locale_data {
pub _address: u8,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct __crt_multibyte_data {
pub _address: u8,
}
Comment on lines +21 to +190
Copy link
Owner

@kevinmehall kevinmehall Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like these shouldn't be exposed by this library? Just stuff from system headers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, probably so. I wanted to preserve any tests that bindgen created (just to check something if we can) and I believe these are a dependency, but there's probably a smarter way to test the bindings.

Loading