Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,45 @@ build:windows --copt=/w
build:windows --copt=/D_USE_MATH_DEFINES
build:windows --host_copt=/D_USE_MATH_DEFINES

# windows arm64
build:windows_arm64 --config=windows
build:windows_arm64 --cpu=arm64_windows
build:windows_arm64 --platforms=@//mediapipe:windows_arm64_platform
build:windows_arm64 --enable_runfiles
# Disable GPU for ARM64 build
build:windows_arm64 --define=MEDIAPIPE_DISABLE_GPU=1
# MSVC does not support __builtin_expect; disable its use in farmhash.
build:windows_arm64 --copt=/DFARMHASH_NO_BUILTIN_EXPECT
# MSVC conformant preprocessor and Windows header macros to reduce
# namespace pollution and avoid macro conflicts (min/max, GDI, etc.)
build:windows_arm64 --copt=/Zc:preprocessor
build:windows_arm64 --host_copt=/Zc:preprocessor
build:windows_arm64 --copt=/DNOMINMAX
build:windows_arm64 --host_copt=/DNOMINMAX
build:windows_arm64 --copt=/DWIN32_LEAN_AND_MEAN
build:windows_arm64 --host_copt=/DWIN32_LEAN_AND_MEAN
build:windows_arm64 --copt=/DNOGDI
# MSVC for ARM64 does not support __fp16 arithmetic
build:windows_arm64 --define=xnn_enable_arm_fp16_scalar=false
build:windows_arm64 --define=xnn_enable_arm_fp16_vector=false
build:windows_arm64 --define=xnn_enable_arm_dotprod=false
# MSVC for ARM64 does not support inline assembly
build:windows_arm64 --define=xnn_enable_assembly=false
# MSVC for ARM64 does not support SVE/SVE2 intrinsics. Disable SME/SME2 kernels.
build:windows_arm64 --define=xnn_enable_arm_sme=false
build:windows_arm64 --define=xnn_enable_arm_sme2=false
# Disable TFLite XNNPACK delegate for Windows ARM64.
build:windows_arm64 --define=tflite_with_xnnpack=false
# Windows ARM64: Bazel exec config misses protobuf src include path; add
# external/com_google_protobuf/src so "google/protobuf/..." headers resolve.
build:windows_arm64 --host_copt=/Iexternal/com_google_protobuf/src
build:windows_arm64 --copt=/Iexternal/com_google_protobuf/src
# Exclude WinUser.h to avoid GDI macro conflicts (Rectangle, DrawText, etc.)
# that clash with identifiers in these source files.
build:windows_arm64 --per_file_copt=mediapipe/util/annotation_renderer\.cc@/DNOUSER
build:windows_arm64 --per_file_copt=mediapipe/framework/tool/proto_util_lite\.cc@/DNOUSER
build:windows_arm64 --per_file_copt=mediapipe/framework/tool/template_parser\.cc@/DNOUSER

