bazelbuild / bazel-central-registry

The central registry of Bazel modules for the Bzlmod external dependency system.
https://registry.bazel.build
Apache License 2.0
244 stars 286 forks source link

[Bug]: Many modules add `-lrt` as a linkopt, which only works on Linux #2017

Closed eyebrowsoffire closed 1 month ago

eyebrowsoffire commented 3 months ago

What happened?

It appears many of the module definitions add the -lrt linkopt explicitly in their BUILD file definition. See for example https://github.com/bazelbuild/bazel-central-registry/blob/8645666979c124eb30d1b20d85f0040b9f0d7b38/modules/websocketpp/0.8.2/patches/add_build_file.patch#L16

This link option is only valid on Linux. Other platforms, such as macOS, this just causes a link failure.

Version

Development (host) and target OS/architectures: macOS 13.6.6 (22G630)

Output of bazel --version: bazel 7.1.2

How to reproduce

Just create a simple hello world that links on `websocketpp` as an example.

Build file:

cc_binary(
    name = "hello_world",
    srcs = [
        "main.cpp",
    ],
    deps = [
        "@websocketpp",
    ],
)

In the MODULE.bazel file:

bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "websocketpp", version = "0.8.2")


### Any other information?

I'm guessing probably this linkopt should be gated on a platform configuration so it is only added on linux.
fmeum commented 3 months ago

You could submit a new version (with a customary .bcr.1 suffix) and e.g. add a select based on the target platform.

Wyverald commented 1 month ago

Please feel free to sent PRs! As the module contents aren't maintained centrally, this bug isn't going to be actionable. I'll go ahead and close it.