Skip to content

Commit

Permalink
Add visionOS support
Browse files Browse the repository at this point in the history
  • Loading branch information
keith committed Aug 3, 2023
1 parent 7ed631e commit 47626a5
Show file tree
Hide file tree
Showing 34 changed files with 297 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/MODULE.tools
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ bazel_dep(name = "rules_license", version = "0.0.3")
bazel_dep(name = "rules_proto", version = "4.0.0")
bazel_dep(name = "rules_python", version = "0.4.0")

bazel_dep(name = "platforms", version = "0.0.4")
bazel_dep(name = "platforms", version = "0.0.7")
bazel_dep(name = "protobuf", version = "3.19.6", repo_name = "com_google_protobuf")
bazel_dep(name = "zlib", version = "1.2.13")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#end

<li><a href="${bazelbuildGithub}/rules_appengine" target="_blank" rel="noopener">AppEngine</a></li>
<li><a href="${bazelbuildGithub}/rules_apple" target="_blank" rel="noopener">Apple (Swift, iOS, macOS, tvOS, watchOS)</a></li>
<li><a href="${bazelbuildGithub}/rules_apple" target="_blank" rel="noopener">Apple (Swift, iOS, macOS, tvOS, visionOS, watchOS)</a></li>
<li><a href="${bazelbuildGithub}/rules_dotnet" target="_blank" rel="noopener">C#</a></li>
<li><a href="${bazelbuildGithub}/rules_d" target="_blank" rel="noopener">D</a></li>
<li><a href="${bazelbuildGithub}/rules_docker" target="_blank" rel="noopener">Docker</a></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ toc:
- title: AppEngine
path: https://github.com/bazelbuild/rules_appengine
status: external
- title: Apple (Swift, iOS, macOS, tvOS, watchOS)
- title: Apple (Swift, iOS, macOS, tvOS, visionOS, watchOS)
path: https://github.com/bazelbuild/rules_apple
status: external
- title: C#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private static String moduleFileContent(String repositoryName) {
"module(name = \"%s\")",
// Try to keep this updated with the src/MODULE.tools file. (Due to MVS, even if this is
// not kept up to date, we'll use the latest version anyhow)
"bazel_dep(name = \"platforms\", version = \"0.0.4\")"),
"bazel_dep(name = \"platforms\", version = \"0.0.7\")"),
repositoryName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ public class AppleCommandLineOptions extends FragmentOptions {
+ "If unspecified, uses default iOS SDK version from 'xcode_version'.")
public DottedVersion.Option iosSdkVersion;

@Option(
name = "visionos_sdk_version",
defaultValue = "null",
converter = DottedVersionConverter.class,
documentationCategory = OptionDocumentationCategory.TOOLCHAIN,
effectTags = {OptionEffectTag.LOSES_INCREMENTAL_STATE},
help =
"Specifies the version of the visionOS SDK to use to build visionOS applications. "
+ "If unspecified, uses default visionOS SDK version from 'xcode_version'.")
public DottedVersion.Option visionOsSdkVersion;

