Skip to content

protect unistd.h inclusion with HAVE_UNISTD_H #339

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
Mar 2, 2018

Conversation

compnerd
Copy link
Member

This ensures that all the inclusions of unistd.h inclusion are protected
with the check that the header exists. This header is only available on
unix like environments to define the standard of compliance. This
protection is needed for other environments like Windows.

@compnerd
Copy link
Member Author

CC: @MadCoder @parkera

@compnerd
Copy link
Member Author

@swift-ci please test

@@ -35,7 +35,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <stdarg.h>
#if !defined(HAVE_UNISTD_H) || HAVE_UNISTD_H
#if HAVE_UNISTD_H
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't work in public headers sadly because HAVE_UNISTD_H is a configure option, so doing that will break unix because HAVE_UNISTD_H is not defined.

there are two options, either use __has_include() but that requires clang support for the library user which I'm not a fan of (while requiring clang to build dispatch is a thing, requiring clang to build clients is another).

However, a thing we've started to do on the darwin side is to unifdef headers that we install.

I would be more than willing to accept a patch like that if the cmake build system is able to unifdef installed headers, and when installing on windows you'd unifdef -DHAVE_UNISTD_H=0 and on unix unifdef -DHAVE_UNISTD_H=1 and done.

@@ -19,7 +19,9 @@
*/

#include <dispatch/dispatch.h>
#if HAVE_UNISTD_H
#include <unistd.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for all of these because <dispatch/dispatch.h> will do the right thing we should just remove the #include instead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typically nowadays (not merged back to github yet) Darwin does this to headers:

unifdef -U__DISPATCH_BUILDING_DISPATCH__ -U__linux__ -DTARGET_OS_WIN32=0 -U__ANDROID__

it allows to cleanup the headers from stuff that makes no sense on darwin to clean them up, I think we should do the same for various platforms to that headers for said plaforms are decluttered from stuff that makes no sense on said platform.

but we can't have '#if HAVE_*' on public/installed headers as we don't want to ship a <dispatch/config.h> (Darwin certainly doesn't so that change as is would break darwin).

Copy link
Member Author

@compnerd compnerd Feb 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, another option is to use the compiler instead. unistd.h is only available on Unix and macOS X. We could also use:

#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))

I think that adding the hooks for the unifdef should be done anyways as @das mentioned there was interest in unifying the macOS build into the CMake system as well, but I need to look into how to do that nicely (so I think that doing that a bit later would be nice).

This ensures that all the inclusions of unistd.h inclusion are protected
with the check that the header exists.  This header is only available on
unix like environments to define the standard of compliance.  This
protection is needed for other environments like Windows.
@compnerd
Copy link
Member Author

@swift-ci please test

@compnerd
Copy link
Member Author

compnerd commented Mar 1, 2018

@MadCoder okay with this? Once this is done, I'll update the other patch with more fixes :-)

@MadCoder MadCoder merged commit 9295346 into swiftlang:master Mar 2, 2018
@compnerd compnerd deleted the unistd branch March 2, 2018 01:26
ktopley-apple pushed a commit that referenced this pull request Dec 6, 2018
protect unistd.h inclusion with HAVE_UNISTD_H

Signed-off-by: Daniel A. Steffen <dsteffen@apple.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants