From ce62636e41dd6dd6671dcd6b2ce7ad97989c9906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Stabell?= Date: Fri, 7 Jan 2022 11:08:26 -0800 Subject: [PATCH] fix: Build for darwin-arm64 (Apple M1) - `liblzma-config.sh`: Run autogen.sh if configure fails, fixes Apple M1 build failure (*) - refactor `build` action in `bindings.gyp` so that config and build scripts output is shown, making troubleshooting easier - `build` action refactored into `build` and `configure` actions with dependencies between them - since `configure` is a separate action instead of a command that runs as part of the 'input' key, it is free to output anything - script output is made less verbose and more clear, so it's not necessary to send to log file - added `manual:config` and `manual:build` targets to `package.json` so it's easier to troubleshoot step-by-step (*) The drawback of this is that the fallback to autoconf requires a full autoconf type build environment. --- .gitignore | 2 ++ binding.gyp | 15 ++++++++------ liblzma-build.sh | 9 ++++++++- liblzma-config.sh | 50 ++++++++++++++++++++++++++++++++++++++++------- package.json | 4 +++- 5 files changed, 65 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 7d8a3d0..0e1df88 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*.log build/ binding*/ node_modules/ @@ -8,3 +9,4 @@ README.md.xz .nyc_output /.idea/ prebuilds/ +/.vscode diff --git a/binding.gyp b/binding.gyp index 8bcda26..41e3d61 100644 --- a/binding.gyp +++ b/binding.gyp @@ -52,14 +52,17 @@ "conditions" : [ [ 'OS!="win"' , { "actions" : [ + { + "action_name" : "configure", + 'inputs': ['liblzma-config.sh'], + 'outputs': ['build/liblzma'], + 'action': ['eval', 'sh liblzma-config.sh build deps/xz-5.2.3.tar.bz2'], + }, { "action_name" : "build", - # a hack to run deps/xz-5.2.3 ./configure during `node-gyp configure` - 'inputs': ['node_liblzma_config.log 2>&1 +configure +if [ $? -ne 0 ] ; then + set +x + echo + echo "--- ./configure failed => trying to run autoconf first" + echo "--- NOTE: This requires a full autoconf build environment, and so may also fail" + echo + set -x + autoconf && configure +fi -export CFLAGS="-fPIC $CFLAGS" -sh xz-*/configure --enable-static --disable-shared --disable-scripts --disable-lzmainfo \ - --disable-lzma-links --disable-lzmadec --disable-xzdec --disable-xz --disable-rpath \ - --prefix="$TARGET_DIR/build" CFLAGS="$CFLAGS" >>node_liblzma_config.log 2>&1 diff --git a/package.json b/package.json index 6d3ac12..bf25df2 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,9 @@ "test": "mocha --expose-gc -s 1000 -t 5000", "prepare": "npm run prepare-win32 || true", "prepare-win32": "cd deps && 7z x -y xz-5.2.3-windows.7z bin_i686/liblzma.dll bin_x86-64/liblzma.dll include doc/liblzma.def", - "jshint": "jshint ." + "jshint": "jshint .", + "manual:config": "./liblzma-config.sh build deps/xz-5.2.3.tar.bz2", + "manual:build": "./liblzma-build.sh build" }, "gypfile": true, "bugs": {