[libcxx-commits] [libcxx] 1b06d2c - [libc++] Refactor the Apple build scripts

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Feb 16 13:28:23 PST 2022


Author: Louis Dionne
Date: 2022-02-16T16:28:13-05:00
New Revision: 1b06d2cf152ed8b9b480ddcdc66ea35b1fa4a76a

URL: https://github.com/llvm/llvm-project/commit/1b06d2cf152ed8b9b480ddcdc66ea35b1fa4a76a
DIFF: https://github.com/llvm/llvm-project/commit/1b06d2cf152ed8b9b480ddcdc66ea35b1fa4a76a.diff

LOG: [libc++] Refactor the Apple build scripts

This patch upstreams some changes we've made internally to how we're
building the libc++ dylib on Apple platforms. The goal is still to
eventually get rid of `apple-install-libcxx.sh` entirely and have a
proper way to mirror what we do internally with just the normal CMake
configuration.

Differential Revision: https://reviews.llvm.org/D118912

Added: 
    

Modified: 
    libcxx/cmake/caches/Apple.cmake
    libcxx/utils/ci/apple-install-libcxx.sh
    libcxx/utils/ci/run-buildbot

Removed: 
    


################################################################################
diff  --git a/libcxx/cmake/caches/Apple.cmake b/libcxx/cmake/caches/Apple.cmake
index 6f4030ec05b63..4581d4d87b803 100644
--- a/libcxx/cmake/caches/Apple.cmake
+++ b/libcxx/cmake/caches/Apple.cmake
@@ -19,5 +19,7 @@ set(LIBCXXABI_HERMETIC_STATIC_LIBRARY ON CACHE BOOL "")
 set(LIBCXXABI_ENABLE_ASSERTIONS OFF CACHE BOOL "")
 set(LIBCXXABI_ENABLE_FORGIVING_DYNAMIC_CAST ON CACHE BOOL "")
 
+set(LIBCXX_TEST_CONFIG "apple-libc++-shared.cfg.in" CACHE STRING "")
+set(LIBCXXABI_TEST_CONFIG "apple-libc++abi-shared.cfg.in" CACHE STRING "")
 set(LIBCXX_TEST_PARAMS "stdlib=apple-libc++" CACHE STRING "")
 set(LIBCXXABI_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "")

diff  --git a/libcxx/utils/ci/apple-install-libcxx.sh b/libcxx/utils/ci/apple-install-libcxx.sh
index 54d08b3dee923..a0e8874a03022 100755
--- a/libcxx/utils/ci/apple-install-libcxx.sh
+++ b/libcxx/utils/ci/apple-install-libcxx.sh
@@ -30,15 +30,14 @@ ${PROGNAME} [options]
 
 --symbols-dir <DIR>          Path to the directory to install the .dSYM bundle to.
 
