Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions qualcomm-software/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -786,13 +786,20 @@ if(ENABLE_LINUX_LIBRARIES)
DESTINATION .
COMPONENT llvm-toolchain-libs
REGEX "resource-dir" EXCLUDE
REGEX "cfgs" EXCLUDE
)
# compiler-rt
install(
DIRECTORY ${LLVM_BINARY_DIR}/linux-libraries/resource-dir/.
DESTINATION lib/clang/${LLVM_VERSION_MAJOR}
COMPONENT llvm-toolchain-libs
)
# per-variant clang configuration files
install(
DIRECTORY ${LLVM_BINARY_DIR}/linux-libraries/cfgs/.
DESTINATION bin
COMPONENT llvm-toolchain-libs
)
endif()

if(ENABLE_WINDOWS_LIBRARIES)
Expand Down
23 changes: 23 additions & 0 deletions qualcomm-software/cmake/copy_target_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ def move_folder(src_glob, dest):
shutil.move(src_dir, dest)


def move_files(src_glob, dest):
"""
Move every file matched by `src_glob` into the `dest` directory.
"""

os.makedirs(dest, exist_ok=True)
matched = glob.glob(src_glob)
if not matched:
raise RuntimeError(f"No files matched glob '{src_glob}'")

for src_file in matched:
shutil.move(src_file, os.path.join(dest, os.path.basename(src_file)))


def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
Expand Down Expand Up @@ -102,6 +116,15 @@ def main():
for folder in linux_lib_folders:
move_folder(os.path.join(tmp, "*", folder), linux_lib_dir)

# Move the per-variant clang configuration files. These live in
# the distribution's bin/ directory; the `musl_` prefix
# distinguishes them from musl-embedded.cfg (which is not a
# linux-runtime variant cfg and must stay put).
move_files(
os.path.join(tmp, "*", "bin", "musl_linux_*.cfg"),
os.path.join(linux_lib_dir, "cfgs"),
)


if __name__ == "__main__":
main()
54 changes: 54 additions & 0 deletions qualcomm-software/scripts/build_linux_runtimes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ fi

CLANG_RESOURCE_DIR="$(clang --print-resource-dir)"

# The resource dir's path relative to the directory containing the clang
# binary. This is a property of the LLVM build (always <bin>/../lib/clang/<major>)
# rather than of any particular install location, so it can be reused as-is
# with clang's <CFGDIR> token when generating per-variant configuration files
# below, regardless of whether TOOLS_PATH is an in-tree build's bin/ dir or
# the final installed package's bin/ dir.
CLANG_RESOURCE_DIR_REL="$(realpath --relative-to="${TOOLS_PATH}" "${CLANG_RESOURCE_DIR}")"

# Variants to build and the basic set of compile flags to use for each. There's
# surely more elegant ways of doing this, but this doesn't require any extra
# dependencies and is intended as temporary code.
Expand Down Expand Up @@ -476,6 +484,7 @@ done
# Also, while we use `*-linux-gnu` triples to build, we want to install these
# in `*-linux-musl` directories.
echo "Copying libraries to their final locations"
mkdir -p "${BASE_INSTALL_DIR}/cfgs"
for VARIANT in "${VARIANTS[@]}"; do
VARIANT_TMP_SYSROOT="${BASE_BUILD_DIR}/${VARIANT}/sysroot"
VARIANT_TARGET="$(get_target_from_flags ${VARIANT_BUILD_FLAGS[$VARIANT]})"
Expand All @@ -491,4 +500,49 @@ for VARIANT in "${VARIANTS[@]}"; do
mv "${VARIANT_TMP_SYSROOT}/resource-dir/lib/temp" \
"${VARIANT_TMP_SYSROOT}/resource-dir/lib/${VARIANT_TARGET_MUSL}/${VARIANT}"
cp -r "${VARIANT_TMP_SYSROOT}/resource-dir" "${BASE_INSTALL_DIR}"

# Generate a clang configuration file for this variant so it can be used via
# `--config=musl_linux_<variant>.cfg` without needing to know the toolchain's
# internal layout. Paths are all relative to <CFGDIR> (the directory
# containing the .cfg file itself, i.e. the installed bin/ dir) so the file
# remains valid wherever the package is installed. See
# https://clang.llvm.org/docs/UsersManual.html#configuration-files
echo "Generating clang config for ${VARIANT}"
VARIANT_STDLIB_REL="../${VARIANT_TARGET_MUSL}/${VARIANT}"
VARIANT_RT_LIB_REL="${CLANG_RESOURCE_DIR_REL}/lib/${VARIANT_TARGET_MUSL}/${VARIANT}"
{
# The variant's build flags contain `--target=<triple>-gnu`; swap in the
# musl target instead so the emitted .cfg doesn't reference the gnu triple
for word in ${VARIANT_BUILD_FLAGS[$VARIANT]}; do
if [[ "${word}" == --target=* ]]; then
echo "--target=${VARIANT_TARGET_MUSL}"
else
echo "${word}"
fi
done
echo "-nostdinc"
echo "-nostdinc++"
echo "-isystem <CFGDIR>/${CLANG_RESOURCE_DIR_REL}/include"
echo "-cxx-isystem <CFGDIR>/${VARIANT_STDLIB_REL}/include/c++/v1"
echo "-cxx-isystem <CFGDIR>/${VARIANT_STDLIB_REL}/include/c++/v1/support/musl"
echo "-isystem <CFGDIR>/${VARIANT_STDLIB_REL}/include"
# The following are only applied when linking, and are appended after
# all user-specified linker inputs.
echo "\$-nostdlib"
echo "\$-L <CFGDIR>/${VARIANT_STDLIB_REL}/lib"
echo "\$-L <CFGDIR>/${VARIANT_RT_LIB_REL}"
echo "\$-Wl,--as-needed"
echo "\$-lc++"
echo "\$-lc++abi"
echo "\$-lunwind"
echo "\$-Wl,--no-as-needed"
echo "\$<CFGDIR>/${VARIANT_STDLIB_REL}/lib/crt1.o"
echo "\$<CFGDIR>/${VARIANT_STDLIB_REL}/lib/crti.o"
echo "\$<CFGDIR>/${VARIANT_STDLIB_REL}/lib/crtn.o"
echo "\$-Wl,--start-group"
echo "\$-lc"
echo "\$-lclang_rt.builtins"
echo "\$-Wl,--end-group"
echo "\$-Wl,--defsym,__dso_handle=0"
} > "${BASE_INSTALL_DIR}/cfgs/musl_linux_${VARIANT}.cfg"
done
Loading