@@ -144,10 +144,38 @@ def main():
144144 ]
145145 )
146146
147- env_vars = {
148- # add the venv bin directory to PATH so that meson can find ninja
149- "PATH" : f"{ os .path .join (tmpdir , VENV_NAME , 'bin' )} { os .pathsep } { os .environ ['PATH' ]} " ,
150- }
147+ # Inherit the current environment so PKG_CONFIG_PATH, CFLAGS, LDFLAGS, etc. are preserved.
148+ env_vars = os .environ .copy ()
149+ # Prepend the venv bin directory so meson/ninja from the venv are used.
150+ env_vars ["PATH" ] = f"{ os .path .join (tmpdir , VENV_NAME , 'bin' )} { os .pathsep } { env_vars .get ('PATH' ,'' )} "
151+
152+ # Ensure Homebrew-provided pkgconfig and include/lib paths are present on macOS ARM.
153+ if sys .platform == "darwin" :
154+ try :
155+ # Try to get specific prefix for lzo (safer for opt path), fall back to generic brew prefix.
156+ brew_prefix = subprocess .check_output (["brew" , "--prefix" , "lzo" ], text = True ).strip ()
157+ except subprocess .CalledProcessError :
158+ try :
159+ brew_prefix = subprocess .check_output (["brew" , "--prefix" ], text = True ).strip ()
160+ except Exception :
161+ brew_prefix = None
162+
163+ if brew_prefix :
164+ # pkg-config files can live in lib/pkgconfig or opt/<pkg>/lib/pkgconfig
165+ pkgconfig_paths = [f"{ brew_prefix } /lib/pkgconfig" , f"{ brew_prefix } /opt/lzo/lib/pkgconfig" ]
166+ # merge with any existing PKG_CONFIG_PATH
167+ existing_pc = env_vars .get ("PKG_CONFIG_PATH" , "" )
168+ merged_pc = ":" .join ([p for p in pkgconfig_paths if p ]) + (f":{ existing_pc } " if existing_pc else "" )
169+ env_vars ["PKG_CONFIG_PATH" ] = merged_pc
170+
171+ # Ensure compiler & linker flags include brew include/lib
172+ existing_cflags = env_vars .get ("CFLAGS" , "" )
173+ existing_ldflags = env_vars .get ("LDFLAGS" , "" )
174+ env_vars ["CFLAGS" ] = f"-I{ brew_prefix } /include { existing_cflags } " .strip ()
175+ env_vars ["LDFLAGS" ] = f"-L{ brew_prefix } /lib { existing_ldflags } " .strip ()
176+
177+ # Debugging: log environment keys relevant to detection
178+ # logger.info(f"env vars for meson: {env_vars}")
151179
152180 with gha_group ("Building and Installing Cairo" ):
153181 logger .info ("Running meson setup" )
0 commit comments