From 59d734515798588fa38e3153531be6ada4d807b1 Mon Sep 17 00:00:00 2001 From: Danny McClanahan <1305167+cosmicexplorer@users.noreply.github.com> Date: Wed, 13 Jun 2018 08:36:05 -0700 Subject: [PATCH] statically link xz (#74) See #71, #72, #73. Our `xz` is picking up travis's `xz` installation and using its (incompatible) `liblzma` shared library. On the suggestion of @stuhood in pantsbuild/pants#5936, we statically link `xz` here to avoid ever having this problem ever again. Proof: *linux*: ``` > ldd ./xz-5.2.4-linux/xz-install/bin/xz linux-vdso.so.1 (0x00007ffc865cd000) libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f1fa385f000) libc.so.6 => /usr/lib/libc.so.6 (0x00007f1fa34a3000) /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007f1fa3cb4000) ``` *osx*: ``` > otool -L ./xz-5.2.4-linux/xz-install/bin/xz ./xz-5.2.4-linux/xz-install/bin/xz: /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.50.4) ``` --- .../bin/xz/linux/x86_64/5.2.4-3/build-xz.sh | 64 +++++++++++++++++++ .../bin/xz/linux/x86_64/5.2.4-3/build.sh | 5 ++ .../bin/xz/mac/10.13/5.2.4-3/build-xz.sh | 64 +++++++++++++++++++ .../bin/xz/mac/10.13/5.2.4-3/build.sh | 5 ++ 4 files changed, 138 insertions(+) create mode 100755 build-support/bin/xz/linux/x86_64/5.2.4-3/build-xz.sh create mode 100755 build-support/bin/xz/linux/x86_64/5.2.4-3/build.sh create mode 100755 build-support/bin/xz/mac/10.13/5.2.4-3/build-xz.sh create mode 100755 build-support/bin/xz/mac/10.13/5.2.4-3/build.sh diff --git a/build-support/bin/xz/linux/x86_64/5.2.4-3/build-xz.sh b/build-support/bin/xz/linux/x86_64/5.2.4-3/build-xz.sh new file mode 100755 index 0000000..64100f7 --- /dev/null +++ b/build-support/bin/xz/linux/x86_64/5.2.4-3/build-xz.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +source "$(git rev-parse --show-toplevel)/utils.v1.bash" + +set_strict_mode + +function package_xz { + local -r installed_dir_abs="$1" + + with_pushd "$installed_dir_abs" \ + create_gz_package 'xz' bin +} + +function fetch_extract_xz_source_release { + local -r archive_dirname="xz-${XZ_VERSION}" + local -r archive_filename="${archive_dirname}.tar.gz" + local -r release_url="https://tukaani.org/xz/${archive_filename}" + + local -r downloaded_archive="$(curl_file_with_fail "$release_url" "$archive_filename")" + extract_for "$downloaded_archive" "$archive_dirname" +} + +function build_xz { + local -r install_dir_abs="$1" + + # We statically link the `xz` executable to avoid conflicts with any liblzma.so on the host + # machine (see pantsbuild/pants#5639). + ./configure \ + --enable-static --disable-shared \ + --prefix="$install_dir_abs" + + make "-j${MAKE_JOBS}" + + make install +} + +function fetch_build_xz { + local -r install_dir_abs="$(mkdirp_absolute_path 'xz-install')" + + local -r xz_src_extracted_abs="$(fetch_extract_xz_source_release)" + + with_pushd >&2 "$xz_src_extracted_abs" \ + build_xz "$install_dir_abs" + + package_xz "$install_dir_abs" +} + +readonly TARGET_PLATFORM="$1" XZ_VERSION="$2" + +readonly MAKE_JOBS="${MAKE_JOBS:-2}" + +case "$TARGET_PLATFORM" in + osx) + with_pushd "$(mkdirp_absolute_path "xz-${XZ_VERSION}-osx")" \ + fetch_build_xz + ;; + linux) + with_pushd "$(mkdirp_absolute_path "xz-${XZ_VERSION}-linux")" \ + fetch_build_xz + ;; + *) + die "xz does not support building for '${TARGET_PLATFORM}'" + ;; +esac diff --git a/build-support/bin/xz/linux/x86_64/5.2.4-3/build.sh b/build-support/bin/xz/linux/x86_64/5.2.4-3/build.sh new file mode 100755 index 0000000..ca19551 --- /dev/null +++ b/build-support/bin/xz/linux/x86_64/5.2.4-3/build.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +readonly result="$(./build-xz.sh linux 5.2.4)" + +cp "$result" ./xz.tar.gz diff --git a/build-support/bin/xz/mac/10.13/5.2.4-3/build-xz.sh b/build-support/bin/xz/mac/10.13/5.2.4-3/build-xz.sh new file mode 100755 index 0000000..64100f7 --- /dev/null +++ b/build-support/bin/xz/mac/10.13/5.2.4-3/build-xz.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +source "$(git rev-parse --show-toplevel)/utils.v1.bash" + +set_strict_mode + +function package_xz { + local -r installed_dir_abs="$1" + + with_pushd "$installed_dir_abs" \ + create_gz_package 'xz' bin +} + +function fetch_extract_xz_source_release { + local -r archive_dirname="xz-${XZ_VERSION}" + local -r archive_filename="${archive_dirname}.tar.gz" + local -r release_url="https://tukaani.org/xz/${archive_filename}" + + local -r downloaded_archive="$(curl_file_with_fail "$release_url" "$archive_filename")" + extract_for "$downloaded_archive" "$archive_dirname" +} + +function build_xz { + local -r install_dir_abs="$1" + + # We statically link the `xz` executable to avoid conflicts with any liblzma.so on the host + # machine (see pantsbuild/pants#5639). + ./configure \ + --enable-static --disable-shared \ + --prefix="$install_dir_abs" + + make "-j${MAKE_JOBS}" + + make install +} + +function fetch_build_xz { + local -r install_dir_abs="$(mkdirp_absolute_path 'xz-install')" + + local -r xz_src_extracted_abs="$(fetch_extract_xz_source_release)" + + with_pushd >&2 "$xz_src_extracted_abs" \ + build_xz "$install_dir_abs" + + package_xz "$install_dir_abs" +} + +readonly TARGET_PLATFORM="$1" XZ_VERSION="$2" + +readonly MAKE_JOBS="${MAKE_JOBS:-2}" + +case "$TARGET_PLATFORM" in + osx) + with_pushd "$(mkdirp_absolute_path "xz-${XZ_VERSION}-osx")" \ + fetch_build_xz + ;; + linux) + with_pushd "$(mkdirp_absolute_path "xz-${XZ_VERSION}-linux")" \ + fetch_build_xz + ;; + *) + die "xz does not support building for '${TARGET_PLATFORM}'" + ;; +esac diff --git a/build-support/bin/xz/mac/10.13/5.2.4-3/build.sh b/build-support/bin/xz/mac/10.13/5.2.4-3/build.sh new file mode 100755 index 0000000..ca19551 --- /dev/null +++ b/build-support/bin/xz/mac/10.13/5.2.4-3/build.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +readonly result="$(./build-xz.sh linux 5.2.4)" + +cp "$result" ./xz.tar.gz