---sdk <SDK>                  SDK used for building the library. This represents
-                             the target platform that the library will run on.
-                             You can get a list of SDKs with \`xcodebuild -showsdks\`.
-
 --architectures "<arch>..."  A whitespace separated list of architectures to build for.
                              The library will be built for each architecture independently,
                              and a universal binary containing all architectures will be
                              created from that.
 
+--headers-only               Only install the header part of the library -- don't actually
+                             build the full library.
+
 --version X[.Y[.Z]]          The version of the library to encode in the dylib.
 EOF
 }
@@ -65,14 +64,14 @@ while [[ $# -gt 0 ]]; do
             install_dir="${2}"
             shift; shift
             ;;
-        --sdk)
-            sdk="${2}"
-            shift; shift
-            ;;
         --architectures)
             architectures="${2}"
             shift; shift
             ;;
+        --headers-only)
+            headers_only=true
+            shift
+            ;;
         --version)
             version="${2}"
             shift; shift
@@ -83,7 +82,7 @@ while [[ $# -gt 0 ]]; do
     esac
 done
 
-for arg in llvm_root build_dir symbols_dir install_dir sdk architectures version; do
+for arg in llvm_root build_dir symbols_dir install_dir architectures version; do
     if [ -z ${!arg+x} ]; then
         error "Missing required argument '--${arg//_/-}'"
     elif [ "${!arg}" == "" ]; then
@@ -111,22 +110,22 @@ function step() {
 for arch in ${architectures}; do
     step "Building libc++.dylib and libc++abi.dylib for architecture ${arch}"
     mkdir -p "${build_dir}/${arch}"
-    (cd "${build_dir}/${arch}" &&
-        xcrun --sdk "${sdk}" cmake "${llvm_root}/runtimes" \
-            -GNinja \
-            -DCMAKE_MAKE_PROGRAM="$(xcrun --sdk "${sdk}" --find ninja)" \
-            -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
-            -C "${llvm_root}/libcxx/cmake/caches/Apple.cmake" \
-            -DCMAKE_INSTALL_PREFIX="${build_dir}/${arch}-install" \
-            -DCMAKE_INSTALL_NAME_DIR="/usr/lib" \
-            -DCMAKE_OSX_ARCHITECTURES="${arch}" \
-            -DLIBCXXABI_LIBRARY_VERSION="${version}" \
-            -DLIBCXX_INCLUDE_BENCHMARKS=OFF \
-            -DLIBCXX_TEST_CONFIG="apple-libc++-shared.cfg.in" \
-            -DLIBCXXABI_TEST_CONFIG="apple-libc++abi-shared.cfg.in"
-    )
-
-    xcrun --sdk "${sdk}" cmake --build "${build_dir}/${arch}" --target install-cxx install-cxxabi -- -v
+    xcrun cmake -S "${llvm_root}/runtimes" \
+                -B "${build_dir}/${arch}" \
+                -GNinja \
+                -DCMAKE_MAKE_PROGRAM="$(xcrun --find ninja)" \
+                -C "${llvm_root}/libcxx/cmake/caches/Apple.cmake" \
+                -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
+                -DCMAKE_INSTALL_PREFIX="${build_dir}/${arch}-install" \
+                -DCMAKE_INSTALL_NAME_DIR="/usr/lib" \
+                -DCMAKE_OSX_ARCHITECTURES="${arch}" \
+                -DLIBCXXABI_LIBRARY_VERSION="${version}"
+
+    if [ "$headers_only" = true ]; then
+        xcrun cmake --build "${build_dir}/${arch}" --target install-cxx-headers -- -v
+    else
+        xcrun cmake --build "${build_dir}/${arch}" --target install-cxx install-cxxabi -- -v
+    fi
 done
 
 function universal_dylib() {
@@ -135,21 +134,23 @@ function universal_dylib() {
     inputs=$(for arch in ${architectures}; do echo "${build_dir}/${arch}-install/lib/${dylib}"; done)
 
     step "Creating a universal dylib ${dylib} from the dylibs for all architectures"
-    xcrun --sdk "${sdk}" lipo -create ${inputs} -output "${build_dir}/${dylib}"
+    xcrun lipo -create ${inputs} -output "${build_dir}/${dylib}"
 
     step "Installing the (stripped) universal dylib to ${install_dir}/usr/lib"
     mkdir -p "${install_dir}/usr/lib"
     cp "${build_dir}/${dylib}" "${install_dir}/usr/lib/${dylib}"
-    xcrun --sdk "${sdk}" strip -S "${install_dir}/usr/lib/${dylib}"
+    xcrun strip -S "${install_dir}/usr/lib/${dylib}"
 
     step "Installing the unstripped dylib and the dSYM bundle to ${symbols_dir}"
-    xcrun --sdk "${sdk}" dsymutil "${build_dir}/${dylib}" -o "${symbols_dir}/${dylib}.dSYM"
+    xcrun dsymutil "${build_dir}/${dylib}" -o "${symbols_dir}/${dylib}.dSYM"
     cp "${build_dir}/${dylib}" "${symbols_dir}/${dylib}"
 }
 
-universal_dylib libc++.1.dylib
-universal_dylib libc++abi.dylib
-(cd "${install_dir}/usr/lib" && ln -s "libc++.1.dylib" libc++.dylib)
+if [ "$headers_only" != true ]; then
+    universal_dylib libc++.1.dylib
+    universal_dylib libc++abi.dylib
+    (cd "${install_dir}/usr/lib" && ln -s "libc++.1.dylib" libc++.dylib)
+fi
 
 # Install the headers by copying the headers from one of the built architectures
 # into the install directory. Headers from all architectures should be the same.
@@ -162,15 +163,17 @@ if [[ $EUID -eq 0 ]]; then # Only chown if we're running as root
     chown -R root:wheel "${install_dir}/usr/include"
 fi
 
-step "Installing the libc++ and libc++abi licenses"
-mkdir -p "${install_dir}/usr/local/OpenSourceLicenses"
-cp "${llvm_root}/libcxx/LICENSE.TXT" "${install_dir}/usr/local/OpenSourceLicenses/libcxx.txt"
-cp "${llvm_root}/libcxxabi/LICENSE.TXT" "${install_dir}/usr/local/OpenSourceLicenses/libcxxabi.txt"
-
-# Also install universal static archives for libc++ and libc++abi
-libcxx_archives=$(for arch in ${architectures}; do echo "${build_dir}/${arch}-install/lib/libc++.a"; done)
-libcxxabi_archives=$(for arch in ${architectures}; do echo "${build_dir}/${arch}-install/lib/libc++abi.a"; done)
-step "Creating universal static archives for libc++ and libc++abi from the static archives for each architecture"
-mkdir -p "${install_dir}/usr/local/lib/libcxx"
-xcrun --sdk "${sdk}" libtool -static ${libcxx_archives} -o "${install_dir}/usr/local/lib/libcxx/libc++-static.a"
-xcrun --sdk "${sdk}" libtool -static ${libcxxabi_archives} -o "${install_dir}/usr/local/lib/libcxx/libc++abi-static.a"
+if [ "$headers_only" != true ]; then
+    step "Installing the libc++ and libc++abi licenses"
+    mkdir -p "${install_dir}/usr/local/OpenSourceLicenses"
+    cp "${llvm_root}/libcxx/LICENSE.TXT" "${install_dir}/usr/local/OpenSourceLicenses/libcxx.txt"
+    cp "${llvm_root}/libcxxabi/LICENSE.TXT" "${install_dir}/usr/local/OpenSourceLicenses/libcxxabi.txt"
+
+    # Also install universal static archives for libc++ and libc++abi
+    libcxx_archives=$(for arch in ${architectures}; do echo "${build_dir}/${arch}-install/lib/libc++.a"; done)
+    libcxxabi_archives=$(for arch in ${architectures}; do echo "${build_dir}/${arch}-install/lib/libc++abi.a"; done)
+    step "Creating universal static archives for libc++ and libc++abi from the static archives for each architecture"
+    mkdir -p "${install_dir}/usr/local/lib/libcxx"
+    xcrun libtool -static ${libcxx_archives} -o "${install_dir}/usr/local/lib/libcxx/libc++-static.a"
+    xcrun libtool -static ${libcxxabi_archives} -o "${install_dir}/usr/local/lib/libcxx/libc++abi-static.a"
+fi

diff  --git a/libcxx/utils/ci/run-buildbot b/libcxx/utils/ci/run-buildbot
index 11b26e6b61f31..d0dbedddcff51 100755
--- a/libcxx/utils/ci/run-buildbot
+++ b/libcxx/utils/ci/run-buildbot
@@ -416,17 +416,15 @@ generic-abi-unstable)
 apple-system)
     clean
 
-    sdk_root="$(xcrun --sdk macosx --show-sdk-path)"
     arch="$(uname -m)"
-
-    ${MONOREPO_ROOT}/libcxx/utils/ci/apple-install-libcxx.sh    \
-        --llvm-root ${MONOREPO_ROOT}                            \
-        --build-dir ${BUILD_DIR}                                \
-        --install-dir ${INSTALL_DIR}                            \
-        --symbols-dir "${BUILD_DIR}/symbols"                    \
-        --sdk "macosx"                                          \
-        --architectures "${arch}"                               \
-        --version "999.99"
+    xcrun --sdk macosx                                              \
+        ${MONOREPO_ROOT}/libcxx/utils/ci/apple-install-libcxx.sh    \
+            --llvm-root ${MONOREPO_ROOT}                            \
+            --build-dir ${BUILD_DIR}                                \
+            --install-dir ${INSTALL_DIR}                            \
+            --symbols-dir "${BUILD_DIR}/symbols"                    \
+            --architectures "${arch}"                               \
+            --version "999.99"
 
     # TODO: It would be better to run the tests against the fake-installed version of libc++ instead
     xcrun --sdk macosx ninja -vC "${BUILD_DIR}/${arch}" check-cxx check-cxxabi check-cxx-abilist


        


More information about the libcxx-commits mailing list