mike-neckのブログ

JavaかJavaFXかJavaEE(なんかJava8が多め)

Swift Package Manager が Objectiv-C module 'Darwin' をビルドできなかったときの対策

Swift Package Manager が不調(?)で、 swift package generate-xcodeproj すると、コケる

【2018/08/05 22:27 追記】この方法は正しくない。正しい対処の仕方は不明。

$ swift --version
Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2)
Target: x86_64-apple-darwin17.7.0

$ swift package generate-xcodeproj
/Users/mike/swift-projects/http-client/HTTP-CLIENT: error: manifest parse error(s):
<module-includes>:5:9: note: in file included from <module-includes>:5:
#import "copyfile.h"
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/copyfile.h:41:9: error: unknown type name 'uint32_t'
typedef uint32_t copyfile_flags_t;
        ^
<module-includes>:5:9: note: in file included from <module-includes>:5:
#import "copyfile.h"
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/copyfile.h:62:44: error: unknown type name 'uint32_t'
int copyfile_state_get(copyfile_state_t s, uint32_t flag, void * dst);
                                           ^
<module-includes>:5:9: note: in file included from <module-includes>:5:
#import "copyfile.h"
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/copyfile.h:63:44: error: unknown type name 'uint32_t'
int copyfile_state_set(copyfile_state_t s, uint32_t flag, const void * src);
                                           ^
<unknown>:0: error: could not build Objective-C module 'Darwin'

仕方ないので、 /usr/bin/swift ではなく、 /Applications/... の方の swift で実行する

$ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift --version
Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2)
Target: x86_64-apple-darwin17.7.0

$ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift package generate-xcodeproj
Fetching https://github.com/apple/swift-nio.git
Fetching https://github.com/apple/swift-nio-zlib-support.git
Cloning https://github.com/apple/swift-nio.git
Resolving https://github.com/apple/swift-nio.git at 1.8.0
Cloning https://github.com/apple/swift-nio-zlib-support.git
Resolving https://github.com/apple/swift-nio-zlib-support.git at 1.0.0
generated: ./HTTP-CLIENT.xcodeproj

なぜか、実行できる…