Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS Metal + AppKit app #2205

Merged
merged 41 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c1f1800
macos build
louwers Mar 15, 2024
0c65a6b
it builds somehow
louwers Mar 16, 2024
d5a0dcd
add .gitignore
louwers Mar 16, 2024
779c943
Build macos_app
louwers Mar 18, 2024
9203a92
Render on macOS
louwers Mar 18, 2024
f04cf9b
Some macOS CI
louwers Mar 18, 2024
596268d
Merge branch 'main' into macos-metal
louwers Mar 18, 2024
e197e1e
Update app icons
louwers Mar 18, 2024
e1372c1
fix macos-ci
louwers Mar 18, 2024
6a66e93
Intial GLFW macOS scaffolding
louwers Mar 22, 2024
5f9e3bc
Delete some cruft and update README.md
louwers Mar 22, 2024
103d6ad
Install dependencies
louwers Mar 22, 2024
adde2dc
Update macos-ci
louwers Mar 22, 2024
c6ce91e
Add icu4c
louwers Mar 22, 2024
cc5c7dc
Add icu4c
louwers Mar 22, 2024
f81e934
Add glfw_app to Xcode project
louwers Mar 26, 2024
96dd1dc
Add MetalBackend
louwers Mar 26, 2024
c4f7dd6
Implement swap()
louwers Mar 27, 2024
c0a62a3
Set window title
louwers Mar 27, 2024
147eb49
Automatically set macOS link opt on macOS
louwers Mar 27, 2024
595732a
fix .bazelrc
louwers Mar 27, 2024
68e6b9b
Set depth stencil attachments
mwilsnd Mar 27, 2024
7a7d70d
env vars
louwers Mar 27, 2024
93ef34b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 27, 2024
672d65f
Fix backend size
mwilsnd Mar 27, 2024
1d4b237
Use framebuffer size in backend
mwilsnd Mar 27, 2024
137af3c
Some cleanup
louwers Mar 28, 2024
47ff187
CI
louwers Mar 28, 2024
079d512
Merge remote-tracking branch 'louwers/macos-metal' into macos-metal
louwers Mar 28, 2024
188eb0a
Merge branch 'main' into macos-metal
louwers Mar 28, 2024
f4927df
pre-commit and clang-format
louwers Mar 28, 2024
8e1e085
add glfw to macos-ci
louwers Mar 28, 2024
1b6e4bc
Merge remote-tracking branch 'louwers/macos-metal' into macos-metal
louwers Mar 28, 2024
2c25db8
Uncommend MLN_CUSTOM_COMBINED_BUNDLE
louwers Mar 28, 2024
e37be62
Remove focused targets
louwers Mar 28, 2024
9de30ac
Remove comment
louwers Mar 28, 2024
56ca285
Improve config loading
louwers Apr 1, 2024
a05240a
Replace with @darwin_config//:config.bzl
louwers Apr 1, 2024
2920df3
Remove print
louwers Apr 1, 2024
6005023
Fix typo
louwers Apr 1, 2024
63e0643
Update README.md
louwers Apr 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
...
97 changes: 25 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,26 @@ 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: Setup Bazel
run: cp bazel/example_config.bzl bazel/config.bzl

- 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": [],
}),
)
14 changes: 14 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "glfw",
build_file = "@//vendor:glfw.BUILD",
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",
)
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
2 changes: 2 additions & 0 deletions platform/darwin/src/MLNLocationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,12 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)startUpdatingHeading;

#if TARGET_OS_IPHONE
/**
Stops the generation of heading updates.
*/
- (void)stopUpdatingHeading;
#endif

/**
Dissmisses immediately the heading calibration view from screen.
Expand Down