Skip to content

[DRAFT][libc++][modules] Improves std.compat module. #74945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
15 changes: 11 additions & 4 deletions libcxx/modules/CMakeLists.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ cmake_minimum_required(VERSION 3.26)
project(libc++-modules LANGUAGES CXX)

# Enable CMake's module support
if(CMAKE_VERSION VERSION_LESS "3.27.0")
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "2182bf5c-ef0d-489a-91da-49dbc3090d2a")
if(CMAKE_VERSION VERSION_LESS "3.28.0")
if(CMAKE_VERSION VERSION_LESS "3.27.0")
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "2182bf5c-ef0d-489a-91da-49dbc3090d2a")
else()
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "aa1f7df0-828a-4fcd-9afc-2dc80491aca7")
endif()
set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)
else()
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "aa1f7df0-828a-4fcd-9afc-2dc80491aca7")
cmake_policy(VERSION 3.28)
endif()
set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)

# Default to C++ extensions being off. Libc++'s modules support have trouble
# with extensions right now.
Expand Down Expand Up @@ -74,9 +78,12 @@ target_compile_options(std.compat
-nostdinc++
-Wno-reserved-module-identifier
-Wno-reserved-user-defined-literal
-fprebuilt-module-path=${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/std.dir/
@LIBCXX_COMPILE_FLAGS@
)
set_target_properties(std.compat
PROPERTIES
OUTPUT_NAME "c++std.compat"
)
link_libraries(std.compat std)
add_dependencies(std.compat std)
125 changes: 2 additions & 123 deletions libcxx/modules/std.compat.cppm.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,17 @@ module;

// The headers of Table 24: C++ library headers [tab:headers.cpp]
// and the headers of Table 25: C++ headers for C library facilities [tab:headers.cpp.c]
#include <algorithm>
#include <any>
#include <array>
#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
# include <atomic>
#endif
#if !defined(_LIBCPP_HAS_NO_THREADS)
# include <barrier>
#endif
#include <bit>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfenv>
#include <cfloat>
#include <charconv>
#include <chrono>
#include <cinttypes>
#include <climits>
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
# include <clocale>
#endif
#include <cmath>
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
# include <codecvt>
#endif
#include <compare>
#include <complex>
#include <concepts>
#include <condition_variable>
#include <coroutine>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
Expand All @@ -65,107 +44,6 @@ module;
#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
# include <cwctype>
#endif
#include <deque>
#include <exception>
#include <execution>
#include <expected>
#include <filesystem>
#include <format>
#include <forward_list>
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
# include <fstream>
#endif
#include <functional>
#if !defined(_LIBCPP_HAS_NO_THREADS)
# include <future>
#endif
#include <initializer_list>
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
# include <iomanip>
#endif
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
# include <ios>
#endif
#include <iosfwd>
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
# include <iostream>
#endif
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
# include <istream>
#endif
#include <iterator>
#if !defined(_LIBCPP_HAS_NO_THREADS)
# include <latch>
#endif
#include <limits>
#include <list>
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
# include <locale>
#endif
#include <map>
#include <mdspan>
#include <memory>
#include <memory_resource>
#include <mutex>
#include <new>
#include <numbers>
#include <numeric>
#include <optional>
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
# include <ostream>
#endif
#include <print>
#include <queue>
#include <random>
#include <ranges>
#include <ratio>
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
# include <regex>
#endif
#include <scoped_allocator>
#if !defined(_LIBCPP_HAS_NO_THREADS)
# include <semaphore>
#endif
#include <set>
#if !defined(_LIBCPP_HAS_NO_THREADS)
# include <shared_mutex>
#endif
#include <source_location>
#include <span>
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
# include <sstream>
#endif
#include <stack>
#include <stdexcept>
#if !defined(_LIBCPP_HAS_NO_THREADS)
# include <stop_token>
#endif
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
# include <streambuf>
#endif
#include <string>
#include <string_view>
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
# include <strstream>
#endif
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
# include <syncstream>
#endif
#include <system_error>
#if !defined(_LIBCPP_HAS_NO_THREADS)
# include <thread>
#endif
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <variant>
#include <vector>
#include <version>

// *** Headers not yet available ***
#if __has_include(<debugging>)
Expand Down Expand Up @@ -203,6 +81,7 @@ module;
#endif // __has_include(<text_encoding>)

export module std.compat;
export import std;


@LIBCXX_MODULE_STD_INCLUDE_SOURCES@
@LIBCXX_MODULE_STD_COMPAT_INCLUDE_SOURCES@
1 change: 1 addition & 0 deletions libcxx/modules/std.cppm.in
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,5 @@ module;

export module std;


@LIBCXX_MODULE_STD_INCLUDE_SOURCES@
34 changes: 32 additions & 2 deletions libcxx/utils/generate_libcxx_cppm_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,35 @@


def write_file(module):

# TODO REMOVE THIS HACK, WE NEED A BETTER WAY TO DETECT C HEADERS
Module_headers = (
module_headers
if module == "std"
else [
"cassert",
"cctype",
"cerrno",
"cfenv",
"cfloat",
"cinttypes",
"climits",
"clocale",
"cmath",
"csetjmp",
"csignal",
"cstdarg",
"cstddef",
"cstdint",
"cstdio",
"cstdlib",
"cstring",
"ctime",
"cuchar",
"cwchar",
"cwctype",
]
)
libcxx_module_directory = os.path.join(
os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "modules"
)
Expand Down Expand Up @@ -44,7 +73,7 @@ def write_file(module):
// and the headers of Table 25: C++ headers for C library facilities [tab:headers.cpp.c]
"""
)
for header in module_headers:
for header in Module_headers:
if header in header_restrictions:
module_cpp_in.write(
f"""\
Expand All @@ -69,8 +98,9 @@ def write_file(module):
module_cpp_in.write(
f"""
export module {module};
{'export import std;' if module == 'std.compat' else ''}

@LIBCXX_MODULE_STD_INCLUDE_SOURCES@
{'@LIBCXX_MODULE_STD_INCLUDE_SOURCES@' if module == 'std' else ''}
{'@LIBCXX_MODULE_STD_COMPAT_INCLUDE_SOURCES@' if module == 'std.compat' else ''}"""
)

Expand Down