Sharp: Is is possible to work around -Wcast-function-type warnings produced by Nan?

Created on 23 Jul 2019  路  2Comments  路  Source: lovell/sharp

What are you trying to achieve?

I'm attempting to build the latest vips with a new APK docker image. I've followed all of the setup steps beginning with @wjordan's docker image, and then adding build-base for all of the GCC tools.

The problem I'm running into is with the NodeJS Nan package, Native Abstractions for Node.js. The build goes fine up to the point where it begins building Sharp, and then fails due to -Wcast-function-type warnings.

Build output

Step 12/33 : RUN yarn install --non-interactive --silent
 ---> Running in c28b91d6690b
error /var/www/node_modules/sharp: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments:
Directory: /var/www/node_modules/sharp
Output:
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp http GET https://nodejs.org/download/release/v10.16.0/node-v10.16.0-headers.tar.gz
gyp http 200 https://nodejs.org/download/release/v10.16.0/node-v10.16.0-headers.tar.gz
gyp http GET https://nodejs.org/download/release/v10.16.0/SHASUMS256.txt
gyp http 200 https://nodejs.org/download/release/v10.16.0/SHASUMS256.txt
gyp info spawn /usr/bin/python2
gyp info spawn args [ '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/var/www/node_modules/sharp/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/root/.node-gyp/10.16.0/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/root/.node-gyp/10.16.0',
gyp info spawn args   '-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/root/.node-gyp/10.16.0/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/var/www/node_modules/sharp',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/var/www/node_modules/sharp/build'
  TOUCH Release/obj.target/libvips-cpp.stamp
  CXX(target) Release/obj.target/sharp/src/common.o
In file included from ../src/common.cc:24:
../../nan/nan.h: In function 'void Nan::AsyncQueueWorker(Nan::AsyncWorker*)':
../../nan/nan.h:2298:62: warning: cast between incompatible function types from 'void (*)(uv_work_t*)' {aka 'void (*)(uv_work_s*)'} to 'uv_after_work_cb' {aka 'void (*)(uv_work_s*, int)'} [-Wcast-function-type]
     , reinterpret_cast<uv_after_work_cb>(AsyncExecuteComplete)
                                                              ^
In file included from /root/.node-gyp/10.16.0/include/node/node.h:63,
                 from ../src/common.cc:22:
/root/.node-gyp/10.16.0/include/node/v8.h: In instantiation of 'void v8::PersistentBase<T>::SetWeak(P*, typename v8::WeakCallbackInfo<P>::Callback, v8::WeakCallbackType) [with P = node::ObjectWrap; T = v8::Object; typename v8::WeakCallbackInfo<P>::Callback = void (*)(const v8::WeakCallbackInfo<node::ObjectWrap>&)]':
/root/.node-gyp/10.16.0/include/node/node_object_wrap.h:84:78:   required from here
/root/.node-gyp/10.16.0/include/node/v8.h:9502:16: warning: cast between incompatible function types from 'v8::WeakCallbackInfo<node::ObjectWrap>::Callback' {aka 'void (*)(const v8::WeakCallbackInfo<node::ObjectWrap>&)'} to 'Callback' {aka 'void (*)(const v8::WeakCallbackInfo<void>&)'} [-Wcast-function-type]
                reinterpret_cast<Callback>(callback), type);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/root/.node-gyp/10.16.0/include/node/v8.h: In instantiation of 'void v8::PersistentBase<T>::SetWeak(P*, typename v8::WeakCallbackInfo<P>::Callback, v8::WeakCallbackType) [with P = Nan::ObjectWrap; T = v8::Object; typename v8::WeakCallbackInfo<P>::Callback = void (*)(const v8::WeakCallbackInfo<Nan::ObjectWrap>&)]':
../../nan/nan_object_wrap.h:65:61:   required from here
/root/.node-gyp/10.16.0/include/node/v8.h:9502:16: warning: cast between incompatible function types from 'v8::WeakCallbackInfo<Nan::ObjectWrap>::Callback' {aka 'void (*)(const v8::WeakCallbackInfo<Nan::ObjectWrap>&)'} to 'Callback' {aka 'void (*)(const v8::WeakCallbackInfo<void>&)'} [-Wcast-function-type]
  CXX(target) Release/obj.target/sharp/src/metadata.o
