Skip to content

Commit

Permalink
[libc++][C++03] Use __cxx03/ headers in C++03 mode
Browse files Browse the repository at this point in the history
  • Loading branch information
philnik777 committed Dec 11, 2024
1 parent ef3c389 commit 2696de4
Show file tree
Hide file tree
Showing 246 changed files with 1,881 additions and 1,462 deletions.
1 change: 1 addition & 0 deletions .github/workflows/libcxx-build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
fail-fast: false
matrix:
config: [
'frozen-cxx03-headers',
'generic-cxx03',
'generic-cxx26',
'generic-modules'
Expand Down
2 changes: 2 additions & 0 deletions libcxx/cmake/caches/frozen-cxx03-headers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set(LIBCXX_TEST_PARAMS "std=c++03;test_frozen_cxx03_headers=True" CACHE STRING "")
set(LIBCXXABI_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "")
7 changes: 5 additions & 2 deletions libcxx/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1047,12 +1047,15 @@ set(files
wctype.h
)

add_subdirectory(__cxx03)

configure_file("__config_site.in" "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__config_site" @ONLY)
configure_file("${LIBCXX_ASSERTION_HANDLER_FILE}" "${LIBCXX_GENERATED_INCLUDE_DIR}/__assertion_handler" COPYONLY)

set(_all_includes "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__config_site"
"${LIBCXX_GENERATED_INCLUDE_DIR}/__assertion_handler")
foreach(f ${files})
message(STATUS "C++03 headers: ${LIBCXX_FROZEN_CXX03_HEADERS}")
foreach(f ${files} ${LIBCXX_FROZEN_CXX03_HEADERS})
set(src "${CMAKE_CURRENT_SOURCE_DIR}/${f}")
set(dst "${LIBCXX_GENERATED_INCLUDE_DIR}/${f}")
add_custom_command(OUTPUT ${dst}
Expand Down Expand Up @@ -1082,7 +1085,7 @@ target_include_directories(cxx-headers INTERFACE ${LIBCXX_GENERATED_INCLUDE_TARG
${LIBCXX_GENERATED_INCLUDE_DIR})

if (LIBCXX_INSTALL_HEADERS)
foreach(file ${files})
foreach(file ${files} ${LIBCXX_FROZEN_CXX03_HEADERS})
get_filename_component(dir ${file} DIRECTORY)
install(FILES ${file}
DESTINATION "${LIBCXX_INSTALL_INCLUDE_DIR}/${dir}"
Expand Down
54 changes: 7 additions & 47 deletions libcxx/include/__cxx03/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ set(files
__configuration/abi.h
__configuration/availability.h
__configuration/compiler.h
__configuration/config_site_shim.h
__configuration/language.h
__configuration/platform.h
__coroutine/coroutine_handle.h
Expand Down Expand Up @@ -1018,75 +1019,34 @@ set(files
wctype.h
)

configure_file("__config_site.in" "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__config_site" @ONLY)
configure_file("${LIBCXX_ASSERTION_HANDLER_FILE}" "${LIBCXX_GENERATED_INCLUDE_DIR}/__assertion_handler" COPYONLY)

set(_all_includes "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__config_site"
"${LIBCXX_GENERATED_INCLUDE_DIR}/__assertion_handler")
set(_all_includes "")
foreach(f ${files})
set(src "${CMAKE_CURRENT_SOURCE_DIR}/${f}")
set(dst "${LIBCXX_GENERATED_INCLUDE_DIR}/${f}")
set(dst "${LIBCXX_GENERATED_INCLUDE_DIR}/__cxx03/${f}")
add_custom_command(OUTPUT ${dst}
DEPENDS ${src}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
COMMENT "Copying CXX header ${f}")
list(APPEND _all_includes "${dst}")
endforeach()

# Generate the IWYU mapping. This depends on all header files but it's also considered as an
# "include" for dependency tracking.
add_custom_command(OUTPUT "${LIBCXX_GENERATED_INCLUDE_DIR}/libcxx.imp"
COMMAND "${Python3_EXECUTABLE}" "${LIBCXX_SOURCE_DIR}/utils/generate_iwyu_mapping.py" "-o" "${LIBCXX_GENERATED_INCLUDE_DIR}/libcxx.imp"
DEPENDS "${LIBCXX_SOURCE_DIR}/utils/libcxx/header_information.py"
COMMENT "Generate the mapping file for include-what-you-use"
)
list(APPEND _all_includes "${LIBCXX_GENERATED_INCLUDE_DIR}/libcxx.imp")

add_custom_target(generate-cxx-headers ALL DEPENDS ${_all_includes})

add_library(cxx-headers INTERFACE)
target_link_libraries(cxx-headers INTERFACE libcxx-libc-headers libcxx-abi-headers)
add_dependencies(cxx-headers generate-cxx-headers)
# It's important that the arch directory be included first so that its header files
# which interpose on the default include dir be included instead of the default ones.
target_include_directories(cxx-headers INTERFACE ${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}
${LIBCXX_GENERATED_INCLUDE_DIR})
add_custom_target(generate-frozen-cxx03-headers ALL DEPENDS ${_all_includes})

if (LIBCXX_INSTALL_HEADERS)
foreach(file ${files})
get_filename_component(dir ${file} DIRECTORY)
install(FILES ${file}
DESTINATION "${LIBCXX_INSTALL_INCLUDE_DIR}/${dir}"
install(FILES "${file}"
DESTINATION "${LIBCXX_INSTALL_INCLUDE_DIR}/__cxx03/${dir}"
COMPONENT cxx-headers
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
endforeach()

# Install the generated __config_site file to the per-target include dir.
install(FILES "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__config_site"
DESTINATION "${LIBCXX_INSTALL_INCLUDE_TARGET_DIR}"
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
COMPONENT cxx-headers)

# Install the generated __assertion_handler file to the generic include dir.
install(FILES "${LIBCXX_GENERATED_INCLUDE_DIR}/__assertion_handler"
DESTINATION "${LIBCXX_INSTALL_INCLUDE_DIR}"
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
COMPONENT cxx-headers)

# Install the generated IWYU file to the generic include dir.
install(FILES "${LIBCXX_GENERATED_INCLUDE_DIR}/libcxx.imp"
DESTINATION "${LIBCXX_INSTALL_INCLUDE_DIR}"
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
COMPONENT cxx-headers)

if (NOT CMAKE_CONFIGURATION_TYPES)
add_custom_target(install-cxx-headers
add_custom_target(install-frozen-cxx03-headers
DEPENDS cxx-headers
COMMAND "${CMAKE_COMMAND}"
-DCMAKE_INSTALL_COMPONENT=cxx-headers
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
# Stripping is a no-op for headers
add_custom_target(install-cxx-headers-stripped DEPENDS install-cxx-headers)
endif()
endif()
2 changes: 1 addition & 1 deletion libcxx/include/__cxx03/__config
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifndef _LIBCPP___CXX03___CONFIG
#define _LIBCPP___CXX03___CONFIG

#include <__config_site>
#include <__cxx03/__configuration/config_site_shim.h>
#include <__cxx03/__configuration/abi.h>
#include <__cxx03/__configuration/availability.h>
#include <__cxx03/__configuration/compiler.h>
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__cxx03/__configuration/abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#ifndef _LIBCPP___CXX03___CONFIGURATION_ABI_H
#define _LIBCPP___CXX03___CONFIGURATION_ABI_H

#include <__config_site>
#include <__cxx03/__configuration/compiler.h>
#include <__cxx03/__configuration/config_site_shim.h>
#include <__cxx03/__configuration/platform.h>

#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__cxx03/__configuration/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifndef _LIBCPP___CXX03___CONFIGURATION_COMPILER_H
#define _LIBCPP___CXX03___CONFIGURATION_COMPILER_H

#include <__config_site>
#include <__cxx03/__configuration/config_site_shim.h>

#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
# pragma GCC system_header
Expand Down
80 changes: 80 additions & 0 deletions libcxx/include/__cxx03/__configuration/config_site_shim.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___CXX03___CONFIGURATION_CONFIG_SITE_WRAPPER_H
#define _LIBCPP___CXX03___CONFIGURATION_CONFIG_SITE_WRAPPER_H

#include <__config_site>

#if !_LIBCPP_ABI_FORCE_ITANIUM
# undef _LIBCPP_ABI_FORCE_ITANIUM
#endif

#if !_LIBCPP_ABI_FORCE_MICROSOFT
# undef _LIBCPP_ABI_FORCE_MICROSOFT
#endif

#if !_LIBCPP_HAS_THREADS
# define _LIBCPP_HAS_NO_THREADS
#endif

#if !_LIBCPP_HAS_MONOTONIC_CLOCK
# define _LIBCPP_HAS_NO_MONOTONIC_CLOCK
#endif

#if !_LIBCPP_HAS_MUSL_LIBC
# undef _LIBCPP_HAS_MUSL_LIBC
#endif

#if !_LIBCPP_HAS_THREAD_API_PTHREAD
# undef _LIBCPP_HAS_THREAD_API_PTHREAD
#endif

#if !_LIBCPP_HAS_THREAD_API_EXTERNAL
# undef _LIBCPP_HAS_THREAD_API_EXTERNAL
#endif

#if !_LIBCPP_HAS_THREAD_API_WIN32
# undef _LIBCPP_HAS_THREAD_API_WIN32
#endif

#undef _LIBCPP_HAS_THREAD_API_C11

#if !_LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS
# define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS
#endif

#if !_LIBCPP_HAS_FILESYSTEM
# define _LIBCPP_HAS_NO_FILESYSTEM
#endif

#if !_LIBCPP_HAS_RANDOM_DEVICE
# define _LIBCPP_HAS_NO_RANDOM_DEVICE
#endif

#if !_LIBCPP_HAS_LOCALIZATION
# define _LIBCPP_HAS_NO_LOCALIZATION
#endif

#if !_LIBCPP_HAS_UNICODE
# define _LIBCPP_HAS_NO_UNICODE
#endif

#if !_LIBCPP_HAS_WIDE_CHARACTERS
# define _LIBCPP_HAS_NO_WIDE_CHARACTERS
#endif

#if !_LIBCPP_HAS_TIME_ZONE_DATABASE
# define _LIBCPP_HAS_NO_TIME_ZONE_DATABASE
#endif

#if !_LIBCPP_INSTRUMENTED_WITH_ASAN
# undef _LIBCPP_INSTRUMENTED_WITH_ASAN
#endif

#endif // _LIBCPP___CXX03___CONFIGURATION_CONFIG_SITE_WRAPPER_H
2 changes: 1 addition & 1 deletion libcxx/include/__cxx03/__configuration/language.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifndef _LIBCPP___CXX03___CONFIGURATION_LANGUAGE_H
#define _LIBCPP___CXX03___CONFIGURATION_LANGUAGE_H

#include <__config_site>
#include <__cxx03/__configuration/config_site_shim.h>

#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
# pragma GCC system_header
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__cxx03/__configuration/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifndef _LIBCPP___CXX03___CONFIGURATION_PLATFORM_H
#define _LIBCPP___CXX03___CONFIGURATION_PLATFORM_H

#include <__config_site>
#include <__cxx03/__configuration/config_site_shim.h>

#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
# pragma GCC system_header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include <__cxx03/__locale_dir/locale_base_api/locale_guard.h>
#include <__cxx03/cstdio>
#include <__cxx03/stdarg.h>
#include <stdarg.h>
#include <__cxx03/stdlib.h>

#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/__cxx03/__thread/support/pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include <__cxx03/__config>
#include <__cxx03/ctime>
#include <__cxx03/errno.h>
#include <__cxx03/pthread.h>
#include <__cxx03/sched.h>
#include <pthread.h>
#include <sched.h>

#ifdef __MVS__
# include <__cxx03/__support/ibm/nanosleep.h>
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__cxx03/climits
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Macros:

#include <__cxx03/__config>

#include <__cxx03/limits.h>
#include <limits.h>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__cxx03/locale
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ template <class charT> class messages_byname;
// Most unix variants have catopen. These are the specific ones that don't.
# if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) && !defined(__EMSCRIPTEN__)
# define _LIBCPP_HAS_CATOPEN 1
# include <__cxx03/nl_types.h>
# include <nl_types.h>
# endif
# endif

Expand Down
Loading

0 comments on commit 2696de4

Please sign in to comment.