Unable to build libmongocrypt Node.js bindings on Alpine Linux

I’m trying to build libmongocrypt Node.js bindings on Alpine Linux (edge).

I have installed the following additional packages: alpine-sdk, node, npm, python3, cmake, openssl-dev, bash, linux-headers.

The versions that I have tried to reproduce this behaviour with are: 2.4.0 and git master.

In order to reproduce, do the following:

cd libmongocrypt/bindings/node
node-gyp rebuild

The output of node-gyp:

gyp info it worked if it ends with ok
gyp info using node-gyp@9.3.0
gyp info using node@18.13.0 | linux | x64
gyp info find Python using Python version 3.11.1 found at "/usr/bin/python3"
gyp info spawn /usr/bin/python3
gyp info spawn args [
gyp info spawn args   '/usr/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   '/root/libmongocrypt/bindings/node/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/root/.cache/node-gyp/18.13.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/.cache/node-gyp/18.13.0',
gyp info spawn args   '-Dnode_gyp_dir=/usr/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/root/.cache/node-gyp/18.13.0/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/root/libmongocrypt/bindings/node',
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 args ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/root/libmongocrypt/bindings/node/build'
  CXX(target) Release/obj.target/mongocrypt/src/mongocrypt.o
  SOLINK_MODULE(target) Release/obj.target/mongocrypt.node
/usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find /root/libmongocrypt/bindings/node/deps/lib/libmongocrypt-static.a: No such file or directory
/usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find /root/libmongocrypt/bindings/node/deps/lib/libkms_message-static.a: No such file or directory
/usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find /root/libmongocrypt/bindings/node/deps/lib/libbson-static-for-libmongocrypt.a: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [mongocrypt.target.mk:140: Release/obj.target/mongocrypt.node] Error 1
make: Leaving directory '/root/libmongocrypt/bindings/node/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:203:23)
gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:291:12)
gyp ERR! System Linux 4.14.300-burmilla
gyp ERR! command "/usr/bin/node" "/usr/bin/node-gyp" "rebuild"
gyp ERR! cwd /root/libmongocrypt/bindings/node
gyp ERR! node -v v18.13.0
gyp ERR! node-gyp -v v9.3.0
gyp ERR! not ok

For some reason, static libraries libmongocrypt-static.a, libkms_message-static.a and libbson-static-for-libmongocrypt.a are not being built. I can’t figure out why exactly. Am I missing some important step in the process? Am I missing some prerequisite?

I think the problem is that bash ./etc/build-static.sh should be run before node-gyp. Running it manually solves it, but I’m curious why this doesn’t happen automatically.

I have succeeded with building mongosh with patched libmongocrypt and os-dns-native on Alpine Linux 3.16. Unfortunately, it won’t work on newer versions, because mongosh 1.6.2 works with Node.js 16, but not with Node.js 18. Hopefully, later versions can be updated for newer Node.js.

Here are the build instructions: GitHub
And here is a working example: Docker Hub