Skip to content

Commit 5f6dc10

Browse files
committed
checkout const-serialize as per DioxusLabs#4932 and fix build
1 parent 4f938f2 commit 5f6dc10

File tree

11 files changed

+43
-36
lines changed

11 files changed

+43
-36
lines changed

packages/cli/src/build/assets.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,13 @@ impl ManganisVersion {
169169
}
170170
ManganisVersion::New => {
171171
// New format: serialize as BundledAsset directly (backward compatible)
172-
// Use a 4096-byte buffer to match the buffer size used in macro serialization
173-
let buffer = serialize_const(asset, ConstVec::<u8, 4096>::new_with_max_size());
174-
buffer.as_ref().to_vec()
172+
// Pad to 4096 bytes to match the linker output size
173+
let buffer = serialize_const(asset, ConstVec::new());
174+
let mut data = buffer.as_ref().to_vec();
175+
if data.len() < 4096 {
176+
data.resize(4096, 0);
177+
}
178+
data
175179
}
176180
}
177181
}
@@ -180,8 +184,12 @@ impl ManganisVersion {
180184
match self {
181185
ManganisVersion::Legacy => None,
182186
ManganisVersion::New => {
183-
let buffer = serialize_const(data, ConstVec::<u8, 4096>::new_with_max_size());
184-
Some(buffer.as_ref().to_vec())
187+
let buffer = serialize_const(data, ConstVec::new());
188+
let mut bytes = buffer.as_ref().to_vec();
189+
if bytes.len() < 4096 {
190+
bytes.resize(4096, 0);
191+
}
192+
Some(bytes)
185193
}
186194
}
187195
}

packages/const-serialize/src/array.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ unsafe impl<const N: usize, T: SerializeConst> SerializeConst for [T; N] {
2222
}
2323

2424
/// Serialize a constant sized array that is stored at the pointer passed in
25-
pub(crate) const unsafe fn serialize_const_array<const MAX_SIZE: usize>(
25+
pub(crate) const unsafe fn serialize_const_array(
2626
ptr: *const (),
27-
mut to: ConstVec<u8, MAX_SIZE>,
27+
mut to: ConstVec<u8>,
2828
layout: &ArrayLayout,
29-
) -> ConstVec<u8, MAX_SIZE> {
29+
) -> ConstVec<u8> {
3030
let len = layout.len;
3131
let mut i = 0;
3232
to = write_array(to, len);

packages/const-serialize/src/enum.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::*;
22

33
/// Serialize an enum that is stored at the pointer passed in
4-
pub(crate) const unsafe fn serialize_const_enum<const MAX_SIZE: usize>(
4+
pub(crate) const unsafe fn serialize_const_enum(
55
ptr: *const (),
6-
mut to: ConstVec<u8, MAX_SIZE>,
6+
mut to: ConstVec<u8>,
77
layout: &EnumLayout,
8-
) -> ConstVec<u8, MAX_SIZE> {
8+
) -> ConstVec<u8> {
99
let byte_ptr = ptr as *const u8;
1010
let discriminant = layout.discriminant.read(byte_ptr);
1111

packages/const-serialize/src/lib.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ pub unsafe trait SerializeConst: Sized {
6666
}
6767

6868
/// Serialize a pointer to a type that is stored at the pointer passed in
69-
const unsafe fn serialize_const_ptr<const MAX_SIZE: usize>(
69+
const unsafe fn serialize_const_ptr(
7070
ptr: *const (),
71-
to: ConstVec<u8, MAX_SIZE>,
71+
to: ConstVec<u8>,
7272
layout: &Layout,
73-
) -> ConstVec<u8, MAX_SIZE> {
73+
) -> ConstVec<u8> {
7474
match layout {
7575
Layout::Enum(layout) => serialize_const_enum(ptr, to, layout),
7676
Layout::Struct(layout) => serialize_const_struct(ptr, to, layout),
@@ -103,10 +103,7 @@ const unsafe fn serialize_const_ptr<const MAX_SIZE: usize>(
103103
/// assert_eq!(buffer.as_ref(), &[0xa3, 0x61, 0x61, 0x1a, 0x11, 0x11, 0x11, 0x11, 0x61, 0x62, 0x18, 0x22, 0x61, 0x63, 0x1a, 0x33, 0x33, 0x33, 0x33]);
104104
/// ```
105105
#[must_use = "The data is serialized into the returned buffer"]
106-
pub const fn serialize_const<T: SerializeConst, const MAX_SIZE: usize>(
107-
data: &T,
108-
to: ConstVec<u8, MAX_SIZE>,
109-
) -> ConstVec<u8, MAX_SIZE> {
106+
pub const fn serialize_const<T: SerializeConst>(data: &T, to: ConstVec<u8>) -> ConstVec<u8> {
110107
let ptr = data as *const T as *const ();
111108
// SAFETY: The pointer is valid and the layout is correct
112109
unsafe { serialize_const_ptr(ptr, to, &T::MEMORY_LAYOUT) }

packages/const-serialize/src/list.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ impl ListLayout {
3535
}
3636

3737
/// Serialize a dynamically sized list that is stored at the pointer passed in
38-
pub(crate) const unsafe fn serialize_const_list<const MAX_SIZE: usize>(
38+
pub(crate) const unsafe fn serialize_const_list(
3939
ptr: *const (),
40-
mut to: ConstVec<u8, MAX_SIZE>,
40+
mut to: ConstVec<u8>,
4141
layout: &ListLayout,
42-
) -> ConstVec<u8, MAX_SIZE> {
42+
) -> ConstVec<u8> {
4343
// Read the length of the list
4444
let len_ptr = ptr.wrapping_byte_offset(layout.len_offset as _);
4545
let len = layout.len_layout.read(len_ptr as *const u8) as usize;

packages/const-serialize/src/primitive.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ impl_serialize_const!(f32);
7171
impl_serialize_const!(f64);
7272

7373
/// Serialize a primitive type that is stored at the pointer passed in
74-
pub(crate) const unsafe fn serialize_const_primitive<const MAX_SIZE: usize>(
74+
pub(crate) const unsafe fn serialize_const_primitive(
7575
ptr: *const (),
76-
to: ConstVec<u8, MAX_SIZE>,
76+
to: ConstVec<u8>,
7777
layout: &PrimitiveLayout,
78-
) -> ConstVec<u8, MAX_SIZE> {
78+
) -> ConstVec<u8> {
7979
let ptr = ptr as *const u8;
8080
let mut offset = 0;
8181
let mut i64_bytes = [0u8; 8];

packages/const-serialize/src/struct.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ impl StructLayout {
3434
}
3535

3636
/// Serialize a struct that is stored at the pointer passed in
37-
pub(crate) const unsafe fn serialize_const_struct<const MAX_SIZE: usize>(
37+
pub(crate) const unsafe fn serialize_const_struct(
3838
ptr: *const (),
39-
to: ConstVec<u8, MAX_SIZE>,
39+
to: ConstVec<u8>,
4040
layout: &StructLayout,
41-
) -> ConstVec<u8, MAX_SIZE> {
41+
) -> ConstVec<u8> {
4242
let mut i = 0;
4343
let field_count = layout.data.len();
4444
let mut to = write_map(to, field_count);

packages/dx-macro-helpers/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ pub const fn serialize_to_const_with_max<const MAX_SIZE: usize>(
4848
value: &impl SerializeConst,
4949
memory_layout_size: usize,
5050
) -> ConstVec<u8, MAX_SIZE> {
51-
// Serialize directly into the larger buffer to avoid overflow
51+
// Serialize using the default buffer, then copy into the larger buffer
52+
let serialized = const_serialize::serialize_const(value, ConstVec::new());
5253
let mut data: ConstVec<u8, MAX_SIZE> = ConstVec::new_with_max_size();
53-
data = const_serialize::serialize_const(value, data);
54+
data = data.extend(serialized.as_ref());
5455
// Reserve the maximum size of the type (pad to MEMORY_LAYOUT size)
5556
while data.len() < memory_layout_size {
5657
data = data.push(0);

packages/manganis/manganis/src/macro_helpers.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ pub const fn create_bundled_asset_relative(
3232
/// linker section size. const-serialize deserialization will ignore
3333
/// the padding (zeros) at the end.
3434
pub const fn serialize_asset(asset: &BundledAsset) -> ConstVec<u8, 4096> {
35-
// Serialize directly into a 4096-byte buffer and pad to full size
36-
// This matches the CLI's expectation for the fixed buffer size
35+
// Serialize using the default buffer, then expand into the fixed-size buffer
36+
let serialized = const_serialize::serialize_const(asset, ConstVec::new());
3737
let mut data: ConstVec<u8, 4096> = ConstVec::new_with_max_size();
38-
data = const_serialize::serialize_const(asset, data);
38+
data = data.extend(serialized.as_ref());
3939
// Pad to full buffer size (4096) to match linker section size
4040
while data.len() < 4096 {
4141
data = data.push(0);

packages/permissions/permissions/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ pub mod macro_helpers {
5959
/// the padding (zeros) at the end.
6060
pub const fn serialize_permission(permission: &Permission) -> ConstVec<u8, 4096> {
6161
let symbol_data = SymbolData::Permission(*permission);
62-
// Serialize into a 4096-byte buffer and pad to full size
63-
// This matches the CLI's expectation for the fixed buffer size
62+
// Serialize using the default buffer, then expand into the fixed-size buffer
63+
let serialized = const_serialize::serialize_const(&symbol_data, ConstVec::new());
6464
let mut data: ConstVec<u8, 4096> = ConstVec::new_with_max_size();
65-
data = const_serialize::serialize_const(&symbol_data, data);
65+
data = data.extend(serialized.as_ref());
6666
// Pad to full buffer size (4096) to match linker section size
6767
while data.len() < 4096 {
6868
data = data.push(0);

0 commit comments

Comments
 (0)