Files
swift-mirror/stdlib/public/Platform/glibc.modulemap.gyb
martinboehme c5b7e7fb9c Fix two issues with the SwiftGlibc module map (#32404)
* Fix two issues with the SwiftGlibc module map.

The issues are:

- Today, some submodules in `SwiftGlibc` fail to provide definitions that
  they should contain. As a consequence, Swift fails to import some code
  that compiles correctly with standalone Clang. As just one example,
  including `signal.h` should make the type `pid_t` available, but it
  currently does not.

- `SwiftGlibc` is not compatible with the libc++ module map. Trying to
  include libc++ headers in a C++ module imported into Swift results in an
  error message about cyclic dependencies.

This change fixes both of these issues by making it so that `SwiftGlibc`
no actually longer defines a module map for the glibc headers but merely makes
all of the symbols from those headers available in a module that can be
imported into Swift. C / Objective-C / C++ code, on the other hand, will now
include the glibc headers texually.

For more context on the two issues and this fix, see this forum
discussion:

https://forums.swift.org/t/problems-with-swiftglibc-and-proposed-fix/37594

This change only modifies `glibc.modulemap.gyb` for the time being but
leaves `bionic.modulemap.gyb` and `libc-openbsd.modulemap.gyb` unchanged. The
intent is to fix these in the same way, but it will be easier to do this
in separate PRs that can be tested individually.

Co-authored-by: zoecarver <z.zoelec2@gmail.com>
Co-authored-by: Marcel Hlopko <hlopko@google.com>
2021-01-11 14:25:41 +01:00

53 lines
1.6 KiB
Plaintext

//===--- glibc.modulemap.gyb ----------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
/// This is a semi-complete modulemap that maps glibc's headers in a roughly
/// similar way to the Darwin SDK modulemap. We do not take care to list every
/// single header which may be included by a particular submodule, so there can
/// still be issues if imported into the same context as one in which someone
/// included those headers directly.
///
/// It's not named just Glibc so that it doesn't conflict in the event of a
/// future official glibc modulemap.
module SwiftGlibc [system] {
% if CMAKE_SDK == "LINUX":
link "m"
% end
% if CMAKE_SDK in ["LINUX", "FREEBSD", "CYGWIN"]:
link "pthread"
// FIXME: util contains rarely used functions and not usually needed. Unfortunately
// link directive doesn't work in the submodule yet.
link "util"
% end
% if CMAKE_SDK != "FREEBSD" and CMAKE_SDK != "HAIKU":
link "dl"
% end
% if CMAKE_SDK == "HAIKU":
link "network"
link "bsd"
link "execinfo"
% end
header "SwiftGlibc.h"
export *
}
% if CMAKE_SDK != "WASI":
module CUUID [system] {
header "${GLIBC_INCLUDE_PATH}/uuid/uuid.h"
link "uuid"
export *
}
% end