0

I'm having multiple Swift Packages which produce cross-platform libraries (iOS, macOS).

I'm trying to build those packages (as a part of CI), and got the following observation:

When running swift build:

swift build
[1/1] Build complete!

Then, when specifying iOS Simulator specifcially:

xcodebuild -showsdks                 

iOS SDKs:
    iOS 15.0                        -sdk iphoneos15.0

iOS Simulator SDKs:
    Simulator - iOS 15.0            -sdk iphonesimulator15.0

macOS SDKs:
    macOS 12.0                      -sdk macosx12.0


swift build --sdk iphonesimulator15.0
clang: warning: no such sysroot directory: '/Users/louis/Code/json/iphonesimulator15.0' [-Wmissing-sysroot]
In file included from /Users/louis/Code/json/_SwiftPackageManagerFile.cpp:5:
In file included from /Users/louis/Code/json/single_include/nlohmann/json.hpp:37:
In file included from /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:641:
In file included from /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstring:60:
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string.h:60:15: fatal error: 'string.h' file not found
#include_next <string.h>

And getting exactly the same error when I try a different SDK, e.g.: swift build --sdk macosx12.0

How can swift build succeed, but whenever I specify an SDK it fails? What is the default SDK?

Note: the packages I'm working with are C++ packages.

Richard Topchii
  • 7,075
  • 8
  • 48
  • 115
  • 1
    What version of xcode-select is running on the machine? – Jake Jul 29 '21 at 12:10
  • Both, Xcode 12.5.1 12E507 and Xcode 13.0 13A5201i and both of them give the same result as shown in my question. – Richard Topchii Jul 30 '21 at 08:24
  • Do you have a `CMAKE_SYSROOT` in your bash profile? I am seeing similar errors that people post in the c++ space – Jake Jul 30 '21 at 09:19
  • No, I don't have that variable set. What should I set it to? I'm using a standard macOS with the latest Xcode. – Richard Topchii Jul 30 '21 at 10:41
  • You know... I'm not sure, I haven't done anything with C++ But I see similar errors and answers like this one here https://stackoverflow.com/a/63188875/9333764 – Jake Jul 30 '21 at 11:05

2 Answers2

1

Try this flag.

swift build -v 

-v, --verbose Increase verbosity of informational output

It prints the following string on my machine: enter image description here

and lots of additional info)

Gopito
  • 61
  • 6
  • Thanks, but why the output and the result differ so drastically when running `swift build` (succeeds) and `swift build --sdk macosx` (fails with the string error mentioned in the question)? – Richard Topchii Jul 30 '21 at 08:20
0

This worked:

swift build -Xswiftc "-sdk" -Xswiftc "$(xcrun --sdk iphonesimulator --show-sdk-path)" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios14.0-simulator"
Richard Topchii
  • 7,075
  • 8
  • 48
  • 115