I'm attempting to build a Swift project on Ubuntu 18.04 which includes mbedTLS in a C system library module.
When I attempt to build the C module, I get the following error:
declaration of 'time_t' must be imported from module 'SwiftGlibc.POSIX.sys.types' before it is required
typedef time_t mbedtls_time_t;
//usr/include/x86_64-linux-gnu/bits/types/time_t.h:7:18: note: previous declaration is here
typedef __time_t time_t;
/swift-client/Sources/Client/main.swift:4:8: error: could not build C module 'CMODULE'
So it seems like the issue3 is that
time_t is defined in both mbedTLS and also in the Swift system libraries.
How can I get around this issue?
You'll notice that the second
time_t is actually defined in the system glibc headers, which the glibc modulemap is pulling in. My guess is that you're also hitting the long-standing SR-486, which I hit last year.
A variation of the workaround mentioned by Bryan Chan there should work, try adding
/usr/include/x86_64-linux-gnu/bits/types/time_t.h to your mbedTLS modulemap, before this
platform_time.h one or it won't work, or to the
glibc.modulemap in the Swift toolchain's
lib/swift/linux/x86_64 if that doesn't work.
Thanks for the reply!
I was also able to solve this by including the sys/types header in my umbrella header:
I'm not sure if this approach has advantages or drawbacks compared to the solution you describe
OK, I assumed that all necessary headers were already included to use mbedTLS as a C library, and in my case the problem was Swift code from Foundation calling the Bionic libc headers, so there was no intermediary C header that I controlled and could edit. Anyway, Bryan Chan's original workaround in that bug report was to modify such a C header, so your fix is closer to what he suggested.