Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boost framework not added correctly on visionOS #18

Closed
skalarproduktraum opened this issue Sep 17, 2024 · 12 comments
Closed

Boost framework not added correctly on visionOS #18

skalarproduktraum opened this issue Sep 17, 2024 · 12 comments

Comments

@skalarproduktraum
Copy link

skalarproduktraum commented Sep 17, 2024

Description of Issue

When adding MetaverseKit to a visionOS project, the binary target for the boost framework is not added correctly. Instead of the one that should be downloaded, a basically empty one is used, with missing Info.plist. When running the application on the visionOS Simulator then, Xcode will fail with a message similar to:

Please try again later. Failed to load Info.plist from bundle at path /Users/[...]/Library/Developer/CoreSimulator/Devices/DE76A799-5008-45ED-9182-B7F151113576/data/Library/Caches/com.apple.mobile.installd.staging/temp.otZMQc/extracted/Payload/[...].app/Frameworks/boost.framework; [...]

Steps to Reproduce

  1. Create an Xcode project with visionOS as target
  2. Add MetaverseKit as package dependency, with a scheme that has a dependency on Boost (e.g. Alembic, OpenImageIO, tested both 1.8.3 and 1.8.4)
  3. Try to launch the project on the simulator.

System Information (OS, Hardware)

Xcode 16 RC, visionOS 2.0 Simulator.

Package Versions

1.8.3, 1.8.4

Build Flags

(none)

PS: Thanks for the great initiative. This library collection is extremely useful 👍

@furby-tm
Copy link
Member

furby-tm commented Sep 17, 2024

@skalarproduktraum First off, thanks for your interest in this project! I really appreciate you filling out an issue for this, as it helps iron out the development experience for everyone else who also finds this Swift package useful.

I must say, this is quite odd behavior you're experiencing, I frequently run on visionOS simulator and have not yet run into this issue, but I mostly build, bundle, and run my visionOS simulator apps through my fork of @stackotter's SwiftBundler project.

I will go ahead and try to build some of my apps with Xcode to see if I can reproduce the issue you're having on your end, but in the meantime, you should not experience this issue if you use SwiftBundler to run your app on visionOS (and iOS) simulator.


Instructions on how to use SwiftBundler

Install @stackotter's SwiftBundler, however; utilize my fork of the project which supports properly building and bundling iOS, visionOS, (and macOS) projects (until these changes are approved in a pending PR):

git clone https://github.com/wabiverse/wabi-swift-bundler
cd wabi-swift-bundler

swift build -c release
sudo cp .build/release/swift-bundler /usr/local/bin/

Ensure that your app has an executable target in its Package.swift file:

// ...
.executableTarget(
  name: "MyAwesomeApp",
  dependencies: [
    .product(name: "Boost", package: "MetaverseKit")
  ],
  swiftSettings: [
    .interoperabilityMode(.Cxx)
  ]
)

And create a file called Bundler.toml at the root of your app's repository:

format_version = 2

[apps.MyAwesomeApp]
identifier = 'foundation.wabi.MyAwesomeApp'
product = 'MyAwesomeApp'
version = '1.0.0'
category = 'public.app-category.graphics-design'

[apps.MyAwesomeApp.plist]
commit = '$(COMMIT_HASH)'

Then run the following to build, bundle, and run it on a visionOS Simulator:

# list available iOS and visionOS simulators.
swift bundler simulators

# boot a simulator from the list.
swift bundler simulators boot [id-of-device]

# this will then build and bundle your app and
# then proceed to run it on the simulator.
swift bundler run -p visionOSSimulator MyAwesomeApp

@skalarproduktraum
Copy link
Author

Thanks for the quick reply @furby-tm! SwiftBundler indeed looks very interesting, I will give this a shot 👍

In the meantime, I had also tried renaming the Boost target that contains the downloaded framework, in case Xcode might confuse it with the boost directory in Sources (for whatever reason). That turned out not to be the case, though.

@skalarproduktraum
Copy link
Author

@furby-tm I've tried your version of swift-bundler now, too. This seems to work fine, until the step of bundling the app. There, I run into:

