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

add compiler package script #57

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build-cmake-3.9.5.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ for rev in "10.8" "10.9" "10.10" "10.11" "10.12" "10.13"; do
DEST_BASE="build-support/bin/cmake/mac/${rev}"
mkdir -p "${DEST_BASE}"
pushd "${DEST_BASE}" > /dev/null
ln -s "../10.7/3.9.5" "3.9.5"
ln -sf "../10.7/3.9.5" "3.9.5"
popd > /dev/null
done
141 changes: 141 additions & 0 deletions build-compiler-5.0.1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/bin/bash

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compiler is too generic a name... clang, probably?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang is definitely better than compiler, but thinking about it now I might actually suggest to call it clang-llvm, or even clang+llvm, because the LLVM version (5.0.1) is what's used in the release download url from the LLVM downloads page, not the clang version. Also, the MacOS binary release download unpacks into an archive named clang+llvm-5.0.1-<platform>.tar.xz, so calling it clang+llvm would match that convention. It could be clang-llvm too, but I prefer clang+llvm because that makes it clear which part of clang+llvm-5.0.1.tar.gz is the package name and which part is the version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you planning to package something in here other than clang itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the C and C++ standard library headers. The C standard library headers are already included -- I hadn't tested the C++ standard library headers because we don't have a python_dist() target with C++ code in testprojects/ yet in the pants repo. These would be provided with the compiler so that they are compatible with the compiler, and so we don't have to rely on headers existing in standard locations (which is a requirement for an internal consumer of python_dist() with native code).

I'm not planning to package anything that's not considered part of clang, however. It might make sense to just call it clang, by that logic. Since we're not packaging any other LLVM tools, it might be confusing/surprising to call it clang+llvm.

After concentrating on this for a bit, my vote goes to just calling it clang.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to build-clang-5.0.1.sh, producing clang.tar.gz in supportdir build-support/bin/clang in ad67ff4.

if ! hash xz; then
cat >&2 <<EOF
'xz' is required to run this script. You may have to install it using your
operating system's package manager.
EOF
exit 1
fi

set -euxo pipefail

LLVM_VERSION='5.0.1'
CORRESPONDING_CLANG_BIN_VERSION='5.0'
LLVM_RELEASE_BUILD_DIRNAME='llvm-tmp'
LLVM_PANTS_ARCHIVE_NAME='compiler.tar.gz'
COMPILER_SUPPORTDIR='build-support/bin/compiler'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to clang in ad67ff4.


# default to -j2
MAKE_JOBS="${MAKE_JOBS:-2}"

mkdir -p "$LLVM_RELEASE_BUILD_DIRNAME"

CLANG_BINARIES=(
clang
clang++
clang-"${CORRESPONDING_CLANG_BIN_VERSION}"
)

function extract-required-files-from-unpacked-llvm {
local -r unpacked_llvm_dir="$1"
local -r pants_output_archive_name="$2"

mkdir -p bin/ include/

for bin_path in ${CLANG_BINARIES[@]}; do
cp "${unpacked_llvm_dir}/bin/${bin_path}" bin/
done

find "$unpacked_llvm_dir"/lib/clang/"$LLVM_VERSION"/include \
-type f \
-name '*.h' \
-exec cp '{}' include/ ';'

tar czf "$pants_output_archive_name" bin/ include/
}


## MacOS (LLVM-packaged release binaries)
MACOS_REVS=(
10.7
10.8
10.9
10.10
10.11
10.12
10.13
)
LLVM_TMP_MACOS_PKG_DIR='llvm-macos-pkg'

pushd "$LLVM_RELEASE_BUILD_DIRNAME"

curl -L -O "https://releases.llvm.org/${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-x86_64-apple-darwin.tar.xz"
tar xf "clang+llvm-${LLVM_VERSION}-x86_64-apple-darwin.tar.xz"
llvm_macos_bin_release_dir_abs="$(pwd)/clang+llvm-${LLVM_VERSION}-final-x86_64-apple-darwin"

mkdir -p "$LLVM_TMP_MACOS_PKG_DIR"
pushd "$LLVM_TMP_MACOS_PKG_DIR"

extract-required-files-from-unpacked-llvm \
"$llvm_macos_bin_release_dir_abs" \
"$LLVM_PANTS_ARCHIVE_NAME"

llvm_macos_packaged_abs="$(pwd)/${LLVM_PANTS_ARCHIVE_NAME}"
popd

popd

for rev in ${MACOS_REVS[@]}; do
dest_base="${COMPILER_SUPPORTDIR}/mac/${rev}/${LLVM_VERSION}"
mkdir -p "$dest_base"
cp "$llvm_macos_packaged_abs" "${dest_base}/${LLVM_PANTS_ARCHIVE_NAME}"
done


## Linux (from source release)
# We need cmake >= 3.4, so use the one we already build for pants.
CMAKE_VERSION='3.9.5'
CMAKE_BUILD_TMP_DIR='cmake-build-tmp'
LLVM_BUILD_TMP_DIR='llvm-build'
LLVM_TMP_LINUX_PKG_DIR='llvm-linux-pkg'

"./build-cmake-${CMAKE_VERSION}.sh"
cmake_linux_packaged_abs="$(pwd)/build-support/bin/cmake/linux/x86_64/${CMAKE_VERSION}/cmake.tar.gz"

mkdir -p "$CMAKE_BUILD_TMP_DIR"
pushd "$CMAKE_BUILD_TMP_DIR"
tar zxf "$cmake_linux_packaged_abs"
cmake_linux_bin_abs="$(pwd)/bin/cmake"
popd

pushd "$LLVM_RELEASE_BUILD_DIRNAME"

# LLVM requires you to download the source for LLVM and the Clang frontend
# separately. The alternative is checking out their SVN repo, which takes much
# longer.
curl -L -O "https://releases.llvm.org/${LLVM_VERSION}/llvm-${LLVM_VERSION}.src.tar.xz"
curl -L -O "https://releases.llvm.org/${LLVM_VERSION}/cfe-${LLVM_VERSION}.src.tar.xz"
tar xf "llvm-${LLVM_VERSION}.src.tar.xz"
tar xf "cfe-${LLVM_VERSION}.src.tar.xz"

mkdir -p "$LLVM_BUILD_TMP_DIR"
pushd "$LLVM_BUILD_TMP_DIR"

"$cmake_linux_bin_abs" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_EXTERNAL_CLANG_SOURCE_DIR="../cfe-${LLVM_VERSION}.src" \
-DLLVM_EXTERNAL_PROJECTS='clang' \
"../llvm-${LLVM_VERSION}.src"

make -j"$MAKE_JOBS"

llvm_linux_source_release_dir_abs="$(pwd)"

popd

mkdir -p "$LLVM_TMP_LINUX_PKG_DIR"
pushd "$LLVM_TMP_LINUX_PKG_DIR"

extract-required-files-from-unpacked-llvm \
"$llvm_linux_source_release_dir_abs" \
"$LLVM_PANTS_ARCHIVE_NAME"

llvm_linux_packaged_abs="$(pwd)/${LLVM_PANTS_ARCHIVE_NAME}"

popd

popd

mkdir -p "${COMPILER_SUPPORTDIR}/linux/x86_64/${LLVM_VERSION}"
cp "$llvm_linux_packaged_abs" "${COMPILER_SUPPORTDIR}/linux/x86_64/${LLVM_VERSION}/${LLVM_PANTS_ARCHIVE_NAME}"