From 6d2583fd902e9a42607372ae01353f9eaa1fd224 Mon Sep 17 00:00:00 2001
From: Markus Hofbauer <markus.hofbauer@luminartech.com>
Date: Mon, 11 Nov 2024 13:22:24 +0100
Subject: [PATCH] Fix empty glob in boost.thread (#3142)

Needs skip-url-check

---------

Co-authored-by: Daisuke Nishimatsu <42202095+wep21@users.noreply.github.com>
---
 .../boost.thread/1.83.0.bcr.1/MODULE.bazel    |  38 ++++
 .../1.83.0.bcr.1/overlay/BUILD.bazel          | 167 +++++++++++++++
 .../1.83.0.bcr.1/overlay/MODULE.bazel         |   1 +
 .../1.83.0.bcr.1/overlay/test/BUILD.bazel     | 193 ++++++++++++++++++
 .../1.83.0.bcr.1/overlay/test/MODULE.bazel    |  13 ++
 .../1.83.0.bcr.1/patches/fix_assert.patch     |  12 ++
 .../boost.thread/1.83.0.bcr.1/presubmit.yml   |  45 ++++
 modules/boost.thread/1.83.0.bcr.1/source.json |  15 ++
 modules/boost.thread/metadata.json            |   3 +-
 9 files changed, 486 insertions(+), 1 deletion(-)
 create mode 100644 modules/boost.thread/1.83.0.bcr.1/MODULE.bazel
 create mode 100644 modules/boost.thread/1.83.0.bcr.1/overlay/BUILD.bazel
 create mode 120000 modules/boost.thread/1.83.0.bcr.1/overlay/MODULE.bazel
 create mode 100644 modules/boost.thread/1.83.0.bcr.1/overlay/test/BUILD.bazel
 create mode 100644 modules/boost.thread/1.83.0.bcr.1/overlay/test/MODULE.bazel
 create mode 100644 modules/boost.thread/1.83.0.bcr.1/patches/fix_assert.patch
 create mode 100644 modules/boost.thread/1.83.0.bcr.1/presubmit.yml
 create mode 100644 modules/boost.thread/1.83.0.bcr.1/source.json

diff --git a/modules/boost.thread/1.83.0.bcr.1/MODULE.bazel b/modules/boost.thread/1.83.0.bcr.1/MODULE.bazel
new file mode 100644
index 00000000000..2d2b2dcfb70
--- /dev/null
+++ b/modules/boost.thread/1.83.0.bcr.1/MODULE.bazel
@@ -0,0 +1,38 @@
+module(
+    name = "boost.thread",
+    version = "1.83.0.bcr.1",
+    bazel_compatibility = [">=7.2.1"],
+    compatibility_level = 108300,
+)
+
+bazel_dep(name = "boost.algorithm", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.assert", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.atomic", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.bind", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.chrono", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.concept_check", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.config", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.container", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.container_hash", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.core", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.date_time", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.exception", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.function", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.intrusive", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.io", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.iterator", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.lexical_cast", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.move", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.optional", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.predef", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.preprocessor", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.smart_ptr", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.static_assert", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.system", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.throw_exception", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.tuple", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.type_traits", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.utility", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.winapi", version = "1.83.0.bcr.1")
+bazel_dep(name = "rules_cc", version = "0.0.14")
+bazel_dep(name = "platforms", version = "0.0.10")
diff --git a/modules/boost.thread/1.83.0.bcr.1/overlay/BUILD.bazel b/modules/boost.thread/1.83.0.bcr.1/overlay/BUILD.bazel
new file mode 100644
index 00000000000..a6f4c0057a9
--- /dev/null
+++ b/modules/boost.thread/1.83.0.bcr.1/overlay/BUILD.bazel
@@ -0,0 +1,167 @@
+load("@rules_cc//cc:defs.bzl", "cc_library")
+
+package(default_visibility = ["//visibility:public"])
+
+_COMMON_DEPS = [
+    "@boost.bind",
+    "@boost.config",
+    "@boost.core",
+    "@boost.date_time",
+    "@boost.move",
+    "@boost.system",
+    "@boost.type_traits",
+    "@boost.chrono",
+]
+
+_COMMON_HDRS = [
+    "include/boost/thread/detail/*.hpp",
+    "include/boost/thread/*.hpp",
+    "include/boost/thread/futures/*.hpp",
+    "include/boost/thread/csbl/*.hpp",
+    "include/boost/thread/executors/*.hpp",
+]
+
+_WINDOWS_HDRS = [
+    "include/boost/thread/win32/*.hpp",
+]
+
+_POSIX_HDRS = [
+    "include/boost/thread/pthread/*.hpp",
+]
+
+_MAC_HDRS = [
+    "include/boost/thread/pthread/*.hpp",
+]
+
+_WINDOWS_SRCS = [
+    "src/win32/*.cpp",
+]
+
+_MAC_SRCS = [
+    "src/pthread/once.cpp",
+    "src/pthread/thread.cpp",
+]
+
+_POSIX_SRCS = [
+    "src/pthread/thread.cpp",
+    "src/pthread/once.cpp",
+]
+
+_COMMON_SRCS = [
+    "src/future.cpp",
+]
+
+_COMMON_EXCLUDE_SRCS = ["src/pthread/once_atomic.cpp"]
+
+cc_library(
+    name = "thread_posix",
+    srcs = glob(
+        _POSIX_SRCS + _COMMON_SRCS,
+        exclude = _COMMON_EXCLUDE_SRCS,
+    ),
+    hdrs = glob(_POSIX_HDRS + _COMMON_HDRS),
+    defines = [
+        "BOOST_THREAD_DONT_USE_ATOMIC",
+    ],
+    includes = ["include"],
+    linkopts = ["-lpthread"],
+    target_compatible_with = select({
+        "@platforms//os:windows": ["@platforms//:incompatible"],
+        "@platforms//os:macos": ["@platforms//:incompatible"],
+        "//conditions:default": [],
+    }),
+    deps = _COMMON_DEPS,
+)
+
+cc_library(
+    name = "thread_windows",
+    srcs = glob(
+        _WINDOWS_SRCS + _COMMON_SRCS,
+        exclude = _COMMON_EXCLUDE_SRCS,
+    ),
+    hdrs = glob(_WINDOWS_HDRS + _COMMON_HDRS),
+    defines = [
+        "BOOST_THREAD_WIN32",
+        "BOOST_THREAD_DONT_USE_ATOMIC",
+    ],
+    includes = ["include"],
+    linkopts = ["-DEFAULTLIB:shell32"],
+    local_defines = [
+        "BOOST_THREAD_BUILD_LIB",
+    ],
+    target_compatible_with = select({
+        "@platforms//os:windows": [],
+        "@platforms//os:macos": ["@platforms//:incompatible"],
+        "//conditions:default": ["@platforms//:incompatible"],
+    }),
+    deps = _COMMON_DEPS + [
+        "@boost.atomic",
+    ],
+)
+
+cc_library(
+    name = "thread_mac",
+    srcs = glob(
+        _MAC_SRCS + _COMMON_SRCS,
+        exclude = _COMMON_EXCLUDE_SRCS,
+    ),
+    hdrs = glob(_MAC_HDRS + _COMMON_HDRS),
+    defines = [
+        "BOOST_THREAD_DONT_USE_ATOMIC",
+    ],
+    includes = ["include"],
+    target_compatible_with = select({
+        "@platforms//os:windows": ["@platforms//:incompatible"],
+        "@platforms//os:macos": [],
+        "//conditions:default": ["@platforms//:incompatible"],
+    }),
+    deps = _COMMON_DEPS,
+)
+
+cc_library(
+    name = "boost.thread",
+    srcs = glob(
+        ["src/**/*.cpp"],
+        exclude = _POSIX_SRCS + _WINDOWS_SRCS + _MAC_SRCS + _COMMON_SRCS + _COMMON_EXCLUDE_SRCS,
+    ),
+    hdrs = glob(
+        [
+            "include/**/*.hpp",
+        ],
+        exclude = _POSIX_HDRS + _WINDOWS_HDRS + _MAC_HDRS + _COMMON_HDRS,
+    ),
+    includes = ["include"],
+    deps = [
+        "@boost.algorithm",
+        "@boost.assert",
+        "@boost.atomic",
+        "@boost.concept_check",
+        "@boost.container",
+        "@boost.container_hash",
+        "@boost.exception",
+        "@boost.function",
+        "@boost.intrusive",
+        "@boost.io",
+        "@boost.iterator",
+        "@boost.lexical_cast",
+        "@boost.optional",
+        "@boost.predef",
+        "@boost.preprocessor",
+        "@boost.smart_ptr",
+        "@boost.static_assert",
+        "@boost.throw_exception",
+        "@boost.tuple",
+        "@boost.utility",
+    ] + select({
+        "@platforms//os:windows": [
+            ":thread_windows",
+            "@boost.winapi",
+        ],
+        "@platforms//os:macos": [
+            ":thread_mac",
+        ],
+        "//conditions:default": [
+            ":thread_posix",
+        ],
+    }) + _COMMON_DEPS,
+)
diff --git a/modules/boost.thread/1.83.0.bcr.1/overlay/MODULE.bazel b/modules/boost.thread/1.83.0.bcr.1/overlay/MODULE.bazel
new file mode 120000
index 00000000000..9b599e3ad9c
--- /dev/null
+++ b/modules/boost.thread/1.83.0.bcr.1/overlay/MODULE.bazel
@@ -0,0 +1 @@
+../MODULE.bazel
\ No newline at end of file
diff --git a/modules/boost.thread/1.83.0.bcr.1/overlay/test/BUILD.bazel b/modules/boost.thread/1.83.0.bcr.1/overlay/test/BUILD.bazel
new file mode 100644
index 00000000000..6eb412c1ed8
--- /dev/null
+++ b/modules/boost.thread/1.83.0.bcr.1/overlay/test/BUILD.bazel
@@ -0,0 +1,193 @@
+load("@rules_cc//cc:defs.bzl", "cc_test")
+
+_TESTS = {
+    "test_366_1": [],
+    "test_366_2": [],
+    "test_366_3": [],
+    "test_366_4": [],
+    "test_2309": [],
+    "test_2501": [],
+    "test_2741": [],
+    "test_3628": [],
+    # Uses a function that is undefined "test_3837": [],
+    "test_4521": [],
+    "test_4648": [],
+    "test_4882": [],
+    "test_5351": [],
+    # Fails and it is unclear why. Needs further investigation. "test_5502": [],
+    "test_5542_1": [],
+    "test_5542_2": [],
+    "test_5542_3": [],
+    "test_5891": [],
+    "test_6170": [],
+    "test_6174": [],
+    "test_7160": [],
+    "test_7328": [],
+    "test_7571": [],
+    "test_7665": [],
+    "test_7666": [],
+    "test_7720": [],
+    "test_7755": [],
+    "test_8508": [],
+    # Misses malloc.h which is deprecated "test_8557": [],
+    "test_8586": [],
+    "test_8596": [],
+    "test_8600": [],
+    "test_8674": [],
+    "test_8943": [],
+    "test_8960": [],
+    "test_9079_a": [],
+    # Misses iostream "test_9079_b": [],
+    # Misses iostream "test_9192": ["@boost.interprocess"],
+    # Uses boost::future which cannot compile "test_9303": ["@boost.asio"],
+    "test_9319": [],
+    "test_9711": [],
+    "test_9856": [],
+    "test_10340": [],
+    # Fails and is unclear why. Needs further investigation. "test_10963": [],
+    "test_10964": [],
+    "test_11053": [],
+    "test_11256": [],
+    "test_11266": [],
+    "test_11499": [],
+    "test_11611": [],
+    "test_11796": [],
+    # Misses iostream "test_11818": [],
+    "test_12293": [],
+    "test_12949": [],
+    "test_13480b": ["@boost.variant"],
+    # Misses a nonexistent file from @boost.system "test_13561": [],
+    "test_barrier_size_fct": [],
+    "test_barrier_void_fct": [],
+    "test_barrier": [],
+    "test_completion_latch": [],
+    "test_condition_notify_all": [],
+    "test_condition_notify_one": [],
+    "test_condition_timed_wait_times_out": [],
+    "test_condition": [],
+    "test_futures": [],
+    "test_generic_locks": [],
+    "test_hardware_concurrency": [],
+    "test_latch": [],
+    "test_lock_concept": [],
+    "test_ml": [],
+    "test_ml2": [],
+    "test_move_function": [],
+    "test_mutex": [],
+    "test_once": [],
+    "test_physical_concurrency": [],
+    "test_scheduled_tp": [],
+    "test_scheduling_adaptor": [],
+    "test_shared_mutex_part_2": [],
+    "test_shared_mutex_timed_locks_chrono": [],
+    "test_shared_mutex": [],
+    "test_thread_exit": [],
+    "test_thread_id": [],
+    "test_thread_launching": [],
+    "test_thread_mf": [],
+    "test_thread_move_return": [],
+    "test_thread_move": [],
+    "test_thread_return_local": [],
+    "test_thread": [],
+    # Uses boost::future which cannot compile "test_time_jumps": [],
+    "test_tss": [],
+    "test_xtime": [],
+}
+
+_POSIX_ONLY_TESTS = {
+}
+
+_MAC_ONLY_TESTS = {
+    "test_6130": [],
+    "test_8455": [],
+}
+
+_WINDOWS_ONLY_TESTS = {
+    "test_6130": [],
+}
+
+[cc_test(
+    name = test,
+    srcs = ["{}.cpp".format(test), "util.inl"] + glob(["*.hpp"]),
+    defines = select({
+        "@platforms//os:windows": ["WIN32_LEAN_AND_MEAN=1"],
+        "@platforms//os:macos": [],
+        "//conditions:default": [],
+    }),
+    deps = [
+        "@boost.test",
+        "@boost.test//:unit_test_main",
+        "@boost.thread",
+    ] + _TESTS[test],
+    linkstatic = select({
+        # Windows needs to link statically to get rid of undefined symbols
+        "@platforms//os:windows": True,
+        "@platforms//os:macos": False,
+        # Posix needs to link statically to get rid of undefined symbols
+        "//conditions:default": True,
+    }),
+) for test in _TESTS]
+
+[cc_test(
+    name = "posix_{}".format(test),
+    srcs = ["{}.cpp".format(test), "util.inl"] + glob(["*.hpp"]),
+    defines = select({
+        "@platforms//os:windows": ["WIN32_LEAN_AND_MEAN=1"],
+        "@platforms//os:macos": [],
+        "//conditions:default": [],
+    }),
+    target_compatible_with = select({
+        "@platforms//os:windows": ["@platforms//:incompatible"],
+        "@platforms//os:macos": ["@platforms//:incompatible"],
+        "//conditions:default": [],
+    }),
+    deps = [
+        "@boost.test",
+        "@boost.test//:unit_test_main",
+        "@boost.thread",
+    ] + _POSIX_ONLY_TESTS[test],
+    # Posix needs to link statically to get rid of undefined symbols
+    linkstatic = True,
+) for test in _POSIX_ONLY_TESTS]
+
+[cc_test(
+    name = "mac_{}".format(test),
+    srcs = ["{}.cpp".format(test), "util.inl"] + glob(["*.hpp"]),
+    defines = select({
+        "@platforms//os:windows": ["WIN32_LEAN_AND_MEAN=1"],
+        "@platforms//os:macos": [],
+        "//conditions:default": [],
+    }),
+    target_compatible_with = select({
+        "@platforms//os:windows": ["@platforms//:incompatible"],
+        "@platforms//os:macos": [],
+        "//conditions:default": ["@platforms//:incompatible"],
+    }),
+    deps = [
+        "@boost.test",
+        "@boost.test//:unit_test_main",
+        "@boost.thread",
+    ] + _MAC_ONLY_TESTS[test],
+) for test in _MAC_ONLY_TESTS]
+
+[cc_test(
+    name = "windows_{}".format(test),
+    srcs = ["{}.cpp".format(test), "util.inl"] + glob(["*.hpp"]),
+    defines = select({
+        "@platforms//os:windows": ["WIN32_LEAN_AND_MEAN=1"],
+        "@platforms//os:macos": [],
+        "//conditions:default": [],
+    }),
+    target_compatible_with = select({
+        "@platforms//os:windows": [],
+        "@platforms//os:macos": ["@platforms//:incompatible"],
+        "//conditions:default": ["@platforms//:incompatible"],
+    }),
+    deps = [
+        "@boost.test",
+        "@boost.test//:unit_test_main",
+        "@boost.thread",
+    ] + _WINDOWS_ONLY_TESTS[test],
+    # Windows needs to link statically to get rid of undefined symbols
+    linkstatic = True,
+) for test in _WINDOWS_ONLY_TESTS]
diff --git a/modules/boost.thread/1.83.0.bcr.1/overlay/test/MODULE.bazel b/modules/boost.thread/1.83.0.bcr.1/overlay/test/MODULE.bazel
new file mode 100644
index 00000000000..6b19dee5033
--- /dev/null
+++ b/modules/boost.thread/1.83.0.bcr.1/overlay/test/MODULE.bazel
@@ -0,0 +1,13 @@
+bazel_dep(name = "boost.asio", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.interprocess", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.test", version = "1.83.0.bcr.1")
+bazel_dep(name = "boost.thread")
+
+local_path_override(
+    module_name = "boost.thread",
+    path = "..",
+)
+
+bazel_dep(name = "boost.variant", version = "1.83.0.bcr.1")
+bazel_dep(name = "rules_cc", version = "0.0.14")
+bazel_dep(name = "platforms", version = "0.0.10")
diff --git a/modules/boost.thread/1.83.0.bcr.1/patches/fix_assert.patch b/modules/boost.thread/1.83.0.bcr.1/patches/fix_assert.patch
new file mode 100644
index 00000000000..3d7e49164bc
--- /dev/null
+++ b/modules/boost.thread/1.83.0.bcr.1/patches/fix_assert.patch
@@ -0,0 +1,12 @@
+diff --git include/boost/thread/pthread/pthread_helpers.hpp include/boost/thread/pthread/pthread_helpers.hpp
+index 68099941..2d60f829 100644
+--- include/boost/thread/pthread/pthread_helpers.hpp
++++ include/boost/thread/pthread/pthread_helpers.hpp
+@@ -7,6 +7,7 @@
+ //  accompanying file LICENSE_1_0.txt or copy at
+ //  http://www.boost.org/LICENSE_1_0.txt)
+ 
++#include <boost/assert.hpp>
+ #include <boost/thread/detail/config.hpp>
+ #include <boost/throw_exception.hpp>
+ #include <pthread.h>
diff --git a/modules/boost.thread/1.83.0.bcr.1/presubmit.yml b/modules/boost.thread/1.83.0.bcr.1/presubmit.yml
new file mode 100644
index 00000000000..d32b242089c
--- /dev/null
+++ b/modules/boost.thread/1.83.0.bcr.1/presubmit.yml
@@ -0,0 +1,45 @@
+matrix:
+  platform:
+    - debian10
+    - debian11
+    - macos
+    - macos_arm64
+    - ubuntu2004
+    - ubuntu2204
+    - ubuntu2404
+    - windows
+  bazel: [7.x, rolling]
+tasks:
+  verify_targets:
+    name: Verify build targets
+    platform: ${{ platform }}
+    bazel: ${{ bazel }}
+    build_flags:
+      - '--process_headers_in_dependencies'
+    build_targets:
+      - '@boost.thread//:boost.thread'
+
+bcr_test_module:
+  module_path: test
+  matrix:
+    platform:
+      - debian10
+      - debian11
+      - macos
+      - macos_arm64
+      - ubuntu2004
+      - ubuntu2204
+      - ubuntu2404
+      - windows
+    bazel: [7.x, rolling]
+  tasks:
+    run_test_module:
+      name: Run test module
+      platform: ${{ platform }}
+      bazel: ${{ bazel }}
+      build_flags:
+        - '--process_headers_in_dependencies'
+      build_targets:
+        - //...
+      test_targets:
+        - //...
diff --git a/modules/boost.thread/1.83.0.bcr.1/source.json b/modules/boost.thread/1.83.0.bcr.1/source.json
new file mode 100644
index 00000000000..c907fa585d1
--- /dev/null
+++ b/modules/boost.thread/1.83.0.bcr.1/source.json
@@ -0,0 +1,15 @@
+{
+    "integrity": "sha256-zIFNyvMDzgajwBoU+gvJoAGXbEPKHOoeATxxNeoxB5s=",
+    "strip_prefix": "thread-boost-1.83.0",
+    "url": "https://github.com/boostorg/thread/archive/refs/tags/boost-1.83.0.tar.gz",
+    "patch_strip": 0,
+    "overlay": {
+        "BUILD.bazel": "sha256-ec85Zp/2Y4kqR7RN2bp0qA1UQmmAnnUZKM718nKtltg=",
+        "MODULE.bazel": "sha256-LF2hR/JRsMevLwhhR3Jxh47TZCSO3YXG6TF1z25fmM4=",
+        "test/BUILD.bazel": "sha256-hDHQt6H7E+evp01hiFXa0c0bUs61V9YBiHLS/QI5ooY=",
+        "test/MODULE.bazel": "sha256-NjutTRW+vVjCW7P03idgTM26Q/lYPegotoOhSc/8RTQ="
+    },
+    "patches": {
+        "fix_assert.patch": "sha256-dI4h1MBB+qjM08R8lXSXNgCL3b0AhX96WjNBV2b1c1A="
+    }
+}
diff --git a/modules/boost.thread/metadata.json b/modules/boost.thread/metadata.json
index 5033ad2fa76..54a21faea43 100644
--- a/modules/boost.thread/metadata.json
+++ b/modules/boost.thread/metadata.json
@@ -16,7 +16,8 @@
         "github:boostorg/thread"
     ],
     "versions": [
-        "1.83.0"
+        "1.83.0",
+        "1.83.0.bcr.1"
     ],
     "yanked_versions": {}
 }