Skip to content

[cxx-interop][linux] modularize the bits part of libstdc++ #67596

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

Merged
merged 1 commit into from
Jul 29, 2023
Merged
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
42 changes: 41 additions & 1 deletion lib/ClangImporter/ClangIncludePaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,47 @@ static void getLibStdCxxFileMapping(
"codecvt",
// C++17 and newer:
"any", "charconv", "filesystem", "memory_resource", "optional",
"string_view", "variant"};
"string_view", "variant", "bits/algorithmfwd.h", "bits/align.h",
"bits/alloc_traits.h", "bits/allocated_ptr.h", "bits/allocator.h",
"bits/atomic_base.h", "bits/atomic_futex.h",
"bits/atomic_lockfree_defines.h", "bits/basic_ios.h",
"bits/basic_string.h", "bits/c++0x_warning.h", "bits/char_traits.h",
"bits/charconv.h", "bits/codecvt.h", "bits/concept_check.h",
"bits/cpp_type_traits.h", "bits/cxxabi_forced.h",
"bits/cxxabi_init_exception.h", "bits/enable_special_members.h",
"bits/erase_if.h", "bits/exception.h", "bits/exception_defines.h",
"bits/exception_ptr.h", "bits/forward_list.h", "bits/fs_dir.h",
"bits/fs_fwd.h", "bits/fs_ops.h", "bits/fs_path.h", "bits/functexcept.h",
"bits/functional_hash.h", "bits/gslice.h", "bits/gslice_array.h",
"bits/hash_bytes.h", "bits/hashtable.h", "bits/hashtable_policy.h",
"bits/indirect_array.h", "bits/invoke.h", "bits/ios_base.h",
"bits/iterator_concepts.h", "bits/locale_classes.h", "bits/locale_conv.h",
"bits/locale_facets.h", "bits/locale_facets_nonio.h", "bits/localefwd.h",
"bits/mask_array.h", "bits/max_size_type.h", "bits/memoryfwd.h",
"bits/move.h", "bits/nested_exception.h", "bits/node_handle.h",
"bits/ostream_insert.h", "bits/parse_numbers.h", "bits/postypes.h",
"bits/predefined_ops.h", "bits/ptr_traits.h", "bits/quoted_string.h",
"bits/random.h", "bits/range_access.h", "bits/ranges_algo.h",
"bits/ranges_algobase.h", "bits/ranges_base.h", "bits/ranges_cmp.h",
"bits/ranges_uninitialized.h", "bits/ranges_util.h", "bits/refwrap.h",
"bits/shared_ptr.h", "bits/shared_ptr_atomic.h", "bits/shared_ptr_base.h",
"bits/slice_array.h", "bits/std_abs.h", "bits/std_function.h",
"bits/std_mutex.h", "bits/std_thread.h", "bits/stl_algo.h",
"bits/stl_algobase.h", "bits/stl_bvector.h", "bits/stl_construct.h",
"bits/stl_deque.h", "bits/stl_function.h", "bits/stl_heap.h",
"bits/stl_iterator.h", "bits/stl_iterator_base_funcs.h",
"bits/stl_iterator_base_types.h", "bits/stl_list.h", "bits/stl_map.h",
"bits/stl_multimap.h", "bits/stl_multiset.h", "bits/stl_numeric.h",
"bits/stl_pair.h", "bits/stl_queue.h", "bits/stl_raw_storage_iter.h",
"bits/stl_relops.h", "bits/stl_set.h", "bits/stl_stack.h",
"bits/stl_tempbuf.h", "bits/stl_tree.h", "bits/stl_uninitialized.h",
"bits/stl_vector.h", "bits/stream_iterator.h",
"bits/streambuf_iterator.h", "bits/stringfwd.h",
"bits/this_thread_sleep.h", "bits/uniform_int_dist.h",
"bits/unique_lock.h", "bits/unique_ptr.h", "bits/unordered_map.h",
"bits/unordered_set.h", "bits/uses_allocator.h",
"bits/uses_allocator_args.h", "bits/valarray_after.h",
"bits/valarray_array.h", "bits/valarray_before.h"};
std::string additionalHeaderDirectives;
llvm::raw_string_ostream os(additionalHeaderDirectives);
os << contents.substr(0, headerInjectionPoint);
Expand Down
6 changes: 6 additions & 0 deletions stdlib/public/Cxx/libstdcxx/libstdcxx.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,11 @@ module std {
requires cplusplus
export *
}

module cstdlib {
header "cstdlib"
requires cplusplus
export *
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
#define TEST_INTEROP_CXX_FOREIGN_REFERENCE_INPUTS_REFERENCE_COUNTED_H

#include <stdlib.h>
#include <new>

#include "visibility.h"

inline void *operator new(size_t, void *p) { return p; }

SWIFT_BEGIN_NULLABILITY_ANNOTATIONS

static int finalLocalRefCount = 100;
Expand Down
29 changes: 29 additions & 0 deletions test/Interop/Cxx/stdlib/foundation-and-std-module.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -c -enable-experimental-cxx-interop -Xcc -std=c++14 -Xcc -fmodules-cache-path=%t
// RUN: %target-swift-frontend %s -c -enable-experimental-cxx-interop -Xcc -std=c++17 -Xcc -fmodules-cache-path=%t
// RUN: %target-swift-frontend %s -c -enable-experimental-cxx-interop -Xcc -std=c++20 -Xcc -fmodules-cache-path=%t

// RUN: find %t | %FileCheck %s

// RUN: %empty-directory(%t)

// RUN: %target-swift-frontend %s -c -enable-experimental-cxx-interop -Xcc -std=c++17 -Xcc -fmodules-cache-path=%t -DADD_CXXSTDLIB
// RUN: %target-swift-frontend %s -c -enable-experimental-cxx-interop -Xcc -std=c++20 -Xcc -fmodules-cache-path=%t -DADD_CXXSTDLIB

// REQUIRES: OS=macosx || OS=linux-gnu

#if canImport(Foundation)
import Foundation
#endif

#if ADD_CXXSTDLIB
import CxxStdlib
#endif

func test() {
#if ADD_CXXSTDLIB
let _ = std.string()
#endif
}

// CHECK: std-{{.*}}.pcm