Benchmark cmake: Added SWIFT_BENCHMARK_USE_OS_LIBRARIES

Cleanup and document the configuration of the library path and rpath.

With SWIFT_BENCHMARK_USE_OS_LIBRARIES, it's now possible to directly
build benchmarks for a target device and run those benchmarks on the
device without building or installing Swift.

It's also possible now to specify an absolute SWIFT_LIBRARY_PATH to be
used as an rpath so installation can be skipped.
This commit is contained in:
Andrew Trick
2019-04-05 09:44:41 -07:00
parent 8e5dbcfde2
commit b127216946
3 changed files with 111 additions and 20 deletions

View File

@@ -24,6 +24,9 @@ macro(configure_build)
if(${c_compiler} STREQUAL "clang")
set(CLANG_EXEC ${CMAKE_C_COMPILER})
else()
if(NOT SWIFT_DARWIN_XCRUN_TOOLCHAIN)
set(SWIFT_DARWIN_XCRUN_TOOLCHAIN "XcodeDefault")
endif()
runcmd(COMMAND "xcrun" "-toolchain" "${SWIFT_DARWIN_XCRUN_TOOLCHAIN}" "-f" "clang"
VARIABLE CLANG_EXEC
ERROR "Unable to find Clang driver")
@@ -57,12 +60,47 @@ macro(configure_build)
endif()
endif()
# We always infer the SWIFT_LIBRARY_PATH from SWIFT_EXEC unless
# SWIFT_LIBRARY_PATH is specified explicitly.
if(NOT SWIFT_LIBRARY_PATH)
get_filename_component(tmp_dir "${SWIFT_EXEC}" DIRECTORY)
get_filename_component(tmp_dir "${tmp_dir}" DIRECTORY)
set(SWIFT_LIBRARY_PATH "${tmp_dir}/lib/swift")
# Set LIBRARY_PATH and either RPATH or RPATH_BASE. To build and run
# for multiple platforms, RPATH_BASE must be set instead of RPATH. It
# is the platform-independent runtime library directory. The platform
# subdirectory name will be appended to form a different RPATH for
# on platform.
# If requested, use Swift-in-the-OS. This way, the benchmarks may be built
# standalone on the host, and the binaries can run directly from a temp dir
# on any target machine. Of course, this factors out performance changes in
# stdlib or overlays.
if(SWIFT_BENCHMARK_USE_OS_LIBRARIES)
set(SWIFT_RPATH "/usr/lib/swift")
endif()
# When SWIFT_LIBRARY_PATH is specified explicitly for a standalone
# build, use it as an absolute RPATH_BASE. This only works when
# running benchmarks on the host machine. Otherwise, RPATH is set
# assuming that libraries will be installed later (manually)
# relative to the benchmark binaries.
#
# When not building standalone, SWIFT_LIBRARY_PATH is set by LLVM
# cmake to the build directory for Swift dylibs. Otherwise, assume
# that the dylibs are built relative to SWIFT_EXEC.
if(SWIFT_LIBRARY_PATH AND SWIFT_BENCHMARK_BUILT_STANDALONE)
if (NOT SWIFT_RPATH)
set(SWIFT_RPATH_BASE ${SWIFT_LIBRARY_PATH})
endif()
else()
if (NOT SWIFT_LIBRARY_PATH)
get_filename_component(tmp_dir "${SWIFT_EXEC}" DIRECTORY)
get_filename_component(tmp_dir "${tmp_dir}" DIRECTORY)
set(SWIFT_LIBRARY_PATH "${tmp_dir}/lib/swift")
endif()
if (NOT SWIFT_RPATH)
# If the benchmarks are built against a local swift build, assume that
# either the benchmarks will be installed in the swift build dir,
# or the swift libraries will be installed in the benchmark location in
# a platform specific subdirectory.
# This way, performance always factors in changes to the libraries.
set(SWIFT_RPATH_BASE "@executable_path/../lib/swift")
endif()
endif()
endmacro()
@@ -571,6 +609,11 @@ function (swift_benchmark_compile_archopts)
# both do exactly the same thing with both sets of arguments. It also lets us
# avoid issues around code-signing.
if (is_darwin)
if (SWIFT_RPATH)
set(SWIFT_LINK_RPATH "${SWIFT_RPATH}")
else()
set(SWIFT_LINK_RPATH "${SWIFT_RPATH_BASE}/${BENCH_COMPILE_ARCHOPTS_PLATFORM}")
endif()
add_custom_command(
OUTPUT "${OUTPUT_EXEC}"
DEPENDS
@@ -593,7 +636,7 @@ function (swift_benchmark_compile_archopts)
"-lobjc"
"-L${SWIFT_LIBRARY_PATH}/${BENCH_COMPILE_ARCHOPTS_PLATFORM}"
"-Xlinker" "-rpath"
"-Xlinker" "@executable_path/../lib/swift/${BENCH_COMPILE_ARCHOPTS_PLATFORM}"
"-Xlinker" "${SWIFT_LINK_RPATH}"
${bench_library_objects}
${bench_driver_objects}
${SWIFT_BENCH_OBJFILES}
@@ -612,7 +655,7 @@ function (swift_benchmark_compile_archopts)
"${SWIFT_EXEC}"
"-O"
"-target" "${target}"
"-L${SWIFT_LIBRARY_PATH}/${BENCH_COMPILE_ARCHOPTS_PLATFORM}"
"-L${SWIFT_LIBRARY_PATH}"
${bench_library_objects}
${bench_driver_objects}
${SWIFT_BENCH_OBJFILES}