leetal / ios-cmake

A CMake toolchain file for iOS/iPadOS, visionOS, macOS, watchOS & tvOS C/C++/Obj-C++ development
BSD 3-Clause "New" or "Revised" License
1.91k stars 450 forks source link

fix: add visionOS x64 #216

Closed okwasniewski closed 1 month ago

okwasniewski commented 2 months ago

This PR adds SIMULATOR64_VISIONOS and modifies VISIONOSCOMBINED to also include x86_64 slice for visionOS simulator.

It looks like Apple still requires us to build an x86_64 slice when working with the Release build on the simulator.

kambala-decapitator commented 2 months ago

It looks like Apple still requires us to build an x86_64 slice when working with the Release build on the simulator.

That sounds weird. Iirc developing for vision is possible only on arm Macs.

okwasniewski commented 2 months ago

It looks like Apple still requires us to build an x86_64 slice when working with the Release build on the simulator.

That sounds weird. Iirc developing for vision is possible only on arm Macs.

Totally agree that this is weird and this shouldn't be the case but you can easily check this by running a release build for the simulator, as you can see on the screenshot it builds for both archs (Im on M1 mac):

CleanShot 2024-08-26 at 16 43 12@2x

kambala-decapitator commented 2 months ago

I believe it's a problem in your project file. For example, by default it sets "build active architecture only" only for debug build.

Was this xcode project generated by cmake?

okwasniewski commented 2 months ago

I believe it's a problem in your project file. For example, by default it sets "build active architecture only" only for debug build.

Was this xcode project generated by cmake?

Nope, this project wasn't generated by CMake but it shouldn't matter. I can test out again with build only active arch but the x64 build was also triggered when archiving the app for AppStore release.

If you google this issue you will find similar cases, for example this: https://forums.swift.org/t/archiving-swift-package-that-supports-visionos-requires-x86-64-architecture/71964

kambala-decapitator commented 2 months ago

The Apple Silicon requirement is fake and you can disable it:

now that's funny! :)

will check on a test project to see if it's reproducible

kambala-decapitator commented 2 months ago

indeed, Intel arch is available by default:

Screenshot 2024-08-27 at 14 46 57

You can disable it using either of the two: 1.

Screenshot 2024-08-27 at 14 50 29

2.

Screenshot 2024-08-27 at 14 51 06

Considering that one must take explicit actions to enable vision simulator on Intel, I'd rather adjust this PR to enable Intel support through an option that is off by default.

okwasniewski commented 2 months ago

Considering that one must take explicit actions to enable vision simulator on Intel, I'd rather adjust this PR to enable Intel support through an option that is off by default.

I think support for running visionOS for intel is going to be dropped soon so Im not sure if adding this makes sense for the long term. Have you tried archiving the app? Does the archive process take into account excluded architectures?

kambala-decapitator commented 2 months ago

I think support for running visionOS for intel is going to be dropped soon so Im not sure if adding this makes sense for the long term

fully agree

Have you tried archiving the app? Does the archive process take into account excluded architectures?

archiving from Xcode does build both archs regardless of those settings which is also strange. However, archiving from command line builds only arm64 even without those settings, tried with the following 2 commands:

# 1
xcodebuild archive -scheme vision-test -destination 'platform=visionOS Simulator,name=Any visionOS Simulator Device'

#2
xcodebuild archive -scheme vision-test -destination 'platform=visionOS Simulator,name=Any visionOS Simulator Device,arch=arm64'

(the difference is only in additional arch=arm64 passed to the -destination param)

okwasniewski commented 2 months ago

@kambala-decapitator Thanks for checking this out.

So what's your suggested resolution of this issue?

archiving from Xcode does build both archs regardless of those settings which is also strange

This was my original issue which persists for Xcode 16, maybe we can temporairly support this in ios-cmake until this behaviour isn't removed from Xcode?

I don't think adding Intel support makes sense as we mentioned.

But I think getting .frameworks to build for properly for all archs is necessary. Additionally if someone is using Xcode cloud they are going to run into some issues without x86 slice (at least that's my guess)

kambala-decapitator commented 2 months ago

building for simulator in release mode is a rather rare use case afaik (oh, unless it's a library/framework), and building for visionOS simulator on Intel is even rarer. As you can see, archiving from command line workarounds the issue.

Additionally if someone is using Xcode cloud they are going to run into some issues without x86 slice (at least that's my guess)

not sure why. Pretty sure Xcode cloud builds stuff using command line.

but anyway, I'm not a maintainer, @leetal should decide.

okwasniewski commented 2 months ago

But if you have library/framework that you provide for your users and then they build for the AppStore you need to have the x86 slice for the build to succeed.

In that case building with the CLI won't fix it

kambala-decapitator commented 2 months ago

they build for the AppStore you need to have the x86 slice for the build to succeed

um, what?.. AppStore requires only device archs and Intel is simulator-only.

Also don't understand how CLI wouldn't work it around since you can do the same there as what Xcode GUI does.

okwasniewski commented 2 months ago

As we discussed before, during archiving (for AppStore) Xcode is building x86 architecture of the App. If your .xcframework (built with ios-cmake) doesn't support x86 slice the archive will fail.

You can ask users of your framework to "use the cli" but it is an inconvenience for them

kambala-decapitator commented 2 months ago

you can easily check this by running a release build for the simulator

if I understand correctly, this is your bug report. One doesn't use simulator destination when building/archiving for App Store - instead device destination should be used.

okwasniewski commented 2 months ago

Oh okay sorry I got confused, you are right. This doesn't happen when archiving for the AppStore.

So this happens only if you are building your app for release targeting the simulator.

We've got two use cases:

kambala-decapitator commented 2 months ago

I believe that >= 95% of library maintainers already have build scripts to automate things :)

okwasniewski commented 1 month ago

Okay, after thinking about this let's leave this as is.

I'm going to close the PR and just don't ship x86 slice in our framework. Thanks for your help