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

build: fallback to autogen.sh if configure fails, and refactor config and build scripts for easier troubleshooting #125

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.log
build/
binding*/
node_modules/
Expand All @@ -8,3 +9,4 @@ README.md.xz
.nyc_output
/.idea/
prebuilds/
/.vscode
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 9 additions & 6 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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': ['<!@(sh liblzma-config.sh "<(module_root_dir)/build" "<(module_root_dir)/deps/xz-5.2.3.tar.bz2")'],
'outputs': [''],
'action': [
'sh', '<(module_root_dir)/liblzma-build.sh', '<(module_root_dir)/build'
]
'inputs': ['build/liblzma', 'liblzma-build.sh'],
'outputs': ['build/liblzma/Release'],
'action': ['eval', 'sh liblzma-build.sh build'],
}
]
}, {
Expand Down
9 changes: 8 additions & 1 deletion liblzma-build.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#!/bin/sh

echo
echo "--- liblzma-build.sh $*"
echo "--- CWD = $PWD"
echo

set -e

case $(uname | tr '[:upper:]' '[:lower:]') in
*bsd) alias make='gmake';;
*)
esac

cd "$1/liblzma"
set -x
cd "$1" && cd liblzma
make
make install
55 changes: 45 additions & 10 deletions liblzma-config.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,57 @@
#!/bin/sh
set -e

echo
echo "--- liblzma-config.sh $*"
echo "--- CWD = $PWD"
echo

SRC_TARBALL="$2"
TARGET_DIR="$1/liblzma"

mkdir -p "$TARGET_DIR"

tar xjf "$SRC_TARBALL" -C "$TARGET_DIR" || exit 1

cd "$TARGET_DIR"
TARGET_DIR="$(pwd)" # ensure absolute since --prefix needs it

function autoconf() {
( cd xz-* ; sh ./autogen.sh --no-po4a )
return $?
}

tar xvjf "$SRC_TARBALL" >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