From 5eb29d99dd3e3944da43b29c0eafb8608202ddba
Date: Tue, 11 May 2021 01:10:50 +0530
Subject: [PATCH] [android] Switch to new single-header modulemap for Bionic
 too

---
 stdlib/public/Platform/CMakeLists.txt         |   4 +-
 stdlib/public/Platform/SwiftGlibc.h.gyb       |   1 -
 stdlib/public/Platform/bionic.modulemap.gyb   | 393 ------------------
 stdlib/public/Platform/glibc.modulemap.gyb    |   4 +-
 stdlib/public/SwiftShims/LibcShims.h          |   2 +-
 test/Interop/C/libc/include-signal.swift      |   4 +-
 .../Cxx/class/memory-layout-silgen.swift      |   3 -
 test/Interop/Cxx/libc/include-glibc.swift     |   2 +-
 8 files changed, 7 insertions(+), 406 deletions(-)
 delete mode 100644 stdlib/public/Platform/bionic.modulemap.gyb

diff --git a/swift/stdlib/public/Platform/CMakeLists.txt b/swift/stdlib/public/Platform/CMakeLists.txt
index 9d6fccd4082ca..6ae5209186fd3 100644
--- a/swift/stdlib/public/Platform/CMakeLists.txt
+++ b/swift/stdlib/public/Platform/CMakeLists.txt
@@ -130,9 +130,7 @@ foreach(sdk ${SWIFT_SDKS})
     set(module_dir "${SWIFTLIB_DIR}/${arch_subdir}")
     set(module_dir_static "${SWIFTSTATICLIB_DIR}/${arch_subdir}")
 
-    if(${sdk} STREQUAL ANDROID)
-      set(glibc_modulemap_source "bionic.modulemap.gyb")
-    elseif(${sdk} STREQUAL OPENBSD)
+    if(${sdk} STREQUAL OPENBSD)
       set(glibc_modulemap_source "libc-openbsd.modulemap.gyb")
     else()
       set(glibc_modulemap_source "glibc.modulemap.gyb")