# macOS
build:macos --cxxopt=-std=c++20
build:macos --host_cxxopt=-std=c++20
Expand Down
22 changes: 21 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ http_archive(
# gflags needed by glog
http_archive(
name = "com_github_gflags_gflags",
patch_args = ["-p1"],
patches = [
"@//third_party:com_github_gflags_gflags_windows_patch.diff",
],
sha256 = "19713a36c9f32b33df59d1c79b4958434cb005b5b47dc5400a7a4b078111d9b5",
strip_prefix = "gflags-2.2.2",
url = "https://github.com/gflags/gflags/archive/v2.2.2.zip",
Expand Down Expand Up @@ -278,6 +282,8 @@ http_archive(
http_archive(
name = "XNNPACK",
# `curl -L <url> | shasum -a 256`
patch_args = ["-p1", "-l"],
patches = ["@//third_party:xnnpack_windows_arm64.diff"],
sha256 = "7235b2b55fbf11b64f38db130efae0f293d2d6d6fd90613221b598a8847f41c5",
strip_prefix = "XNNPACK-68167d1fefa50296f0588ec280f48c58357ca898",
url = "https://github.com/google/XNNPACK/archive/68167d1fefa50296f0588ec280f48c58357ca898.zip",
Expand Down Expand Up @@ -325,6 +331,8 @@ http_archive(
# 2025-09-08
http_archive(
name = "cpuinfo",
patch_args = ["-p1"],
patches = ["@//third_party:cpuinfo.diff"],
sha256 = "c0254ce97f7abc778dd2df0aaca1e0506dba1cd514fdb9fe88c07849393f8ef4",
strip_prefix = "cpuinfo-8a9210069b5a37dd89ed118a783945502a30a4ae",
urls = [
Expand All @@ -336,6 +344,8 @@ http_archive(
http_archive(
name = "pthreadpool",
# `curl -L <url> | shasum -a 256`
patch_args = ["-p1"],
patches = ["@//third_party:pthreadpool.diff"],
sha256 = "d5a78b017839ee0474e6aef6e21742b03f641b260f29faf9538a0a6b8fae0704",
strip_prefix = "pthreadpool-995229919303dd98c0f1b3b585b54527067ef893",
urls = ["https://github.com/google/pthreadpool/archive/995229919303dd98c0f1b3b585b54527067ef893.zip"],
Expand All @@ -361,6 +371,8 @@ http_archive(
# Works around Bazel issue with objc_library.
# See https://github.com/bazelbuild/bazel/issues/19912
"@//third_party:org_tensorflow_objc_build_fixes.diff",
# Fix ICU build for Windows ARM64: add /utf-8 flag for arm64_windows CPU.
"@//third_party:org_tensorflow_icu_windows_arm64.diff",
],
sha256 = _TENSORFLOW_SHA256,
strip_prefix = "tensorflow-%s" % _TENSORFLOW_GIT_COMMIT,
Expand Down Expand Up @@ -552,6 +564,8 @@ http_archive(
http_archive(
name = "pffft",
build_file = "@//third_party:pffft.BUILD",
patch_args = ["-p1"],
patches = ["@//third_party:pffft.diff"],
strip_prefix = "jpommier-pffft-7c3b5a7dc510",
urls = ["https://bitbucket.org/jpommier/pffft/get/7c3b5a7dc510.zip"],
)
Expand Down Expand Up @@ -653,6 +667,12 @@ new_local_repository(
path = "C:\\opencv\\build",
)

new_local_repository(
name = "windows_opencv_arm64",
build_file = "@//third_party:opencv_windows_arm64.BUILD",
path = "C:\\opencv\\build",
)

# protobuf requires @system_python in WORKSPACE
new_local_repository(
name = "system_python",
Expand Down Expand Up @@ -965,4 +985,4 @@ http_archive(
sha256 = "d15ebab765d793e2e96db090f0e172d127859d78ca6f6391d7eafecfd894bbc0",
strip_prefix = "curl-8.10.1",
url = "https://curl.haxx.se/download/curl-8.10.1.tar.gz",
)
)
10 changes: 10 additions & 0 deletions mediapipe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ config_setting_and_platform(
visibility = ["//visibility:public"],
)

# Windows ARM64.
config_setting_and_platform(
name = "windows_arm64",
constraint_values = [
"@platforms//os:windows",
"@platforms//cpu:arm64",
],
visibility = ["//visibility:public"],
)

# Linux 64-bit.
config_setting_and_platform(
name = "linux",
Expand Down
8 changes: 5 additions & 3 deletions mediapipe/framework/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1813,9 +1813,11 @@ cc_test(
name = "packet_delete_test",
size = "small",
srcs = ["packet_delete_test.cc"],
copts = [
"-Werror",
],
# MSVC doesn't support -Werror
copts = select({
"@bazel_tools//src/conditions:windows": ["/WX"],
"//conditions:default": ["-Werror"],
}),
linkstatic = 1,
deps = [
":packet",
Expand Down
8 changes: 4 additions & 4 deletions mediapipe/framework/api3/calculator_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,8 @@ auto VisitPacketOrDie(F&& visitor, const mediapipe::Packet& packet) {
return std::forward<F>(visitor)(packet.Get<T>());
}

template <typename T, typename U, typename... Rest, int&... DoNotSpecify,
typename F>
//DoNotSpecify argument removed since it is not being referenced in the function definition nor in any call site
template <typename T, typename U, typename... Rest, typename F>
auto VisitPacketOrDie(F&& visitor, const mediapipe::Packet& packet) {
if (packet.ValidateAsType<T>().ok()) {
return std::forward<F>(visitor)(packet.Get<T>());
Expand All @@ -447,8 +447,8 @@ auto VisitPacketAsPacketOrDie(F&& visitor, const mediapipe::Packet& packet) {
return std::forward<F>(visitor)(WrapLegacyPacket<T>(packet).value());
}

template <typename T, typename U, typename... Rest, int&... DoNotSpecify,
typename F>
//DoNotSpecify argument removed since it is not being referenced in the function definition nor in any call site
template <typename T, typename U, typename... Rest, typename F>
auto VisitPacketAsPacketOrDie(F&& visitor, const mediapipe::Packet& packet) {
if (packet.ValidateAsType<T>().ok()) {
return std::forward<F>(visitor)(WrapLegacyPacket<T>(packet).value());
Expand Down
8 changes: 7 additions & 1 deletion mediapipe/framework/api3/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ class Graph;
class GenericGraph;
class FunctionGraphBuilder;

// Forward declaration needed for MSVC to correctly resolve the template friend
// declaration inside GenericGraph (avoids conflict with non-template
// mediapipe::SubgraphContext from subgraph.h).
template <typename NodeT>
class SubgraphContext;

// `GraphNode` is returned by `Graph<...>::AddNode<...>()` function.
//
// Common pattern to use it:
Expand Down Expand Up @@ -738,4 +744,4 @@ class Repeated<

} // namespace mediapipe::api3

#endif // MEDIAPIPE_FRAMEWORK_API3_GRAPH_H_
#endif // MEDIAPIPE_FRAMEWORK_API3_GRAPH_H_
9 changes: 9 additions & 0 deletions mediapipe/framework/calculator_graph_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

#include "mediapipe/framework/calculator_graph.h"

// pthread.h is not available on Windows
#ifndef _WIN32
#include <pthread.h>
#endif

#include <atomic>
#include <cstdint>
Expand Down Expand Up @@ -975,6 +978,8 @@ class OneShot20MsCalculator : public CalculatorBase {
};
REGISTER_CALCULATOR(OneShot20MsCalculator);

// Excluded on Windows: pthread_self() and pthread_t are not available.
#ifndef _WIN32
// A source calculator that outputs a packet containing the return value of
// pthread_self() (the pthread id of the current thread).
class PthreadSelfSourceCalculator : public CalculatorBase {
Expand All @@ -991,6 +996,7 @@ class PthreadSelfSourceCalculator : public CalculatorBase {
}
};
REGISTER_CALCULATOR(PthreadSelfSourceCalculator);
#endif

// A source calculator for testing the Calculator::InputTimestamp() method.
// It outputs five int packets with timestamps 0, 1, 2, 3, 4.
Expand Down Expand Up @@ -4364,6 +4370,8 @@ TEST(CalculatorGraph, NumThreadsAndNonDefaultExecutorConfig) {
// "ApplicationThreadExecutor" is specified. In this test
// "ApplicationThreadExecutor" is specified in the ExecutorConfig for the
// default executor.
// Excluded on Windows: this test uses PthreadSelfSourceCalculator which is unavailable on Windows.
#ifndef _WIN32
TEST(CalculatorGraph, RunWithNumThreadsInExecutorConfig) {
const struct {
std::string executor_type;
Expand Down Expand Up @@ -4405,6 +4413,7 @@ TEST(CalculatorGraph, RunWithNumThreadsInExecutorConfig) {
<< "for case " << i;
}
}
#endif

TEST(CalculatorGraph, CalculatorGraphNotInitialized) {
CalculatorGraph graph;
Expand Down
32 changes: 26 additions & 6 deletions mediapipe/framework/calculator_node_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@

#include "mediapipe/framework/calculator_node.h"

//POSIX unistd.h is not available on Windows.
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif

#include <memory>

Expand Down Expand Up @@ -50,8 +55,13 @@ class CountCalculator : public CalculatorBase {
++num_open_;
// Simulate doing nontrivial work to ensure that the time spent in the
// method will register on streamz each time it is called.
usleep(100);
return absl::OkStatus();
// Windows has no usleep(); use Sleep(1ms) as equivalent delay.
#ifdef _WIN32
Sleep(1);
#else
usleep(100);
#endif
return absl::OkStatus();
}

absl::Status Process(CalculatorContext* cc) override {
Expand All @@ -65,16 +75,26 @@ class CountCalculator : public CalculatorBase {
.At(cc->InputTimestamp()));
// Simulate doing nontrivial work to ensure that the time spent in the
// method will register on streamz each time it is called.
usleep(100);
return absl::OkStatus();
// Windows has no usleep(); use Sleep(1ms) as equivalent delay.
#ifdef _WIN32
Sleep(1);
#else
usleep(100);
#endif
return absl::OkStatus();
}

absl::Status Close(CalculatorContext* cc) override {
++num_close_;
// Simulate doing nontrivial work to ensure that the time spent in the
// method will register on streamz each time it is called.
usleep(100);
return absl::OkStatus();
// Windows has no usleep(); use Sleep(1ms) as equivalent delay.
#ifdef _WIN32
Sleep(1);
#else
usleep(100);
#endif
return absl::OkStatus();
}

static int num_constructed_;
Expand Down
4 changes: 3 additions & 1 deletion mediapipe/framework/deps/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ cc_library(
"@com_google_absl//absl/strings",
] + select({
"//mediapipe:windows": [],
"//mediapipe:windows_arm64": [],
"//conditions:default": ["//mediapipe/framework/formats:unique_fd"],
}),
)
Expand Down Expand Up @@ -407,6 +408,7 @@ cc_library(
name = "threadpool",
srcs = select({
"//mediapipe:windows": ["threadpool_std_thread_impl.cc"],
"//mediapipe:windows_arm64": ["threadpool_std_thread_impl.cc"],
"//conditions:default": ["threadpool_pthread_impl.cc"],
}),
hdrs = ["threadpool.h"],
Expand Down Expand Up @@ -549,4 +551,4 @@ cc_library(
name = "compile_time_string",
hdrs = ["compile_time_string.h"],
deps = ["@com_google_absl//absl/strings:string_view"],
)
)
3 changes: 2 additions & 1 deletion mediapipe/framework/graph_service_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ TEST(ServiceBindingTest, CrashesWhenGettingNullServiceObject) {
ServiceBinding<TestServiceData> binding(nullptr);
(void)binding.GetObject();
},
testing::ContainsRegex("Check failed: [a-z_]* Service is unavailable"));
// MSVC regex engine misparses the underscore pattern here. Use exact string match instead.
"Check failed: service_ Service is unavailable.");
}

TEST(ServiceBindingTest, IsAvailableReturnsFalsOnNullServiceObject) {
Expand Down
2 changes: 1 addition & 1 deletion mediapipe/framework/legacy_calculator_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class LegacyCalculatorSupport {
//
// ABSL_CONST_INIT triggers b/155992786 with some versions of Clang on Apple
// platforms.
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(_MSC_VER)
ABSL_CONST_INIT
#endif // !__APPLE__
static thread_local C* current_; // NOLINT
Expand Down
Loading