From 8e7cfb9867f5f98cd0d98b3bf4bd5617bed22876 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`: If configure fails, run autogen.sh / autoconf (*) - 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 - this essentially means that configure & build could be the same script (configure is not run as part of configure stage of gyp) - for reference, add link to XZ library used to README.md (*) The drawback of this is that the fallback to autoconf requires a full autoconf type build environment, but it is a last resort fallback. --- .gitignore | 2 ++ README.md | 2 +- binding.gyp | 15 +++++++------ liblzma-build.sh | 9 +++++++- liblzma-config.sh | 55 ++++++++++++++++++++++++++++++++++++++--------- 5 files changed, 65 insertions(+), 18 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/README.md b/README.md index 69c7e5b..f07a00d 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ lzma-native [![Dependency Status](https://david-dm.org/addaleax/lzma-native.svg?style=flat)](https://david-dm.org/addaleax/lzma-native) [![devDependency Status](https://david-dm.org/addaleax/lzma-native/dev-status.svg?style=flat)](https://david-dm.org/addaleax/lzma-native#info=devDependencies) -Node.js interface to the native liblzma compression library (.xz file format, among others) +Node.js interface for the native [XZ Utils liblzma native compression library](https://tukaani.org/xz/) (.xz file format, among others) This package provides interfaces for compression and decompression of `.xz` (and legacy `.lzma`) files, both stream-based and string-based. 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 +function configure() { + sh xz-*/configure \ + --quiet --enable-silent-rules \ + --prefix="$TARGET_DIR/build" \ + CFLAGS="-fPIC $CFLAGS" \ + --enable-static \ + --disable-xz \ + --disable-xzdec \ + --disable-lzmadec \ + --disable-lzmainfo \ + --disable-lzma-links \ + --disable-rpath \ + --disable-shared \ + --disable-scripts + return $? +} -export CFLAGS="-fPIC $CFLAGS" +set -x -# Fix build on Apple Silicon +# FIXME: Remove after XZ 5.3 is released if [ $(uname) = "Darwin" -a $(uname -m) = "arm64" ]; then - XZ_SRC_DIR=$(ls | grep xz-*) - sed -i '' 's/\tnone)/\tarm64-*)\n\t\tbasic_machine=$(echo $basic_machine | sed "s\/arm64\/aarch64\/")\n\t\t;;\n\t\tnone)/g' $XZ_SRC_DIR/build-aux/config.sub + echo "--- Patching config.sub for Apple Silicon" + sed -i \ + 's/\tnone)/\tarm64-*)\n\t\tbasic_machine=$(echo $basic_machine | sed "s\/arm64\/aarch64\/")\n\t\t;;\n\t\tnone)/g' \ + xz-*/build-aux/config.sub + echo fi -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 +configure # || exit 1 # uncomment to disable use of autoconf +if [ $? -ne 0 ] ; then + echo + echo "--- ./configure failed => trying to run autoconf first" + echo "--- NOTE: This requires a full autoconf build environment, and so may also fail" + echo + autoconf && configure +fi