How to build Swift Package as XCFramework

I tried multiple solutions which I found online, but none were working. And now that swift package generate-xcodeproj has been removed I don't see any way of getting this working the plain swift package way without 3rd party software like swift-create-xcframework. Only feasible solution is to go back to standard xcode project.

If anyone is interested in what I tried:

  1. Using swift build does not support building for a specific platform. There are workarounds but they are ugly.
  2. Using xcodebuild build does not work when using release build if you have tests. It will fail because it says "... was not build for testing" and the only way to stop xcode from building the tests (which I don't want do build in the first place) is to manually edit the scheme and uncheck "run" for the test target. Because I want this process to be fully automated that it not an option.
  3. Using xcodebuild archive runs but the generated archive only contains a simple .o file and no headers, swiftmodule files or whatsoever.