Skip to content

Building on MacOS Sequoia with Clang 17 #476

@chiefenne

Description

@chiefenne

NOTE: I posted mostly the same text in the MicroPython Issues as it is also relevant there.

I was trying to build LVGL MicroPython binding on MacOS Sequoia, Apple clang version 17.0.0 (clang-1700.3.19.1), Target: x86_64-apple-darwin24.6.0 and I got compilation errors with respect to MP_STATIC_ASSERT in misc.h.

With the help of ChatGPT I could fix misc.h and sucessfull build:
LVGL (9.3.0) MicroPython (1.25.0) Binding compiled on 2025-10-19; Generic ESP32 module with ESP32

The suggested change in lib/micropython/py/misc.h was:

/*
// Static assertion macro
define MP_STATIC_ASSERT(cond) ((void)sizeof(char[1 - 2 * !(cond)]))
*/

// -----------------------------------------------------------------------------
// Static assertion macros (portable across GCC, Clang, MSVC)
// -----------------------------------------------------------------------------

// Use C11 _Static_assert when available (Clang/GCC both support it)
#if defined(__clang__) || defined(__GNUC__) || \
    (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
    #define MP_STATIC_ASSERT(cond) _Static_assert(cond, "MP_STATIC_ASSERT failed")
#else
    // Fallback for pre-C11 compilers
    #define MP_STATIC_ASSERT(cond) \
        typedef char mp_static_assert_##__LINE__[(cond) ? 1 : -1]
#endif

// -----------------------------------------------------------------------------
// Some macros (like mp_obj_is_type) place these inside expressions.
// _Static_assert cannot appear there, so make this a no-op in such contexts.
// -----------------------------------------------------------------------------
#if !defined(MP_STATIC_ASSERT_NONCONSTEXPR)
    #define MP_STATIC_ASSERT_NONCONSTEXPR(cond) ((void)0)
#endif

That did the trick. Maybe that helps someone as an intermediate solution. It seems that this will be addressed in MicroPython.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions