conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.13k stars 968 forks source link

[bug] BazelDeps generator produces invalid absolute glob #16733

Open AndersSundman opened 1 month ago

AndersSundman commented 1 month ago

Describe the bug

This conanfile.py

from conan import ConanFile
from conan.tools.google import bazel_layout

class CompressorRecipe(ConanFile):
    settings = "os", "compiler", "build_type", "arch"
    generators = "BazelDeps", "BazelToolchain"

    def requirements(self):
        self.requires("glfw/3.3.2")

    def build_requirements(self):
        self.tool_requires("cmake/3.22.6")

    def layout(self):
        bazel_layout(self)

Creates an invalid BUILD.bazel file for the glfw dependency xorg. Note: these specific libraries are just examples. I think it might be a problem for all libraries that use absolute paths.

The problem is the generated BUILD.bazel file that has this cc_library

cc_library(
    name = "xorg-uuid",
    hdrs = glob([
        "/usr/include/uuid/**",
    ]),
    includes = [
        "/usr/include/uuid",
    ],
    linkopts = [
        "-luuid",
    ],
    visibility = ["//visibility:public"],
)

Error message is:

hdrs = glob([
Error in glob: pattern cannot be absolute

Bazel doesn't (afaik) support absolute globs, so the hdrs attribute can't be generated with a glob that takes an absolute path.

How to reproduce it

I'm trying this on ubuntu 22.

Create a minimal project with the conanfile above,

Put this in the MODULE.bazel

load_conan_dependencies = use_extension("//conan:conan_deps_module_extension.bzl", "conan_extension")
use_repo(load_conan_dependencies, "glfw")

and create a dummy cc_library with empty files and a deps = ["@glfw"] then bazel build the target and you get the error

memsharded commented 1 month ago

Hi @AndersSundman

Thanks for your report.

The xorg recipe is what we call a "system" recipe, just a wrapper around some existing system libraries, but not containing the libraries itself. It is possible that the BazelDeps integration is not taking system packages into account, I am assigning @franramirez688 to check this.

franramirez688 commented 1 week ago

Hi @AndersSundman

I can't reproduce the issue. I just tried your example, and it's working fine. The xorg recipe is empty as it doesn't contain the library itself. Could you please provide a minimum repro case? I'm using Bazel 7.1.2 and Conan 2.7.0. I also recommend to update the requirements just in case you're using an older version:

$ conan create . --build=missing --update