Skip to content

Boost.Predef should provide a way to detect WASM #131

Open

Description

@jcelerier

Relevant macros gathered from echo | em++ -dM -E -x c++ -:

#define EMSCRIPTEN 1
#define __EMSCRIPTEN__ 1
#define __wasm 1
#define __wasm32 1
#define __wasm32__ 1
#define __wasm__ 1

Activity

  1. jcelerier commented on Aug 10, 2023

    @jcelerier
    Author

    Also it's already detected in some way by boost.config: https://www.boost.org/doc/libs/1_82_0/boost/config/detail/select_platform_config.hpp

  2. sleeptightAnsiC commented on Feb 3, 2025

    @sleeptightAnsiC
  3. sleeptightAnsiC commented on Feb 3, 2025

    @sleeptightAnsiC
  4. rainerdeyke commented on Apr 23, 2026

    @rainerdeyke

    Can somebody make an executive decision here?

    My opinion, FWIW:

    wasm32 and wasm64 are architectures. The correct macros should be BOOST_ARCH_WASM32 and BOOST_ARCH_WASM64.

    Emscripten is analogous to mingw: an emulation layer that emulates POSIX on a different platform (a web browser and Windows respectively), plus a compiler that targets that emulation layer. Since mingw is treated as a platform, so should Emscripten be. So the correct macro would be BOOST_PLAT_EMSCRIPTEN. Emscripten is based on clang, so BOOST_COMP_CLANG should also be detected.

    Architecture and platform are orthogonal here: non-Emscripten clang can target the wasm architecture, and Emscripten can (or could) output Javascript instead of wasm.

    If we're running in a web browser is the third not-quite-orthogonal concern, analogous to the OS. Emscripten can target node.js and standalone wasm runtimes in addition to targeting web browsers. However, this may not be possible to detect at compile time, because the same wasm files can run both in web browsers and standalone.

  5. grafikrobot commented on Apr 23, 2026

    @grafikrobot
    Member

    @rainerdeyke I like that suggestion.

  6. grafikrobot commented on Apr 23, 2026

    @grafikrobot
    Member

    @rainerdeyke although.. wondering if there's a difference between WASM32 and WASM64 that isn't covered by WASM, BOOST_ARCH_WORD_BITS_32, and BOOST_ARCH_WORD_BITS_64?

  7. rainerdeyke commented on Apr 24, 2026

    @rainerdeyke

    I'm mostly going by the precedent of having both BOOST_ARCH_X86_32 and BOOST_ARCH_X86_64. That said, there doesn't seem to be a clear policy here.

    • For x86 there's the generic BOOST_ARCH_X86, plus BOOST_ARCH_X86_32 and BOOST_ARCH_X86_64.
    • For PowerPC there's the generic BOOST_ARCH_PPC plus BOOST_ARCH_PPC_64, but no BOOST_ARCH_PPC_32.
    • For Arm there's just BOOST_ARCH_ARM.

    So this could go either way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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