Skip to content
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

Endianness/Byte-order detection on build machine #4843

Closed
Hyiker opened this issue Mar 16, 2024 · 2 comments
Closed

Endianness/Byte-order detection on build machine #4843

Hyiker opened this issue Mar 16, 2024 · 2 comments

Comments

@Hyiker
Copy link
Contributor

Hyiker commented Mar 16, 2024

Is your feature request related to a problem? Please describe.

I'm trying to put some byte-order related functionality in my cpp code, it works like(from UE5 source code):

struct {
#if PLATFORM_LITTLE_ENDIAN
			uint32	Mantissa : 23;
			uint32	Exponent : 8;
			uint32	Sign : 1;			
#else
			uint32	Sign : 1;
			uint32	Exponent : 8;
			uint32	Mantissa : 23;			
#endif
}

c/cpp lacks standard macros for this, I noticed there was once an issue mentioned this: #514 .However, __BYTE_ORDER__ is not a portable way to do this, for some compilers such as MSVC doesn't have such definition.

CMake provides TestBigEndian snippet(supserseded by CMAKE_<LANG>_BYTE_ORDER since 3.20), supporting c/c++/cuda/objc/objcxx. Providing resembling API greatly empowers languages such as cpp lack the ability of compile-time byte order determination.

Describe the solution you'd like

CMake uses TestEndianess.c.in for this functionality, and we can refer to TestEndianess.c.in to do such test.
I suggest run this test in configuration stage( xmake f ), and provide an variable var.$(byteorder) describing the endianness. To reduce complexity, the value should be either big_endian or little_endian, ignoring other conditions.

Describe alternatives you've considered

No response

Additional context

No response

@waruqi
Copy link
Member

waruqi commented Mar 16, 2024

you can refer this patch. #4349

then open a pr to add check_bigendian

Hyiker added a commit to Hyiker/xmake that referenced this issue Mar 17, 2024
waruqi added a commit that referenced this issue Mar 17, 2024
feat: Add check_bigendian #4843
@waruqi waruqi added this to the v2.8.9 milestone Mar 17, 2024
@waruqi
Copy link
Member

waruqi commented Mar 17, 2024

Thanks!

@waruqi waruqi closed this as completed Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants