Skip to content

Commit 7fd946f

Browse files
committed
[cxx-interop][linux] modularize the bits part of libstdc++
Fixes #64457
1 parent 1d7288e commit 7fd946f

File tree

3 files changed

+154
-2
lines changed

3 files changed

+154
-2
lines changed

lib/ClangImporter/ClangIncludePaths.cpp

Lines changed: 121 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,9 @@ static void getLibStdCxxFileMapping(
333333

334334
auto contents = (*buf)->getBuffer();
335335
auto headerInjectionPoint = contents.find("/// additional headers");
336-
if (headerInjectionPoint == StringRef::npos) {
336+
auto bitsInjectionPoint = contents.find("/// additional bits");
337+
if (headerInjectionPoint == StringRef::npos ||
338+
bitsInjectionPoint == StringRef::npos) {
337339
fileMapping.redirectedFiles.push_back(
338340
{std::string(injectedModuleMapPath), std::string(actualModuleMapPath)});
339341
return;
@@ -357,7 +359,124 @@ static void getLibStdCxxFileMapping(
357359
};
358360
for (StringRef additionalFile : additionalFiles)
359361
includeHeaderInModuleMap(additionalFile);
360-
os << contents.substr(headerInjectionPoint);
362+
os << contents.substr(headerInjectionPoint,
363+
bitsInjectionPoint - headerInjectionPoint);
364+
365+
StringRef additionalBits[] = {"bits/algorithmfwd.h",
366+
"bits/align.h",
367+
"bits/alloc_traits.h",
368+
"bits/allocated_ptr.h",
369+
"bits/allocator.h",
370+
"bits/atomic_base.h",
371+
"bits/atomic_futex.h",
372+
"bits/atomic_lockfree_defines.h",
373+
"bits/basic_ios.h",
374+
"bits/basic_string.h",
375+
"bits/c++0x_warning.h",
376+
"bits/char_traits.h",
377+
"bits/charconv.h",
378+
"bits/codecvt.h",
379+
"bits/concept_check.h",
380+
"bits/cpp_type_traits.h",
381+
"bits/cxxabi_forced.h",
382+
"bits/cxxabi_init_exception.h",
383+
"bits/enable_special_members.h",
384+
"bits/erase_if.h",
385+
"bits/exception.h",
386+
"bits/exception_defines.h",
387+
"bits/exception_ptr.h",
388+
"bits/forward_list.h",
389+
"bits/fs_dir.h",
390+
"bits/fs_fwd.h",
391+
"bits/fs_ops.h",
392+
"bits/fs_path.h",
393+
"bits/functexcept.h",
394+
"bits/functional_hash.h",
395+
"bits/gslice.h",
396+
"bits/gslice_array.h",
397+
"bits/hash_bytes.h",
398+
"bits/hashtable.h",
399+
"bits/hashtable_policy.h",
400+
"bits/indirect_array.h",
401+
"bits/invoke.h",
402+
"bits/ios_base.h",
403+
"bits/iterator_concepts.h",
404+
"bits/locale_classes.h",
405+
"bits/locale_conv.h",
406+
"bits/locale_facets.h",
407+
"bits/locale_facets_nonio.h",
408+
"bits/localefwd.h",
409+
"bits/mask_array.h",
410+
"bits/max_size_type.h",
411+
"bits/memoryfwd.h",
412+
"bits/move.h",
413+
"bits/nested_exception.h",
414+
"bits/node_handle.h",
415+
"bits/ostream_insert.h",
416+
"bits/parse_numbers.h",
417+
"bits/postypes.h",
418+
"bits/predefined_ops.h",
419+
"bits/ptr_traits.h",
420+
"bits/quoted_string.h",
421+
"bits/random.h",
422+
"bits/range_access.h",
423+
"bits/ranges_algo.h",
424+
"bits/ranges_algobase.h",
425+
"bits/ranges_base.h",
426+
"bits/ranges_cmp.h",
427+
"bits/ranges_uninitialized.h",
428+
"bits/ranges_util.h",
429+
"bits/refwrap.h",
430+
"bits/shared_ptr.h",
431+
"bits/shared_ptr_atomic.h",
432+
"bits/shared_ptr_base.h",
433+
"bits/slice_array.h",
434+
"bits/std_abs.h",
435+
"bits/std_function.h",
436+
"bits/std_mutex.h",
437+
"bits/std_thread.h",
438+
"bits/stl_algo.h",
439+
"bits/stl_algobase.h",
440+
"bits/stl_bvector.h",
441+
"bits/stl_construct.h",
442+
"bits/stl_deque.h",
443+
"bits/stl_function.h",
444+
"bits/stl_heap.h",
445+
"bits/stl_iterator.h",
446+
"bits/stl_iterator_base_funcs.h",
447+
"bits/stl_iterator_base_types.h",
448+
"bits/stl_list.h",
449+
"bits/stl_map.h",
450+
"bits/stl_multimap.h",
451+
"bits/stl_multiset.h",
452+
"bits/stl_numeric.h",
453+
"bits/stl_pair.h",
454+
"bits/stl_queue.h",
455+
"bits/stl_raw_storage_iter.h",
456+
"bits/stl_relops.h",
457+
"bits/stl_set.h",
458+
"bits/stl_stack.h",
459+
"bits/stl_tempbuf.h",
460+
"bits/stl_tree.h",
461+
"bits/stl_uninitialized.h",
462+
"bits/stl_vector.h",
463+
"bits/stream_iterator.h",
464+
"bits/streambuf_iterator.h",
465+
"bits/stringfwd.h",
466+
"bits/this_thread_sleep.h",
467+
"bits/uniform_int_dist.h",
468+
"bits/unique_lock.h",
469+
"bits/unique_ptr.h",
470+
"bits/unordered_map.h",
471+
"bits/unordered_set.h",
472+
"bits/uses_allocator.h",
473+
"bits/uses_allocator_args.h",
474+
"bits/valarray_after.h",
475+
"bits/valarray_array.h",
476+
"bits/valarray_before.h"};
477+
for (StringRef additionalFile : additionalBits)
478+
includeHeaderInModuleMap(additionalFile);
479+
os << contents.substr(bitsInjectionPoint);
361480

362481
fileMapping.overridenFiles.push_back(
363482
{std::string(injectedModuleMapPath), std::move(os.str())});

stdlib/public/Cxx/libstdcxx/libstdcxx.modulemap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ module std {
7272
header "unordered_set"
7373
/// additional headers.
7474

75+
module bits {
76+
/// additional bits.
77+
78+
export *
79+
}
80+
7581
requires cplusplus
7682
export *
7783

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %s -c -enable-experimental-cxx-interop -Xcc -std=c++14 -Xcc -fmodules-cache-path=%t
3+
// RUN: %target-swift-frontend %s -c -enable-experimental-cxx-interop -Xcc -std=c++17 -Xcc -fmodules-cache-path=%t
4+
// RUN: %target-swift-frontend %s -c -enable-experimental-cxx-interop -Xcc -std=c++20 -Xcc -fmodules-cache-path=%t
5+
6+
// RUN: find %t | %FileCheck %s
7+
8+
// RUN: %empty-directory(%t)
9+
10+
// RUN: %target-swift-frontend %s -c -enable-experimental-cxx-interop -Xcc -std=c++17 -Xcc -fmodules-cache-path=%t -DADD_CXXSTDLIB
11+
// RUN: %target-swift-frontend %s -c -enable-experimental-cxx-interop -Xcc -std=c++20 -Xcc -fmodules-cache-path=%t -DADD_CXXSTDLIB
12+
13+
// REQUIRES: OS=macosx || OS=linux-gnu
14+
15+
import Foundation
16+
17+
#if ADD_CXXSTDLIB
18+
import CxxStdlib
19+
#endif
20+
21+
func test() {
22+
#if ADD_CXXSTDLIB
23+
let _ = std.string()
24+
#endif
25+
}
26+
27+
// CHECK: std-{{.*}}.pcm

0 commit comments

Comments
 (0)