Skip to content

Conversation

miklhh
Copy link
Contributor

@miklhh miklhh commented Sep 5, 2025

The logic for providing fmts header-only dependency is currently causing problems with building projects targeting WASM. This seems to be because, when the fmt meson option header-only is set, fmt_lib and fmt_dep are still provided in fmts meson.build file, even though they are not the header-only targets of fmt. The following error message is emitted when trying to build a project using the WASM32/Emscripten backend (even though fmt_lib and fmt_dep are unused throughout the project):

ERROR: ld.wasm does not support shared libraries.

This PR fixes this issue by only providing fmt_lib and fmt_dep when header-only is not set. When header-only is set, this meson patch only provides fmt_header_only_dep.

Extract from faulty build:

  apytypes 0.4.0.dev78+g45a1126c2
  
    Subprojects
      fmt         : YES
      highway     : YES
      nanobind    : YES
      robin-map   : YES (from nanobind)
  
    User defined options
      Cross files : /tmp/cibw-run-pz6qboh_/cp312-pyodide_wasm32/build/venv/lib/python3.12/site-packages/pyodide_build/tools/emscripten.meson.cross
      Native files: /home/runner/work/apytypes/apytypes/.mesonpy-3pdk3853/meson-python-native-file.ini
      b_ndebug    : if-release
      b_vscrt     : md
      buildtype   : release
  
  Found ninja-1.13.1 at /usr/local/bin/ninja
  Running compile:
  Working directory:  /tmp/tmp0n0pvf2j
  Code:
  int i = static_cast<int>(0);
  -----------
  Command line: `/tmp/tmpsmf8oq99/c++ /tmp/tmp0n0pvf2j/testfile.cpp -o /tmp/tmp0n0pvf2j/output.o -D_FILE_OFFSET_BITS=64 -c -std=c++17` -> 0
  Compiler accepts -std=c++17: YES
  Running compile:
  Working directory:  /home/runner/work/apytypes/apytypes/.mesonpy-3pdk3853/meson-private/tmpd3dggrpi
  Code:
  
  -----------
  Command line: `/tmp/tmpsmf8oq99/c++ /home/runner/work/apytypes/apytypes/.mesonpy-3pdk3853/meson-private/tmpd3dggrpi/testfile.cpp -o /home/runner/work/apytypes/apytypes/.mesonpy-3pdk3853/meson-private/tmpd3dggrpi/output.o -c -fexceptions -D_FILE_OFFSET_BITS=64 -O0 -fpermissive -Werror=implicit-function-declaration -Werror=unknown-warning-option -Werror=unused-command-line-argument --print-search-dirs` -> 0
  stdout:
  programs: =/home/runner/.cache/cibuildwheel/emsdk-3.1.58/emsdk-3.1.58/upstream/bin
  libraries: =/home/runner/.cache/cibuildwheel/emsdk-3.1.58/emsdk-3.1.58/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten
  -----------
  Running compile:
  Working directory:  /tmp/tmpedgdo8rp
  Code:
  int i = static_cast<int>(0);
  -----------
  Command line: `/tmp/tmpsmf8oq99/c++ /tmp/tmpedgdo8rp/testfile.cpp -o /tmp/tmpedgdo8rp/output.o -D_FILE_OFFSET_BITS=64 -c -std=c++14` -> 0
  Compiler accepts -std=c++14: YES
  
  ERROR: ld.wasm does not support shared libraries.   # <------

@neheb
Copy link
Collaborator

neheb commented Sep 5, 2025

Have you tried defaultlibrary=static?

@miklhh
Copy link
Contributor Author

miklhh commented Sep 6, 2025

Have you tried defaultlibrary=static?

Yes, we have tried default_library=static, which yields the same error whether it is set or not. The WASM compiler still complains that ld.wasm does not support shared libraries unless we apply the provided patch to fmt.

@miklhh miklhh force-pushed the fmt-header-only-provide-fix branch 3 times, most recently from 882487a to 6f26839 Compare September 8, 2025 08:39
@neheb
Copy link
Collaborator

neheb commented Sep 8, 2025

Add meson_version of 0.50.0 and this looks good to go.

@miklhh miklhh force-pushed the fmt-header-only-provide-fix branch from 6f26839 to 3697919 Compare September 8, 2025 09:16
@miklhh
Copy link
Contributor Author

miklhh commented Sep 8, 2025

I've added meson_version >=0.50.0 to the fmt project. Should I also remove default_options: 'cpp_std=c++14' from the project, since the linter is complaining about it?

@neheb
Copy link
Collaborator

neheb commented Sep 8, 2025

Yes

@miklhh miklhh force-pushed the fmt-header-only-provide-fix branch from 3697919 to a5ee149 Compare September 9, 2025 04:21
@miklhh
Copy link
Contributor Author

miklhh commented Sep 9, 2025

All right. I removed the default option cpp_std=c++14 now as well.

@neheb neheb merged commit 39f46c4 into mesonbuild:master Sep 9, 2025
16 checks passed
@miklhh miklhh deleted the fmt-header-only-provide-fix branch September 9, 2025 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants