Permalink
Browse files

use umbrella headers for C modules (#636)

Motivation:

SwiftPM only generates fully usable clang modules for C modules if they
have umbrella headers. Therefore, adding a generated NIO.xcodeproj to
another Xcode project as a sub-project never worked.
To make a header an umbrella header you need to name them _exactly_ like
the module.

Modifications:

give each C module an umbrella header

Result:

generated NIO Xcode projects can be used as sub-projects.
  • Loading branch information...
weissi authored and Lukasa committed Oct 19, 2018
1 parent ed28803 commit 9bae007a15b49d7fe685b6b33308822c6d0536c0
@@ -15,6 +15,8 @@
#include <stdbool.h>
#include <stdint.h>
#include "cpp_magic.h"
#if __clang_major__ == 3 && __clang_minor__ <= 6
/* clang 3.6 doesn't seem to know about _Nonnull yet */
#define _Nonnull __attribute__((nonnull))
@@ -18,7 +18,7 @@
#include <inttypes.h>
#include <stdio.h>
#include "../include/c-atomics.h"
#include "../include/CNIOAtomics.h"
#include "../include/cpp_magic.h"
struct catmc_atomic_flag {
@@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
#ifdef __APPLE__
#include <c_nio_darwin.h>
#include <CNIODarwin.h>
#include <err.h>
#include <sysexits.h>
#include <stdlib.h>
@@ -14,6 +14,8 @@
#ifndef C_NIO_LINUX_H
#define C_NIO_LINUX_H
#include "ifaddrs-android.h"
#ifdef __linux__
#include <sys/epoll.h>
#include <sys/eventfd.h>
@@ -22,11 +24,7 @@
#include <sys/socket.h>
#include <sched.h>
#include <errno.h>
#ifdef __ANDROID__
#include <pthread.h>
#include "ifaddrs-android.h"
#endif
// Some explanation is required here.
//
@@ -48,10 +48,12 @@ struct ifaddrs {
unsigned int ifa_flags;
struct sockaddr* ifa_addr;
struct sockaddr* ifa_netmask;
union {
struct sockaddr *ifu_broadaddr;
struct sockaddr *ifu_dstaddr;
} ifa_ifu;
union {
struct sockaddr *ifu_broadaddr;
struct sockaddr *ifu_dstaddr;
} ifa_ifu;
/* Real ifaddrs has broadcast, point to point and data members.
* We don't need them (yet?). */
};
int android_getifaddrs(struct ifaddrs** result);
@@ -14,7 +14,7 @@
#ifdef __linux__
#define _GNU_SOURCE
#include <c_nio_linux.h>
#include <CNIOLinux.h>
#include <pthread.h>
#include <sched.h>
#include <stdio.h>
@@ -4,6 +4,7 @@
- removed the _KERNEL include guards
- defined the __min_size macro inline
- included sys/types.h in c_nio_sha1.h
- included sys/endian.h on Android
*/
/* $KAME: sha1.c,v 1.5 2000/11/08 06:13:08 itojun Exp $ */
/*-
@@ -51,7 +52,7 @@
#include <sys/time.h>
#include <strings.h>
#include "include/c_nio_sha1.h"
#include "include/CNIOSHA1.h"
/* sanity check */
#if BYTE_ORDER != BIG_ENDIAN
@@ -4,6 +4,7 @@
- removed the _KERNEL include guards
- defined the __min_size macro inline
- included sys/types.h in c_nio_sha1.h
- included sys/endian.h on Android
*/
/* $FreeBSD$ */
/* $KAME: sha1.h,v 1.5 2000/03/27 04:36:23 sumikawa Exp $ */
@@ -47,7 +48,6 @@
#ifndef _CRYPTO_SHA1_H_
#define _CRYPTO_SHA1_H_
#include <sys/types.h>
#ifdef __ANDROID__
#include <sys/endian.h>
#endif
@@ -33,6 +33,7 @@ for f in sha1.c sha1.h; do
echo " - removed the _KERNEL include guards"
echo " - defined the __min_size macro inline"
echo " - included sys/types.h in c_nio_sha1.h"
echo " - included sys/endian.h on Android"
echo "*/"
curl -Ls "https://raw.githubusercontent.com/freebsd/freebsd/master/sys/crypto/$f"
) > "$here/c_nio_$f"
@@ -41,16 +42,17 @@ for f in sha1.c sha1.h; do
"$sed" -i \
-e "s/$func/c_nio_$func/g" \
-e 's#<sys/systm.h>#<strings.h>#g' \
-e 's#<crypto/sha1.h>#"include/c_nio_sha1.h"#g' \
-e 's#<crypto/sha1.h>#"include/CNIOSHA1.h"#g' \
-e 's%#ifdef _KERNEL%#define __min_size(x) static (x)%g' \
-e 's%#endif /\* _KERNEL \*/%%g' \
-e 's%__FBSDID("$FreeBSD$");%%g' \
"$here/c_nio_$f"
done
done
gsed -i $'/#define _CRYPTO_SHA1_H_/a #ifdef __ANDROID__\\\n#include <sys/endian.h>\\\n#endif' "$here/c_nio_sha1.h"
gsed -i '/#define _CRYPTO_SHA1_H_/a #include <sys/types.h>' "$here/c_nio_sha1.h"
mv "$here/c_nio_sha1.h" "$here/include/c_nio_sha1.h"
mv "$here/c_nio_sha1.h" "$here/include/CNIOSHA1.h"
tmp=$(mktemp -d /tmp/.test_compile_XXXXXX)
@@ -38,7 +38,7 @@ for language in swift-or-c bash dtrace; do
matching_files=( -name '*' )
case "$language" in
swift-or-c)
exceptions=( -name c_nio_http_parser.c -o -name c_nio_http_parser.h -o -name cpp_magic.h -o -name Package.swift -o -name c_nio_sha1.h -o -name c_nio_sha1.c -o -name ifaddrs-android.c -o -name ifaddrs-android.h)
exceptions=( -name c_nio_http_parser.c -o -name c_nio_http_parser.h -o -name cpp_magic.h -o -name Package.swift -o -name CNIOSHA1.h -o -name c_nio_sha1.c -o -name ifaddrs-android.c -o -name ifaddrs-android.h)
matching_files=( -name '*.swift' -o -name '*.c' -o -name '*.h' )
cat > "$tmp" <<"EOF"
//===----------------------------------------------------------------------===//

0 comments on commit 9bae007

Please sign in to comment.