Consolidate developer documentation in mdBook docs (#3115)

This commit is contained in:
Bart Louwers
2025-01-06 20:16:49 +01:00
committed by GitHub
parent 660f78c583
commit c7e6b0c796
14 changed files with 321 additions and 132 deletions

View File

@@ -2,7 +2,11 @@
## Build Locally
Get the `mdbook` utility, see https://rust-lang.github.io/mdBook/guide/installation.html
Get the `mdbook` utility as well as [`mdbook-alerts`](https://github.com/lambdalisue/rs-mdbook-alerts), see https://rust-lang.github.io/mdBook/guide/installation.html
```
cargo install mdbook mdbook-alerts
```
Run

View File

@@ -3,7 +3,9 @@ authors = ["MapLibre Contributors"]
language = "en"
multilingual = false
src = "src"
title = "MapLibre Native Documentation"
title = "MapLibre Native Developer Documentation"
[output.html]
additional-css = ["diff.css"]
[preprocessor.alerts]

View File

@@ -2,13 +2,23 @@
[Introduction](./introduction.md)
- [Platforms](./platforms.md)
- [Android](./android/README.md)
- [Tests](./android/android-tests.md)
- [Documentation](./android/android-documentation.md)
- [iOS](./ios/README.md)
- [Tests](ios/ios-tests.md)
- [Documentation](ios/ios-documentation.md)
- [Design](./design/README.md)
- [Ten Thousand Foot View](design/ten-thousand-foot-view.md)
- [Coordinate System](design/coordinate-system.md)
- [Expressions](design/expressions.md)
- [Architectural Problems and Recommendations](design/archictural-problems-and-recommendations.md)
- [Android Map Rendering Data Flow](design/android-map-rendering-data-flow.md)
- [Geometry Tile Worker](design/geometry-tile-worker.md)
- [Ten Thousand Foot View](design/ten-thousand-foot-view.md)
- [Coordinate System](design/coordinate-system.md)
- [Expressions](design/expressions.md)
- [Architectural Problems and Recommendations](design/archictural-problems-and-recommendations.md)
- [Android Map Rendering Data Flow](design/android-map-rendering-data-flow.md)
- [Geometry Tile Worker](design/geometry-tile-worker.md)
- [Profiling applications that use MapLibre Native](./profiling/README.md)
- [Tracy profiling](./profiling/tracy-profiling.md)
- [Tracy profiling](./profiling/tracy-profiling.md)

View File

@@ -0,0 +1,66 @@
# MapLibre Android Developer Guide
These instructions are for developers interested in making code-level contributions to MapLibre Native for Android.
## Getting the source
Clone the git repository and pull in submodules:
```bash
git clone git@github.com:maplibre/maplibre-native.git
cd maplibre-native
git submodule update --init --recursive
cd platform/android
```
## Requirements
[Android Studio](https://developer.android.com/studio) needs to be installed.
Open the `platform/android` directory to get started.
## Setting an API Key
_The test application (used for development purposes) uses MapTiler vector tiles, which require a MapTiler account and API key._
With the first Gradle invocation, Gradle will take the value of the `MLN_API_KEY` environment variable and save it to `MapLibreAndroidTestApp/src/main/res/values/developer-config.xml`. If the environment variable wasn't set, you can edit `developer-config.xml` manually and add your API key to the `api_key` resource.
## Running the TestApp
Run the configuration for the `MapLibreAndroidTestApp` module and select a device or emulator to deploy on.
<p align="left">
<img src="https://github.com/maplibre/maplibre-native/assets/649392/5494925e-8cbb-4d5d-8033-8a2f141ede3c" alt="Android TestApp menu" width="15%"> <img src="https://github.com/maplibre/maplibre-native/assets/649392/f169db51-615d-4fca-b297-ac6197bec674" alt="Android TestApp showing Demotiles" width="15%">
</p>
## Kotlin
All new code should be written in [Kotlin](https://kotlinlang.org/).
## Style Checking
To check Kotlin style, we use [ktlint](https://pinterest.github.io/ktlint/). This linter is based on the [official Kotlin coding conventions](https://kotlinlang.org/docs/coding-conventions.html). We intergrate with it using the [kotlinder](https://github.com/jeremymailen/kotlinter-gradle) Gradle plugin.
To check the style of all Kotlin source files, use:
```
$ ./gradlew checkStyle
```
To format all Kotlin source files, use:
```
$ ./gradlew formatKotlin
```
## Benchmarks in Pull Request
To run the benchmarks (for Android) include the following line on a PR comment:
```
!benchmark android
```
## Profiling
See [Tracy Profiling](/profiling/tracy-profiling.md) to understand how Tracy can be used for profiling.

View File

@@ -0,0 +1,49 @@
# Documentation for MapLibre Android
## API Documentation
We use Dokka for the MapLibre Android API documentation. The live documentation site can be found [here](https://maplibre.org/maplibre-native/android/api/).
## Examples Documentation
The documentation site with examples uses MkDocs along with [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/). You can check out the site [here](https://maplibre.org/maplibre-native/android/examples/).
### Building
To build the Examples Documentation you need to have Docker installed.
From `platform/android`, run:
```
make mkdocs
```
Next, visit [`http://localhost:8000/maplibre-native/android/examples/`](http://localhost:8000/maplibre-native/android/examples/).
### Snippets
We use [a Markdown extension for snippets](https://facelessuser.github.io/pymdown-extensions/extensions/snippets/#snippet-sections). This way code can be referenced instead of copy pasted into the documentation. This avoids code examples from becoming out of date or failing to compile. The syntax is as follows:
````kotlin
// --8<-- [start:fun]
fun double(x: Int): Int {
return 2 * x
}
// --8<-- [end:fun]
````
Next, you'll be able to reference that piece of code in Markdown like so:
```
--8<-- "example.kt:fun"
```
Where `example.kt` is the path to the file.
### Static Assets
Static assets are ideally uploaded to the [MapLibre Native S3 Bucket](https://maplibre-native.s3.eu-central-1.amazonaws.com/index.html#android-documentation-resources/).
Please open an issue with the ARN of your AWS account to get upload privileges.
You can use the macro `{{ s3_url("filename.example") }}` which will use a CDN instead of linking to the S3 bucket directly.

View File

@@ -0,0 +1,91 @@
# MapLibre Android Tests
## Render Tests
To run the render tests for Android, run the configuration for the `androidRenderTest.app` module.
### Filtering Render Tests
You can filter the tests to run by passing a flag to the file `platform/android/src/test/render_test_runner.cpp`:
```cpp
std::vector<std::string> arguments = {..., "-f", "background-color/literal"};
```
### Viewing the Results
Once the application quits, use the Device Explorer to navigate to `/data/data/org.maplibre.render_test_runner/files`.
<img width="980" alt="image" src="https://github.com/maplibre/maplibre-native/assets/649392/0dc42d4a-6221-46b6-8352-1eb24d466e91">
Double click `android-render-test-runner-style.html`. Right click on the opened tab and select _Open In > Browser_. You should see that a single render test passed.
<img width="801" alt="image" src="https://github.com/maplibre/maplibre-native/assets/649392/33e88999-7787-492f-afd9-f5a3e3fd61f7">
Alternatively to download (and open) the results from the command line, use:
```
adb shell "run-as org.maplibre.render_test_runner cat files/metrics/android-render-test-runner-style.html" > android-render-test-runner-style.html
open android-render-test-runner-style.html
```
### Updating the Render Tests
Now let's edit `metrics/integration/render-tests/background-color/literal/style.json`, change this line:
```
"background-color": "red"
```
to
```
"background-color": "yellow"
```
We need to make sure that the new `data.zip` with the data for the render tests is installed on the device. You can use the following commands:
```
tar chf render-test/android/app/src/main/assets/data.zip --format=zip --files-from=render-test/android/app/src/main/assets/to_zip.txt
adb push render-test/android/app/src/main/assets/data.zip /data/local/tmp/data.zip
adb shell chmod 777 /data/local/tmp/data.zip
adb shell "run-as org.maplibre.render_test_runner unzip -o /data/local/tmp/data.zip -d files"
```
Rerun the render test app and reload the Device Explorer. When you re-open the HTML file with the results you should now see a failing test:
<img width="685" alt="image" src="https://github.com/maplibre/maplibre-native/assets/649392/303ad75a-cf74-4b8c-927c-c9bd59a79de4">
Now download the `actual.png` in `metrics/integration/render-tests/background-color/literal` with the Device Explorer. Replace the corresponding `expected.png` on your local file system. Upload the new render test data again and run the test app once more.
<img width="800" alt="image" src="https://github.com/maplibre/maplibre-native/assets/649392/04734c6a-9cf1-489a-b9bb-8d857581261c">
Of we don't want to commit this change. But know you can add and debug (Android) render tests.
## Instrumentation Tests
To run the instrumentation tests, choose the "Instrumentation Tests" run configuration.
Your device needs remain unlocked for the duration of the tests.
## C++ Unit Tests
There is a separate Gradle project that contains a test app which runs the C++ Unit Tests. It does not depend on the Android platform implementations.
You can find the project in `test/android.` You can open this project in Android Studio and run the C++ Tests on an Android device or Simulator.
To run a particular set of tests you can modify the `--gtest_filter` flag in `platform/android/src/test/test_runner.cpp`. See the [GoogleTest documentation](https://google.github.io/googletest/advanced.html#running-a-subset-of-the-tests) for details how to use this flag.
### AWS Device Farm
The instrumentation tests and C++ unit tests are running on AWS Device Farm. To see the results and the logs, go to:
[https://us-west-2.console.aws.amazon.com/devicefarm/home?region=us-east-1#/mobile/projects/20687d72-0e46-403e-8f03-0941850665bc/runs](https://us-west-2.console.aws.amazon.com/devicefarm/home?region=us-east-1#/mobile/projects/20687d72-0e46-403e-8f03-0941850665bc/runs).
Use the following login details (this is a read-only account):
| | |
|------------|------------|
| Alias | `maplibre` |
| Username | `maplibre` |
| Password | `maplibre` |

View File

@@ -1,3 +1,6 @@
> [!NOTE]
> These notes are partially outdated since the [renderer modularization](https://github.com/maplibre/maplibre-native/blob/main/design-proposals/2022-10-27-rendering-modularization.md).
# Design
This section is dedicated to documenting current state of MapLibre Native. [Architectural Problems and Recommendations](./archictural-problems-and-recommendations.md) section notes recommendations for future improvements from an architectural perspective.
This section is dedicated to documenting current state of MapLibre Native as of end 2022. [Architectural Problems and Recommendations](./archictural-problems-and-recommendations.md) section notes recommendations for future improvements from an architectural perspective.

View File

@@ -3,3 +3,5 @@
*[MapLibre Native](https://github.com/maplibre/maplibre-native)* is a community led fork of *Mapbox GL Native*. It's a C++ library that powers
vector maps in native applications on multiple platforms by taking stylesheets that conform to the *[MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/)*, a fork of the
Mapbox Style Spec. Since it is derived from Mapbox's original work it also uses *Mapbox Vector Tile Specification* as its choice of vector tile format.
This documentation is intended for developers of MapLibre Native. If you are interested in *using* MapLibre Native, check out the [main `README.md`](https://github.com/maplibre/maplibre-native?tab=readme-ov-file#maplibre-native) on GitHub.

View File

@@ -0,0 +1,78 @@
# MapLibre iOS Developer Guide
## Bazel
[Bazel](https://bazel.build/) is used for building on iOS.
You can generate an Xcode project thanks to [rules_xcodeproj](https://github.com/MobileNativeFoundation/rules_xcodeproj) intergration.
You need to install [bazelisk](https://github.com/bazelbuild/bazelisk), which is a wrapper around Bazel which ensures that the version specified in `.bazelversion` is used.
```
brew install bazelisk
```
### Creating `config.bzl`
Configure Bazel, otherwise the default config will get used.
```
cp platform/darwin/bazel/example_config.bzl platform/darwin/bazel/config.bzl
```
You need to set your `BUNDLE_ID_PREFIX` to be unique (ideally use a domain that you own in reverse domain name notation).
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, go to your [Apple Developer account](https://developer.apple.com/account), log in, and scroll down to find your Team ID.
If you don't already have a developer account, continue this guide and let Xcode generate a provisioning profile for you. You will need to update the Team ID later once a certificate is generated.
## Create the Xcode Project
Run the following commands:
```
bazel run //platform/ios:xcodeproj --@rules_xcodeproj//xcodeproj:extra_common_flags="--//:renderer=metal"
xed platform/ios/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.
> [!IMPORTANT]
> The Bazel configuration files are the source of truth of the build configuration. All changes to the build settings need to be done through Bazel, not in Xcode.
### Troubleshooting
#### Provisioning Profiles
If you get a Python `KeyError` when processing provisioning profiles, you probably have some _really_ old or corrupted profiles.
Have a look through `~/Library/MobileDevice/Provisioning\ Profiles` and remove any expired profiles. Removing all profiles here can also resolve some issues.
#### Cleaning Bazel environments
You should almost never have to do this, but sometimes problems can be solved with:
```
bazel clean --expunge
```
## 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 --//:renderer=metal
```
You can also build targets from the command line. For example, if you want to build your own XCFramework, see the 'Build XCFramework' step in the [iOS CI workflow](../../.github/workflows/ios-ci.yml).
## Swift App
There is also an example app built with Swift instead of Objective-C. The target is called `MapLibreApp` and the source code lives in `platform/ios/app-swift`.

View File

@@ -0,0 +1,53 @@
# iOS Documentation
We use [DocC](https://www.swift.org/documentation/docc) for the MapLibre iOS documentation. The live documentation site can be found [here](https://maplibre.org/maplibre-native/ios/latest/documentation/maplibre/).
## Resources
You need to have [aws-cli](https://github.com/aws/aws-cli) installed to download the resources from S3 (see below). Run the following command:
```
aws s3 sync --no-sign-request "s3://maplibre-native/ios-documentation-resources" "platform/ios/MapLibre.docc/Resources"
```
Then, to build the documentation locally, run the following command:
```
platform/ios/scripts/docc.sh preview
```
Resources like images should not be checked in but should be uploaded to the [S3 Bucket](https://s3.eu-central-1.amazonaws.com/maplibre-native/index.html#ios-documentation-resources/). You can share a `.zip` with all files that should be added in the PR.
If you want to get direct access you need an AWS account to get permissions to upload files. Create an account and authenticate with aws-cli. Share the account ARN that you can get with
```
aws sts get-caller-identity
```
## Examples
The code samples in the documentation should ideally be compiled on CI so they do not go out of date.
Fence your example code with
```swift
// #-example-code(LineTapMap)
...
// #-end-example-code
```
Prefix your documentation code block with
````md
<!-- include-example(LineTapMap) -->
```swift
...
```
````
Then the code block will be updated when you run:
```sh
node scripts/update-ios-examples.mjs
```

View File

@@ -0,0 +1,18 @@
# iOS Tests
## Render Tests
To run the render tests, run the `RenderTest` target from iOS.
When running in a simulator, use
```
# check for 'DataContainer' of the app with `*.maplibre.RenderTestApp` id
xcrun simctl listapps booted
```
to get the data directory of the render test app. This allows you to inspect test results. When adding new tests, the generated expectations and `actual.png` file can be copied into the source directory from here.
## C++ Unit Tests
Run the tests from the `CppUnitTests` target in Xcode to run the C++ Unit Tests on iOS.

View File

@@ -0,0 +1,56 @@
# Platforms
This page describes the platforms that MapLibre Native is available on.
## Overview
MapLibre Native uses a monorepo. Source code for all platforms lives in [`maplibre/maplibre-native`](https://github.com/maplibre/maplibre-native) on GitHub.
| Platform | Source | Notes |
|---|---|---|
| Android | [`platform/android`](https://github.com/maplibre/maplibre-native/tree/main/platform/android) | Integrates with the C++ core via JNI. |
| iOS | [`platform/ios`](https://github.com/maplibre/maplibre-native/tree/main/platform/ios), [`platform/darwin`](https://github.com/maplibre/maplibre-native/tree/main/platform/darwin) | Integrates with the C++ core via Objective-C++. |
| Linux | [`platform/linux`](https://github.com/maplibre/maplibre-native/tree/main/platform/linux) | Used for development. Also widely used in production for raster tile generation. |
| Windows | [`platform/windows`](https://github.com/maplibre/maplibre-native/tree/main/platform/windows) | |
| macOS | [`platform/macos`](https://github.com/maplibre/maplibre-native/tree/main/platform/macos), [`platform/darwin`](https://github.com/maplibre/maplibre-native/tree/main/platform/darwin) | Mainly used for development. There is some legacy AppKit code. |
| Node.js | [`platform/node`](https://github.com/maplibre/maplibre-native/tree/main/platform/node) | Uses [NAN](https://github.com/nodejs/nan). Available as [@maplibre/maplibre-gl-native](https://www.npmjs.com/package/@maplibre/maplibre-gl-native) on npm. |
| Qt | [maplibre/maplibre-qt](https://github.com/maplibre/maplibre-native/tree/main/platform/qt), [`platform/qt`](https://github.com/maplibre/maplibre-native) | Only platform that partially split to another repository. |
Of these, **Android** and **iOS** are considered [core projects](https://github.com/maplibre/maplibre/blob/main/PROJECT_TIERS.md) of the MapLibre Organization.
### GLFW
You can find an app that uses GLFW in [`platform/glfw`](https://github.com/maplibre/maplibre-native/tree/main/platform/glfw). It works on macOS, Linux and Windows. The app shows an interactive map that can be interacted with. Since GLFW adds relatively little complexity this app is used a lot for development. You can also learn about the C++ API by studying the source code of the GLFW app.
## Rendering Backends
Originally the project only supported OpenGL 2.0. In 2023, the [renderer was modularized](https://github.com/maplibre/maplibre-native/blob/main/design-proposals/2022-10-27-rendering-modularization.md) allowing for the implementation of alternate rendering backends. The first alternate rendering backend that was implemented was [Metal](https://maplibre.org/news/2024-01-19-metal-support-for-maplibre-native-ios-is-here/), followed by [Vulkan](https://maplibre.org/news/2024-12-12-maplibre-android-vulkan/). In the future other rendering backends could be implemented such as WebGPU.
What platfroms support which rendering backend can be found below.
| Platform | OpenGL ES 3.0 | Vulkan 1.0 | Metal |
|---|---|---|---|
| Android | ✅ | ✅ | ❌ |
| iOS | ❌ | ❌ | ✅ |
| Linux | ✅ | ✅ | ❌ |
| Windows | ✅ | ❌ | ❌ |
| macOS | ❌ | ✅ | ✅[^1] |
| Node.js | ✅ | ❌ | ✅ [^2] |
| Qt | ✅ | ❌ | ❌ |
[^1]: Requires MoltenVK. Only available when built via CMake.
[^2]: Issue reported, see [#2928](https://github.com/maplibre/maplibre-native/issues/2928).
## Build Tooling
In 2023 we co-opted Bazel as a build tool (generator), mostly due to it having better support for iOS compared to CMake. Some platforms can use CMake as well as Bazel.
| Platform | CMake | Bazel |
|---|---|---|
| Android | ✅ (via Gradle) | ❌ |
| iOS | ❌ | ✅ |
| Linux | ✅ | ✅ |
| Windows | ✅ | ❌ |
| macOS | ✅ | ✅ |
| Node.js | ✅ | ❌ |
| Qt | ✅ | ❌ |