I have built the Feb 8th snapshot into /usr/local on Linux 64. I have enabled libdispatch, and it's installed to /usr/local as well. Additionally, I cherry-picked the PR https://github.com/apple/swift/pull/1212. It compiles, installs, everything's fine.
My /usr/local/include/dispatch directory has
# ls /usr/local/include/dispatch/
Dispatch.swiftdoc base.h data.h group.h io.h object.h queue.h source.h
Dispatch.swiftmodule block.h dispatch.h introspection.h module.map once.h semaphore.h time.h
Now I attempt to use Dispatch via
swift -Xcc -fblocks -L/usr/local/lib -I /usr/local/include/dispatch -lBlocksRuntime -L/usr/lib/x86_64-linux-gnu
This is because:
-Xcc -fblocks to pick up blocks support
-I /usr/local/include/dispatch to pick up /usr/local/include/dispatch/Dispatch.swiftmodule (as well as module.modulemap etc.)
-lBlocksRuntime -L/usr/lib/x86_64-linux-gnu to pick up blocks runtime
Okay. So now I import Dispatch:
Welcome to Swift version 3.0-dev (LLVM a7663bb722, Clang 4ca3c7fa28, Swift 319a912638). Type :help for assistance.
1> import Dispatch
What I find is about half the time, this works just fine. The other half the time, I hit an import error:
<module-includes>:1:10: note: in file included from <module-includes>:1:
/usr/local/include/dispatch/dispatch.h:34:10: note: in file included from /usr/local/include/dispatch/dispatch.h:34:
/usr/include/fcntl.h:67:11: note: in file included from /usr/include/fcntl.h:67:
# include <time.h>
/usr/local/include/dispatch/time.h:25:2: error: "Please #include <dispatch/dispatch.h> instead of this file directly."
#error "Please #include <dispatch/dispatch.h> instead of this file directly."
What seems to be happening here is that we interpret /usr/include/fcntl.h's #include <time.h> to be /usr/local/include/dispatch/time.h instead of /usr/include/time.h.
This behavior is puzzling to me.
I don't understand why the behavior is nondeterministic. Shouldn't an import failure be deterministic behavior? Or are we just trying imports in random order? That seems like a bad implementation.
I don't understand how to make sure fcntl's `time.h` goes to the right time.h without also losing Dispatch.swiftmodule and module.modulemap in the exchange.
Thanks in advance.