Skip to content
Merged
11 changes: 11 additions & 0 deletions modules/dylib/2.2.1/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""muda"""

module(
name = "dylib",
version = "2.2.1",
compatibility_level = 1,
)

bazel_dep(name = "rules_cc", version = "0.2.8")
bazel_dep(name = "platforms", version = "1.0.0")
bazel_dep(name = "googletest", version = "1.17.0", dev_dependency = True)
42 changes: 42 additions & 0 deletions modules/dylib/2.2.1/patches/add_build_file.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--- /dev/null
+++ BUILD.bazel
@@ -0,0 +1,39 @@
+load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
+
+cc_library(
+ name = "dylib",
+ hdrs = ["include/dylib.hpp"],
+ copts = ["-std=c++11"],
+ includes = ["include"],
+ linkopts = select({
+ "@platforms//os:linux": ["-ldl"],
+ "//conditions:default": [],
+ }),
+ visibility = ["//visibility:public"],
+)
+
+
+# Example usage and tests
+cc_binary(
+ name = "dynamic_lib",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't the example binary depend on dylib?

Copy link
Contributor Author

@hugooole hugooole Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dynamic_lib is in data field in cc_test, which as runtime data, not as dep. dynamic_lib itself is a simple test function, only dep c++ std, Only cc_test depend on dylib. cc_test will use dylib to load dynamic_lib.so at runtime

+ srcs = ["tests/lib.cpp"],
+ copts = [
+ "-std=c++17",
+ "-fPIC",
+ ],
+ linkshared = True,
+ visibility = ["//visibility:private"],
+)
+
+cc_test(
+ name = "unit_tests",
+ srcs = ["tests/tests.cpp"],
+ copts = ["-std=c++17"],
+ data = [":dynamic_lib"],
+ visibility = ["//visibility:private"],
+ deps = [
+ ":dylib",
+ "@googletest//:gtest",
+ "@googletest//:gtest_main",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want cc_test here? googletest is never available.

Copy link
Contributor Author

@hugooole hugooole Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add googletest as dev dependency. But googletest is not available when run test CI, Why? If I want to run test_binary in CI env, have I to make it as dependency not dev_dependency?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want, you can run the module as a root module via https://github.com/bazelbuild/bazel-central-registry/blob/main/docs/README.md#test-module (setting module_path to .) Then dev_dependency will be available.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also you may want to add --process_headers_in_dependencies as a build flag otherwise the presubmit isn't testing anything since it's a header only cc_library.

See examples from BCR:

build_flags:
- '--process_headers_in_dependencies'

+ ],
+)
14 changes: 14 additions & 0 deletions modules/dylib/2.2.1/patches/module_dot_bazel.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- MODULE.bazel
+++ MODULE.bazel
@@ -0,0 +1,11 @@
+"""muda"""
+
+module(
+ name = "dylib",
+ version = "2.2.1",
+ compatibility_level = 1,
+)
+
+bazel_dep(name = "rules_cc", version = "0.2.8")
+bazel_dep(name = "platforms", version = "1.0.0")
+bazel_dep(name = "googletest", version = "1.17.0", dev_dependency = True)
15 changes: 15 additions & 0 deletions modules/dylib/2.2.1/presubmit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
matrix:
platform:
- ubuntu2204
- windows
bazel: [8.x]

tasks:
verify_targets:
name: Verify build targets
platform: ${{ platform }}
bazel: ${{ bazel }}
build_targets:
- '@dylib//:dylib'
test_targets:
- '@dylib//:unit_tests'
10 changes: 10 additions & 0 deletions modules/dylib/2.2.1/source.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"url": "https://github.com/martin-olivier/dylib/archive/refs/tags/v2.2.1.tar.gz",
"integrity": "sha256-avDSqRhgdD3J9WS6CrfwNqmzfJBDlWECiHkVcdTb6ls=",
"strip_prefix": "dylib-2.2.1",
"patches": {
"add_build_file.patch": "sha256-RLbSXWuisVCgbVMK2pbmTUYV++8+s4AKxl2MHHcuLIo=",
"module_dot_bazel.patch": "sha256-PGediE7WWitufUHz6LogWxZBB407mL3BIu/3va0m5Ik="
},
"patch_strip": 0
}
18 changes: 18 additions & 0 deletions modules/dylib/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"homepage": "https://github.com/martin-olivier/dylib",
"maintainers": [
{
"email": "[email protected]",
"github": "hugooole",
"github_user_id": 232750829,
"name": "zhiguo"
}
],
"repository": [
"github:martin-olivier/dylib"
],
"versions": [
"2.2.1"
],
"yanked_versions": {}
}
Loading