Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On macOs with apple silicon impossible to build the library (pb with libjpeg and giflib) #1898

Closed
1 task done
Nico-Guyon opened this issue Sep 14, 2021 · 2 comments
Closed
1 task done

Comments

@Nico-Guyon
Copy link

Issue or Feature

Steps to Reproduce

brew install pkg-config cairo pango libpng jpeg giflib librsvg
yarn add --dev canvas

Your Environment

  • Version of node-canvas (output of npm list canvas or yarn list canvas): canvas@2.8.0
  • Environment (node 16.8.0 on Mac OS X 11.4):

Explanation

On apple silicon, there is no prebuilt version available, so the install command attempt to build this library from source.
I have every dependency required (xcode-select install, and all brew libs or tools).

The first thing that I noticed is that has_lib.js is not searching on the correct folder.
On intel mac homebrew will install its files on /opt/local but on apple silicon the folder will be /opt/homebrew.
There's already a merged pull request that add the folder /opt/homebrew to the lists of folders has_lib is checking but the version of node-canvas available on npm does not yet include this modification.
#1872

So I tried to use the library directly from github, but this time I still had problems with both libjpeg and giflib which weren't configured correctly (missing lib search path and include).

I'm not sure why this happened but looking at the binding.gyp file it seems that it's not configuring libjpeg and giflib.
So I tried to modify binding.gyp to include those two missing libs :

        }, {  # 'OS!="win"'
          'libraries': [
            '<!@(pkg-config pixman-1 --libs)',
            '<!@(pkg-config cairo --libs)',
            '<!@(pkg-config libpng --libs)',
            '<!@(pkg-config pangocairo --libs)',
            '<!@(pkg-config freetype2 --libs)',
            '<!@(pkg-config libjpeg --libs)',
            '<!@(pkg-config giflib --libs)'
          ],
          'include_dirs': [
            '<!@(pkg-config cairo --cflags-only-I | sed s/-I//g)',
            '<!@(pkg-config libpng --cflags-only-I | sed s/-I//g)',
            '<!@(pkg-config pangocairo --cflags-only-I | sed s/-I//g)',
            '<!@(pkg-config freetype2 --cflags-only-I | sed s/-I//g)',
            '<!@(pkg-config libjpeg --cflags-only-I | sed s/-I//g)',
            '<!@(pkg-config giflib --cflags-only-I | sed s/-I//g)'

Unfortunately pkg-config was not able to locate giflib.
After looking more deeply, libjpeg does have a pkgconfig/libjpeg.pc file but giflib does not.
So I created a giflib.pc file inside /usr/local/lib/pkgconfig with the install path location of giflib on my system

prefix=/opt/homebrew/Cellar/giflib/5.2.1
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: giflib
Description: Reads and writes gif files
Version: 5.2.1
Libs: -L${libdir} -lgif
Cflags: -I${includedir}

After all that I can correctly build node-canvas from source and use it on macOS apple silicon.
I'll leave this here as a workaround in case somebody has the same problem.

But the thing is, I'm not sure why I had to do all this ?
Is there something wrong on my system configuration, or is there a problem with binding.pyc ?
How the build process is supposed to find libjpeg and giflib without the correct paths configured via binding.gyp ?

@flohall
Copy link

flohall commented Mar 4, 2022

I had issues before with Apple Silicon too.
I use:
macOs Monterey 12.0.1
Apple M1 Pro

I answered already on stack overflow - here how I solved it:
https://stackoverflow.com/questions/67031187/error-node-canvas-was-built-without-jpeg-support/70064802#70064802

But since canvas@2.9.0 I don't have to do anythings special anymore. The only thing I have to do in advance:

brew install pkg-config cairo pango libpng jpeg giflib librsvg libjpeg-turbo

Can't this issue be closed now?

@LinusU
Copy link
Collaborator

LinusU commented Mar 7, 2022

I believe that this was indeed fixed by #1910 👍

@LinusU LinusU closed this as completed Mar 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants