Gem cairo installation issue on osx-vs4mac-stable

Bitrise Build Issue Report template

Description of the issue

In one of our build steps, we issue a bundle install of several dependencies. Transitively, the cairo gem is being installed at version 1.15.9.

The compilation of the native part of the gem fails on the osx-vs4mac-stable saying that zlib.pc file cannot be found anywhere.


Start a project using the current oxs-vs4mac-stable stack. Use the current bitrise.yml:

    - script@1.1.4:
        title: Test gem cairo problem
        - content: |-
            gem install cairo -v '1.15.9'

            find /usr/local/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-16/2.4.0/cairo-1.15.9 -type f | xargs -n1 cat


Might be breaking other part of stack, apply with caution.

- script@1.1.4:
    title: Native Dependencies (for bundle install)
    run_if: .IsCI
    - content: |-
       brew uninstall node icu4c yarn
       brew install node zlib

       envman add --key PKG_CONFIG_PATH --value "$PKG_CONFIG_PATH:/usr/local/opt/zlib/lib/pkgconfig"

The bundle install calls fails to install cairo gem. This is because the zlib.pc pkg-config is not found by default. This file seems not to be present in Xcode zlib distribution which makes the executing
of step bundle install fails.

To overcome the problem, we first install zlib from homebrew which installs zlib as well as the zlib.pc file. But since this is a keg-only file (meaning it’s not linked to /usr/local which is in pkg-config default search path). As such, we export a modified version of PKG_CONFIG_PATH containing zlib.pc file to ensure we are able to correctly install the gem later on.

Sadly, what seems to be a problematic side-effect for this is that later on in the process, icu4c seems to be updated which does not work with node anymore.

To overcome this new issue, we first uninstall node, yarn and icu4c (yarn is being uninstall because being a dependencies of node) and then reinstall both zlib and node (so that node dependency on icu4c version is met correctly). Yarn in my case is reinstalled to a more up-to-date version in a subsequent step.

This has you can see is rather fragile and cumbersome to my builds. Furthermore, this workaround seems to break ImageMagick as my add badge step is not working anymore. Not clear if it would be a problem even without the workaround though …


Stack: osx-vs4mac-stable


  • Does a “Rebuild” help? (You can trigger a rebuild from the Build’s page, by clicking the “Rebuild” button in the top right corner of a finished build) : No
  • If it’s an issue which happens sporadically, what’s the frequency? (e.g. Once a day ; about x% of the builds) : Always
  • When did the issue start? : No sure when, but I could find out if needed

Other stacks

Can it be reproduced by running the build locally with our CLI ( ), after doing a new git clone of the repository into the /tmp directory and running the build from there with the Bitrise CLI ( )?: It possibly could, but problem is caused by machine configuration so unless dev machine is setup the same, no.

Build log

Successfully installed pkg-config-1.2.7
Successfully installed native-package-installer-1.0.4
Building native extensions.  This could take a while...
ERROR:  Error installing cairo:
	ERROR: Failed to build gem native extension.
    current directory: /usr/local/lib/ruby/gems/2.4.0/gems/cairo-1.15.9/ext/cairo
/usr/local/opt/ruby/bin/ruby -r ./siteconf20170912-830-1ugkor8.rb extconf.rb
checking for GCC... yes
checking for Win32 OS... no
checking for cairo version (>= 1.2.0)... no
installing 'cairo' native package... succeeded
checking for cairo version (>= 1.2.0)... yes
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.
Provided configuration options:
/usr/local/lib/ruby/gems/2.4.0/gems/pkg-config-1.2.7/lib/pkg-config.rb:299:in `parse_pc': .pc for zlib doesn't exist. (RuntimeError)
	from /usr/local/lib/ruby/gems/2.4.0/gems/pkg-config-1.2.7/lib/pkg-config.rb:196:in `declaration'
	from /usr/local/lib/ruby/gems/2.4.0/gems/pkg-config-1.2.7/lib/pkg-config.rb:210:in `collect_cflags'
	from /usr/local/lib/ruby/gems/2.4.0/gems/pkg-config-1.2.7/lib/pkg-config.rb:145:in `cflags'
	from /usr/local/lib/ruby/gems/2.4.0/gems/pkg-config-1.2.7/lib/pkg-config.rb:212:in `block in collect_cflags'
	from /usr/local/lib/ruby/gems/2.4.0/gems/pkg-config-1.2.7/lib/pkg-config.rb:211:in `collect'
	from /usr/local/lib/ruby/gems/2.4.0/gems/pkg-config-1.2.7/lib/pkg-config.rb:211:in `collect_cflags'
	from /usr/local/lib/ruby/gems/2.4.0/gems/pkg-config-1.2.7/lib/pkg-config.rb:145:in `cflags'
	from /usr/local/lib/ruby/gems/2.4.0/gems/pkg-config-1.2.7/lib/pkg-config.rb:215:in `block in collect_cflags'
	from /usr/local/lib/ruby/gems/2.4.0/gems/pkg-config-1.2.7/lib/pkg-config.rb:214:in `collect'
	from /usr/local/lib/ruby/gems/2.4.0/gems/pkg-config-1.2.7/lib/pkg-config.rb:214:in `collect_cflags'
	from /usr/local/lib/ruby/gems/2.4.0/gems/pkg-config-1.2.7/lib/pkg-config.rb:154:in `cflags_only_other'
	from /usr/local/lib/ruby/gems/2.4.0/gems/pkg-config-1.2.7/lib/pkg-config.rb:472:in `cflags_only_other'
	from /usr/local/lib/ruby/gems/2.4.0/gems/pkg-config-1.2.7/lib/pkg-config.rb:519:in `have_package'
	from extconf.rb:57:in `required_pkg_config_package'
	from extconf.rb:60:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
extconf failed, exit code 1

Hi @mvachon,

Thanks for reporting the issue here! :slight_smile:

Did you try it on other stack(s)?

Good catch! Unfortunately this also means that probably the workaround script you included (thanks for that! :slight_smile:) is the right solution at least for now, because, as you mentioned,

We’re of course open to modify the stacks if required and reasonable, so if you can find a reliable solution which does not break any other tool just let us know!

I checked the cairo gem’s issue tracker and found this, seems to be the same issue:

Can you try the possible fix(es) mentioned there?

No I did not try any other stack. I really need to make it work on this stack to build Android and iOS version in one build. I could try to see if appears on another one however, just to see.

Thanks for this finding, I will try to check it out when I have more time.

I keep you posted.


1 Like