info: Bundling 'testapplication.app'
info: Copying executable
error: Failed to copy executable from './.build/arm64-apple-xrsimulator/Build/Products/Debug-xrsimulator/testapplication' to './.build/bundler/testapplication.app/testapplication'
debug: Error details: failedToCopyExecutable(source: ./.build/arm64-apple-xrsimulator/Build/Products/Debug-xrsimulator/testapplication -- file:///Users/[...]/testapplication/, destination: ./.build/bundler/testapplication.app/testapplication -- file:///Users/[...]/testapplication/, Error Domain=NSCocoaErrorDomain Code=260 "The file “testapplication” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/[…]/testapplication/.build/arm64-apple-xrsimulator/Build/Products/Debug-xrsimulator/testapplication, NSUnderlyingError=0x600003c38d20 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}})

This might be a bug in your PR, as the binary it wants to copy is in Build/Products/Debug-xrsimulator/testapplication.app/testapplication, and not in Build/Products/Debug-xrsimulator/testapplication. Any ideas how to solve this one?

@skalarproduktraum
Copy link
Author

I've tried now hard-linking the binary to the directory where swift-bundler expects it, and it got me a little further, buuuuut:

info: Bundling 'testapplication.app'
info: Copying executable
info: Creating 'PkgInfo'
info: Creating 'Info.plist'
info: Copying dynamic libraries
debug: Running command: '/usr/bin/install_name_tool' with arguments: ["-rpath", "@executable_path/../lib", "@executable_path", "/Users/[...]/testapplication/.build/bundler/testapplication.app/testapplication"]
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: no LC_RPATH load command with path: @executable_path/../lib found in: /Users/[...]/testapplication/.build/bundler/testapplication.app/testapplication (for architecture arm64), required for specified option "-rpath @executable_path/../lib @executable_path"
error: Failed to copy dynamic libraries: Failed to update the app's rpath from '@executable_path/../lib' to '@executable_path': The process returned a non-zero exit status (1)
debug: Error details: failedToCopyDynamicLibraries(swift_bundler.DynamicLibraryBundlerError.failedToUpdateAppRPath(original: "@executable_path/../lib", new: "@executable_path", swift_bundler.ProcessError.nonZeroExitStatus(1))

@furby-tm
Copy link
Member

furby-tm commented Sep 18, 2024

as the binary it wants to copy is in Build/Products/Debug-xrsimulator/testapplication.app/testapplication, and not in Build/Products/Debug-xrsimulator/testapplication

@skalarproduktraum hmm, that's peculiar! When it (xcodebuild) builds my apps, it places the binary here for me: Build/Products/Debug-xrsimulator/SomeApp.

I'm not sure why (xcodebuild) is placing your executable inside of an app bundle within that build products directory, but what I will do is modify the bundler to check:

  • If Build/Products/Debug-xrsimulator/SomeApp.app exists.
  • If there is an app bundle in that directory, use that path to copy over the binary instead of attempting to copy over the binary from Build/Products/Debug-xrsimulator/SomeApp.

I will let you know as soon as I've made that fix in SwiftBundler, allow me an hour or so to fix it, thanks for finding this edge case!

I've tried now hard-linking the binary to the directory where swift-bundler expects it, and it got me a little further, buuuuut:

error: Failed to copy dynamic libraries: Failed to update the app's rpath

As far as I'm aware - I believe the issue here was whichever method you used to "hard-link the binary", but the suggested fix I will make to SwiftBundler above, should fix the need for any sort of manual intervention anyway, however; if you keep running into this issue after my suggested fix, please feel free to reach out so I can get that corrected as well, thanks!

@furby-tm
Copy link
Member

furby-tm commented Sep 18, 2024

@skalarproduktraum okay, I believe I have fixed the issue you were experiencing here! Go ahead and attempt to build again, remember to first update SwiftBundler with the following commands:

git clone https://github.com/wabiverse/wabi-swift-bundler
cd wabi-swift-bundler

swift build -c release
sudo cp .build/release/swift-bundler /usr/local/bin/

@skalarproduktraum
Copy link
Author

skalarproduktraum commented Sep 18, 2024

Okay great, thank you @furby-tm - this worked and got me to the other error I've mentionered before - any ideas about that one?

Also, for clarification - with hard-linking I meant doing ln testapplication.app/testapplication . (in the Debug-xrsimulator directory) to create a hard link. Symlinking doesn't work, as the bundler will then just copy the symlink, which of course breaks things.

@furby-tm
Copy link
Member

furby-tm commented Sep 18, 2024

Okay great, thank you @furby-tm - this worked and got me to #18 (comment) - any ideas about that one?

👀 looking into this now, will update you as soon as I issue another fix to the bundler, thanks for your patience as we work through this together, I believe the fix for this should be quite simple as well... investigating...

@furby-tm
Copy link
Member

furby-tm commented Sep 18, 2024

@skalarproduktraum alright! Go ahead and see if this fix gets things working for you, I imagine there may be the possibility of a few last remaining additional errors after this one, but I've never seen the bundle get generated in the Build/Products/Debug-xrsimulator directory like it is for you to test this edge case. Please let me know if there's any more additional issues you face after updating SwiftBundler, and rebuilding your app again, thanks for all your help shaping things up!

@furby-tm
Copy link
Member

furby-tm commented Sep 18, 2024

@skalarproduktraum also, do you still have the .xcodeproj in your project by chance? If so, that's likely to cause xcodebuild to do some pretty strange things, I recommend deleting that file.

@skalarproduktraum
Copy link
Author

Hey @furby-tm! Sorry for the late reply, I've been busy the last days. I have moved the Xcode project file out of the way, it seems this got picked up. For the moment it fails now to compile things correctly, but I'll investigate more tomorrow. Thanks for your help so far 👍

@furby-tm
Copy link
Member

@skalarproduktraum I had just went ahead and built some of my own projects which depend on MetaverseKit and SwiftUSD in Xcode (v16.1) for macOS, iOS, and visionOS. Each of my projects built successfully across these different platforms and I could not reproduce the error you experienced.

Some Troubleshooting Steps

Try the following if you're still experiencing Xcode related issues when building your project.

  1. Quit Xcode
  2. Delete Xcode's DerivedData cache
  3. Open Xcode and build your project.

I'm going to close out this issue, but please feel free to comment on it again or submit a new issue if you still continue to experience any problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants