mapbox / mapbox-gl-native-ios

Interactive, thoroughly customizable maps for iOS powered by vector tiles and OpenGL
https://www.mapbox.com/mobile/
Other
210 stars 122 forks source link

Distribute as XCFramework #171

Open johankool opened 4 years ago

johankool commented 4 years ago

Apple has introduced a new way to distributed binary frameworks XCFramework which (in theory) would make workarounds like the strip-frameworks.sh script unnecessary.

Is this something Mapbox could support?

julianrex commented 4 years ago

This is definitely something we would like to support. Keeping this ticket open and transferring.

julianrex commented 4 years ago

cc @nishant-karajgikar @frederoni

julianrex commented 4 years ago

This is blocked by xcframework support in Carthage.

KaneCheshire commented 4 years ago

This also impacts pure SPM projects because you can't currently even download the built binary to include in a local package

johankool commented 4 years ago

Relevant issues in Carthage: https://github.com/Carthage/Carthage/pull/2881 https://github.com/Carthage/Carthage/pull/2801 https://github.com/Carthage/Carthage/pull/3071

1ec5 commented 4 years ago

This is blocked by xcframework support in Carthage.

Upon closer inspection, I don’t think this work is blocked by any of the issues listed in https://github.com/mapbox/mapbox-gl-native-ios/issues/171#issuecomment-716411557:

This also impacts pure SPM projects because you can't currently even download the built binary to include in a local package

Yes, #546 tracks SPM support and is blocked by XCFramework support.

chazapis commented 3 years ago

This is blocked by xcframework support in Carthage.

Carthage now supports xcframeworks. I have successfully compiled several packages into xcframeworks by running carthage update --no-use-binaries --use-xcframeworks using a compiled version of carthage from the master branch.

simonseyer commented 3 years ago

Hi. What's the timeline here? I just updated all our dependencies to use xcframeworks with a Carthage master build to fix build errors we experience and unfortunately this is the only dependency that is not available as xcframework and that we also cannot rebuild ourselves.

ferologics commented 3 years ago

^ What he said 😄 I'm trying to get my project running on an M1 mac book but I get:

Couldn't find framework at Carthage/Build/iOS/Mapbox.xcframework

Is anything blocking this? How can the community help move this along?

fousa commented 3 years ago

It would be great to get some kind of timeline. I've got the same problem, I would love to port my app to Mac, but preferably with Catalyst.

Mapbox is really the core of my app and for obvious reason. It's just the best map framework around.

ferologics commented 3 years ago

@nishant-karajgikar @frederoni could you take a look?

1ec5 commented 3 years ago

mapbox/mapbox-maps-ios#48 tracks the same issue in MapboxMaps v10.

mikehardy commented 3 years ago

Until this is fixed I believe it blocks people upgrading to cocoapods 1.10+ from downstream projects, which puts the projects in a bind because other libraries have moved to .xcframework distribution specifically to support Apple Silicon / macOS-catalyst-variant, which necessarily requires 1.10+ so downstream projects can't update other libraries until this supports .xcframeworks / cocoapods 1.10+

likely https://github.com/notifee/react-native-notifee/issues/230#issuecomment-760077326 definitely https://github.com/transistorsoft/react-native-background-fetch/issues/318#issue-813247200

ferologics commented 3 years ago

@1ec5 @julianrex did PR #2808 introduce binary XCFramework distribution? If so then this issue can be closed.

noway commented 3 years ago

@1ec5 @julianrex did PR #2808 introduce binary XCFramework distribution? If so then this issue can be closed.

This is a PR to mapbox-navigation-ios, mapbox-gl-native-ios still has no XCFramework support

noway commented 3 years ago

Any update on when this would be available? It is not possible to use mapbox on an iOS Simulator on an Apple Silicon mac atm. Resolving this should resolve #558

mdab121 commented 3 years ago

Is there any way to unit test modules that include Mapbox SDK in Xcode 12 without XCFramework support? I'm stuck updating an old project with this. Is there a plan to support this?

isoiphone commented 3 years ago

Any updates? xcframeworks are several years mature now, carthage support exists, M1 silicon Macs are more and more common.

mikehardy commented 3 years ago

I am only subscribed here because in other react-native repos I maintain this issue blows up their ability to use Apple Silicon since it is a transitive dependency, and I heard about it enough I listened here. Maybe this battle-tested xcframework builder will help. We use it for Notifee.app's library (in production, piles of users, no complaints with the built product). Been meaning to write a blog post since most of the libraries for react-native are based on old tutorials but haven't gotten a chance yet 🤷

I won't have time to PR anything but maybe this gives someone a start in case just getting it built was the holdup

Enjoy?

#!/bin/bash
set -eo pipefail

