Description
swift-corelibs-foundation uses strlcpy
and strlcat
functions, which are originally from BSD and not available in glibc. However, glibc 2.38 added these functions as an extension, so swift-corelibs-foundation includes a CMake check for these functions and uses them from glibc if available; otherwise, it provides its own implementation like this:
#if !TARGET_OS_MAC
#if !HAVE_STRLCPY
CF_INLINE size_t
strlcpy(char * dst, const char * src, size_t maxlen) {
// omitting the implementation
}
#endif
See 8d1a679 and 48076cb for more details.
However, when the new CMakeFiles were added in c772413, this check wasn't added to the new CMakeLists.txt, so the build fails when glibc 2.38+ is used.
For example, see my build log at https://download.copr.fedorainfracloud.org/results/leebc/swift-lang-main/fedora-40-x86_64/07741791-swift-lang/builder-live.log.gz. The build failed with:
Details
[472/573][ 82%][102.959s] /builddir/build/BUILD/swift-source/build/buildbot_linux/llvm-linux-x86_64/bin/clang -I/builddir/build/BUILD/swift-source/swift-corelibs-foundation/Sources/CoreFoundation/include -I/builddir/build/BUILD/swift-source/swift-corelibs-foundation/Sources/CoreFoundation/internalInclude -I/builddir/build/BUILD/swift-source/swift-foundation-icu/icuSources/include -isystem /builddir/build/BUILD/swift-source/build/buildbot_linux/libdispatch-linux-x86_64 -isystem /builddir/build/BUILD/swift-source/swift-corelibs-libdispatch -isystem /builddir/build/BUILD/swift-source/swift-corelibs-libdispatch/src -isystem /builddir/build/BUILD/swift-source/build/buildbot_linux/libdispatch-linux-x86_64/src -isystem /builddir/build/BUILD/swift-source/swift-corelibs-libdispatch/src/BlocksRuntime -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector -O3 -DNDEBUG -fPIC -DDEPLOYMENT_RUNTIME_SWIFT -DCF_BUILDING_CF -DDEPLOYMENT_ENABLE_LIBDISPATCH -DHAVE_STRUCT_TIMESPEC -DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS -Wno-shorten-64-to-32 -Wno-deprecated-declarations -Wno-unreachable-code -Wno-conditional-uninitialized -Wno-unused-variable -Wno-unused-function -Wno-microsoft-enum-forward-reference -Wno-int-conversion -fblocks -fconstant-cfstrings -fdollars-in-identifiers -fno-common -fcf-runtime-abi=swift -fexceptions -D_GNU_SOURCE -I/usr/lib/swift -Winvalid-pch -fpch-instantiate-templates -Xclang -emit-pch -Xclang -include -Xclang /builddir/build/BUILD/swift-source/build/buildbot_linux/foundation-linux-x86_64/Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h -x c-header -MD -MT Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h.pch -MF Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h.pch.d -o Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h.pch -c /builddir/build/BUILD/swift-source/build/buildbot_linux/foundation-linux-x86_64/Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h.c
FAILED: Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h.pch
/builddir/build/BUILD/swift-source/build/buildbot_linux/llvm-linux-x86_64/bin/clang -I/builddir/build/BUILD/swift-source/swift-corelibs-foundation/Sources/CoreFoundation/include -I/builddir/build/BUILD/swift-source/swift-corelibs-foundation/Sources/CoreFoundation/internalInclude -I/builddir/build/BUILD/swift-source/swift-foundation-icu/icuSources/include -isystem /builddir/build/BUILD/swift-source/build/buildbot_linux/libdispatch-linux-x86_64 -isystem /builddir/build/BUILD/swift-source/swift-corelibs-libdispatch -isystem /builddir/build/BUILD/swift-source/swift-corelibs-libdispatch/src -isystem /builddir/build/BUILD/swift-source/build/buildbot_linux/libdispatch-linux-x86_64/src -isystem /builddir/build/BUILD/swift-source/swift-corelibs-libdispatch/src/BlocksRuntime -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector -O3 -DNDEBUG -fPIC -DDEPLOYMENT_RUNTIME_SWIFT -DCF_BUILDING_CF -DDEPLOYMENT_ENABLE_LIBDISPATCH -DHAVE_STRUCT_TIMESPEC -DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS -Wno-shorten-64-to-32 -Wno-deprecated-declarations -Wno-unreachable-code -Wno-conditional-uninitialized -Wno-unused-variable -Wno-unused-function -Wno-microsoft-enum-forward-reference -Wno-int-conversion -fblocks -fconstant-cfstrings -fdollars-in-identifiers -fno-common -fcf-runtime-abi=swift -fexceptions -D_GNU_SOURCE -I/usr/lib/swift -Winvalid-pch -fpch-instantiate-templates -Xclang -emit-pch -Xclang -include -Xclang /builddir/build/BUILD/swift-source/build/buildbot_linux/foundation-linux-x86_64/Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h -x c-header -MD -MT Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h.pch -MF Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h.pch.d -o Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h.pch -c /builddir/build/BUILD/swift-source/build/buildbot_linux/foundation-linux-x86_64/Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h.c
In file included from <built-in>:1:
In file included from /builddir/build/BUILD/swift-source/build/buildbot_linux/foundation-linux-x86_64/Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h:4:
/builddir/build/BUILD/swift-source/swift-corelibs-foundation/Sources/CoreFoundation/internalInclude/CoreFoundation_Prefix.h:205:1: error: static declaration of 'strlcpy' follows non-static declaration
205 | strlcpy(char * dst, const char * src, size_t maxlen) {
| ^
/usr/include/string.h:506:15: note: previous declaration is here
506 | extern size_t strlcpy (char *__restrict __dest,
| ^
In file included from <built-in>:1:
In file included from /builddir/build/BUILD/swift-source/build/buildbot_linux/foundation-linux-x86_64/Sources/CoreFoundation/CMakeFiles/CoreFoundation.dir/cmake_pch.h:4:
/builddir/build/BUILD/swift-source/swift-corelibs-foundation/Sources/CoreFoundation/internalInclude/CoreFoundation_Prefix.h:219:1: error: static declaration of 'strlcat' follows non-static declaration
219 | strlcat(char * dst, const char * src, size_t maxlen) {
| ^
/usr/include/string.h:512:15: note: previous declaration is here
512 | extern size_t strlcat (char *__restrict __dest,
| ^
2 errors generated.
We should add the check for strlcpy and strlcat functions in the new CMakeLists.txt as well.