Skip to content

Wasm build fails: #ifndef EMSCRIPTEN guards never fire (Emscripten defines __EMSCRIPTEN__, not EMSCRIPTEN) #14

Description

@rustyconover

Summary

While building this extension as part of the DuckDB community extensions program (via the haybarn-community-extensions fork's CI, which builds every community extension across Linux/macOS/Windows/Wasm), all three Wasm targets (wasm_eh, wasm_mvp, wasm_threads) fail to compile.

Error

/duckdb_build_dir/src/quack_oauth_extension.cpp:19:10: fatal error: 'telemetry.hpp' file not found
/duckdb_build_dir/src/check_authorization_function.cpp:32:10: fatal error: 'telemetry.hpp' file not found
/duckdb_build_dir/src/diagnose.cpp:22:10: fatal error: 'telemetry.hpp' file not found
/duckdb_build_dir/src/settings.cpp:8:10: fatal error: 'telemetry.hpp' file not found

Full failing job: https://github.com/Query-farm-haybarn/haybarn-community-extensions/actions/runs/33027342386 (wasm_eh leg; wasm_mvp/wasm_threads fail identically)

Root cause

CMakeLists.txt correctly skips building posthog-telemetry (and its include path) for Wasm:

if(NOT EMSCRIPTEN)
    include_directories(posthog-telemetry/include)
    add_subdirectory(posthog-telemetry)
    ...
endif()

and each .cpp that includes "telemetry.hpp" does guard it with #ifndef EMSCRIPTEN / #endif, e.g. in src/quack_oauth_extension.cpp:

#ifndef EMSCRIPTEN
#include "acquire_function.hpp"
...
#include "telemetry.hpp"
#endif

The mismatch: if(EMSCRIPTEN) in CMakeLists.txt is a CMake-level variable (set by CMake's Emscripten toolchain file), but #ifndef EMSCRIPTEN in the .cpp files is a C preprocessor check for a macro that emcc never actually defines — Emscripten auto-defines __EMSCRIPTEN__ (double leading/trailing underscore), not bare EMSCRIPTEN. Since nothing in CMakeLists.txt does an explicit add_definitions(-DEMSCRIPTEN) / target_compile_definitions(... EMSCRIPTEN) to bridge the two, the preprocessor guard is always false on a real Wasm build, so the include always fires — right after CMake has correctly excluded the header/library it points at.

Suggested fix

Swap the preprocessor guards from #ifndef EMSCRIPTEN to #ifndef __EMSCRIPTEN__ in the affected files (quack_oauth_extension.cpp, check_authorization_function.cpp, diagnose.cpp, settings.cpp, and any others using the same pattern) — that's the macro Emscripten's compiler actually provides, and it'll make the guard do what the surrounding comments already say it's meant to do. Native (Linux/macOS/Windows) builds all pass fine today, so this is Wasm-only.

Thanks for maintaining this extension — happy to help verify a fix if useful!

Activity

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