diff --git a/libcxx/cmake/caches/AIX.cmake b/libcxx/cmake/caches/AIX.cmake new file mode 100644 --- /dev/null +++ b/libcxx/cmake/caches/AIX.cmake @@ -0,0 +1,21 @@ +set(CMAKE_BUILD_TYPE Release CACHE STRING "") +set(CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "") +set(CMAKE_C_FLAGS "-D_ALL_SOURCE -mignore-xcoff-visibility" CACHE STRING "") +set(CMAKE_CXX_FLAGS "-D_ALL_SOURCE -mignore-xcoff-visibility" CACHE STRING "") +set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-G -Wl,-bcdtors:all:-2147483548:s" CACHE STRING "") + +set(LIBCXX_ABI_VERSION "1" CACHE STRING "") +set(LIBCXX_ENABLE_ASSERTIONS OFF CACHE BOOL "") +set(LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "") +set(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY OFF CACHE BOOL "") +set(LIBCXX_ENABLE_SHARED ON CACHE BOOL "") +set(LIBCXX_ENABLE_STATIC OFF CACHE BOOL "") +set(LIBCXX_CXX_ABI libcxxabi CACHE STRING "") +set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "") + +set(LIBCXXABI_ENABLE_SHARED ON CACHE BOOL "") +set(LIBCXXABI_ENABLE_STATIC OFF CACHE BOOL "") +set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "") + +set(LIBUNWIND_ENABLE_SHARED ON CACHE BOOL "") +set(LIBUNWIND_ENABLE_STATIC OFF CACHE BOOL "") diff --git a/libcxx/utils/ci/aix-install-libcxx.sh b/libcxx/utils/ci/aix-install-libcxx.sh new file mode 100755 --- /dev/null +++ b/libcxx/utils/ci/aix-install-libcxx.sh @@ -0,0 +1,160 @@ +#!/usr/bin/env bash +#===----------------------------------------------------------------------===## +# +# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# +#===----------------------------------------------------------------------===## + +set -e + +PROGNAME="$(basename "${0}")" + +function error() { + printf "error: %s\n" "$*" + exit 1 +} + +function usage() { +cat < Path to the root of the LLVM monorepo. Only the libcxx, + libcxxabi and libunwind directories are required. + +--build-dir Path to the directory to use for building. This will + contain intermediate build products. + +--clobber Remove the build and install directories before building. + +--install-dir Path to the directory to install the library to. + +--cache The CMake cache to use to control how the library gets built. +EOF +} + +function realpath() { + if [[ $1 = /* ]]; then echo "$1"; else echo "$(pwd)/${1#./}"; fi +} + +function parse_args() { + while [[ $# -gt 0 ]]; do + case ${1} in + -h|--help) + usage + exit 0 + ;; + --llvm-root) + llvm_root="${2}" + shift + ;; + --build-dir) + build_dir="${2}" + shift + ;; + --clobber) + clobber=1 + ;; + --install-dir) + install_dir="${2}" + shift + ;; + --cache) + cache="${2}" + shift + ;; + *) + error "Unknown argument '${1}'" + ;; + esac + shift + done + + for arg in llvm_root build_dir install_dir cache; do + if [ -z ${!arg+x} ]; then + error "Missing required argument '--${arg//_/-}'" + elif [ "${!arg}" == "" ]; then + error "Argument to --${arg//_/-} must not be empty" + fi + done + + # Allow using relative paths + for arg in llvm_root build_dir install_dir cache; do + path="$(realpath "${!arg}")" + eval "${arg}=\"${path}\"" + done +} + +function step() { + separator="$(printf "%0.s-" $(seq 1 ${#1}))" + echo + echo "${separator}" + echo "${1}" + echo "${separator}" +} + +function configure_and_build() { + for bitmode in 32 64; do + step "Building libc++.a, libc++abi.a and libunwind.a for ${bitmode}-bit" + [[ ! -d "${build_dir}/${bitmode}" ]] && mkdir -p "${build_dir}/${bitmode}" + [[ ! -e "${build_dir}/${bitmode}/build.ninja" ]] && \ + (cd "${build_dir}/${bitmode}" && + env OBJECT_MODE="${bitmode}" cmake "${llvm_root}/llvm" \ + -C "${cache}" \ + -GNinja \ + -DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi;libunwind" \ + -DCMAKE_INSTALL_PREFIX="${build_dir}/${bitmode}-install" + ) + env OBJECT_MODE="${bitmode}" cmake --build "${build_dir}/${bitmode}" --target install-cxx install-cxxabi install-unwind + done +} + +function merge_libraries() { + local libs="libc++ libc++abi libunwind" + + step "Merging the resulting 32-bit and 64-bit libc++.a, libc++abi.a and libunwind.a into single libraries" + mkdir -p "${install_dir}/lib" + + + cd "${install_dir}/lib" + for lib in ${libs}; do + cp "${build_dir}/32/lib/${lib}.a" . + ar -X64 -x "${build_dir}/64/lib/${lib}.a" + ar -X64 r "${lib}.a" "${lib}.so.1" + rm "${lib}.so.1" + done +} + +function install() { + # Install the headers by copying the headers from one of the builds into the + # install directory. Headers from both bitmodes should be the same. + local libs="libcxx libcxxabi libunwind" + + step "Installing the libc++, libc++abi and libunwind headers to ${install_dir}/include" + mkdir -p "${install_dir}" + cp -r "${build_dir}/32-install/include" "${install_dir}" + [[ ! -d "${install_dir}/include/c++/v1" ]] && error "${install_dir}/include/c++/v1 was not created during install" + cp -r "${llvm_root}/libcxxabi/include/"* "${install_dir}/include/c++/v1" # TODO: libcxxabi should install its headers in CMake + + step "Installing the libc++, libc++abi and libunwind licenses" + mkdir -p "${install_dir}/notices" + for lib in ${libs}; do + cp "${llvm_root}/${lib}/LICENSE.TXT" "${install_dir}/notices/${lib}.txt" + done +} + +function main() { + parse_args "$@" + + [[ -n "${clobber}" ]] && rm -rf "${build_dir}" && rm -rf "${install_dir}" + + configure_and_build + merge_libraries + install +} + +main "$@"