Skip to content

Commit

Permalink
macOS Metal + AppKit app (#2205)
Browse files Browse the repository at this point in the history
Co-authored-by: mwilsnd <mwilsnd@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 1, 2024
1 parent adf029c commit e4a4b9e
Show file tree
Hide file tree
Showing 97 changed files with 950 additions and 3,948 deletions.
6 changes: 3 additions & 3 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# https://github.com/aspect-build/rules_js/issues/1408
startup --host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1

# TODO: remove with bazel 7.x
common --enable_bzlmod

common --enable_platform_specific_config
# TODO: remove once bazel flips this flag
common --incompatible_disallow_empty_glob

coverage --experimental_ui_max_stdouterr_bytes=10485760

common:macos --linkopt=-L/opt/homebrew/lib
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.0.0
7.1.0
6 changes: 5 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ BinPackParameters: false
ColumnLimit: 120
IncludeBlocks: Preserve
IndentWidth: 4
Language: Cpp
PackConstructorInitializers: Never
PenaltyBreakAssignment: 80
SortIncludes: false
SpacesBeforeTrailingComments: 1
Standard: c++17
---
Language: Cpp
---
Language: ObjC
BasedOnStyle: Google
...
2 changes: 0 additions & 2 deletions .github/workflows/ios-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ jobs:
${{ runner.os }}-bazel-
path: ~/.cache/bazel

- run: cp bazel/example_config.bzl bazel/config.bzl

- name: Check debug symbols
run: bazel run //platform:check-public-symbols --//:renderer=metal

Expand Down
94 changes: 22 additions & 72 deletions .github/workflows/macos-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,11 @@ on:
workflow_dispatch:
push:
branches:
- opengl-2
- macos-*.*.x
tags:
- 'macos-*'
paths:
- CMakeLists.txt
- 'platform/ios/**'
- 'platform/darwin/**'
- ".github/workflows/macos-ci.yml"
- "bin/**"
- "expression-test/**"
- "include/**"
- "metrics/**"
- "platform/default/**"
- "render-test/**"
- "scripts/**"
- "src/**"
- "test/**"
- "vendor/**"
- ".gitmodules"
- "!**/*.md"
- main

pull_request:
branches:
- opengl-2
paths:
- CMakeLists.txt
- 'platform/ios/**'
- 'platform/darwin/**'
- ".github/workflows/macos-ci.yml"
- "bin/**"
- "expression-test/**"
- "include/**"
- "metrics/**"
- "platform/default/**"
- "render-test/**"
- "scripts/**"
- "src/**"
- "test/**"
- "vendor/**"
- ".gitmodules"
- "!**/*.md"
- main

concurrency:
# cancel jobs on PRs only
Expand All @@ -55,15 +18,10 @@ concurrency:
jobs:
build:
name: MacOS CI Tests
runs-on: [self-hosted, macOS, ARM64]
env:
BUILDTYPE: Debug
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_NO_INSTALL_CLEANUP: 1

runs-on: [macos-14]
defaults:
run:
working-directory: platform/ios
working-directory: platform/macos
shell: bash

steps:
Expand All @@ -72,31 +30,23 @@ jobs:
submodules: recursive
fetch-depth: 0

- uses: actions/setup-node@v4
- name: Cache Bazel
uses: actions/cache@v4
with:
node-version: 18

- name: npm install
run: npm ci --ignore-scripts

- name: Run macOS Objective-C tests
run: |
../macos/scripts/run-in-macos-gui-env.sh "make macos-test"
- name: npm install # C++ tests are run with root as working directory
run: npm ci --ignore-scripts
working-directory: .

- name: Run macOS C++ unit tests
key: ${{ runner.os }}-bazel-${{ hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE', 'WORKSPACE.bazel', 'MODULE.bazel') }}
restore-keys: |
${{ runner.os }}-bazel-
path: ~/.cache/bazel

- name: Install dependencies
run: |
cmake -S . -B "$BUILD_DIR"
cmake --build "$BUILD_DIR" --target mbgl-test-runner
ctest -VV --test-dir "$BUILD_DIR" -R mbgl-test-runner
env:
BUILD_DIR: ../../../maplibre-gl-native-macostestbuild

- name: Check public symbols
run: make darwin-check-public-symbols

- name: Lint plist files
run: make macos-lint
brew install bazelisk webp libuv webp icu4c jpeg-turbo glfw
brew link icu4c --force
- name: Build AppKit app, GLFW app, cache tool, render tool for macOS
run: bazel build //platform/macos/app:macos_app //platform/glfw:glfw_app //bin:cache_tool //bin:render_tool --//:renderer=metal

- name: Generate Xcode project for macOS
run: bazel run //platform/macos:xcodeproj --@rules_xcodeproj//xcodeproj:extra_common_flags="--//:renderer=metal"


1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ repos:
rev: v4.5.0
hooks:
- id: check-yaml
args: [--allow-multiple-documents]
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.2
hooks:
Expand Down
13 changes: 13 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ cc_library(
"@platforms//os:ios": [
"//vendor:icu",
],
"@platforms//os:osx": [
"//vendor:icu",
],
"//conditions:default": [],
}) + select({
":metal_renderer": [
Expand Down Expand Up @@ -240,3 +243,13 @@ js_library(
":node_modules/ejs",
],
)

cc_library(
name = "maplibre_lib",
srcs = [],
visibility = ["//visibility:public"],
deps = select({
"@platforms//os:macos": ["//platform:macos-objcpp"],
"//conditions:default": [],
}),
)
20 changes: 20 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//platform/darwin:bazel/darwin_config_repository_rule.bzl", "darwin_config")

http_archive(
name = "glfw",
build_file = "@//vendor:glfw.BUILD",
integrity = "sha256-tewASycS/Qjohh3CcUKPBId1IAot9xnM9XUUO6dJo+k=",
strip_prefix = "glfw-3.4",
url = "https://github.com/glfw/glfw/releases/download/3.4/glfw-3.4.zip",
)

new_local_repository(
name = "libuv",
build_file = "@//vendor:libuv.BUILD",
path = "/opt/homebrew/opt/libuv",
)

darwin_config(
name = "darwin_config",
)
8 changes: 8 additions & 0 deletions bazel/flags.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ WARNING_FLAGS = {
"-Wno-tautological-constant-compare",
"-Wno-gnu-anonymous-struct",
] + GCC_CLANG_COMMON_FLAGS,
"macos": [
"-Wno-newline-eof",
"-Wno-nested-anon-types",
"-Wno-c++11-narrowing",
"-Wno-pointer-to-int-cast",
"-Wno-tautological-constant-compare",
"-Wno-gnu-anonymous-struct",
] + GCC_CLANG_COMMON_FLAGS,
"linux": GCC_CLANG_COMMON_FLAGS,
"windows": MSVC_FLAGS,
}
Expand Down
23 changes: 23 additions & 0 deletions bin/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
load("//bazel:flags.bzl", "CPP_FLAGS", "MAPLIBRE_FLAGS")

cc_binary(
name = "cache_tool",
srcs = [
"cache.cpp",
],
copts = CPP_FLAGS + MAPLIBRE_FLAGS,
deps = [
"//platform:macos-objcpp",
],
)

cc_binary(
name = "render_tool",
srcs = [
"render.cpp",
],
copts = CPP_FLAGS + MAPLIBRE_FLAGS,
deps = [
"//platform:macos-objcpp",
],
)
2 changes: 1 addition & 1 deletion bin/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <fstream>

int main(int argc, char* argv[]) {
args::ArgumentParser argumentParser("Mapbox GL render tool");
args::ArgumentParser argumentParser("MapLibre Native render tool");
args::HelpFlag helpFlag(argumentParser, "help", "Display this help menu", {"help"});

args::ValueFlag<std::string> backendValue(argumentParser, "Backend", "Rendering backend", {"backend"});
Expand Down
10 changes: 5 additions & 5 deletions include/mbgl/gfx/backend_scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ class RendererBackend;

class BackendScope {
public:
/// There are two types of scopes: Creating an "Implicit" scope tells Mapbox
/// GL that the supporting windowing system has already activated the GL
/// Backend and that no further actions are required. Creating an "Explicit"
/// scope actually enables the GL Backend, and disables it when the
/// BackendScope is destroyed.
/// There are two types of scopes: Creating an "Implicit" scope tells MapLibre
/// Native that the supporting windowing system has already activated the
/// RenderBackend and that no further actions are required. Creating an "Explicit"
/// scope (the default) actually enables the RenderBackend, and disables it when
/// the BackendScope is destroyed.
enum class ScopeType : bool {
Implicit,
Explicit,
Expand Down
83 changes: 81 additions & 2 deletions platform/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,82 @@
load("@aspect_rules_js//js:defs.bzl", "js_binary")
load("//bazel:flags.bzl", "CPP_FLAGS", "MAPLIBRE_FLAGS", "WARNING_FLAGS")

objc_library(
name = "macos-objcpp",
srcs = [
"//platform/darwin:darwin_objcpp_custom_drawable_srcs",
"//platform/darwin:darwin_objcpp_srcs",
"//platform/darwin:darwin_private_hdrs",
"//platform/darwin:generated_style_srcs",
"//platform/macos:macos_objcpp_srcs",
"//platform/macos:macos_private_hdrs",
"//platform/macos:macos_public_hdrs",
],
hdrs = [
"//platform/darwin:include/mbgl/util/image+MLNAdditions.hpp",
],
copts = CPP_FLAGS + MAPLIBRE_FLAGS + [
"-fcxx-modules",
"-fmodules",
"-Wno-vla-extension",
"-Wno-gnu-conditional-omitted-operand",
"-Wno-deprecated-declarations",
],
includes = [
"darwin/include",
"darwin/src",
"macos/src",
],
module_name = "MapLibre",
sdk_frameworks = [
"Metal",
"MetalKit",
"QuartzCore",
"CoreGraphics",
"CoreLocation",
"AppKit",
"SystemConfiguration",
],
visibility = ["//visibility:public"],
deps = [
"macos-objc",
"//:mbgl-core",
"//platform/darwin:darwin-generated-style-artifacts",
"//platform/darwin:darwin-objcpp",
"//platform/default:mbgl-default",
],
)

objc_library(
name = "macos-objc",
srcs = [
"//platform/darwin:darwin_objc_hdrs",
"//platform/darwin:darwin_objc_srcs",
"//platform/darwin:darwin_private_hdrs",
"//platform/macos:macos_objc_srcs",
"//platform/macos:macos_private_hdrs",
"//platform/macos:macos_public_hdrs",
],
copts = select({
"@platforms//os:ios": WARNING_FLAGS["ios"],
"@platforms//os:macos": WARNING_FLAGS["macos"],
}) + MAPLIBRE_FLAGS + [
"-fmodules",
"-Wno-deprecated-declarations",
],
includes = [
"darwin/include",
"darwin/src",
],
visibility = ["//visibility:public"],
deps = [
"//:mbgl-core",
"//platform/darwin:darwin-generated-style-artifacts",
"//platform/darwin:darwin-objc",
"//platform/default:mbgl-default",
],
)

# Objcpp files for the iOS source
objc_library(
name = "objcpp-sdk",
Expand Down Expand Up @@ -68,7 +144,10 @@ objc_library(
hdrs = [
"//platform/darwin:include/mbgl/util/image+MLNAdditions.hpp",
],
copts = WARNING_FLAGS["ios"] + MAPLIBRE_FLAGS + [
copts = select({
"@platforms//os:ios": WARNING_FLAGS["ios"],
"@platforms//os:macos": WARNING_FLAGS["macos"],
}) + MAPLIBRE_FLAGS + [
"-fmodules",
"-Wno-gnu-zero-variadic-macro-arguments",
"-Wno-variadic-macros",
Expand Down Expand Up @@ -187,9 +266,9 @@ objc_library(
objc_library(
name = "iosapp",
srcs = [
"//platform/ios:ios_app_srcs",
"//platform/darwin:app/CustomStyleLayerExample.h",
"//platform/darwin:app/CustomStyleLayerExample.m",
"//platform/ios:ios_app_srcs",
],
defines = ["GLES_SILENCE_DEPRECATION"],
includes = [
Expand Down
1 change: 1 addition & 0 deletions platform/darwin/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ objc_library(
],
visibility = ["//visibility:public"],
deps = [
"darwin-objc",
"//:mbgl-core",
"//platform/default:mbgl-default",
],
Expand Down
File renamed without changes.

0 comments on commit e4a4b9e

Please sign in to comment.