Skip to content

Update default rust target to 1.33. #1530

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

Merged
merged 3 commits into from
Mar 4, 2019
Merged
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
60 changes: 41 additions & 19 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,56 @@
- [Removed](#removed)
- [Fixed](#fixed)
- [Security](#security)
- [0.47.3](#0473)
- [0.48.0](#0480)
- [Changed](#changed-1)
- [0.47.2](#0472)
- [Fixed](#fixed-1)
- [0.47.1](#0471)
- [0.47.3](#0473)
- [Changed](#changed-2)
- [0.47.2](#0472)
- [Fixed](#fixed-2)
- [0.47.0](#0470)
- [0.47.1](#0471)
- [Changed](#changed-3)
- [Fixed](#fixed-3)
- [0.47.0](#0470)
- [Changed](#changed-4)
- [Fixed](#fixed-4)
- [0.33.1 .. 0.46.0](#0331--0460)
- [Added](#added-1)
- [Removed](#removed-1)
- [Changed](#changed-4)
- [Fixed](#fixed-4)
- [0.33.1](#0331)
- [Changed](#changed-5)
- [Fixed](#fixed-5)
- [0.33.1](#0331)
- [Fixed](#fixed-6)
- [0.33.0](#0330)
- [Added](#added-2)
- [Changed](#changed-5)
- [Changed](#changed-6)
- [Deprecated](#deprecated-1)
- [Removed](#removed-2)
- [Fixed](#fixed-6)
- [Fixed](#fixed-7)
- [Security](#security-1)
- [0.32.2](#0322)
- [Fixed](#fixed-7)
- [0.32.1](#0321)
- [Fixed](#fixed-8)
- [0.32.1](#0321)
- [Fixed](#fixed-9)
- [0.32.0](#0320)
- [Added](#added-3)
- [Changed](#changed-6)
- [Fixed](#fixed-9)
- [Changed](#changed-7)
- [Fixed](#fixed-10)
- [0.31.0](#0310)
- [Added](#added-4)
- [Changed](#changed-7)
- [Changed](#changed-8)
- [Deprecated](#deprecated-2)
- [Removed](#removed-3)
- [Fixed](#fixed-10)
- [Fixed](#fixed-11)
- [0.30.0](#0300)
- [Added](#added-5)
- [Changed](#changed-8)
- [Changed](#changed-9)
- [Deprecated](#deprecated-3)
- [Fixed](#fixed-11)
- [Fixed](#fixed-12)
- [0.29.0](#0290)
- [Added](#added-6)
- [Changed](#changed-9)
- [Fixed](#fixed-12)
- [Changed](#changed-10)
- [Fixed](#fixed-13)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down Expand Up @@ -89,6 +92,25 @@ Released YYYY/MM/DD

* TODO (or remove section if none)


--------------------------------------------------------------------------------

# 0.48.0

Released 2019/03/04

## Changed

* Default rust target was changed to 1.33, which means that bindgen can get much
more often the layout of structs right. [#1529][]

## Fixed

* Bindgen will output repr(align) just when needed for unions. [#1498][]

[#1529]: https://github.com/rust-lang-nursery/rust-bindgen/issues/1529
[#1498]: https://github.com/rust-lang-nursery/rust-bindgen/issues/1498

--------------------------------------------------------------------------------

# 0.47.3
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ readme = "README.md"
repository = "https://github.com/rust-lang/rust-bindgen"
documentation = "https://docs.rs/bindgen"
homepage = "https://rust-lang.github.io/rust-bindgen/"
version = "0.47.3"
version = "0.48.0"
build = "build.rs"

include = [
Expand Down
2 changes: 0 additions & 2 deletions bindgen-integration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ fn test_bitfield_constructors() {

let mut second = bindings::bitfields::Second {
_bitfield_1: bindings::bitfields::Second::new_bitfield_1(1337, true),
__bindgen_align: [],
};
assert!(unsafe { second.assert(1337, true) });

Expand All @@ -189,7 +188,6 @@ fn test_bitfield_constructors() {
false,
bindings::bitfields::ItemKind::ITEM_KIND_TRES,
),
__bindgen_align: [],
};
assert!(unsafe {
third.assert(42, false, bindings::bitfields::ItemKind::ITEM_KIND_TRES)
Expand Down
3 changes: 1 addition & 2 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,7 @@ impl CodeGenerator for CompInfo {
// TODO(emilio): It'd be nice to unify this with the struct path
// above somehow.
let layout = layout.expect("Unable to get layout information?");
struct_layout.saw_union(layout);

if struct_layout.requires_explicit_align(layout) {
explicit_align = Some(layout.align);
Expand All @@ -1600,8 +1601,6 @@ impl CodeGenerator for CompInfo {
_bindgen_union_align: #ty ,
}
} else {
struct_layout.saw_union(layout);

quote! {
pub bindgen_union_field: #ty ,
}
Expand Down
6 changes: 3 additions & 3 deletions src/codegen/struct_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ impl<'a> StructLayoutTracker<'a> {
name: &'a str,
) -> Self {
StructLayoutTracker {
name: name,
ctx: ctx,
comp: comp,
name,
ctx,
comp,
is_packed: comp.is_packed(ctx, &ty.layout(ctx)),
latest_offset: 0,
padding_count: 0,
Expand Down
2 changes: 1 addition & 1 deletion src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ rust_target_base!(rust_target_def);
rust_target_base!(rust_target_values_def);

/// Latest stable release of Rust
pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_21;
pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_33;

/// Create RustFeatures struct definition, new(), and a getter for each field
macro_rules! rust_feature_def {
Expand Down
17 changes: 13 additions & 4 deletions tests/expectations/tests/16-byte-alignment.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]

#![allow(
dead_code,
non_snake_case,
non_camel_case_types,
non_upper_case_globals
)]

#[repr(C)]
#[derive(Copy, Clone)]
Expand Down Expand Up @@ -271,11 +274,12 @@ impl Default for rte_ipv6_tuple {
}
}
#[repr(C)]
#[repr(align(16))]
#[derive(Copy, Clone)]
pub union rte_thash_tuple {
pub v4: rte_ipv4_tuple,
pub v6: rte_ipv6_tuple,
_bindgen_union_align: [u8; 48usize],
_bindgen_union_align: [u128; 3usize],
}
#[test]
fn bindgen_test_layout_rte_thash_tuple() {
Expand All @@ -284,6 +288,11 @@ fn bindgen_test_layout_rte_thash_tuple() {
48usize,
concat!("Size of: ", stringify!(rte_thash_tuple))
);
assert_eq!(
::std::mem::align_of::<rte_thash_tuple>(),
16usize,
concat!("Alignment of ", stringify!(rte_thash_tuple))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<rte_thash_tuple>())).v4 as *const _ as usize },
0usize,
Expand Down
1 change: 1 addition & 0 deletions tests/expectations/tests/annotation_hide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

/// <div rustbindgen opaque></div>
#[repr(C)]
#[repr(align(4))]
#[derive(Debug, Default, Copy, Clone)]
pub struct D {
pub _bindgen_opaque_blob: u32,
Expand Down
9 changes: 6 additions & 3 deletions tests/expectations/tests/anon_struct_in_union.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]

#![allow(
dead_code,
non_snake_case,
non_camel_case_types,
non_upper_case_globals
)]

#[repr(C)]
#[derive(Copy, Clone)]
Expand Down
8 changes: 4 additions & 4 deletions tests/expectations/tests/bitfield-enum-basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl ::std::ops::BitAndAssign for Foo {
self.0 &= rhs.0;
}
}
#[repr(C)]
#[repr(transparent)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Foo(pub i32);
impl Buz {
Expand Down Expand Up @@ -86,7 +86,7 @@ impl ::std::ops::BitAndAssign for Buz {
self.0 &= rhs.0;
}
}
#[repr(C)]
#[repr(transparent)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Buz(pub i8);
pub const NS_FOO: _bindgen_ty_1 = _bindgen_ty_1(1);
Expand Down Expand Up @@ -117,7 +117,7 @@ impl ::std::ops::BitAndAssign for _bindgen_ty_1 {
self.0 &= rhs.0;
}
}
#[repr(C)]
#[repr(transparent)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct _bindgen_ty_1(pub u32);
#[repr(C)]
Expand Down Expand Up @@ -153,7 +153,7 @@ impl ::std::ops::BitAndAssign for Dummy__bindgen_ty_1 {
self.0 &= rhs.0;
}
}
#[repr(C)]
#[repr(transparent)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Dummy__bindgen_ty_1(pub u32);
#[test]
Expand Down
73 changes: 73 additions & 0 deletions tests/expectations/tests/bitfield-large.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ where
}
}
#[repr(C)]
#[repr(align(16))]
#[derive(Debug, Default, Copy, Clone)]
pub struct HasBigBitfield {
pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize], u64>,
Expand All @@ -101,8 +102,37 @@ fn bindgen_test_layout_HasBigBitfield() {
16usize,
concat!("Size of: ", stringify!(HasBigBitfield))
);
assert_eq!(
::std::mem::align_of::<HasBigBitfield>(),
16usize,
concat!("Alignment of ", stringify!(HasBigBitfield))
);
}
impl HasBigBitfield {
#[inline]
pub fn x(&self) -> i128 {
unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 128u8) as u128) }
}
#[inline]
pub fn set_x(&mut self, val: i128) {
unsafe {
let val: u128 = ::std::mem::transmute(val);
self._bitfield_1.set(0usize, 128u8, val as u64)
}
}
#[inline]
pub fn new_bitfield_1(x: i128) -> __BindgenBitfieldUnit<[u8; 16usize], u64> {
let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize], u64> =
Default::default();
__bindgen_bitfield_unit.set(0usize, 128u8, {
let x: u128 = unsafe { ::std::mem::transmute(x) };
x as u64
});
__bindgen_bitfield_unit
}
}
#[repr(C)]
#[repr(align(16))]
#[derive(Debug, Default, Copy, Clone)]
pub struct HasTwoBigBitfields {
pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize], u64>,
Expand All @@ -114,4 +144,47 @@ fn bindgen_test_layout_HasTwoBigBitfields() {
16usize,
concat!("Size of: ", stringify!(HasTwoBigBitfields))
);
assert_eq!(
::std::mem::align_of::<HasTwoBigBitfields>(),
16usize,
concat!("Alignment of ", stringify!(HasTwoBigBitfields))
);
}
impl HasTwoBigBitfields {
#[inline]
pub fn x(&self) -> i128 {
unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 80u8) as u128) }
}
#[inline]
pub fn set_x(&mut self, val: i128) {
unsafe {
let val: u128 = ::std::mem::transmute(val);
self._bitfield_1.set(0usize, 80u8, val as u64)
}
}
#[inline]
pub fn y(&self) -> i128 {
unsafe { ::std::mem::transmute(self._bitfield_1.get(80usize, 48u8) as u128) }
}
#[inline]
pub fn set_y(&mut self, val: i128) {
unsafe {
let val: u128 = ::std::mem::transmute(val);
self._bitfield_1.set(80usize, 48u8, val as u64)
}
}
#[inline]
pub fn new_bitfield_1(x: i128, y: i128) -> __BindgenBitfieldUnit<[u8; 16usize], u64> {
let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize], u64> =
Default::default();
__bindgen_bitfield_unit.set(0usize, 80u8, {
let x: u128 = unsafe { ::std::mem::transmute(x) };
x as u64
});
__bindgen_bitfield_unit.set(80usize, 48u8, {
let y: u128 = unsafe { ::std::mem::transmute(y) };
y as u64
});
__bindgen_bitfield_unit
}
}
Loading