@Option(
name = "watchos_sdk_version",
defaultValue = "null",
Expand Down Expand Up @@ -126,6 +137,17 @@ public class AppleCommandLineOptions extends FragmentOptions {
+ "If unspecified, uses 'ios_sdk_version'.")
public DottedVersion.Option iosMinimumOs;

@Option(
name = "visionos_minimum_os",
defaultValue = "null",
converter = DottedVersionConverter.class,
documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS,
effectTags = {OptionEffectTag.LOSES_INCREMENTAL_STATE},
help =
"Minimum compatible visionOS version for target simulators and devices. "
+ "If unspecified, uses 'visionos_sdk_version'.")
public DottedVersion.Option visionosMinimumOs;

@Option(
name = "watchos_minimum_os",
defaultValue = "null",
Expand Down Expand Up @@ -182,11 +204,16 @@ public class AppleCommandLineOptions extends FragmentOptions {
public boolean preferMutualXcode;

@VisibleForTesting public static final String DEFAULT_IOS_SDK_VERSION = "8.4";
@VisibleForTesting public static final String DEFAULT_VISIONOS_SDK_VERSION = "1.0";
@VisibleForTesting public static final String DEFAULT_WATCHOS_SDK_VERSION = "2.0";
@VisibleForTesting public static final String DEFAULT_MACOS_SDK_VERSION = "10.11";
@VisibleForTesting public static final String DEFAULT_TVOS_SDK_VERSION = "9.0";
@VisibleForTesting static final String DEFAULT_IOS_CPU = "x86_64";

/** The default visionOS CPU value. */
public static final String DEFAULT_VISIONOS_CPU =
CPU.getCurrent() == CPU.AARCH64 ? "sim_arm64" : "x86_64";

/** The default watchos CPU value. */
public static final String DEFAULT_WATCHOS_CPU =
CPU.getCurrent() == CPU.AARCH64 ? "arm64" : "x86_64";
Expand Down Expand Up @@ -292,6 +319,16 @@ public class AppleCommandLineOptions extends FragmentOptions {
+ "is a universal binary containing all specified architectures.")
public List<String> iosMultiCpus;

@Option(
name = "visionos_cpus",
allowMultiple = true,
converter = CommaSeparatedOptionListConverter.class,
defaultValue = "null",
documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS,
effectTags = {OptionEffectTag.LOSES_INCREMENTAL_STATE, OptionEffectTag.LOADING_AND_ANALYSIS},
help = "Comma-separated list of architectures for which to build Apple visionOS binaries.")
public List<String> visionosCpus;

@Option(
name = "watchos_cpus",
allowMultiple = true,
Expand Down Expand Up @@ -399,6 +436,9 @@ public DottedVersion getMinimumOsVersion() {
case TVOS:
option = tvosMinimumOs;
break;
case VISIONOS:
option = visionosMinimumOs;
break;
case WATCHOS:
option = watchosMinimumOs;
break;
Expand All @@ -417,6 +457,7 @@ public FragmentOptions getExec() {
exec.xcodeVersionConfig = xcodeVersionConfig;
exec.xcodeVersion = xcodeVersion;
exec.iosSdkVersion = iosSdkVersion;
exec.visionOsSdkVersion = visionOsSdkVersion;
exec.watchOsSdkVersion = watchOsSdkVersion;
exec.tvOsSdkVersion = tvOsSdkVersion;
exec.macOsSdkVersion = macOsSdkVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ public static AppleCpus create(AppleCommandLineOptions options, CoreOptions core
(options.iosMultiCpus == null || options.iosMultiCpus.isEmpty())
? ImmutableList.of(iosCpuFromCpu(coreOptions.cpu))
: ImmutableList.copyOf(options.iosMultiCpus);
ImmutableList<String> visionosCpus =
(options.visionosCpus == null || options.visionosCpus.isEmpty())
? ImmutableList.of(AppleCommandLineOptions.DEFAULT_VISIONOS_CPU)
: ImmutableList.copyOf(options.visionosCpus);
ImmutableList<String> watchosCpus =
(options.watchosCpus == null || options.watchosCpus.isEmpty())
? ImmutableList.of(AppleCommandLineOptions.DEFAULT_WATCHOS_CPU)
Expand All @@ -131,13 +135,15 @@ public static AppleCpus create(AppleCommandLineOptions options, CoreOptions core
: ImmutableList.copyOf(options.catalystCpus);

return new AutoValue_AppleConfiguration_AppleCpus(
appleSplitCpu, iosMultiCpus, watchosCpus, tvosCpus, macosCpus, catalystCpus);
appleSplitCpu, iosMultiCpus, visionosCpus, watchosCpus, tvosCpus, macosCpus, catalystCpus);
}

abstract String appleSplitCpu();

abstract ImmutableList<String> iosMultiCpus();

abstract ImmutableList<String> visionosCpus();

abstract ImmutableList<String> watchosCpus();

abstract ImmutableList<String> tvosCpus();
Expand Down Expand Up @@ -256,6 +262,8 @@ private static String getPrefixedAppleCpu(PlatformType applePlatformType, AppleC
switch (applePlatformType) {
case IOS:
return appleCpus.iosMultiCpus().get(0);
case VISIONOS:
return appleCpus.visionosCpus().get(0);
case WATCHOS:
return appleCpus.watchosCpus().get(0);
case TVOS:
Expand Down Expand Up @@ -304,6 +312,8 @@ public List<String> getMultiArchitectures(PlatformType platformType) {
switch (platformType) {
case IOS:
return appleCpus.iosMultiCpus();
case VISIONOS:
return appleCpus.visionosCpus();
case WATCHOS:
return appleCpus.watchosCpus();
case TVOS:
Expand Down Expand Up @@ -349,6 +359,13 @@ public ApplePlatform getMultiArchPlatform(PlatformType platformType) {
}
}
return ApplePlatform.IOS_SIMULATOR;
case VISIONOS:
for (String arch : architectures) {
if (ApplePlatform.forTarget(PlatformType.VISIONOS, arch) == ApplePlatform.VISIONOS_DEVICE) {
return ApplePlatform.VISIONOS_DEVICE;
}
}
return ApplePlatform.VISIONOS_SIMULATOR;
case WATCHOS:
for (String arch : architectures) {
if (ApplePlatform.forTarget(PlatformType.WATCHOS, arch) == ApplePlatform.WATCHOS_DEVICE) {
Expand Down Expand Up @@ -453,6 +470,8 @@ public enum ConfigurationDistinguisher implements StarlarkValue {
UNKNOWN("unknown"),
/** Distinguisher for {@code apple_binary} rule with "ios" platform_type. */
APPLEBIN_IOS("applebin_ios"),
/** Distinguisher for {@code apple_binary} rule with "visionos" platform_type. */
APPLEBIN_VISIONOS("applebin_visionos"),
/** Distinguisher for {@code apple_binary} rule with "watchos" platform_type. */
APPLEBIN_WATCHOS("applebin_watchos"),
/** Distinguisher for {@code apple_binary} rule with "tvos" platform_type. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public enum ApplePlatform implements ApplePlatformApi {
MACOS("macos", "MacOSX", PlatformType.MACOS, true),
TVOS_DEVICE("tvos_device", "AppleTVOS", PlatformType.TVOS, true),
TVOS_SIMULATOR("tvos_simulator", "AppleTVSimulator", PlatformType.TVOS, false),
VISIONOS_DEVICE("visionos_device", "XROS", PlatformType.VISIONOS, true),
VISIONOS_SIMULATOR("visionos_simulator", "XRSimulator", PlatformType.VISIONOS, false),
WATCHOS_DEVICE("watchos_device", "WatchOS", PlatformType.WATCHOS, true),
WATCHOS_SIMULATOR("watchos_simulator", "WatchSimulator", PlatformType.WATCHOS, false),
CATALYST("catalyst", "MacOSX", PlatformType.CATALYST, true);
Expand All @@ -45,6 +47,10 @@ public enum ApplePlatform implements ApplePlatformApi {
ImmutableSet.of("ios_x86_64", "ios_i386", "ios_sim_arm64");
private static final ImmutableSet<String> IOS_DEVICE_TARGET_CPUS =
ImmutableSet.of("ios_armv6", "ios_arm64", "ios_armv7", "ios_armv7s", "ios_arm64e");
private static final ImmutableSet<String> VISIONOS_SIMULATOR_TARGET_CPUS =
ImmutableSet.of("visionos_x86_64", "visionos_sim_arm64");
private static final ImmutableSet<String> VISIONOS_DEVICE_TARGET_CPUS =
ImmutableSet.of("visionos_arm64");
private static final ImmutableSet<String> WATCHOS_SIMULATOR_TARGET_CPUS =
ImmutableSet.of("watchos_i386", "watchos_x86_64", "watchos_arm64");
private static final ImmutableSet<String> WATCHOS_DEVICE_TARGET_CPUS =
Expand Down Expand Up @@ -135,6 +141,10 @@ private static ApplePlatform forTargetCpuNullable(String targetCpu) {
return IOS_SIMULATOR;
} else if (IOS_DEVICE_TARGET_CPUS.contains(targetCpu)) {
return IOS_DEVICE;
} else if (VISIONOS_SIMULATOR_TARGET_CPUS.contains(targetCpu)) {
return VISIONOS_SIMULATOR;
} else if (VISIONOS_DEVICE_TARGET_CPUS.contains(targetCpu)) {
return VISIONOS_DEVICE;
} else if (WATCHOS_SIMULATOR_TARGET_CPUS.contains(targetCpu)) {
return WATCHOS_SIMULATOR;
} else if (WATCHOS_DEVICE_TARGET_CPUS.contains(targetCpu)) {
Expand Down Expand Up @@ -242,6 +252,7 @@ public UnsupportedPlatformTypeException(String msg) {
@Immutable
public enum PlatformType implements ApplePlatformTypeApi {
IOS("ios"),
VISIONOS("visionos"),
WATCHOS("watchos"),
TVOS("tvos"),
MACOS("macos"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public static String sdkFrameworkDir(ApplePlatform targetPlatform, XcodeConfigIn
}
break;
case MACOS:
case VISIONOS_DEVICE:
case VISIONOS_SIMULATOR:
case WATCHOS_DEVICE:
case WATCHOS_SIMULATOR:
case TVOS_DEVICE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ public ConfiguredTarget create(RuleContext ruleContext)
(appleOptions.iosMinimumOs != null)
? DottedVersion.maybeUnwrap(appleOptions.iosMinimumOs)
: iosSdkVersion;
DottedVersion visionosSdkVersion =
(appleOptions.visionOsSdkVersion != null)
? DottedVersion.maybeUnwrap(appleOptions.visionOsSdkVersion)
: xcodeVersionProperties.getDefaultVisionosSdkVersion();
DottedVersion visionosMinimumOsVersion =
(appleOptions.visionosMinimumOs != null)
? DottedVersion.maybeUnwrap(appleOptions.visionosMinimumOs)
: visionosSdkVersion;
DottedVersion watchosSdkVersion =
(appleOptions.watchOsSdkVersion != null)
? DottedVersion.maybeUnwrap(appleOptions.watchOsSdkVersion)
Expand Down Expand Up @@ -151,6 +159,8 @@ public ConfiguredTarget create(RuleContext ruleContext)
new XcodeConfigInfo(
iosSdkVersion,
iosMinimumOsVersion,
visionosSdkVersion,
visionosMinimumOsVersion,
watchosSdkVersion,
watchosMinimumOsVersion,
tvosSdkVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class XcodeConfigInfo extends NativeInfo

private final DottedVersion iosSdkVersion;
private final DottedVersion iosMinimumOsVersion;
private final DottedVersion visionosSdkVersion;
private final DottedVersion visionosMinimumOsVersion;
private final DottedVersion watchosSdkVersion;
private final DottedVersion watchosMinimumOsVersion;
private final DottedVersion tvosSdkVersion;
Expand All @@ -58,6 +60,8 @@ public class XcodeConfigInfo extends NativeInfo
public XcodeConfigInfo(
DottedVersion iosSdkVersion,
DottedVersion iosMinimumOsVersion,
DottedVersion visionosSdkVersion,
DottedVersion visionosMinimumOsVersion,
DottedVersion watchosSdkVersion,
DottedVersion watchosMinimumOsVersion,
DottedVersion tvosSdkVersion,
Expand All @@ -70,6 +74,8 @@ public XcodeConfigInfo(
boolean includeXcodeReqs) {
this.iosSdkVersion = Preconditions.checkNotNull(iosSdkVersion);
this.iosMinimumOsVersion = Preconditions.checkNotNull(iosMinimumOsVersion);
this.visionosSdkVersion = Preconditions.checkNotNull(visionosSdkVersion);
this.visionosMinimumOsVersion = Preconditions.checkNotNull(visionosMinimumOsVersion);
this.watchosSdkVersion = Preconditions.checkNotNull(watchosSdkVersion);
this.watchosMinimumOsVersion = Preconditions.checkNotNull(watchosMinimumOsVersion);
this.tvosSdkVersion = Preconditions.checkNotNull(tvosSdkVersion);
Expand Down Expand Up @@ -141,6 +147,8 @@ private XcodeConfigProvider() {
public XcodeConfigInfoApi<?, ?> xcodeConfigInfo(
String iosSdkVersion,
String iosMinimumOsVersion,
String visionosSdkVersion,
String visionosMinimumOsVersion,
String watchosSdkVersion,
String watchosMinimumOsVersion,
String tvosSdkVersion,
Expand All @@ -153,6 +161,8 @@ private XcodeConfigProvider() {
return new XcodeConfigInfo(
DottedVersion.fromString(iosSdkVersion),
DottedVersion.fromString(iosMinimumOsVersion),
DottedVersion.fromString(visionosSdkVersion),
DottedVersion.fromString(visionosMinimumOsVersion),
DottedVersion.fromString(watchosSdkVersion),
DottedVersion.fromString(watchosMinimumOsVersion),
DottedVersion.fromString(tvosSdkVersion),
Expand Down Expand Up @@ -199,6 +209,8 @@ public DottedVersion getMinimumOsForPlatformType(ApplePlatform.PlatformType plat
return iosMinimumOsVersion;
case TVOS:
return tvosMinimumOsVersion;
case VISIONOS:
return visionosMinimumOsVersion;
case WATCHOS:
return watchosMinimumOsVersion;
case MACOS:
Expand All @@ -220,6 +232,9 @@ public DottedVersion getSdkVersionForPlatform(ApplePlatform platform) {
case TVOS_DEVICE:
case TVOS_SIMULATOR:
return tvosSdkVersion;
case VISIONOS_DEVICE:
case VISIONOS_SIMULATOR:
return visionosSdkVersion;
case WATCHOS_DEVICE:
case WATCHOS_SIMULATOR:
return watchosSdkVersion;
Expand Down Expand Up @@ -283,6 +298,12 @@ public DottedVersion getTvosSdkVersionForStarlark(StarlarkThread thread) throws
return tvosSdkVersion;
}

@StarlarkMethod(name = "visionos_sdk_version", documented = false, useStarlarkThread = true)
public DottedVersion getVisionosSdkVersionForStarlark(StarlarkThread thread) throws EvalException {
checkAccess(thread);
return visionosSdkVersion;
}

@StarlarkMethod(name = "watchos_sdk_version", documented = false, useStarlarkThread = true)
public DottedVersion getWatchosSdkVersionForStarlark(StarlarkThread thread) throws EvalException {
checkAccess(thread);
Expand Down
Loading

0 comments on commit 47626a5

Please sign in to comment.