WORKING_DIR=$(pwd)
FRAMEWORK_FOLDER_NAME="YOURPROJECT_XCFramework"
FRAMEWORK_NAME="YOURPROJECTCore"
FRAMEWORK_PATH="${WORKING_DIR}/${FRAMEWORK_FOLDER_NAME}/${FRAMEWORK_NAME}.xcframework"
BUILD_SCHEME="YOURPROJECTCore"
SIMULATOR_ARCHIVE_PATH="${WORKING_DIR}/${FRAMEWORK_FOLDER_NAME}/simulator.xcarchive"
IOS_DEVICE_ARCHIVE_PATH="${WORKING_DIR}/${FRAMEWORK_FOLDER_NAME}/iOS.xcarchive"
CATALYST_ARCHIVE_PATH="${WORKING_DIR}/${FRAMEWORK_FOLDER_NAME}/catalyst.xcarchive"
OUTPUT_FOLDER=${WORKING_DIR}/../packages/react-native/ios/

rm -rf "${WORKING_DIR:?}/${FRAMEWORK_FOLDER_NAME}"
echo "Deleted ${FRAMEWORK_FOLDER_NAME}"
mkdir "${FRAMEWORK_FOLDER_NAME}"
echo "Created ${FRAMEWORK_FOLDER_NAME}"

echo "Archiving for iOS Simulator"
xcodebuild archive -workspace "./${FRAMEWORK_NAME}.xcworkspace" -scheme ${BUILD_SCHEME} -configuration Release \
  -destination="iOS Simulator" -archivePath "${SIMULATOR_ARCHIVE_PATH}" \
  -sdk iphonesimulator SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES | xcpretty -k

echo "Archiving for iOS"
xcodebuild archive -workspace "./${FRAMEWORK_NAME}.xcworkspace" -scheme ${BUILD_SCHEME} -configuration Release \
  -destination="iOS" -archivePath "${IOS_DEVICE_ARCHIVE_PATH}" \
  -sdk iphoneos SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES | xcpretty -k

# Do not be tempted to use "-sdk macosx" instead of the "destination" argument. It switches you to AppKit from UIKit
# https://developer.apple.com/forums/thread/120542?answerId=374124022#374124022
echo "Archiving for Mac Catalyst"
xcodebuild archive -workspace "./${FRAMEWORK_NAME}.xcworkspace" -scheme ${BUILD_SCHEME} -configuration Release \
  -destination='platform=macOS,arch=x86_64,variant=Mac Catalyst' -archivePath "${CATALYST_ARCHIVE_PATH}" \
  SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES | xcpretty -k

echo "Packaging archives into ${FRAMEWORK_NAME}.xcframework bundle"
xcodebuild -create-xcframework \
  -framework "${SIMULATOR_ARCHIVE_PATH}/Products/Library/Frameworks/${FRAMEWORK_NAME}.framework" \
  -framework "${IOS_DEVICE_ARCHIVE_PATH}/Products/Library/Frameworks/${FRAMEWORK_NAME}.framework" \
  -framework "${CATALYST_ARCHIVE_PATH}/Products/Library/Frameworks/${FRAMEWORK_NAME}.framework" \
  -output "${FRAMEWORK_PATH}" | xcpretty

rm -rf "${SIMULATOR_ARCHIVE_PATH}"
rm -rf "${IOS_DEVICE_ARCHIVE_PATH}"
rm -rf "${CATALYST_ARCHIVE_PATH}"

# Catalyst framework directory structure flattening step 1:
# - Copy the framework in a specific way: de-referencing symbolic links on purpose
echo "Installing framework into packages/react-native submodule"
rm -rf "${OUTPUT_FOLDER}/${FRAMEWORK_NAME}.xcframework" && \
  cp -rp "${FRAMEWORK_PATH}" "${OUTPUT_FOLDER}"

# Catalyst framework directory structure flattening step 2:
# - Remove the catalyst framework "Versions" directory structure after symbolic link de-reference
rm -rf "${OUTPUT_FOLDER}/${FRAMEWORK_NAME}.xcframework/ios-arm64_x86_64-maccatalyst/${FRAMEWORK_NAME}.framework/Versions"

echo "Cleaning up intermediate files"
rm -rf "${WORKING_DIR:?}/${FRAMEWORK_FOLDER_NAME}"
klundberg commented 3 years ago

If you look at the read me to this repo, they suggest upgrading to sdk v10 in a different repo from this which does support SPM. I haven't tried it yet but looks like they're in release candidate stage so a final release should be coming any day now.

There's also the maplibre repo on GitHub that can also run in spm if you're ok with a 5.x sdk and don't want to migrate to 10 yet

NathanWalker commented 3 years ago

I really don't want to ping this issue again as there's been plenty enough discussion but is there any way a core member of MapBox team could provide a general expectation on when .xcframework support would be available without manually modifying with scripts/Carthage, etc. Just curious since the release candidate stage was in June so seems like something is close?

klundberg commented 3 years ago

The mapbox v10 sdk in a different repo is SPM compatible which means it's an xcframework. I doubt they'll make this v6 sdk available that way too with v10 almost out.

NathanWalker commented 3 years ago

Ok excellent thanks @klundberg will try that one.

noway commented 3 years ago

react-native-mapbox-gl still uses v6, so ideally we get xcframework support for that too...