Move VALUE alignment test from meson.build to sandbox-bindgen

This commit is contained in:
刘皓 2025-01-19 22:37:20 -05:00
parent e346343be4
commit 6d3296906d
No known key found for this signature in database
GPG key ID: 7901753DB465B711
2 changed files with 2 additions and 9 deletions

View file

@ -31,15 +31,6 @@ global_args += '-DHAVE_NANOSLEEP'
# ====================
if get_option('retro') == true
# When Ruby is compiled to wasm32, we need `alignof(std::uint32_t) % 4 == 0`. When Ruby is compiled to wasm64, we need `alignof(std::uint64_t) % 8 == 0`.
# Strictly speaking, we only need to check one of these things depending on whether Ruby was compiled for wasm32 or wasm64, but I'm too lazy to figure out whether Ruby was compiled for wasm32 or wasm64 so let's just check both.
if compilers['cpp'].alignment('std::uint32_t', prefix: '#include <cstdint>') % 4 != 0
error('Alignment of `uint32_t` must be divisible by 4 for Ruby garbage collection to work.')
endif
if compilers['cpp'].alignment('std::uint64_t', prefix: '#include <cstdint>') % 8 != 0
error('Alignment of `uint64_t` must be divisible by 8 for Ruby garbage collection to work.')
endif
retro_phase1 = get_option('retro_phase1_path')
cmake = import('cmake')

View file

@ -357,6 +357,8 @@ PRELUDE = <<~HEREDOC
#include <cstdarg>
#include "mkxp-sandbox-bindgen.h"
static_assert(alignof(VALUE) % sizeof(VALUE) == 0, "Alignment of `VALUE` must be divisible by size of `VALUE` for Ruby garbage collection to work. If you compiled Ruby for wasm64, try compiling it for wasm32 instead.");
#if WABT_BIG_ENDIAN
#define SERIALIZE_32(value) __builtin_bswap32(value)
#define SERIALIZE_64(value) __builtin_bswap64(value)