question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[bug] Bazel issue when using string value for defines

See original GitHub issue

If define is a string value, there is problem in generated build file. String in string is generated and Bazel can’t resolve this. Here is example from generated boost BUILD file: "BOOST_STACKTRACE_ADDR2LINE_LOCATION="/usr/bin/addr2line""

Environment Details

  • Operating System+version: Fedora 34
  • Compiler+version: gcc 11.1.1
  • Conan version: 1.37.2
  • Python version: 3.9.5
  • Bazel version: 1.2.1

Steps to reproduce

Can be reproduces using example project and running:

conan install . --build=missing
bazel build //:hello-world 

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
blackhogzcommented, Jul 30, 2021

@fanStefan @tapia sorry I’m very new to conan and thus new to conan + bazel.

Supposedly this issue has been fixed by 1.39.0, which I have confirmed by running

$ conan --version
Conan version 1.39.0

I downloaded the “project” link in the above comment https://github.com/conan-io/conan/issues/9138#issue-927672935, and run

$ conan install . --build=missing
bazel-string-define-issue$ conan install . --build=missing
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++
compiler.version=9
os=Linux
os_build=Linux
[options]
[build_requires]
[env]

conanfile.py (bazel-example/None): Installing package
Requirements
Packages
Build requirements
    boost/1.76.0 from 'conancenter' - Cache
    bzip2/1.0.8 from 'conancenter' - Cache
    libbacktrace/cci.20210118 from 'conancenter' - Cache
    zlib/1.2.11 from 'conancenter' - Cache
Build requirements packages
    boost/1.76.0:adf48b8e4446dcb68f440fe42ff08878d5c7feed - Cache
    bzip2/1.0.8:da606cf731e334010b0bf6e85a2a6f891b9f36b0 - Cache
    libbacktrace/cci.20210118:6af9cc7cb931c5ad942174fd7838eb655717c709 - Cache
    zlib/1.2.11:6af9cc7cb931c5ad942174fd7838eb655717c709 - Cache

Installing (downloading, building) binaries...
bzip2/1.0.8: Already installed!
bzip2/1.0.8: Appending PATH environment variable: /.../.conan/data/bzip2/1.0.8/_/_/package/da606cf731e334010b0bf6e85a2a6f891b9f36b0/bin
libbacktrace/cci.20210118: Already installed!
zlib/1.2.11: Already installed!
boost/1.76.0: Already installed!
conanfile.py (bazel-example/None): Applying build-requirement: boost/1.76.0
conanfile.py (bazel-example/None): Applying build-requirement: zlib/1.2.11
conanfile.py (bazel-example/None): Applying build-requirement: bzip2/1.0.8
conanfile.py (bazel-example/None): Applying build-requirement: libbacktrace/cci.20210118
conanfile.py (bazel-example/None): WARN: Using the new toolchains and generators without specifying a build profile (e.g: -pr:b=default) is discouraged and might cause failures and unexpected behavior
conanfile.py (bazel-example/None): Generator 'BazelDeps' calling 'generate()'
conanfile.py (bazel-example/None): WARN: Using the new toolchains and generators without specifying a build profile (e.g: -pr:b=default) is discouraged and might cause failures and unexpected behavior
conanfile.py (bazel-example/None): Generator 'BazelToolchain' calling 'generate()'
conanfile.py (bazel-example/None): Generator txt created conanbuildinfo.txt
conanfile.py (bazel-example/None): Aggregating env generators
conanfile.py (bazel-example/None): Generated conaninfo.txt
conanfile.py (bazel-example/None): Generated graphinfo

I do see that files including conandeps/BUILD and conandeps/dependencies.bzl is generated, but the BUILD file is empty, and dependencies.bzl has an def load_conan_dependencies(): pass.

Then if I do bazel build, it failed to find the boost dep.

bazel-string-define-issue$ bazel build //:hello-world
ERROR: /tmp/bazel-string-define-issue/BUILD:3:10: no such package '@boost//': The repository '@boost' could not be resolved and referenced by '//:hello-world'
ERROR: Analysis of target '//:hello-world' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.088s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (3 packages loaded, 4 targets configured)
    Fetching @local_config_cc; fetching

I feel I must have missed some obvious step, but I can figure it out. Can you please kindly provide some pointers on where I should look at to get conan+bazel to work?

Thanks!

0reactions
blackhogzcommented, Jul 30, 2021

Thanks @memsharded , let’s move the discussion to #9354.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot define string literals in cc_library · Issue #10859 - GitHub
Description of the problem / feature request:​​ Cannot #define a variable as a string literal.
Read more >
string | Bazel
A replacement field can be either a name, a number, or empty. Values are converted to strings using the str function.
Read more >
Configurable Build Attributes - Bazel
Configurable attributes, commonly known as select() , is a Bazel feature that lets users toggle the values of build rule attributes at the...
Read more >
Configurable Build Attributes - Bazel 0.29.1
By using select() in a configurable attribute, the attribute effectively takes on different values when different conditions hold.
Read more >
Commands and Options | Bazel
This option determines whether Bazel will strip debugging information from all binaries and shared libraries, by invoking the linker with the -Wl,--strip-debug ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found