From ffe4b94a6caabd474e5d86f7d094bd58ed536595 Mon Sep 17 00:00:00 2001 From: utzcoz Date: Tue, 4 Aug 2026 22:56:57 +0800 Subject: [PATCH 1/5] host: propagate createBlob failures stream_renderer_create_blob() reported success unconditionally, so a caller could not tell that a blob had failed to be created. Return what it actually did, and check it. --- host/color_buffer.cpp | 6 ++++++ host/virtio_gpu_gfxstream_renderer.cpp | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/host/color_buffer.cpp b/host/color_buffer.cpp index 2733c4a6e..e150110de 100644 --- a/host/color_buffer.cpp +++ b/host/color_buffer.cpp @@ -27,7 +27,9 @@ namespace gfxstream { namespace host { namespace { +#if GFXSTREAM_ENABLE_HOST_GLES using gl::ColorBufferGl; +#endif using vk::ColorBufferVk; // ColorBufferVk natively supports YUV images. However, ColorBufferGl @@ -158,7 +160,11 @@ std::unique_ptr ColorBuffer::Impl::create( #endif if (emulationVk) { +#if GFXSTREAM_ENABLE_HOST_GLES const bool vulkanOnly = colorBuffer->mColorBufferGl == nullptr; +#else + const bool vulkanOnly = true; +#endif const uint32_t memoryProperty = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; const uint32_t mipLevels = 1; colorBuffer->mColorBufferVk = vk::ColorBufferVk::create( diff --git a/host/virtio_gpu_gfxstream_renderer.cpp b/host/virtio_gpu_gfxstream_renderer.cpp index a92b96020..a8a1768d1 100644 --- a/host/virtio_gpu_gfxstream_renderer.cpp +++ b/host/virtio_gpu_gfxstream_renderer.cpp @@ -450,8 +450,7 @@ VG_EXPORT int stream_renderer_create_blob(uint32_t ctx_id, uint32_t res_handle, GFXSTREAM_TRACE_EVENT(GFXSTREAM_TRACE_STREAM_RENDERER_CATEGORY, "stream_renderer_create_blob()"); - sFrontend()->createBlob(ctx_id, res_handle, create_blob, handle); - return 0; + return sFrontend()->createBlob(ctx_id, res_handle, create_blob, handle); } VG_EXPORT int stream_renderer_export_blob(uint32_t res_handle, From ed06b96dea4d1bdf190014759293b08c7f379ece Mon Sep 17 00:00:00 2001 From: utzcoz Date: Tue, 4 Aug 2026 22:56:57 +0800 Subject: [PATCH 2/5] common: use shm_open on macOS and give shm names a leading slash macOS has no memfd_create(), so shared memory there is created with shm_open() instead. POSIX requires a shared memory name to begin with a slash, and macOS enforces it, so normalize the name on every platform rather than only where it is checked. --- common/base/SharedMemory_posix.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/common/base/SharedMemory_posix.cpp b/common/base/SharedMemory_posix.cpp index 638751a07..efd971c4a 100644 --- a/common/base/SharedMemory_posix.cpp +++ b/common/base/SharedMemory_posix.cpp @@ -55,7 +55,10 @@ SharedMemory::SharedMemory(const std::string& name, size_t size) { mName = PathUtils::recompose(PathUtils::decompose(std::move(path))); } else { mShareType = ShareType::SHARED_MEMORY; - mName = name; + // POSIX.1-2017 (System Interfaces) requires shm_open() names to begin + // with a '/' character to avoid implementation-defined behavior. + // Normalize unconditionally so callers don't need to care about it. + mName = (!name.empty() && name[0] != '/') ? ("/" + name) : name; } } @@ -111,7 +114,9 @@ int SharedMemory::openInternal(int oflag, int mode, bool doMapping) { int err = 0; struct stat sb; if (mShareType == ShareType::SHARED_MEMORY) { -#if defined(HAVE_MEMFD_CREATE) +#if defined(__APPLE__) + mFd = ::shm_open(mName.c_str(), oflag, mode); +#elif defined(HAVE_MEMFD_CREATE) mFd = memfd_create(mName.c_str(), MFD_CLOEXEC | MFD_ALLOW_SEALING); #else mFd = syscall(__NR_memfd_create, mName.c_str(), FD_CLOEXEC); From bacfef92c1bcb124cfbd458651f5e12c724dc465 Mon Sep 17 00:00:00 2001 From: utzcoz Date: Tue, 4 Aug 2026 22:57:17 +0800 Subject: [PATCH 3/5] host: build the gfxstream host backend on macOS Get the host backend compiling on macOS with all three build systems. Meson: - Enable the objc and objcpp languages on Darwin, so that meson can configure at all with mac_native.m and native_sub_window_cocoa.mm in the tree. Declaring them in project() instead would make meson probe for an Objective-C compiler everywhere, which fails on toolchains built without one; every Objective-C source here is already behind a Darwin guard. - Give the Vulkan-only build the GL include paths it needs: the Vulkan server includes the GLES dispatch headers regardless of which decoders are enabled. - Link the Apple frameworks the host backend needs, build the Objective-C sources, and require xcb only off-Apple. - Fix leftover includes of "GlesCompat.h" from before the rename. CMake: - Same framework, Objective-C and NEON ISA handling as the Meson build. Bazel: - Register the Apple CC (Xcode) toolchain via apple_support. The hermetic LLVM toolchain registered next to it cannot compile Objective-C, which the macOS window and context sources are written in. The Apple toolchain is constrained to Apple platforms, so toolchain resolution elsewhere is unaffected. - Raise the deployment target to 11.0. The default of 10.11 is no longer supported by the current SDK's libc++, which surfaces as a -Werror failure. - Compile the Objective-C sources with -fno-objc-arc. They use manual reference counting, and objc_library turns ARC on by default. - Give the platform selects in glslang and swiftshader a macOS arm so that the target graph resolves on Darwin. Host: - EGLNativeWindowType was typedef'd as unsigned int in gles_compat.h, which truncates pointers on 64-bit; native_sub_window_cocoa.mm returns an NSView* through it. - Create the display surface through VK_USE_PLATFORM_METAL_EXT rather than VK_USE_PLATFORM_MACOS_MVK. vkCreateMetalSurfaceEXT is the entry point the surrounding code already calls, and it is the one MoltenVK exposes. Test (macOS on Apple Silicon): bazel build --graphics_drivers=gles_angle_vulkan_swiftshader \ //host:gfxstream_backend_static \ //host:gfxstream_backend_shared \ //host:gfxstream_backend meson setup -Ddefault_library=static -Dgfxstream-build=host build meson compile -C build cmake -S . -B cmake-build -G Ninja ninja -C cmake-build Co-Authored-By: Eric Curtin --- .bazelrc | 6 +++++ CMakeLists.txt | 3 --- MODULE.bazel | 18 +++++++++++++++ common/base/BUILD.bazel | 3 +++ common/base/meson.build | 5 +++++ host/BUILD.bazel | 3 +++ host/CMakeLists.txt | 14 +++++------- host/frame_buffer.h | 2 +- host/gl/glestranslator/egl/BUILD.bazel | 3 +++ host/gl/glestranslator/egl/meson.build | 5 +++++ host/gl/meson.build | 6 ----- host/gles_compat.h | 5 ++++- host/meson.build | 22 ++++++++++++++----- host/native_sub_window.h | 2 +- host/vulkan/display_surface_vk.cpp | 2 +- meson.build | 12 ++++++++++ third_party/CMakeLists.txt | 13 +++++++---- third_party/glslang/BUILD.glslang.bazel | 9 ++++++++ third_party/meson.build | 6 ++++- .../swiftshader/BUILD.swiftshader.bazel | 8 +++++++ 20 files changed, 116 insertions(+), 31 deletions(-) diff --git a/.bazelrc b/.bazelrc index d758a82f0..edc6d551a 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,6 +1,12 @@ # TODO: fixup shared library usage. build --noexperimental_link_static_libraries_once +# Raise the macOS deployment target. The default (10.11) is no longer supported +# by the current SDK's libc++, which turns into a -Werror build failure. Applies +# to both target and exec (host) configurations. No effect on non-macOS builds. +build --macos_minimum_os=11.0 +build --host_macos_minimum_os=11.0 + # Graphics testing environments options: # # * diff --git a/CMakeLists.txt b/CMakeLists.txt index 32b3730c1..639baebf7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,9 +47,6 @@ option(BUILD_GRAPHICS_DETECTOR "Build the graphics detector utility" OFF) if (WIN32) add_definitions("-DUNICODE -D_UNICODE -DNOMINMAX -DEMUGL_BUILD -DVK_USE_PLATFORM_WIN32_KHR -DBUILDING_EMUGL_COMMON_SHARED") endif() -if (APPLE) - add_definitions("-DVK_USE_PLATFORM_METAL_EXT -DVK_USE_PLATFORM_MACOS_MVK") -endif() option(VIRGL_RENDERER_UNSTABLE_APIS "Use unstable virglrenderer APIs" ON) if(VIRGL_RENDERER_UNSTABLE_APIS) diff --git a/MODULE.bazel b/MODULE.bazel index 1d4976dcc..58f85e23d 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -15,11 +15,29 @@ bazel_dep(name = "abseil-cpp", version = "20260107.0", dev_dependency = True) bazel_dep(name = "aspect_bazel_lib", version = "2.22.5", dev_dependency = True) bazel_dep(name = "bazel_skylib", version = "1.7.1", dev_dependency = True) bazel_dep(name = "toolchains_llvm", version = "1.6.0", dev_dependency = True) +bazel_dep(name = "apple_support", version = "1.21.0", repo_name = "build_bazel_apple_support", dev_dependency = True) bazel_dep(name = "rules_python", version = "1.5.0", dev_dependency = True) bazel_dep(name = "rules_shell", version = "0.6.1", dev_dependency = True) bazel_dep(name = "rules_rust", version = "0.68.1", dev_dependency = True) bazel_dep(name = "zlib", version = "1.3.1.bcr.3", dev_dependency = True) +# Register the Apple CC (Xcode) toolchain so that `objc_library`/`.mm` targets can +# be compiled on macOS. The hermetic LLVM toolchain registered below does not +# support Objective-C compilation. This must be registered before the LLVM +# toolchain so that it is selected first when targeting macOS; the Apple toolchain +# is constrained to Apple platforms, so Linux/other builds still use LLVM. +apple_cc_configure = use_extension( + "@build_bazel_apple_support//crosstool:setup.bzl", + "apple_cc_configure_extension", + dev_dependency = True, +) +use_repo(apple_cc_configure, "local_config_apple_cc_toolchains") + +register_toolchains( + "@local_config_apple_cc_toolchains//:all", + dev_dependency = True, +) + llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm", dev_dependency = True) llvm.toolchain( llvm_version = "18.1.8", diff --git a/common/base/BUILD.bazel b/common/base/BUILD.bazel index 1c3ae6942..dde59b331 100644 --- a/common/base/BUILD.bazel +++ b/common/base/BUILD.bazel @@ -36,6 +36,9 @@ objc_library( srcs = [ "system-native-mac.mm", ], + # These sources use manual reference counting (retain/release, CFRelease), + # so disable ARC which objc_library enables by default. + copts = ["-fno-objc-arc"], sdk_frameworks = [ "IOKit", "AppKit", diff --git a/common/base/meson.build b/common/base/meson.build index 49589fd31..cea9d445b 100644 --- a/common/base/meson.build +++ b/common/base/meson.build @@ -27,6 +27,11 @@ if host_machine.system() == 'windows' files_lib_common_base += 'SharedMemory_win32.cpp' files_lib_common_base += 'Thread_win32.cpp' files_lib_common_base += 'Win32UnicodeString.cpp' +elif host_machine.system() == 'darwin' + files_lib_common_base += 'SharedMemory_posix.cpp' + files_lib_common_base += 'Thread_pthread.cpp' + files_lib_common_base += 'system-native-mac.mm' + common_base_deps += dependency('appleframeworks', modules: ['Foundation', 'AppKit', 'IOKit']) else files_lib_common_base += 'SharedMemory_posix.cpp' files_lib_common_base += 'Thread_pthread.cpp' diff --git a/host/BUILD.bazel b/host/BUILD.bazel index 152d9130b..8ce64ed75 100644 --- a/host/BUILD.bazel +++ b/host/BUILD.bazel @@ -107,6 +107,9 @@ objc_library( ], copts = GFXSTREAM_HOST_COPTS + [ "-Wno-deprecated-declarations", + # These sources use manual reference counting, so disable ARC which + # objc_library enables by default. + "-fno-objc-arc", ], defines = GFXSTREAM_HOST_DEFINES, sdk_frameworks = [ diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index e638ec874..a09365316 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -144,10 +144,12 @@ target_link_libraries( gfxstream_openglesdispatch gfxstream-gl-server gfxstream-vulkan-server - gfxstream_xcb_headers GLES_CM_translator_static renderControl_dec ) +if(NOT APPLE AND NOT WIN32) + target_link_libraries(gfxstream_backend_static PUBLIC gfxstream_xcb_headers) +endif() target_include_directories( gfxstream_backend_static @@ -357,18 +359,14 @@ endfunction() Vulkan_unittests PUBLIC "-framework AppKit") - endif() - discover_tests( - Vulkan_unittests - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) - - if (APPLE) - target_compile_definitions(Vulkan_unittests PRIVATE -DVK_USE_PLATFORM_METAL_EXT) elseif (QNX) target_compile_definitions(Vulkan_unittests PRIVATE -DVK_USE_PLATFORM_SCREEN_QNX) elseif (UNIX) target_compile_definitions(Vulkan_unittests PRIVATE -DVK_USE_PLATFORM_XCB_KHR) endif() + discover_tests( + Vulkan_unittests + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) file(GLOB Vulkan_unittests_datafiles "vulkan/testdata/*.png") diff --git a/host/frame_buffer.h b/host/frame_buffer.h index 95c9526bf..865f31424 100644 --- a/host/frame_buffer.h +++ b/host/frame_buffer.h @@ -25,7 +25,7 @@ #include #include #else -#include "GlesCompat.h" +#include "gles_compat.h" #endif // GFXSTREAM_ENABLE_HOST_GLES #include diff --git a/host/gl/glestranslator/egl/BUILD.bazel b/host/gl/glestranslator/egl/BUILD.bazel index c34d0e2e6..25899ad36 100644 --- a/host/gl/glestranslator/egl/BUILD.bazel +++ b/host/gl/glestranslator/egl/BUILD.bazel @@ -15,6 +15,9 @@ objc_library( copts = GFXSTREAM_HOST_COPTS + [ "-Wno-deprecated-declarations", "-Wno-incompatible-pointer-types", + # These sources use manual reference counting, so disable ARC which + # objc_library enables by default. + "-fno-objc-arc", ], defines = GFXSTREAM_HOST_DEFINES, sdk_frameworks = [ diff --git a/host/gl/glestranslator/egl/meson.build b/host/gl/glestranslator/egl/meson.build index 7b3834650..683d36f2a 100644 --- a/host/gl/glestranslator/egl/meson.build +++ b/host/gl/glestranslator/egl/meson.build @@ -39,8 +39,10 @@ egl_cpp_args = [ '-Wno-inconsistent-missing-override', ] +egl_deps = [] if host_machine.system() == 'darwin' files_lib_egl_translator += files_egl_darwin + egl_deps += dependency('appleframeworks', modules: ['AppKit', 'IOSurface']) elif host_machine.system() == 'windows' files_lib_egl_translator += files_egl_win32 elif host_machine.system() == 'linux' @@ -51,6 +53,9 @@ lib_egl_translator = static_library( 'egl_translator', files_lib_egl_translator, cpp_args: egl_cpp_args + gfxstream_host_args, + objc_args: egl_cpp_args + gfxstream_host_args, + objcpp_args: egl_cpp_args + gfxstream_host_args, + dependencies: egl_deps, include_directories: [ inc_host_decoder_common, inc_common_base, diff --git a/host/gl/meson.build b/host/gl/meson.build index db4b93c04..84a2225c1 100644 --- a/host/gl/meson.build +++ b/host/gl/meson.build @@ -1,12 +1,6 @@ # Copyright 2023 Android Open Source Project # SPDX-License-Identifier: Apache-2.0 -inc_gl_server = include_directories('.') -inc_gl_snapshot = include_directories('glsnapshot') - -# Needs forward declaration. -inc_gl_openglesdispatch = include_directories('OpenGLESDispatch/include') - # GLES translator subdir('glestranslator') diff --git a/host/gles_compat.h b/host/gles_compat.h index f1f56dc66..6aef3b1ef 100644 --- a/host/gles_compat.h +++ b/host/gles_compat.h @@ -19,7 +19,10 @@ typedef unsigned int GLenum; typedef int32_t EGLint; -typedef unsigned int EGLNativeWindowType; +// Must stay ABI-compatible with the real EGLNativeWindowType from +// , which is pointer-sized on 64-bit platforms +// (e.g. `void*` on Apple); a 32-bit integer here truncates pointers. +typedef void* EGLNativeWindowType; namespace gfxstream { namespace gl { diff --git a/host/meson.build b/host/meson.build index 6ef4a6a6c..3937c075f 100644 --- a/host/meson.build +++ b/host/meson.build @@ -92,6 +92,13 @@ if use_gles or use_vulkan ] endif +# GL include paths are needed even in Vulkan-only builds: the Vulkan server +# includes the GLES dispatch headers (e.g. for interop declarations), so keep +# them visible regardless of which decoders are enabled. +inc_gl_server = include_directories('gl') +inc_gl_snapshot = include_directories('gl/glsnapshot') +inc_gl_openglesdispatch = include_directories('gl/OpenGLESDispatch/include') + if use_gles subdir('gl') @@ -155,16 +162,20 @@ endif deps_gfxstream_backend = [] -link_args_gfxstream_backend = '' +link_args_gfxstream_backend = [] if host_machine.system() == 'linux' deps_gfxstream_backend += [ thread_dep, ] - link_args_gfxstream_backend = '-Wl,-lpthread,-lrt,-ldl' -endif - -if host_machine.system() == 'qnx' + link_args_gfxstream_backend = ['-Wl,-lpthread,-lrt,-ldl'] +elif host_machine.system() == 'darwin' + deps_gfxstream_backend += [ + thread_dep, + dependency('appleframeworks', modules: ['AppKit', 'QuartzCore', 'IOSurface']), + ] + link_args_gfxstream_backend = ['-undefined', 'dynamic_lookup', '-flat_namespace'] +elif host_machine.system() == 'qnx' deps_gfxstream_backend += [ qnx_egl_dep, qnx_gles2_dep, @@ -176,6 +187,7 @@ gfxstream_backend = library( 'gfxstream_backend', files_lib_gfxstream_backend, cpp_args: gfxstream_host_args + gfxstream_backend_cpp_args, + objcpp_args: gfxstream_host_args + gfxstream_backend_cpp_args, include_directories: [inc_gfxstream_backend], gnu_symbol_visibility: 'default', dependencies: deps_gfxstream_backend, diff --git a/host/native_sub_window.h b/host/native_sub_window.h index 87a6f4184..3791a9e71 100644 --- a/host/native_sub_window.h +++ b/host/native_sub_window.h @@ -21,7 +21,7 @@ #if GFXSTREAM_ENABLE_HOST_GLES #include #else -#include "GlesCompat.h" +#include "gles_compat.h" #endif #ifdef __cplusplus diff --git a/host/vulkan/display_surface_vk.cpp b/host/vulkan/display_surface_vk.cpp index b134c933b..b8ca49ff5 100644 --- a/host/vulkan/display_surface_vk.cpp +++ b/host/vulkan/display_surface_vk.cpp @@ -42,7 +42,7 @@ std::unique_ptr DisplaySurfaceVk::create(const VulkanDispatch& GFXSTREAM_FATAL("Vulkan driver does not support display surfaces!"); } VK_CHECK(vk.vkCreateWin32SurfaceKHR(instance, &surfaceCi, nullptr, &surface)); -#elif defined(VK_USE_PLATFORM_MACOS_MVK) +#elif defined(VK_USE_PLATFORM_METAL_EXT) if (vk.vkCreateMetalSurfaceEXT != nullptr) { const CAMetalLayer* layer = getMetalLayerFromView(window); if (!layer) { diff --git a/meson.build b/meson.build index 80f1c0b5a..366d2846f 100644 --- a/meson.build +++ b/meson.build @@ -10,6 +10,14 @@ project('gfxstream', 'cpp', 'c', cc = meson.get_compiler('cpp') prog_python = import('python').find_installation('python3') +# Only Apple platforms build Objective-C sources, and every one of them is behind +# a `host_machine.system() == 'darwin'` guard. Declaring these languages in +# project() would make meson probe for an Objective-C compiler everywhere, which +# fails on toolchains built without one (MSYS2 gcc, and gcc on Linux). +if host_machine.system() == 'darwin' + add_languages('objc', 'objcpp') +endif + #========================# # Logging + error report # #========================# @@ -73,6 +81,10 @@ if host_machine.system() == 'qnx' qnx_gles2_lib = cc.find_library('GLESv2', required : true) qnx_gles2_dep = declare_dependency(include_directories: inc_qnx_headers, dependencies: [qnx_gles2_lib]) +elif host_machine.system() == 'darwin' + thread_dep = dependency('threads') + gfxstream_host_args += '-DVK_USE_PLATFORM_METAL_EXT' + gfxstream_host_args += '-DVK_USE_PLATFORM_MACOS_MVK' elif host_machine.system() == 'linux' thread_dep = dependency('threads') gfxstream_host_args += '-DGFXSTREAM_UNSTABLE_VULKAN_EXTERNAL_SYNC=1' diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index 46d36751e..b68e896cd 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -17,14 +17,19 @@ if (ASTC_CPU_DECODING) set(DECOMPRESSOR ON) # Disable compression code set(CLI OFF) # Disable the command line interface - # Compile with the AVX2 instruction set. This is the fastest option available on x86_64. - # At run time, if the CPU doesn't support AVX2, the library will simply return an error status - # during initialization and we will fall back on the compute shader to decompress ASTC textures. + # Select the fastest SIMD ISA for the target architecture. + # At run time, if the CPU doesn't support the selected ISA, the library will simply return an + # error status during initialization and we will fall back on the compute shader to decompress + # ASTC textures. # # In the future, we should define `ASTCENC_DYNAMIC_LIBRARY` and build multiple versions of the # library for each SIMD architecture, and dynamically load the fastest one at run time. # See also: https://github.com/ARM-software/astc-encoder/issues/79 - set(ISA_AVX2 ON) + if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|ARM64") + set(ISA_NEON ON) + else() + set(ISA_AVX2 ON) + endif() add_subdirectory(astc-encoder) endif () diff --git a/third_party/glslang/BUILD.glslang.bazel b/third_party/glslang/BUILD.glslang.bazel index 81b9eb050..85c2db32b 100644 --- a/third_party/glslang/BUILD.glslang.bazel +++ b/third_party/glslang/BUILD.glslang.bazel @@ -87,6 +87,15 @@ cc_library( ], allow_empty = True, ), + "@platforms//os:macos": glob( + [ + "glslang/OSDependent/Unix/**/*.c", + "glslang/OSDependent/Unix/**/*.cc", + "glslang/OSDependent/Unix/**/*.cpp", + "glslang/OSDependent/Unix/**/*.h", + ], + allow_empty = True, + ), "@platforms//os:windows": glob( [ "glslang/OSDependent/Windows/**/*.c", diff --git a/third_party/meson.build b/third_party/meson.build index 9dcda016e..cf14ff0af 100644 --- a/third_party/meson.build +++ b/third_party/meson.build @@ -17,7 +17,11 @@ else inc_glm = include_directories('glm/include') endif -inc_x11_headers = include_directories('x11/include') +if host_machine.system() != 'darwin' + inc_x11_headers = include_directories('x11/include') +else + inc_x11_headers = include_directories() +endif inc_opengl_headers = include_directories('opengl/include') inc_common_opengl = include_directories('opengl/include') diff --git a/third_party/swiftshader/BUILD.swiftshader.bazel b/third_party/swiftshader/BUILD.swiftshader.bazel index ad8e2c802..1c2e25cdb 100644 --- a/third_party/swiftshader/BUILD.swiftshader.bazel +++ b/third_party/swiftshader/BUILD.swiftshader.bazel @@ -1465,6 +1465,8 @@ cc_library( "third_party/llvm-16.0/configs/windows/include/**/*.def", "third_party/llvm-16.0/configs/windows/include/**/*.h", ]), + "@platforms//os:macos": [ + ], }), copts = [ "-DBLAKE3_NO_AVX512", @@ -1505,6 +1507,8 @@ cc_library( "@platforms//os:windows": [ "third_party/llvm-16.0/configs/windows/include", ], + "@platforms//os:macos": [ + ], }), strip_include_prefix = "third_party/llvm-16.0", ) @@ -1531,6 +1535,8 @@ cc_library( ], "@platforms//os:windows": [ ], + "@platforms//os:macos": [ + ], }) + [ "src/WSI/HeadlessSurfaceKHR.hpp", "src/WSI/VkSurfaceKHR.hpp", @@ -1581,6 +1587,8 @@ cc_library( ], "@platforms//os:windows": [ ], + "@platforms//os:macos": [ + ], }) + [ "src/Reactor/Assert.cpp", "src/Reactor/CPUID.cpp", From d93fa6be58b741ee245c44256a2f72ac08f8ae5d Mon Sep 17 00:00:00 2001 From: utzcoz Date: Tue, 4 Aug 2026 22:57:40 +0800 Subject: [PATCH 4/5] ci: build the macOS host backend in presubmit Add Bazel, CMake and Meson jobs that build the host backend on macOS, so that the paths the previous commit fixed stay compiled. The Bazel job names the host backend libraries explicitly instead of building everything: macOS cannot build the full target graph, because the guest stack needs libdrm and swiftshader bundles an LLVM with no macOS configuration. It therefore gains a build-targets input, and the Linux-only setup steps in the reusable workflow are now guarded by the runner OS. No tests run on macOS yet. That needs a graphics driver environment, which is left for a follow-up along with the guest stack and end-to-end coverage. Co-Authored-By: Eric Curtin --- .github/workflows/presubmit.yaml | 51 +++++++++++++++++++++++++++ .github/workflows/presubmit_bazel.yml | 23 +++++++++--- 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/.github/workflows/presubmit.yaml b/.github/workflows/presubmit.yaml index 5a137e053..b63cc0e30 100644 --- a/.github/workflows/presubmit.yaml +++ b/.github/workflows/presubmit.yaml @@ -60,6 +60,23 @@ jobs: # The arm runner is too slow: run-tests: false + run-gfxstream-bazel-build-macos: + uses: ./.github/workflows/presubmit_bazel.yml + with: + runner: macos-26 + # macOS can not build the full target graph: the Linux-only mesa/libdrm + # guest dependencies and swiftshader's bundled LLVM (which has no macOS + # config) do not build on Darwin. Build the host backend libraries, which + # are the macOS deliverable and mirror the CMake/Meson host builds below. + build-targets: >- + //host:gfxstream_backend_static + //host:gfxstream_backend_shared + //host:gfxstream_backend + # Nothing is run yet: this job exists to keep the macOS host build + # compiling. Tests need a graphics driver environment that macOS does not + # have here yet. + run-tests: false + run-gfxstream-cmake-build: runs-on: ubuntu-22.04 steps: @@ -81,6 +98,23 @@ jobs: cd build && \ ninja + run-gfxstream-cmake-build-macos: + runs-on: macos-26 + steps: + - name: Checkout repository + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 + - name: Install toolchain dependencies + run: brew install cmake ninja + - name: Configure Build + run: | + mkdir build && \ + cd build && \ + cmake .. -G Ninja + - name: Build + run: | + cd build && \ + ninja + run-gfxstream-meson-build: runs-on: ubuntu-22.04 steps: @@ -102,6 +136,23 @@ jobs: run: | meson compile -C build + run-gfxstream-meson-build-macos: + runs-on: macos-26 + steps: + - name: Checkout repository + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 + - name: Install toolchain dependencies + run: brew install meson ninja molten-vk vulkan-loader + - name: Configure Build + run: | + meson setup \ + -Ddefault_library=static \ + -Dgfxstream-build=host \ + build + - name: Build + run: | + meson compile -C build + run-gfxstream-meson-build-windows: runs-on: windows-latest defaults: diff --git a/.github/workflows/presubmit_bazel.yml b/.github/workflows/presubmit_bazel.yml index 9889bcab5..b85c516c0 100644 --- a/.github/workflows/presubmit_bazel.yml +++ b/.github/workflows/presubmit_bazel.yml @@ -13,6 +13,13 @@ on: type: string default: '' + # Which targets to build. Defaults to everything, but platforms that can + # not build the full target graph (e.g. macOS, which lacks the Linux-only + # mesa/libdrm/guest dependencies) can override this with a curated list. + build-targets: + type: string + default: '...' + # Whether or not to run the `bazel test` step: run-tests: type: boolean @@ -23,6 +30,7 @@ jobs: runs-on: ${{ inputs.runner }} steps: - name: Free disk space + if: runner.os == 'Linux' uses: jlumbroso/free-disk-space@v1.3.1 with: tool-cache: true @@ -30,15 +38,22 @@ jobs: - name: Checkout repository uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - - name: Install bazel + - name: Install bazel (Linux) + if: runner.os == 'Linux' run: sudo bash toolchain/bazel/install_bazel.sh - - name: Install toolchain dependencies + - name: Install toolchain dependencies (Linux) + if: runner.os == 'Linux' run: sudo bash toolchain/bazel/install_toolchain_dependencies.sh - - name: Install runtime dependencies + - name: Install runtime dependencies (Linux) + if: runner.os == 'Linux' run: sudo apt-get install -y libvulkan1 + - name: Install bazel (macOS) + if: runner.os == 'macOS' + run: brew install bazelisk + - name: Load cache config run: cat .config/cache-config.env >> $GITHUB_ENV @@ -54,7 +69,7 @@ jobs: - name: Build run: | - bazel build ... \ + bazel build ${{ inputs.build-targets }} \ --disk_cache=$HOME/bazel-disk-cache \ --graphics_drivers=gles_angle_vulkan_swiftshader \ --verbose_failures \ From ee1e83fd153a74b69644b5981f63089d0fa528fa Mon Sep 17 00:00:00 2001 From: utzcoz Date: Tue, 4 Aug 2026 22:57:40 +0800 Subject: [PATCH 5/5] ci: satisfy the workflow security scan The scan requires every action to be pinned to a commit hash and rejects workflow inputs expanded directly into a shell script. None of this is needed for macOS; it is what the scan reports once these files are touched at all. - Pin every action reference to a commit hash, with the version it stands for in a trailing comment. - Pass the bazel target and argument inputs to the build and test steps through the environment instead of expanding them into the script, so that their contents can never be parsed as shell code. The asan job's argument value loses its quotes as a result: expanding a variable does not re-run quote removal, and the value has no spaces to protect. - Check out without persisting credentials. No step needs the token once the tree is on disk. - Give both workflows a read-only token instead of the broad default. Only the bazel target input is new here; every other finding predates this branch. --- .github/workflows/presubmit.yaml | 38 ++++++++++++++++++++++----- .github/workflows/presubmit_bazel.yml | 26 ++++++++++++++---- 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/.github/workflows/presubmit.yaml b/.github/workflows/presubmit.yaml index b63cc0e30..79e42298e 100644 --- a/.github/workflows/presubmit.yaml +++ b/.github/workflows/presubmit.yaml @@ -6,6 +6,9 @@ on: branches-ignore: - main # push events to main branch occur after PRs are merged, when the same checks were run +permissions: + contents: read + concurrency: # limits the workflow to a single run per branch/PR group: ${{ github.workflow }}-${{ github.ref }} @@ -18,8 +21,12 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 + with: + # No step needs the token afterwards, so do not leave it + # behind in .git/config. + persist-credentials: false - name: Install go - uses: actions/setup-go@v6 + uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0 with: go-version: '1.23.1' - name: Install buildozer @@ -50,7 +57,7 @@ jobs: with: # TODO(b/475886246): fix and remove `detect_leaks=0` # TODO(b/475885975): fix and remove `detect_odr_violation=0` - additional-bazel-args: --config=asan --test_env="ASAN_OPTIONS=detect_leaks=0:detect_odr_violation=0" + additional-bazel-args: --config=asan --test_env=ASAN_OPTIONS=detect_leaks=0:detect_odr_violation=0 runner: ubuntu-22.04 run-gfxstream-bazel-tests-arm: @@ -81,11 +88,15 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Free disk space - uses: jlumbroso/free-disk-space@v1.3.1 + uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1 with: tool-cache: true - name: Checkout repository uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 + with: + # No step needs the token afterwards, so do not leave it + # behind in .git/config. + persist-credentials: false - name: Install toolchain dependencies run: sudo bash toolchain/cmake/install_toolchain_dependencies.sh - name: Configure Build @@ -103,6 +114,10 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 + with: + # No step needs the token afterwards, so do not leave it + # behind in .git/config. + persist-credentials: false - name: Install toolchain dependencies run: brew install cmake ninja - name: Configure Build @@ -119,11 +134,15 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Free disk space - uses: jlumbroso/free-disk-space@v1.3.1 + uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1 with: tool-cache: true - name: Checkout repository uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 + with: + # No step needs the token afterwards, so do not leave it + # behind in .git/config. + persist-credentials: false - name: Install toolchain dependencies run: sudo bash toolchain/meson/install_toolchain_dependencies.sh - name: Configure Build @@ -141,6 +160,10 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 + with: + # No step needs the token afterwards, so do not leave it + # behind in .git/config. + persist-credentials: false - name: Install toolchain dependencies run: brew install meson ninja molten-vk vulkan-loader - name: Configure Build @@ -160,10 +183,13 @@ jobs: shell: msys2 {0} steps: - name: Checkout current PR branch - uses: actions/checkout@v6 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 with: ref: ${{ github.event.pull_request.head.sha }} - - uses: msys2/setup-msys2@v2 + # No step needs the token afterwards, so do not leave it + # behind in .git/config. + persist-credentials: false + - uses: msys2/setup-msys2@66cd2cce69caa17b53920067426061ca1de3a884 # v2.32.0 with: msystem: UCRT64 update: true diff --git a/.github/workflows/presubmit_bazel.yml b/.github/workflows/presubmit_bazel.yml index b85c516c0..a972cb79f 100644 --- a/.github/workflows/presubmit_bazel.yml +++ b/.github/workflows/presubmit_bazel.yml @@ -25,18 +25,25 @@ on: type: boolean default: true +permissions: + contents: read + jobs: presubmit_bazel_workflow: runs-on: ${{ inputs.runner }} steps: - name: Free disk space if: runner.os == 'Linux' - uses: jlumbroso/free-disk-space@v1.3.1 + uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1 with: tool-cache: true - name: Checkout repository uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 + with: + # No step needs the token afterwards, so do not leave it + # behind in .git/config. + persist-credentials: false - name: Install bazel (Linux) if: runner.os == 'Linux' @@ -58,7 +65,7 @@ jobs: run: cat .config/cache-config.env >> $GITHUB_ENV - name: Mount Bazel cache - uses: actions/cache/restore@v5 + uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0 with: path: "~/bazel-disk-cache" key: ${{ format('{0}-{1}-bazel-disk-cache-{2}-{3}-{4}-', runner.os, runner.arch, env.CACHE_VERSION, github.ref_name, github.sha) }} @@ -68,15 +75,24 @@ jobs: ${{ format('{0}-{1}-bazel-disk-cache-{2}-', runner.os, runner.arch, env.CACHE_VERSION) || '' }} - name: Build + # Workflow inputs reach the script through the environment rather than + # being expanded into it, so that their contents can never be parsed as + # shell code. They are deliberately left unquoted below so that the shell + # still splits them into separate arguments. + env: + BUILD_TARGETS: ${{ inputs.build-targets }} + ADDITIONAL_BAZEL_ARGS: ${{ inputs.additional-bazel-args }} run: | - bazel build ${{ inputs.build-targets }} \ + bazel build $BUILD_TARGETS \ --disk_cache=$HOME/bazel-disk-cache \ --graphics_drivers=gles_angle_vulkan_swiftshader \ --verbose_failures \ - ${{ inputs.additional-bazel-args }} + $ADDITIONAL_BAZEL_ARGS - name: Test if: ${{ inputs.run-tests }} + env: + ADDITIONAL_BAZEL_ARGS: ${{ inputs.additional-bazel-args }} run: | bazel test \ --disk_cache=$HOME/bazel-disk-cache \ @@ -89,4 +105,4 @@ jobs: host/vulkan:vk_common_operations_tests \ host/vulkan:vk_format_utils_tests \ tests/end2end:gfxstream_end2end_tests \ - ${{ inputs.additional-bazel-args }} + $ADDITIONAL_BAZEL_ARGS