From 45b9482e51c367943336d3bf57848429cf2cc22e Mon Sep 17 00:00:00 2001
From: Andrew Udvare <audvare@gmail.com>
Date: Wed, 13 May 2026 11:59:47 -0400
Subject: [PATCH] libchdr_flac: unconditionally include dr_flac.h
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

libchdr_flac.c uses drflac_* symbols (drflac_bool32, drflac_seek_origin,
drflac_metadata, drflac_open_with_metadata, drflac_read_pcm_frames_s16,
DRFLAC_CACHE_*, etc.) unconditionally throughout its implementation,
but the dr_flac.h include is wrapped in #ifdef HAVE_DR_FLAC. The file
is unbuildable without the include.

HAVE_DR_FLAC is only set when --enable-builtinflac is used (defined
in Makefile.common alongside the bundled libFLAC sources). When the
user builds with --disable-builtinflac --enable-flac (system libFLAC
for audio playback), HAVE_FLAC=1 but HAVE_DR_FLAC is unset, yet
Makefile.common line 2157 still adds libchdr_flac.o to OBJ:

   ifeq ($(HAVE_FLAC),1)
      OBJ += $(LIBRETRO_COMM_DIR)/formats/libchdr/libchdr_flac.o \
             $(LIBRETRO_COMM_DIR)/formats/libchdr/libchdr_flac_codec.o
   endif

Result: build fails with "unknown type name 'drflac_bool32'" et al.

dr_flac is a single-header public-domain library bundled at
deps/dr/dr_flac.h, independent of libFLAC. libchdr uses it
internally for CHD codec decompression; libFLAC handles general
audio playback elsewhere. They serve different purposes and aren't
mutually exclusive — system libFLAC users still need dr_flac for
libchdr's CHD-FLAC support.

Drop the HAVE_DR_FLAC guard so the include matches the
unconditional symbol usage in the rest of the file.

Fixes upstream issue #18370.

Signed-off-by: Andrew Udvare <audvare@gmail.com>
---
 libretro-common/formats/libchdr/libchdr_flac.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libretro-common/formats/libchdr/libchdr_flac.c b/libretro-common/formats/libchdr/libchdr_flac.c
index 994bdf72e7..d375399de4 100644
--- a/libretro-common/formats/libchdr/libchdr_flac.c
+++ b/libretro-common/formats/libchdr/libchdr_flac.c
@@ -12,12 +12,10 @@
 #include <stdbool.h>
 
 #include <libchdr/flac.h>
-#ifdef HAVE_DR_FLAC
 #include <retro_inline.h>
 #define DR_FLAC_IMPLEMENTATION
 #define DRFLAC_API static INLINE
 #include <dr/dr_flac.h>
-#endif
 
 /***************************************************************************
  *  FLAC DECODER
-- 
2.54.0

