Skip to content

libarchive: zstd feature check via cc.has_header_symbol() fails with internal (subproject) dependency #2939

Description

@nda-cunh

Bug report

Line 802 of meson.build says:

we can't use cc.has_function() on dependencies since they might be
internal, so check headers instead

However, the zstd block just below does exactly what this comment warns
against, but with cc.has_header_symbol() instead of cc.has_function():

foreach sym : ['ZSTD_compressStream', 'ZSTD_minCLevel']
  if cc.has_header_symbol(
    'zstd.h',
    sym,
    dependencies: zstd_dep,
  )

cc.has_header_symbol() has the same limitation as cc.has_function():
it rejects internal dependencies in the dependencies: kwarg. This
fails with:

meson.build:347:10: ERROR: Dependencies must be external dependencies

To reproduce

Use zstd via a subproject fallback (i.e. dependency('libzstd', ...)
resolves through fallback:/wrap, not pkg-config/cmake), for example
when zstd isn't installed system-wide and libarchive is built as a
subproject with zstd=enabled.

Environment

  • Meson 1.12.0
  • libarchive 3.8.9

Suggested fix

Replace the has_header_symbol() calls with a version check, since
Dependency.version() works for both internal and external
dependencies (see liblzma handling a few lines above for a similar
pattern already in this file):

zstd_version = zstd_dep.version()
if zstd_version == 'unknown' or zstd_version.version_compare('>=1.0.0')
  cdata.set('HAVE_ZSTD_compressStream', 1)
endif
if zstd_version == 'unknown' or zstd_version.version_compare('>=1.4.0')
  cdata.set('HAVE_ZSTD_minCLevel', 1)
endif

I've tested this patch locally and it resolves the issue while keeping
zstd statically linked via a subproject.

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