Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Bazel builds fail when the package provides no binaries #17438

Closed
ericriff opened this issue Dec 9, 2024 · 1 comment · Fixed by #17444
Closed

[bug] Bazel builds fail when the package provides no binaries #17438

ericriff opened this issue Dec 9, 2024 · 1 comment · Fixed by #17444
Assignees
Labels
Milestone

Comments

@ericriff
Copy link

ericriff commented Dec 9, 2024

Environment

$ conan --version
Conan version 2.10.1
$ bazel --version
bazel 8.0.0

Describe the bug

I'm following the tutorial from https://docs.conan.io/2/examples/tools/google/bazeltoolchain/build_simple_bazel_7x_project.html
to learn how to integrate conan into a bazel project.
Granted, the tutorial mentions it is for Bazel 7 yet I'm using 8. Maybe conan doesn't support 8?

Anyways, the build fails with

bazel --bazelrc=./conan/conan_bzl.rc build --config=conan-config //main:demo
Extracting Bazel installation...
Starting local Bazel server and connecting to it...
WARNING: Couldn't auto load rules or symbols, because no dependency on module/repository 'rules_android' found. This will result in a failure if there's a reference to those rules or symbols.
ERROR: Traceback (most recent call last):
	File "/home/eriff/repos/examples2/examples/tools/google/bazeltoolchain/7_x/string_formatter/conan/bazelRootDir/d5c9c1c12146af1a257e11f337e7ccd9/external/+conan_extension+fmt/BUILD.bazel", line 47, column 16, in <toplevel>
		srcs = glob([
Error in glob: glob pattern 'bin/**' didn't match anything, but allow_empty is set to False (the default value of allow_empty can be set with --incompatible_disallow_empty_glob).
ERROR: /home/eriff/repos/examples2/examples/tools/google/bazeltoolchain/7_x/string_formatter/main/BUILD:1:10: Target '@@+conan_extension+fmt//:fmt' contains an error and its package is in error and referenced by '//main:demo'
ERROR: Analysis of target '//main:demo' failed; build aborted: Analysis failed
INFO: Elapsed time: 21.228s, Critical Path: 0.02s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully
FAILED: 
    Fetching repository @@rules_cc++cc_configure_extension+local_config_cc; starting

It complains about the conan-generated files, particularly this part

# Filegroup library declaration
filegroup(
    name = "fmt_binaries",
    srcs = glob([
        "bin/**",
    ]),
    visibility = ["//visibility:public"],
)

Since fmt provides no binaries, that glob matches nothing and Bazel doesn't like it. Commenting out the whole block makes the build pass, but a better fix is to add allow_empty to that glob call.

# Filegroup library declaration
filegroup(
    name = "fmt_binaries",
    srcs = glob([
        "bin/**",
    ],
    allow_empty=True
    ),
    visibility = ["//visibility:public"],
)

With that fix the build passes

 bazel --bazelrc=./conan/conan_bzl.rc build --config=conan-config //main:demo
INFO: Analyzed target //main:demo (12 packages loaded, 66 targets configured).
INFO: Found 1 target...
Target //main:demo up-to-date:
  bazel-bin/main/demo
INFO: Elapsed time: 0.961s, Critical Path: 0.25s
INFO: 6 processes: 4 internal, 2 linux-sandbox.
INFO: Build completed successfully, 6 total actions
@franramirez688
Copy link
Contributor

franramirez688 commented Dec 10, 2024

Hi @ericriff,

Thanks a lot for reporting this 😁
Yes, that would fix the error. Moreover, I just checked older bazel versions and it's also compatible 👏

Proposing #17444 to solve the issue. It'll be released in the next Conan 2.11.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants