Skip to content

Commit 8314dc0

Browse files
committed
fixup! Move CMake code for building multilib and variants to subprojects
1 parent 454b3dd commit 8314dc0

File tree

10 files changed

+209
-50
lines changed

10 files changed

+209
-50
lines changed

CMakeLists.txt

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ option(
138138
the tools every time you update llvm-project."
139139
ON
140140
)
141+
option(
142+
LIBS_USE_COMPILER_LAUNCHER
143+
"Pass CMAKE_C_COMPILER_LAUNCHER and CMAKE_CXX_COMPILER_LAUNCHER
144+
down to the library builds, so that programs such as ccache can
145+
be used to speed up repeated builds. This is not done by default,
146+
as it can also make the inital build slower due to the cold cache."
147+
)
141148
option(
142149
APPLY_LLVM_PERFORMANCE_PATCHES
143150
"During checkout, apply optional downstream patches to
@@ -261,38 +268,11 @@ include(ProcessorCount)
261268
#
262269
# If you want to stop cmake updating the repos then run
263270
# cmake . -DFETCHCONTENT_FULLY_DISCONNECTED=ON
264-
265-
# Read which revisions of the repos to use.
266-
file(READ versions.json VERSIONS_JSON)
267-
function(read_repo_version output_variable_prefix repo)
268-
string(JSON tag GET ${VERSIONS_JSON} "repos" "${repo}" "tag")
269-
string(JSON tagType GET ${VERSIONS_JSON} "repos" "${repo}" "tagType")
270-
if(tagType STREQUAL "commithash")
271-
# GIT_SHALLOW doesn't work with commit hashes.
272-
set(shallow OFF)
273-
elseif(tagType STREQUAL "branch")
274-
set(shallow ON)
275-
# CMake docs recommend that "branch names and tags should
276-
# generally be specified as remote names"
277-
set(tag "origin/${tag}")
278-
elseif(tagType STREQUAL "tag")
279-
set(shallow ON)
280-
else()
281-
message(FATAL_ERROR "Unrecognised tagType ${tagType}")
282-
endif()
283-
284-
set(${output_variable_prefix}_TAG "${tag}" PARENT_SCOPE)
285-
set(${output_variable_prefix}_SHALLOW "${shallow}" PARENT_SCOPE)
286-
endfunction()
287-
read_repo_version(llvmproject llvm-project)
288-
289271
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/fetch_llvm.cmake)
290272
if(LLVM_TOOLCHAIN_C_LIBRARY STREQUAL picolibc)
291-
read_repo_version(picolibc picolibc)
292273
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/fetch_picolibc.cmake)
293274
endif()
294275
if(LLVM_TOOLCHAIN_C_LIBRARY STREQUAL newlib)
295-
read_repo_version(newlib newlib)
296276
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/fetch_newlib.cmake)
297277
endif()
298278

@@ -366,11 +346,6 @@ if(LLVM_TOOLCHAIN_C_LIBRARY STREQUAL llvmlibc)
366346
ExternalProject_Get_property(libc_hdrgen BINARY_DIR)
367347
set(LIBC_HDRGEN ${BINARY_DIR}/bin/libc-hdrgen${CMAKE_EXECUTABLE_SUFFIX})
368348

369-
# Add an empty check target, to simplify the logic below that expects to
370-
# find one for every libc type. We have no current setup to run the LLVM
371-
# libc test suite.
372-
add_custom_target(check-llvmlibc)
373-
374349
# LLVM libc lacks a configuration for AArch64, but the AArch32 one works
375350
# fine. However, setting the configuration for both architectures to the
376351
# arm config directory means the baremetal config.json is never loaded,
@@ -581,17 +556,28 @@ else()
581556
set(library_subdir "")
582557
endif()
583558

