Update bazel docs in getting started and add example code (#1342)

Co-authored-by: Bart Louwers <bart.louwers@gmail.com>
Co-authored-by: Bart Louwers <bart@emeel.net>
This commit is contained in:
Alex Polvi
2023-07-12 08:38:15 -07:00
committed by GitHub
parent 78b112676a
commit 14cc0297b9
5 changed files with 121 additions and 14 deletions

View File

@@ -9,7 +9,7 @@ load(
"xcodeproj",
)
load("bazel/macros.bzl", "info_plist")
load("bazel/config.bzl", "APPLE_MOBILE_PROVISIONING_PROFILE_TEAM_ID")
load("bazel/config.bzl", "APPLE_MOBILE_PROVISIONING_PROFILE_NAME", "APPLE_MOBILE_PROVISIONING_PROFILE_TEAM_ID", "BUNDLE_ID_PREFIX")
# This list of public headers is from what Mapbox vendors with their dynamic framework
# If we forget one the build will fail, and if we add too many there will be a warning
@@ -456,7 +456,7 @@ _IOS_APPLICATION_RESOURCES = [
ios_application(
name = "App",
bundle_id = "com.maplibre.app",
bundle_id = "{}.maplibre.app".format(BUNDLE_ID_PREFIX),
families = [
"iphone",
"ipad",
@@ -508,7 +508,7 @@ genrule(
local_provisioning_profile(
name = "provisioning_profile",
profile_name = "iOS Team Provisioning Profile: *",
profile_name = APPLE_MOBILE_PROVISIONING_PROFILE_NAME,
team_id = APPLE_MOBILE_PROVISIONING_PROFILE_TEAM_ID,
)

View File

@@ -1 +1,3 @@
APPLE_MOBILE_PROVISIONING_PROFILE_TEAM_ID = "TC45MCF93C"
APPLE_MOBILE_PROVISIONING_PROFILE_NAME = "iOS Team Provisioning Profile: *"
BUNDLE_ID_PREFIX = "com.firstnamelastname"

View File

@@ -14,6 +14,49 @@ MapLibre Native for iOS is distributed using the [Swift Package Index](https://s
3. Choose "Next". Xcode should clone the distribution repository and download the binaries.
4. To create a minimal app, update `ContentView.swift` (which should have been automatically created when you initalized the new XCode project) with the following contents:
```swift
import SwiftUI
import Mapbox
struct ContentView: View {
var body: some View {
MapView().edgesIgnoringSafeArea(.all)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct MapView: UIViewRepresentable {
func makeUIView(context: Context) -> MGLMapView {
// Build the style URL
let styleURL = URL(string: "https://demotiles.maplibre.org/style.json")
// Create the map view
let mapView = MGLMapView(frame: .zero, styleURL: styleURL)
mapView.logoView.isHidden = true
mapView.setCenter(
CLLocationCoordinate2D(
latitude: 23.16, longitude: -109.50), animated: false)
mapView.setZoomLevel(4, animated: false)
return mapView
}
func updateUIView(_ mapView: MGLMapView, context: Context) {
// Update the view if needed
}
}
```
There is a an open bounty to extend this Getting Started guide ([#809](https://github.com/maplibre/maplibre-native/issues/809)). In the meantime, refer to one of these external guides:
- [Get Started with MapLibre Native for iOS using SwiftUI](https://docs.maptiler.com/maplibre-gl-native-ios/ios-swiftui-basic-get-started/)
@@ -21,19 +64,28 @@ There is a an open bounty to extend this Getting Started guide ([#809](https://g
## Developing
### CMake
The following are instructions on how to build MapLibre Native for development purposes.
The main build tool generator supported by MapLibre Native is CMake. There is a `Makefile` which calls CMake and `xcodebuild` under the hood to complete various development tasks, including building with various kinds of configurations and running tests. This `Makefile` can also can set up an Xcode project for MapLibre Native development by copying a `.xcodeproj` file part of the source tree and combining that with the output of CMake.
### Downloading Source
To set up an Xcode project and open Xcode, use the following command.
Download the source and install all submodules if you have not already, by running the following from the root of the repository.
```
make iproj
git clone --recurse-submodules git@github.com:maplibre/maplibre-native.git
cd maplibre-native
```
Next run the following to generate some files that are needed:
```
cd platform/ios
make style-code
```
### Bazel
The above setup is quite fragile and relies on the `.xcodeproj` files part of the source tree (making changes hard to review). We are looking into a better way to set up an Xcode project for MapLibre Native iOS development. As of May 2023 we are experimenting with [Bazel](https://bazel.build/) together with [rules_xcodeproj](https://github.com/MobileNativeFoundation/rules_xcodeproj). Please [share your experiences](https://github.com/maplibre/maplibre-native/discussions/1145).
[Bazel](https://bazel.build/) together with [rules_xcodeproj](https://github.com/MobileNativeFoundation/rules_xcodeproj) is the preferred build system. Please [share your experiences](https://github.com/maplibre/maplibre-native/discussions/1145).
You need to install bazelisk, which is a wrapper around Bazel which ensures that the version specified in `.bazelversion` is used.
@@ -41,20 +93,74 @@ You need to install bazelisk, which is a wrapper around Bazel which ensures that
brew install bazelisk
```
Next, you can generate an Xcode project for MapLibre Native development using:
#### Creating `config.bzl`
You need to configure Bazel. Copy the example config from `platform/ios`.
```
bazel run //platform/ios:xcodeproj
cp bazel/example_config.bzl bazel/config.bzl
```
You can now open `platform/ios/MapLibre.xcodeproj` with Xcode to get started.
You need to set your `BUNDLE_ID_PREFIX` to be unique (ideally use a domain that you own in reverse domain name notation).
```
APPLE_MOBILE_PROVISIONING_PROFILE_TEAM_ID = "FFNX6834U8"
APPLE_MOBILE_PROVISIONING_PROFILE_NAME = "iOS Team Provisioning Profile: *"
BUNDLE_ID_PREFIX = "com.firstnamelastname"
```
You can keep leave the `APPLE_MOBILE_PROVISIONING_PROFILE_NAME` alone.
Set the Team ID to the Team ID of your Apple Developer Account (paid or unpaid both work). If you do not know your Team ID, enter the following command in the terminal:
```
cd ~/Library/MobileDevice/Provisioning\ Profiles && open .
```
Then select one of the profiles and click spacebar. Your Team ID is the string between parentheses in the value of "Team".
If there are no provisioning profiles available, continue this guide and let Xcode generate a provisioning profile for you. You will need to update the Team ID after this happened.
#### Create the Xcode Project
_These instructions are for XCode 14.3.1_
From `platform/ios`:
```
bazel run xcodeproj
xed MapLibre.xcodeproj
```
Then once in Xcode, click on "MapLibre" on the left, then "App" under Targets, then "Signing & Capabilities" in the tabbed menu.
Confirm that no errors are shown:
<img width="921" alt="image" src="https://github.com/polvi/maplibre-native/assets/649392/a1ef30cb-97fc-429a-acee-194436f3fb8a">
Try to run the example App in the simulator and on a device to confirm your setup works.
#### Using Bazel from the Command Line
It is also possible to build and run the test application in a simulator from the command line without opening Xcode.
```
bazel run //platform/ios:App
# run the iOS tests
bazel test //platform/ios/platform/ios/test:ios_test --test_output=errors
```
### CMake (deprecated)
The original build tool generator supported by MapLibre Native is CMake. There is a `Makefile` which calls CMake and `xcodebuild` under the hood to complete various development tasks, including building with various kinds of configurations and running tests. This `Makefile` can also can set up an Xcode project for MapLibre Native development by copying a `.xcodeproj` file part of the source tree and combining that with the output of CMake.
To set up an Xcode project and open Xcode, use the following command from `platform/ios`:
```
make iproj
```
## Documentation
- [MapLibre Native for iOS API Reference](https://maplibre.org/maplibre-native/ios/api/)

View File

@@ -1,4 +1,5 @@
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_application")
load("//platform/ios:bazel/config.bzl", "BUNDLE_ID_PREFIX")
cc_library(
name = "ios_test_runner_lib",
@@ -31,7 +32,7 @@ objc_library(
ios_application(
name = "RenderTestApp",
bundle_id = "org.maplibre.RenderTestApp",
bundle_id = "{}.maplibre.RenderTestApp".format(BUNDLE_ID_PREFIX),
families = ["iphone"],
infoplists = [
"//render-test/ios:Info.plist",

View File

@@ -8,8 +8,6 @@
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>RenderTestApp</string>
<key>CFBundleIdentifier</key>
<string>org.maplibre.RenderTestApp</string>
<key>CFBundleGetInfoString</key>
<string>org.maplibre.RenderTestApp</string>
<key>CFBundleInfoDictionaryVersion</key>