In file included from ../src/metadata.cc:19:
../../nan/nan.h: In function 'void Nan::AsyncQueueWorker(Nan::AsyncWorker*)':
../../nan/nan.h:2298:62: warning: cast between incompatible function types from 'void (*)(uv_work_t*)' {aka 'void (*)(uv_work_s*)'} to 'uv_after_work_cb' {aka 'void (*)(uv_work_s*, int)'} [-Wcast-function-type]
     , reinterpret_cast<uv_after_work_cb>(AsyncExecuteComplete)
                                                              ^
../src/metadata.cc: In member function 'virtual void MetadataWorker::Execute()':
../src/metadata.cc:86:28: error: 'VIPS_META_IPCT_NAME' was not declared in this scope
       if (image.get_typeof(VIPS_META_IPCT_NAME) == VIPS_TYPE_BLOB) {
                            ^~~~~~~~~~~~~~~~~~~
../src/metadata.cc:86:28: note: suggested alternative: 'VIPS_META_IPTC_NAME'
       if (image.get_typeof(VIPS_META_IPCT_NAME) == VIPS_TYPE_BLOB) {
                            ^~~~~~~~~~~~~~~~~~~
                            VIPS_META_IPTC_NAME
In file included from /root/.node-gyp/10.16.0/include/node/node.h:63,
                 from ../src/metadata.cc:18:
/root/.node-gyp/10.16.0/include/node/v8.h: In instantiation of 'void v8::PersistentBase<T>::SetWeak(P*, typename v8::WeakCallbackInfo<P>::Callback, v8::WeakCallbackType) [with P = node::ObjectWrap; T = v8::Object; typename v8::WeakCallbackInfo<P>::Callback = void (*)(const v8::WeakCallbackInfo<node::ObjectWrap>&)]':
/root/.node-gyp/10.16.0/include/node/node_object_wrap.h:84:78:   required from here
/root/.node-gyp/10.16.0/include/node/v8.h:9502:16: warning: cast between incompatible function types from 'v8::WeakCallbackInfo<node::ObjectWrap>::Callback' {aka 'void (*)(const v8::WeakCallbackInfo<node::ObjectWrap>&)'} to 'Callback' {aka 'void (*)(const v8::WeakCallbackInfo<void>&)'} [-Wcast-function-type]
                reinterpret_cast<Callback>(callback), type);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/root/.node-gyp/10.16.0/include/node/v8.h: In instantiation of 'void v8::PersistentBase<T>::SetWeak(P*, typename v8::WeakCallbackInfo<P>::Callback, v8::WeakCallbackType) [with P = Nan::ObjectWrap; T = v8::Object; typename v8::WeakCallbackInfo<P>::Callback = void (*)(const v8::WeakCallbackInfo<Nan::ObjectWrap>&)]':
../../nan/nan_object_wrap.h:65:61:   required from here
/root/.node-gyp/10.16.0/include/node/v8.h:9502:16: warning: cast between incompatible function types from 'v8::WeakCallbackInfo<Nan::ObjectWrap>::Callback' {aka 'void (*)(const v8::WeakCallbackInfo<Nan::ObjectWrap>&)'} to 'Callback' {aka 'void (*)(const v8::WeakCallbackInfo<void>&)'} [-Wcast-function-type]
make: *** [sharp.target.mk:128: Release/obj.target/sharp/src/metadata.o] Error 1
make: Leaving directory '/var/www/node_modules/sharp/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:198:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Linux 4.9.125-linuxkit
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /var/www/node_modules/sharp
gyp ERR! node -v v10.16.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
The command '/bin/ash -o pipefail -c yarn install --non-interactive --silent' returned a non-zero code: 1

I've done some research, and tracked it down to https://github.com/nodejs/nan/issues/807. However, it being a dependency of a dependency I don't know how to work around it (or whether it is possible to work around). I tried modifying the bindings.gyp inside of sharp to add 'cflags': [ "-Wno-cast-function-type" ], but that has no effect (I think I may be adding those in the wrong place).

Have you searched for similar questions?

Yes, https://github.com/nodejs/nan/issues/807 is the issue being encountered. Though, aside from silencing the errors there seems to be no solution.

Are you able to provide a standalone code sample that demonstrates this question?

We are using VIPS/Sharp via the EmberJS addon ember-responsive-images. The build for everything is relatively straightforward, and the following Dockerfile and package.json snippet should illustrate the build steps:

Dockerfile

FROM wjordan/libvips
FROM node:10-alpine as dev

SHELL ["/bin/ash", "-o", "pipefail", "-c"]

# the following are debugging tools
# hadolint ignore=DL3018
RUN apk --no-cache add jq strace python2 build-base

RUN apk -q --no-cache --update --virtual \
    --repository http://dl-3.alpinelinux.org/alpine/edge/community add vips-dev

# Set Time to Neighborly Time (a.k.a. Cali Time)
RUN apk --no-cache add tzdata \
    && cp /usr/share/zoneinfo/America/Los_Angeles /etc/localtime \
    && apk del tzdata

# Install Watchman
WORKDIR /tmp/watchman

# The following must be one RUN because it reduces size
# hadolint ignore=DL3018
RUN apk --no-cache add --virtual build-deps \
    bash \
    git \
    build-base \
    automake \
    autoconf \
    linux-headers \
    libtool \
      openssl-dev \
    && git clone https://github.com/facebook/watchman.git \
      && cd watchman \
      && git checkout v4.9.0 \
    && bash autogen.sh \
    && bash configure --enable-lenient --without-python --without-pcre --disable-statedir \
    && MAKEFLAGS="-j$(nproc)" make all \
    && MAKEFLAGS="-j$(nproc)" make install \
    && apk del build-deps \
    && rm -rf /tmp/watchman

# required for watchman to run
# hadolint ignore=DL3018
RUN apk --no-cache add libcrypto1.1

WORKDIR /var/www

COPY package.json yarn.lock .npmrc ./

RUN yarn install --non-interactive --silent

EXPOSE 7400

ENTRYPOINT ["./node_modules/.bin/ember"]
CMD ["server", "--port", "7400", "--host", "0.0.0.0"]

FROM dev as test

RUN apk --no-cache add gifsicle pngquant optipng libjpeg-turbo-utils udev ttf-opensans chromium

COPY . .

SHELL ["/bin/ash", "-c"]
ENV CI=true
ENTRYPOINT npx npm-run-all -pn --silent lint:* test

### BUILD
FROM test as build

ARG TARGET_ENVIRONMENT=develop

RUN set -a && [ -f .env.$TARGET_ENVIRONMENT ] && export $(cat .env.$TARGET_ENVIRONMENT | xargs) || true && ./node_modules/.bin/ember build -e production --watcher polling

# Run stage
FROM nginx:1.15-alpine as prod

# hadolint ignore=DL3018
RUN apk add --no-cache tzdata \
    && cp /usr/share/zoneinfo/America/Los_Angeles /etc/localtime \
    && apk del tzdata

WORKDIR /var/www

# copy in Ember app
COPY --from=build /var/www/dist .

RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/nginx.conf

EXPOSE 7400

ENTRYPOINT ["nginx"]
CMD ["-g", "daemon off;"]

package.json

{
  ...
  "devDependencies": {
    ...
    "ember-responsive-image": "^1.0.0-rc.6",
    ...
  },
  ...
}

Are you able to provide a sample image that helps explain the question?

question

Most helpful comment

This will impact all native modules, not just sharp, so waiting for the nan (and probably node) fixes is the best solution. For now you can silence these via something like:

CXXFLAGS="-Wno-cast-function-type" yarn install ...

All 2 comments

This will impact all native modules, not just sharp, so waiting for the nan (and probably node) fixes is the best solution. For now you can silence these via something like:

CXXFLAGS="-Wno-cast-function-type" yarn install ...

Hi @lovell, thanks for the tip! I was just successful in building my project using your suggested env var,

ENV CXXFLAGS="-Wno-cast-function-type"
RUN yarn install --non-interactive --silent
Was this page helpful?
0 / 5 - 0 ratings