559+
if (LIBS_USE_COMPILER_LAUNCHER)
560+
if(CMAKE_C_COMPILER_LAUNCHER)
561+
list(APPEND compiler_launcher_cmake_args "-DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}")
562+
endif()
563+
if(CMAKE_CXX_COMPILER_LAUNCHER)
564+
list(APPEND compiler_launcher_cmake_args "-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}")
565+
endif()
566+
endif()
567+
584568
ExternalProject_Add(
585569
multilib-${LLVM_TOOLCHAIN_C_LIBRARY}
586570
PREFIX ${CMAKE_BINARY_DIR}/multilib-builds
587571
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/arm-multilib
588572
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/llvm/${TARGET_LIBRARIES_DIR}${library_subdir}
589573
DEPENDS ${lib_tool_dependencies}
590574
CMAKE_ARGS
575+
${compiler_launcher_cmake_args}
591576
-DC_LIBRARY=${LLVM_TOOLCHAIN_C_LIBRARY}
592577
-DLLVM_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}/llvm
593578
-DMULTILIB_JSON=${LLVM_TOOLCHAIN_MULTILIB_JSON}
594579
-DENABLE_VARIANTS=${LLVM_TOOLCHAIN_LIBRARY_VARIANTS}
580+
-DLIBC_HDRGEN=${LIBC_HDRGEN}
595581
-DFVP_INSTALL_DIR=${FVP_INSTALL_DIR}
596582
-DFVP_CONFIG_DIR=${CMAKE_CURRENT_SOURCE_DIR}/fvp/config
597583
-DFETCHCONTENT_SOURCE_DIR_LLVMPROJECT=${FETCHCONTENT_SOURCE_DIR_LLVMPROJECT}

arm-multilib/CMakeLists.txt

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ set(ENABLE_VARIANTS "all" CACHE STRING "Semicolon separated list of variants to
3232
set(C_LIBRARY "picolibc" CACHE STRING "Which C library to use.")
3333
set_property(CACHE C_LIBRARY PROPERTY STRINGS picolibc newlib llvmlibc)
3434
set(LLVM_BINARY_DIR "" CACHE PATH "Path to LLVM toolchain build or install root.")
35+
set(LIBC_HDRGEN "" CACHE PATH "Path to prebuilt lbc-hdrgen if not included in LLVM binaries set by LLVM_BINARY_DIR")
36+
set(
37+
FVP_INSTALL_DIR
38+
"" CACHE STRING
39+
"The directory in which the FVP models are installed. These are not
40+
included in this repository, but can be downloaded by the script
41+
fvp/get_fvps.sh"
42+
)
43+
set(FVP_CONFIG_DIR "${TOOLCHAIN_SOURCE_DIR}/fvp/config" CACHE STRING "The directory in which the FVP models are installed.")
3544

3645
# If a compiler launcher such as ccache has been set, it should be
3746
# passed down to each subproject build.
@@ -46,6 +55,7 @@ endif()
4655
# Arguments to pass down to the library projects.
4756
foreach(arg
4857
LLVM_BINARY_DIR
58+
LIBC_HDRGEN
4959
FVP_INSTALL_DIR
5060
FVP_CONFIG_DIR
5161
)
@@ -65,6 +75,34 @@ elseif(C_LIBRARY STREQUAL newlib)
6575
list(APPEND passthrough_dirs "-DFETCHCONTENT_SOURCE_DIR_NEWLIB=${FETCHCONTENT_SOURCE_DIR_NEWLIB}")
6676
endif()
6777

78+
# Target for any dependencies to build the runtimes project.
79+
add_custom_target(runtimes-depends)
80+
81+
# If building llvm-libc, ensure libc-hdrgen is available.
82+
if(C_LIBRARY STREQUAL llvmlibc)
83+
if(NOT LIBC_HDRGEN)
84+
if(EXISTS ${LLVM_BINARY_DIR}/bin/libc-hdrgen${CMAKE_EXECUTABLE_SUFFIX})
85+
set(LIBC_HDRGEN ${LLVM_BINARY_DIR}/bin/libc-hdrgen${CMAKE_EXECUTABLE_SUFFIX})
86+
else()
87+
ExternalProject_Add(
88+
libc_hdrgen
89+
SOURCE_DIR ${llvmproject_SOURCE_DIR}/llvm
90+
CMAKE_ARGS
91+
-DLLVM_ENABLE_RUNTIMES=libc
92+
-DLLVM_LIBC_FULL_BUILD=ON
93+
-DCMAKE_BUILD_TYPE=Debug
94+
BUILD_COMMAND ${CMAKE_COMMAND} --build . --target libc-hdrgen
95+
INSTALL_COMMAND ${CMAKE_COMMAND} -E true
96+
CONFIGURE_HANDLED_BY_BUILD TRUE
97+
)
98+
ExternalProject_Get_property(libc_hdrgen BINARY_DIR)
99+
set(LIBC_HDRGEN ${BINARY_DIR}/bin/libc-hdrgen${CMAKE_EXECUTABLE_SUFFIX})
100+
add_dependencies(runtimes-depends libc_hdrgen)
101+
endif()
102+
endif()
103+
list(APPEND passthrough_dirs "-DLIBC_HDRGEN=${LIBC_HDRGEN}")
104+
endif()
105+
68106
# Create one target to run all the tests.
69107
add_custom_target(check-${C_LIBRARY})
70108
add_custom_target(check-compiler-rt)
@@ -111,13 +149,14 @@ foreach(lib_idx RANGE ${lib_count_dec})
111149
DIRECTORY ${destination_directory}
112150
DESTINATION ${parent_dir_name}
113151
)
114-
set(variant_json_file ${CMAKE_CURRENT_BINARY_DIR}/json/variants/${variant_json})
152+
set(variant_json_file ${CMAKE_CURRENT_SOURCE_DIR}/json/variants/${variant_json})
115153

116154
ExternalProject_Add(
117155
runtimes-${variant}
118156
PREFIX ${CMAKE_BINARY_DIR}/lib-builds
119157
SOURCE_DIR ${TOOLCHAIN_SOURCE_DIR}/arm-runtimes
120158
INSTALL_DIR ${destination_directory}
159+
DEPENDS runtimes-depends
121160
CMAKE_ARGS
122161
${compiler_launcher_cmake_args}
123162
${passthrough_dirs}

arm-multilib/multilib-generate.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ def generate_extensions(args):
239239
aarch64_features = get_extension_list(args.clang, "aarch64-none-eabi")
240240
aarch32_features = get_extension_list(args.clang, "arm-none-eabi")
241241
all_features = list(aarch64_features)
242+
# Combine the aarch64 and aarch32 lists without duplication.
243+
# Casting to sets and merging would be simpler, but creates
244+
# non-deterministic output.
242245
all_features.extend(feat for feat in list(aarch32_features) if feat not in all_features)
243246

244247
print("# Expand -march=...+[no]feature... into individual options we can match")

arm-runtimes/CMakeLists.txt

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ set(ENABLE_LIBC_TESTS ${ENABLE_LIBC_TESTS_def} CACHE BOOL "Enable libc tests (pi
9696
set(ENABLE_COMPILER_RT_TESTS ${ENABLE_COMPILER_RT_TESTS_def} CACHE BOOL "Enable compiler-rt tests.")
9797
set(ENABLE_LIBCXX_TESTS ${ENABLE_LIBCXX_TESTS_def} CACHE BOOL "Enable libcxx tests.")
9898
set(LLVM_BINARY_DIR "" CACHE PATH "Path to LLVM toolchain root to build libraries with")
99+
set(LIBC_HDRGEN "" CACHE PATH "Path to prebuilt lbc-hdrgen if not included in LLVM binaries set by LLVM_BINARY_DIR")
99100

100101
# Temporary location to collect the libraries as they are built.
101102
set(TEMP_LIB_DIR "${CMAKE_CURRENT_BINARY_DIR}/tmp_install")
@@ -137,16 +138,23 @@ else()
137138
else()
138139
set(target_triple "arm-none-eabi")
139140
endif()
140-
if(flags MATCHES "-mfloat-abi=hard")
141+
if(COMPILE_FLAGS MATCHES "-mfloat-abi=hard")
141142
# Also, compiler-rt looks in the ABI component of the
142143
# triple to decide whether to use the hard float ABI.
143144
set(target_triple "${target_triple}hf")
144145
endif()
145146
set(cpu_family arm)
146147
endif()
147148

149+
# Create a single target for all testing. If no testing is enabled, this
150+
# will simply do nothing.
151+
add_custom_target(check-all)
152+
148153
# If any testing is enabled, prepare test executor settings.
149154
if (ENABLE_LIBC_TESTS OR ENABLE_COMPILER_RT_TESTS OR ENABLE_LIBCXX_TESTS)
155+
# Flags required to link tests.
156+
set(test_link_flags "-nostartfiles -lcrt0-semihost -lsemihost -T picolibcpp.ld")
157+
150158
if(TEST_EXECUTOR STREQUAL qemu)
151159
if(TARGET_ARCH MATCHES "^aarch64")
152160
find_program(QEMU_EXECUTABLE qemu-system-aarch64)
@@ -198,7 +206,6 @@ if (ENABLE_LIBC_TESTS OR ENABLE_COMPILER_RT_TESTS OR ENABLE_LIBCXX_TESTS)
198206
endif()
199207

200208
set(compile_arch_flags "--target=${target_triple} ${COMPILE_FLAGS}")
201-
set(link_flags "-nostartfiles -lcrt0-semihost -lsemihost -T picolibcpp.ld")
202209
# Compiling the libraries benefits from some extra optimization
203210
# flags, and requires a sysroot.
204211
set(lib_compile_flags "${compile_arch_flags} -ffunction-sections -fdata-sections -fno-ident --sysroot ${TEMP_LIB_DIR}")
@@ -238,7 +245,7 @@ if(VARIANT STREQUAL "armv6m_soft_nofp")
238245
endif()
239246

240247
if (ENABLE_COMPILER_RT_TESTS)
241-
set(compiler_rt_test_flags "${lib_compile_flags} ${link_flags}")
248+
set(compiler_rt_test_flags "${lib_compile_flags} ${test_link_flags}")
242249
set(compiler_rt_lit_args "${LLVM_LIT_ARGS} --xunit-xml-output=results.junit.xml")
243250
set(
244251
compiler_rt_test_cmake_args
@@ -298,6 +305,7 @@ ExternalProject_Add(
298305
)
299306

300307
add_custom_target(check-compiler-rt)
308+
add_dependencies(check-all check-compiler-rt)
301309
if (ENABLE_COMPILER_RT_TESTS)
302310
ExternalProject_Add_Step(
303311
compiler_rt
@@ -357,7 +365,7 @@ if(C_LIBRARY STREQUAL picolibc)
357365
to_meson_list("${picolibc_flags}" picolibc_meson_flags)
358366

359367
if (ENABLE_LIBC_TESTS)
360-
set(picolibc_test_executor_bin ${CMAKE_CURRENT_SOURCE_DIR}/picolibc-test-wrapper.py)
368+
set(picolibc_test_executor_bin ${CMAKE_CURRENT_SOURCE_DIR}/test-support/picolibc-test-wrapper.py)
361369
to_meson_list("${test_executor_params}" meson_test_executor_params)
362370
endif()
363371

@@ -394,6 +402,7 @@ if(C_LIBRARY STREQUAL picolibc)
394402
)
395403

396404
add_custom_target(check-picolibc)
405+
add_dependencies(check-all check-picolibc)
397406
if (ENABLE_LIBC_TESTS)
398407
# meson builds the tests at the same time as the library.
399408
# So reconfigure to enable tests at a later point.
@@ -416,7 +425,7 @@ if(C_LIBRARY STREQUAL picolibc)
416425
check
417426
COMMAND ${MESON_EXECUTABLE} test -C <BINARY_DIR>
418427
COMMAND ${Python3_EXECUTABLE}
419-
${TOOLCHAIN_SOURCE_DIR}/test-support/modify-picolibc-xml.py
428+
${CMAKE_CURRENT_SOURCE_DIR}/test-support/modify-picolibc-xml.py
420429
--picolibc-build-dir <BINARY_DIR>
421430
--variant ${VARIANT}
422431
USES_TERMINAL TRUE
@@ -542,6 +551,8 @@ if(C_LIBRARY STREQUAL llvmlibc)
542551
DESTINATION
543552
${LIBC_CFG_DIR}
544553
)
554+
555+
set(lib_compile_flags "${lib_compile_flags} -Wno-error=atomic-alignment")
545556

546557
set(common_llvmlibc_cmake_args
547558
-DCMAKE_AR=${LLVM_BINARY_DIR}/bin/llvm-ar${CMAKE_EXECUTABLE_SUFFIX}
@@ -568,6 +579,9 @@ if(C_LIBRARY STREQUAL llvmlibc)
568579
# If libc-hdrgen is provided, there is no need to build it,
569580
# but a target is still needed to satisfy the dependency.
570581
add_custom_target(libc_hdrgen)
582+
elseif(EXISTS ${LLVM_BINARY_DIR}/bin/libc-hdrgen${CMAKE_EXECUTABLE_SUFFIX})
583+
set(LIBC_HDRGEN ${LLVM_BINARY_DIR}/bin/libc-hdrgen${CMAKE_EXECUTABLE_SUFFIX})
584+
add_custom_target(libc_hdrgen)
571585
else()
572586
ExternalProject_Add(
573587
libc_hdrgen
@@ -576,10 +590,8 @@ if(C_LIBRARY STREQUAL llvmlibc)
576590
-DLLVM_ENABLE_RUNTIMES=libc
577591
-DLLVM_LIBC_FULL_BUILD=ON
578592
-DCMAKE_BUILD_TYPE=Debug
579-
STEP_TARGETS build install
580593
BUILD_COMMAND ${CMAKE_COMMAND} --build . --target libc-hdrgen
581594
INSTALL_COMMAND ${CMAKE_COMMAND} -E true
582-
# Always run the build command so that incremental builds are correct.
583595
CONFIGURE_HANDLED_BY_BUILD TRUE
584596
)
585597
ExternalProject_Get_property(libc_hdrgen BINARY_DIR)
@@ -674,7 +686,7 @@ if(ENABLE_CXX_LIBS)
674686
-DLIBUNWIND_TEST_CONFIG=${CMAKE_CURRENT_SOURCE_DIR}/test-support/llvm-libunwind-picolibc.cfg.in
675687
-DLIBUNWIND_TEST_PARAMS=executor=${lit_test_executor}
676688
-DRUNTIME_TEST_ARCH_FLAGS=${compile_arch_flags}
677-
-DRUNTIME_TEST_LINK_FLAGS=${link_flags}
689+
-DRUNTIME_TEST_LINK_FLAGS=${test_link_flags}
678690
-DLLVM_LIT_ARGS=${cxxlibs_lit_args}
679691
)
680692
endif()
@@ -750,8 +762,11 @@ if(ENABLE_CXX_LIBS)
750762
CONFIGURE_HANDLED_BY_BUILD TRUE
751763
)
752764
add_custom_target(check-cxx)
765+
add_dependencies(check-all check-cxx)
753766
add_custom_target(check-cxxabi)
767+
add_dependencies(check-all check-cxxabi)
754768
add_custom_target(check-unwind)
769+
add_dependencies(check-all check-unwind)
755770
if (ENABLE_LIBCXX_TESTS)
756771
foreach(check_target check-cxx check-cxxabi check-unwind)
757772
ExternalProject_Add_Step(
@@ -772,9 +787,9 @@ if(ENABLE_CXX_LIBS)
772787
endforeach()
773788
endif()
774789

775-
install(
776-
DIRECTORY ${TEMP_LIB_DIR}/
777-
DESTINATION .
778-
)
779-
780790
endif()
791+
792+
install(
793+
DIRECTORY ${TEMP_LIB_DIR}/
794+
DESTINATION .
795+
)

arm-runtimes/test-support/modify-compiler-rt-xml.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ def main():
4747
new_classname = old_classname.replace(old_suitename, new_suitename)
4848
testcase.set("classname", new_classname)
4949

50-
xml_file = os.path.join(args.compiler_rt_build_dir, "test", "results2.junit.xml")
5150
tree.write(xml_file)
5251
print(f"Results written to {xml_file}")
5352

cmake/fetch_llvm.cmake

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66

77
include(FetchContent)
88

9-
set(llvm_patch_script ${CMAKE_CURRENT_SOURCE_DIR}/patch_llvm.py)
10-
set(patch_dir ${CMAKE_CURRENT_SOURCE_DIR}/../patches)
9+
if(NOT VERSIONS_JSON)
10+
include(${CMAKE_CURRENT_LIST_DIR}/read_versions.cmake)
11+
endif()
12+
read_repo_version(llvmproject llvm-project)
13+
14+
set(llvm_patch_script ${CMAKE_CURRENT_LIST_DIR}/patch_llvm.py)
15+
set(patch_dir ${CMAKE_CURRENT_LIST_DIR}/../patches)
1116
set(LLVM_PATCH_COMMAND ${Python3_EXECUTABLE} ${llvm_patch_script} ${patch_dir}/llvm-project)
1217
if(APPLY_LLVM_PERFORMANCE_PATCHES)
1318
set(LLVM_PATCH_COMMAND ${LLVM_PATCH_COMMAND} && ${Python3_EXECUTABLE} ${llvm_patch_script} ${patch_dir}/llvm-project-perf)

cmake/fetch_newlib.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66

77
include(FetchContent)
88

9-
set(newlib_patch ${CMAKE_CURRENT_SOURCE_DIR}/../patches/newlib.patch)
9+
if(NOT VERSIONS_JSON)
10+
include(${CMAKE_CURRENT_LIST_DIR}/read_versions.cmake)
11+
endif()
12+
read_repo_version(newlib newlib)
13+
14+
set(newlib_patch ${CMAKE_CURRENT_LIST_DIR}/../patches/newlib.patch)
1015

1116
FetchContent_Declare(newlib
1217
GIT_REPOSITORY https://sourceware.org/git/newlib-cygwin.git

cmake/fetch_picolibc.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
include(FetchContent)
88

9+
if(NOT VERSIONS_JSON)
10+
include(${CMAKE_CURRENT_LIST_DIR}/read_versions.cmake)
11+
endif()
12+
read_repo_version(picolibc picolibc)
13+
914
set(
1015
picolibc_patches
1116
${CMAKE_CURRENT_SOURCE_DIR}/patches/picolibc/0001-Enable-libcxx-builds.patch

0 commit comments

Comments
 (0)