Skip to content

Commit

Permalink
Allow configuring iOS build with CMake (#3234)
Browse files Browse the repository at this point in the history
  • Loading branch information
louwers authored Feb 28, 2025
1 parent 7562931 commit b09235b
Show file tree
Hide file tree
Showing 45 changed files with 696 additions and 954 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/ios-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,30 @@ jobs:
run: |
VERSION=${{ env.version }} COCOAPODS_TRUNK_TOKEN=${{ secrets.COCOAPODS_PASSWORD }} pod trunk push MapLibre.podspec
ios-build-cmake:
needs: pre_job
runs-on: macos-latest
if: needs.pre_job.outputs.should_skip != 'true'
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: Configure build with CMake
run: cmake --preset ios

- name: Build mbgl-core
run: cmake --build build-ios --target mbgl-core ios-sdk-static app

ios-ci-result:
runs-on: ubuntu-latest
if: needs.pre_job.outputs.should_skip != 'true' && always()
needs:
- pre_job
- ios-build
- ios-build-cmake
steps:
- name: Mark result as failed
if: needs.ios-build.result != 'success'
if: needs.ios-build.result != 'success' || needs.ios-build-cmake.result != 'success'
run: exit 1
13 changes: 2 additions & 11 deletions .github/workflows/node-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ jobs:
if: ${{contains(runner.name, 'GitHub Actions')}}
uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: '3.29.2'
cmake-version: '3.31'

- name: cmake version
run: |
Expand Down Expand Up @@ -204,16 +204,7 @@ jobs:
- name: Configure maplibre-native (MacOS)
if: runner.os == 'MacOS'
run: |
cmake . -B build \
-G Ninja \
-DCMAKE_BUILD_TYPE=${{ env.BUILDTYPE }} \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DMLN_WITH_NODE=ON \
-DMLN_WITH_OPENGL=OFF \
-DMLN_WITH_METAL=ON \
-DMLN_LEGACY_RENDERER=OFF \
-DMLN_DRAWABLE_RENDERER=ON \
-DMLN_WITH_WERROR=OFF
cmake --preset macos-node -DCMAKE_BUILD_TYPE=${{ env.BUILDTYPE }}
- name: Configure maplibre-native (Linux)
if: runner.os == 'Linux'
Expand Down
13 changes: 9 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ target_compile_options(
$<$<STREQUAL:${MLN_WITH_SANITIZER},undefined>:-fsanitize=float-divide-by-zero,
-fsanitize-blacklist=${UBSAN_BLACKLIST}>
$<$<PLATFORM_ID:iOS>:-fembed-bitcode>
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<NOT:$<OR:$<BOOL:${MLN_WITH_RTTI}>,$<CXX_COMPILER_ID:MSVC>>>>:-fno-rtti>
$<$<AND:$<OR:$<COMPILE_LANGUAGE:CXX>,$<COMPILE_LANGUAGE:OBJCXX>>,$<NOT:$<OR:$<BOOL:${MLN_WITH_RTTI}>,$<CXX_COMPILER_ID:MSVC>>>>:-fno-rtti>
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<NOT:$<PLATFORM_ID:Windows>>>:-Wall>
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<NOT:$<PLATFORM_ID:Windows>>>:-Wshadow>
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<NOT:$<PLATFORM_ID:Windows>>>:-Wextra>
Expand Down Expand Up @@ -1268,6 +1268,7 @@ if(MLN_WITH_METAL)
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/raster.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/symbol.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/widevector.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/layers/mtl/custom_layer_render_parameters.cpp
)

find_library(METAL_FRAMEWORK Metal)
Expand Down Expand Up @@ -1372,12 +1373,12 @@ endif()
if(MLN_DRAWABLE_RENDERER)
list(APPEND
SRC_FILES
${PROJECT_SOURCE_DIR}/src/mbgl/style/layers/custom_drawable_layer.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/layermanager/custom_drawable_layer_factory.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/layers/custom_drawable_layer_impl.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/layers/custom_drawable_layer_impl.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/renderer/layers/render_custom_drawable_layer.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/renderer/layers/render_custom_drawable_layer.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/layers/custom_drawable_layer_impl.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/layers/custom_drawable_layer_impl.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/layers/custom_drawable_layer.cpp
)
endif()

Expand Down Expand Up @@ -1579,7 +1580,11 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Android)
elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
include(${PROJECT_SOURCE_DIR}/platform/linux/linux.cmake)
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
include(${PROJECT_SOURCE_DIR}/platform/darwin/darwin.cmake)
include(${PROJECT_SOURCE_DIR}/platform/macos/macos.cmake)
elseif(CMAKE_SYSTEM_NAME STREQUAL iOS)
include(${PROJECT_SOURCE_DIR}/platform/darwin/darwin.cmake)
include(${PROJECT_SOURCE_DIR}/platform/ios/ios.cmake)
elseif(WIN32)
include(${PROJECT_SOURCE_DIR}/platform/windows/windows.cmake)
else()
Expand Down
59 changes: 59 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"version": 10,
"cmakeMinimumRequired": {
"major": 3,
"minor": 21,
"patch": 0
},
"configurePresets": [
{
"name": "ios",
"displayName": "iOS",
"generator": "Xcode",
"description": "Create Xcode project for iOS",
"binaryDir": "${sourceDir}/build-ios",
"cacheVariables": {
"CMAKE_SYSTEM_NAME": "iOS",
"CMAKE_CXX_COMPILER_LAUNCHER": "ccache",
"MLN_WITH_METAL": "ON",
"MLN_WITH_OPENGL": "OFF",
"MLN_DRAWABLE_RENDERER": "ON"
}
},
{
"name": "macos",
"displayName": "macOS",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build-macos",
"cacheVariables": {
"CMAKE_SYSTEM_NAME": "Darwin",
"CMAKE_CXX_COMPILER_LAUNCHER": "ccache",
"MLN_WITH_METAL": "ON",
"MLN_WITH_OPENGL": "OFF",
"MLN_DRAWABLE_RENDERER": "ON"
}
},
{
"name": "macos-vulkan",
"displayName": "macOS",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build-macos-vulkan",
"cacheVariables": {
"CMAKE_SYSTEM_NAME": "Darwin",
"CMAKE_CXX_COMPILER_LAUNCHER": "ccache",
"MLN_WITH_VULKAN": "ON",
"MLN_WITH_OPENGL": "OFF",
"MLN_DRAWABLE_RENDERER": "ON"
}
},
{
"name": "macos-node",
"inherits": "macos",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"MLN_WITH_NODE": "ON",
"MLN_WITH_WERROR": "OFF"
}
}
]
}
18 changes: 16 additions & 2 deletions docs/mdbook/src/ios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ 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
## CMake

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`.
It is also possible to generate an Xcode project using CMake. As of February 2025, targets `mbgl-core`, `ios-sdk-static` and `app` (Objective-C development app) are supported.

```
cmake --preset ios -DDEVELOPMENT_TEAM_ID=YOUR_TEAM_ID
xed build-ios/MapLibre\ Native.xcodeproj
```

## Distribution

MapLibre iOS is distributed as an XCFramework via the [maplibre/maplibre-gl-native-distribution](https://github.com/maplibre/maplibre-gl-native-distribution) repository. See [Release MapLibre iOS](./release.md) for the release process. Refer to the [`ios-ci.yml`](https://github.com/maplibre/maplibre-native/blob/main/.github/workflows/ios-ci.yml) workflow for an up-to-date recipe for building an XCFramework. As of February 2025 we use:

```
bazel build --compilation_mode=opt --features=dead_strip,thin_lto --objc_enable_binary_stripping \
--apple_generate_dsym --output_groups=+dsyms --//:renderer=metal //platform/ios:MapLibre.dynamic --embed_label=maplibre_ios_"$(cat VERSION)"
```
7 changes: 5 additions & 2 deletions docs/mdbook/src/platforms.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ In 2023 we co-opted Bazel as a build tool (generator), mostly due to it having b
| Platform | CMake | Bazel |
|---|---|---|
| Android | ✅ (via Gradle) ||
| iOS | ||
| iOS | [^3] ||
| Linux |||
| Windows || |
| Windows || |
| macOS |||
| Node.js |||
| Qt |||


[^3]: Some targets are supported, see [here](ios/README.md#cmake).
2 changes: 1 addition & 1 deletion include/mbgl/mtl/index_buffer_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace mtl {

class IndexBufferResource : public gfx::IndexBufferResource {
public:
IndexBufferResource() noexcept = default;
IndexBufferResource() noexcept = delete;
IndexBufferResource(BufferResource&&) noexcept;
IndexBufferResource(IndexBufferResource&& other) noexcept
: buffer(std::move(other.buffer)) {}
Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/mtl/vertex_buffer_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace mtl {

class VertexBufferResource : public gfx::VertexBufferResource {
public:
VertexBufferResource() noexcept = default;
VertexBufferResource() noexcept = delete;
VertexBufferResource(BufferResource&&) noexcept;
VertexBufferResource(VertexBufferResource&& other) noexcept
: buffer(std::move(other.buffer)) {}
Expand Down
25 changes: 13 additions & 12 deletions platform/darwin/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ cc_library(
objc_library(
name = "darwin-objc",
srcs = [
"src/native_apple_interface.m",
"core/native_apple_interface.m",
],
hdrs = [
"include/mbgl/interface/native_apple_interface.h",
Expand All @@ -227,15 +227,15 @@ objc_library(
objc_library(
name = "darwin-objcpp",
srcs = [
"core/collator.mm",
"core/http_file_source.mm",
"core/image.mm",
"core/local_glyph_rasterizer.mm",
"core/logging_nslog.mm",
"core/nsthread.mm",
"core/number_format.mm",
"core/string_nsstring.mm",
"src/CFHandle.hpp",
"src/collator.mm",
"src/http_file_source.mm",
"src/image.mm",
"src/local_glyph_rasterizer.mm",
"src/logging_nslog.mm",
"src/nsthread.mm",
"src/number_format.mm",
"src/string_nsstring.mm",
] + select({
"//:metal_renderer": [],
"//conditions:default": ["src/headless_backend_eagl.mm"],
Expand All @@ -252,6 +252,7 @@ objc_library(
],
includes = [
"include",
"src",
],
sdk_frameworks = [
"CoreText",
Expand All @@ -269,9 +270,9 @@ objc_library(
objc_library(
name = "darwin-loop",
srcs = [
"src/async_task.cpp",
"src/run_loop.cpp",
"src/timer.cpp",
"core/async_task.cpp",
"core/run_loop.cpp",
"core/timer.cpp",
] + select({
"//:metal_renderer": [],
"//conditions:default": ["src/gl_functions.cpp"],
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ void cancel() {
public:
Impl(const ResourceOptions& resourceOptions_, const ClientOptions& clientOptions_)
: resourceOptions(resourceOptions_.clone()), clientOptions(clientOptions_.clone()) {
@autoreleasepool {
NSURLSessionConfiguration *sessionConfig = MLNNativeNetworkManager.sharedManager.sessionConfiguration;
session = [NSURLSession sessionWithConfiguration:sessionConfig];

Expand All @@ -95,8 +94,6 @@ void cancel() {
} else {
userAgent = sessionConfig.HTTPAdditionalHeaders[@"User-Agent"];
}

}
}

void setResourceOptions(ResourceOptions options);
Expand Down Expand Up @@ -280,7 +277,7 @@ BOOL isValidMapboxEndpoint(NSURL *url) {
[MLNNativeNetworkManager.sharedManager startDownloadEvent:url.relativePath type:@"tile"];
}

__block NSURLSession *session;
__block NSURLSession *session = nil;

// Use the delegate's session if there is one, otherwise use the one that
// was created when this class was constructed.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit b09235b

Please sign in to comment.