diff --git a/swift/stdlib/public/Platform/SwiftGlibc.h.gyb b/swift/stdlib/public/Platform/SwiftGlibc.h.gyb
index 3391eaee29934..78c725bae8c73 100644
--- a/swift/stdlib/public/Platform/SwiftGlibc.h.gyb
+++ b/swift/stdlib/public/Platform/SwiftGlibc.h.gyb
@@ -28,7 +28,6 @@ headers = [
   'tgmath.h',
   'time.h',
   'utmp.h',
-  'utmpx.h',
 
   # POSIX
   'aio.h',
diff --git a/swift/stdlib/public/Platform/bionic.modulemap.gyb b/swift/stdlib/public/Platform/bionic.modulemap.gyb
deleted file mode 100644
index e44f9082653a6..0000000000000
--- a/swift/stdlib/public/Platform/bionic.modulemap.gyb
+++ /dev/null
@@ -1,393 +0,0 @@
-//===--- bionic.modulemap -------------------------------------------------===//
-//
-// 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 bionics'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 Bionic so that it doesn't conflict in the event of a
-/// future official bionic modulemap.
-module SwiftGlibc [system] {
-
-  link "dl"
-
-  // C standard library
-  module C {
-    module features {
-      header "${GLIBC_INCLUDE_PATH}/features.h"
-      export *
-    }
-
-    module complex {
-      header "${GLIBC_INCLUDE_PATH}/complex.h"
-      export *
-    }
-
-    module pty {
-      header "${GLIBC_INCLUDE_PATH}/pty.h"
-      export *
-    }
-    module utmp {
-      header "${GLIBC_INCLUDE_PATH}/utmp.h"
-      export *
-    }
-
-    module ctype {
-      header "${GLIBC_INCLUDE_PATH}/ctype.h"
-      export *
-    }
-    module errno {
-      header "${GLIBC_INCLUDE_PATH}/errno.h"
-      export *
-    }
-
-    module fenv {
-      header "${GLIBC_INCLUDE_PATH}/fenv.h"
-      export *
-    }
-
-    // note: supplied by compiler
-    // module float {
-    //   header "${GLIBC_INCLUDE_PATH}/float.h"
-    //   export *
-    // }
-
-    module inttypes {
-      header "${GLIBC_INCLUDE_PATH}/inttypes.h"
-      export *
-    }
-
-    // note: potentially supplied by compiler
-    // module iso646 {
-    //   header "${GLIBC_INCLUDE_PATH}/iso646.h"
-    //   export *
-    // }
-    // module limits {
-    //   header "${GLIBC_INCLUDE_PATH}/limits.h"
-    //   export *
-    // }
-
-    module locale {
-      header "${GLIBC_INCLUDE_PATH}/locale.h"
-      export *
-    }
-    module math {
-      link "m"
-      header "${GLIBC_INCLUDE_PATH}/math.h"
-      export *
-    }
-    module setjmp {
-      header "${GLIBC_INCLUDE_PATH}/setjmp.h"
-      export *
-    }
-    module signal {
-      header "${GLIBC_INCLUDE_PATH}/signal.h"
-      export *
-    }
-
-    // note: supplied by the compiler
-    // module stdarg {
-    //   header "${GLIBC_INCLUDE_PATH}/stdarg.h"
-    //   export *
-    // }
-    // module stdbool {
-    //   header "${GLIBC_INCLUDE_PATH}/stdbool.h"
-    //   export *
-    // }
-    // module stddef {
-    //   header "${GLIBC_INCLUDE_PATH}/stddef.h"
-    //   export *
-    // }
-    // module stdint {
-    //   header "${GLIBC_INCLUDE_PATH}/stdint.h"
-    //   export *
-    // }
-
-    module stdio {
-      header "${GLIBC_INCLUDE_PATH}/stdio.h"
-      export *
-    }
-    module stdlib {
-      header "${GLIBC_INCLUDE_PATH}/stdlib.h"
-      export *
-      export stddef
-    }
-    module string {
-      header "${GLIBC_INCLUDE_PATH}/string.h"
-      export *
-    }
-
-    // note: supplied by the compiler
-    // explicit module tgmath {
-    //   header "${GLIBC_INCLUDE_PATH}/tgmath.h"
-    //   export *
-    // }
-
-    module time {
-      header "${GLIBC_INCLUDE_PATH}/time.h"
-      export *
-    }
-  }
-
-  // POSIX
-  module POSIX {
-    module wait {
-      header "${GLIBC_INCLUDE_PATH}/wait.h"
-      export *
-    }
-
-    module cpio {
-      header "${GLIBC_INCLUDE_PATH}/cpio.h"
-      export *
-    }
-    module nl_types {
-      header "${GLIBC_INCLUDE_PATH}/nl_types.h"
-      export *
-    }
-
-    module ftw {
-      header "${GLIBC_INCLUDE_PATH}/ftw.h"
-      export *
-    }
-    module glob {
-      header "${GLIBC_INCLUDE_PATH}/glob.h"
-      export *
-    }
-    module iconv {
-      header "${GLIBC_INCLUDE_PATH}/iconv.h"
-      export *
-    }
-    module langinfo {
-      header "${GLIBC_INCLUDE_PATH}/langinfo.h"
-      export *
-    }
-    module netdb {
-      header "${GLIBC_INCLUDE_PATH}/netdb.h"
-      export *
-    }
-    module ifaddrs {
-      header "${GLIBC_INCLUDE_PATH}/ifaddrs.h"
-      export *
-    }
-    module search {
-      header "${GLIBC_INCLUDE_PATH}/search.h"
-      export *
-    }
-    module spawn {
-      header "${GLIBC_INCLUDE_PATH}/spawn.h"
-      export *
-    }
-    module syslog {
-      header "${GLIBC_INCLUDE_PATH}/syslog.h"
-      export *
-    }
-    module tar {
-      header "${GLIBC_INCLUDE_PATH}/tar.h"
-      export *
-    }
-
-    module arpa {
-      module inet {
-        header "${GLIBC_INCLUDE_PATH}/arpa/inet.h"
-        export *
-      }
-      export *
-    }
-    module dirent {
-      header "${GLIBC_INCLUDE_PATH}/dirent.h"
-      export *
-    }
-    module dlfcn {
-      header "${GLIBC_INCLUDE_PATH}/dlfcn.h"
-      export *
-    }
-    module fcntl {
-      header "${GLIBC_INCLUDE_PATH}/fcntl.h"
-      export *
-    }
-    module fnmatch {
-      header "${GLIBC_INCLUDE_PATH}/fnmatch.h"
-      export *
-    }
-    module grp {
-      header "${GLIBC_INCLUDE_PATH}/grp.h"
-      export *
-    }
-    module ioctl {
-      header "${GLIBC_ARCH_INCLUDE_PATH}/sys/ioctl.h"
-      export *
-    }
-    module libgen {
-      header "${GLIBC_INCLUDE_PATH}/libgen.h"
-      export *
-    }
-    module net {
-      module if {
-        header "${GLIBC_INCLUDE_PATH}/net/if.h"
-        export *
-      }
-    }
-    module netinet {
-      module in {
-        header "${GLIBC_INCLUDE_PATH}/netinet/in.h"
-        export *
-
-        exclude header "${GLIBC_INCLUDE_PATH}/netinet6/in6.h"
-      }
-      module tcp {
-        header "${GLIBC_INCLUDE_PATH}/netinet/tcp.h"
-        export *
-      }
-    }
-    module poll {
-      header "${GLIBC_INCLUDE_PATH}/poll.h"
-      export *
-    }
-    module pthread {
-      header "${GLIBC_INCLUDE_PATH}/pthread.h"
-      export *
-    }
-    module pwd {
-      header "${GLIBC_INCLUDE_PATH}/pwd.h"
-      export *
-    }
-    module regex {
-      header "${GLIBC_INCLUDE_PATH}/regex.h"
-      export *
-    }
-    module sched {
-      header "${GLIBC_INCLUDE_PATH}/sched.h"
-      export *
-    }
-    module semaphore {
-      header "${GLIBC_INCLUDE_PATH}/semaphore.h"
-      export *
-    }
-    module strings {
-      header "${GLIBC_INCLUDE_PATH}/strings.h"
-      export *
-    }
-
-    module sys {
-      export *
-
-      module cdefs {
-        header "${GLIBC_ARCH_INCLUDE_PATH}/sys/cdefs.h"
-        export *
-      }
-      module file {
-        header "${GLIBC_ARCH_INCLUDE_PATH}/sys/file.h"
-        export *
-      }
-      module sem {
-        header "${GLIBC_ARCH_INCLUDE_PATH}/sys/sem.h"
-        export *
-      }
-      module shm {
-        header "${GLIBC_ARCH_INCLUDE_PATH}/sys/shm.h"
-        export *
-      }
-      module inotify {
-        header "${GLIBC_ARCH_INCLUDE_PATH}/sys/inotify.h"
-        export *
-      }
-      module statvfs {
-        header "${GLIBC_ARCH_INCLUDE_PATH}/sys/statvfs.h"
-        export *
-      }
-
-      module ipc {
-        header "${GLIBC_ARCH_INCLUDE_PATH}/sys/ipc.h"
-        export *
-      }
-      module mman {
-        header "${GLIBC_ARCH_INCLUDE_PATH}/sys/mman.h"
-        export *
-      }
-      module msg {
-        header "${GLIBC_ARCH_INCLUDE_PATH}/sys/msg.h"
-        export *
-      }
-      module resource {
-        header "${GLIBC_ARCH_INCLUDE_PATH}/sys/resource.h"
-        export *
-      }
-      module select {
-        header "${GLIBC_ARCH_INCLUDE_PATH}/sys/select.h"
-        export *
-      }
-      module sendfile {
-        header "${GLIBC_ARCH_INCLUDE_PATH}/sys/sendfile.h"
-        export *
-      }
-      module socket {
-        header "${GLIBC_ARCH_INCLUDE_PATH}/sys/socket.h"
-        export *
-      }
-      module stat {
-        header "${GLIBC_ARCH_INCLUDE_PATH}/sys/stat.h"
-        export *
-      }
-      module time {
-        header "${GLIBC_ARCH_INCLUDE_PATH}/sys/time.h"
-        export *
-      }
-      module times {
-        header "${GLIBC_ARCH_INCLUDE_PATH}/sys/times.h"
-        export *
-      }
-      module types {
-        header "${GLIBC_ARCH_INCLUDE_PATH}/sys/types.h"
-        export *
-      }
-      module uio {
-        header "${GLIBC_ARCH_INCLUDE_PATH}/sys/uio.h"
-        export *
-      }
-      module un {
-        header "${GLIBC_ARCH_INCLUDE_PATH}/sys/un.h"
-        export *
-      }
-      module user {
-        header "${GLIBC_ARCH_INCLUDE_PATH}/sys/user.h"
-        export *
-      }
-      module utsname {
-        header "${GLIBC_ARCH_INCLUDE_PATH}/sys/utsname.h"
-        export *
-      }
-      module wait {
-        header "${GLIBC_ARCH_INCLUDE_PATH}/sys/wait.h"
-        export *
-      }
-    }
-    module sysexits {
-      header "${GLIBC_INCLUDE_PATH}/sysexits.h"
-      export *
-    }
-    module termios {
-      header "${GLIBC_INCLUDE_PATH}/termios.h"
-      export *
-    }
-    module unistd {
-      header "${GLIBC_INCLUDE_PATH}/unistd.h"
-      export *
-    }
-    module utime {
-      header "${GLIBC_INCLUDE_PATH}/utime.h"
-      export *
-    }
-  }
-}
-
diff --git a/swift/stdlib/public/Platform/glibc.modulemap.gyb b/swift/stdlib/public/Platform/glibc.modulemap.gyb
index 455dd111e2ce3..8f77e1028001c 100644
--- a/swift/stdlib/public/Platform/glibc.modulemap.gyb
+++ b/swift/stdlib/public/Platform/glibc.modulemap.gyb
@@ -19,7 +19,7 @@
 /// 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":
+% if CMAKE_SDK in ["LINUX", "ANDROID"]:
       link "m"
 % end
 % if CMAKE_SDK in ["LINUX", "FREEBSD", "CYGWIN"]:
@@ -43,7 +43,7 @@ module SwiftGlibc [system] {
   export *
 }
 
-% if CMAKE_SDK != "WASI":
+% if CMAKE_SDK != "WASI" and CMAKE_SDK != "ANDROID":
 module CUUID [system] {
   header "${GLIBC_INCLUDE_PATH}/uuid/uuid.h"
   link "uuid"
diff --git a/swift/stdlib/public/SwiftShims/LibcShims.h b/swift/stdlib/public/SwiftShims/LibcShims.h
index 7dfde65ae46a8..82a43efa06e10 100644
--- a/swift/stdlib/public/SwiftShims/LibcShims.h
+++ b/swift/stdlib/public/SwiftShims/LibcShims.h
@@ -68,7 +68,7 @@ static inline __swift_size_t _swift_stdlib_strlen_unsigned(const unsigned char *
 SWIFT_READONLY
 static inline int _swift_stdlib_memcmp(const void *s1, const void *s2,
                                        __swift_size_t n) {
-#if defined(__APPLE__)
+#if defined(__APPLE__) || defined(__ANDROID__)
   extern int memcmp(const void * _Nullable, const void * _Nullable, __swift_size_t);
 #else
   extern int memcmp(const void *, const void *, __swift_size_t);
diff --git a/swift/test/Interop/C/libc/include-signal.swift b/swift/test/Interop/C/libc/include-signal.swift
index 3b420364f3ce8..83029c9b3b530 100644
--- a/swift/test/Interop/C/libc/include-signal.swift
+++ b/swift/test/Interop/C/libc/include-signal.swift
@@ -28,6 +28,6 @@
 // See https://forums.swift.org/t/problems-with-swiftglibc-and-proposed-fix/37594
 // for further details.
 
-// REQUIRES: OS=linux-gnu
+// REQUIRES: OS=linux-gnu || OS=linux-android
 
-import IncludeSignal
\ No newline at end of file
+import IncludeSignal
diff --git a/swift/test/Interop/Cxx/class/memory-layout-silgen.swift b/swift/test/Interop/Cxx/class/memory-layout-silgen.swift
index a0301a03af7f3..35d3f2797ad32 100644
--- a/swift/test/Interop/Cxx/class/memory-layout-silgen.swift
+++ b/swift/test/Interop/Cxx/class/memory-layout-silgen.swift
@@ -1,8 +1,5 @@
 // RUN: %target-swiftxx-frontend -I %S/Inputs -emit-ir -o - %s | %FileCheck %s
 
-// XFAIL: OS=linux-android
-// XFAIL: OS=linux-androideabi
-
 import MemoryLayout
 
 var v = PrivateMemberLayout()
diff --git a/swift/test/Interop/Cxx/libc/include-glibc.swift b/swift/test/Interop/Cxx/libc/include-glibc.swift
index 116dc88895783..b36e7379d22b0 100644
--- a/swift/test/Interop/Cxx/libc/include-glibc.swift
+++ b/swift/test/Interop/Cxx/libc/include-glibc.swift
@@ -1,7 +1,7 @@
 // RUN: %target-run-simple-swift(-Xfrontend -enable-cxx-interop)
 
 // REQUIRES: executable_test
-// REQUIRES: OS=linux-gnu
+// REQUIRES: OS=linux-gnu || OS=linux-android
 
 import Glibc
 import StdlibUnittest