gradle-native icon indicating copy to clipboard operation
gradle-native copied to clipboard

Detect Xcode target/scheme variants in build adapter

Open lacasseio opened this issue 2 years ago • 1 comments

At the moment, we use whatever is the default when invoking xcodebuild commands. This is wrong as some targets (mostly common for Pods targets) will default to macOS when trying to build for iOS. During testing, we use XCODE_BUILD_TYPE and XCODE_SDK environment variables for -configuration and -sdk respectively. We won't keep this escape hatch for very long. Instead, we want to map each possible value to a variant which allows for building multiple variants at once.

The following are the important build settings (can be shown using -showBuildSettings flag), the information is pulled from https://pewpewthespells.com/blog/buildsettings.html:

  • SUPPORTED_PLATFORMS: The list of supported platforms from which a base SDK can be used. This setting is used if the product can be built for multiple platforms using different SDKs. Can be any value of iphonesimulator, iphoneos, macosx.
  • SUPPORTED_DEVICE_FAMILIES can have multiple value: 1 (iPhone/iPod touch), 2 (iPad), 3 (Apple TV), 4 (Apple Watch), 5 (HomePod), 6 (Mac)
  • TARGETED_DEVICE_FAMILY: Comma-separated list of numeric identifiers. Specifies the device families on which the product must be capable of running.
  • SDKROOT: Specifies the directory of the base SDK to use to build the product.
  • VALID_ARCHS: Specifies the architectures for which the binary may be built. During the build, this list is intersected with the value of the ARCHS build setting; the resulting list specifies the architectures the binary can run on. If the resulting architecture list is empty, the target generates no binary.
  • ARCHS specify the architectures to build

See https://davedelong.com/blog/2018/11/15/building-a-crossplatform-framework/ for additional information on SUPPORTED_PLATFORMS.

First, we should check the SUPPORTED_PLATFORMS attributes, then default SDKROOT value to infer the SUPPORTED_PLATFORMS. As for the configuration, we can just look at the target at its buildConfigurationList property. We can't really rely on the project's buildConfigurationList as it doesn't exactly means a 1 to 1 match with its targets.

lacasseio avatar Jun 05 '22 22:06 lacasseio

As for the SDK version, we don't exactly have a good solution. Normally, users would build using a SDK that satisfy the base constraints, so there should be any variant awareness at this level.

lacasseio avatar Jun 05 '22 22:06 lacasseio