Skip to content

peakschris/bazel7-conan-module-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Modification of https://github.com/bazelbuild/examples/cpp-tutorial/stage3 to demonstrate conan & bazel 7

This repo is a clone of https://github.com/bazelbuild/examples/cpp-tutorial/stage3, fixed for bazel 7 and enhanced to demonstrate usage of conan dependencies

Fixes for bazel 7

  • .bazelrc changes
  • remove WORKSPACE content
  • add MODULE.bazel
  • specify bazel version 7.2.0rc2

Conan demo

  • conan artifact definitions added to deps/conan
  • deps/conan/conan_extension.bzl added. This should be autogenerated by conan
  • deps/conan/artifacts.MODULE.bazel added. This should be autogenerated by conan.
  • include line added to MODULE.bazel, including deps/conan/artifacts.MODULE.bazel. include statements require bazel 7.2.0 (7.2.0rc2 is available and works). For use pre-7.2.0, the lines in artifacts.MODULE.bazel can be inlined into MODULE.bazel

Conan install

  • cd %workspace%
  • conan install deps/conan/conanfile.py

Manual hacks to fixup conan's current autogen content

  • deps/conan/conan/dependencies.bzl manually hacked after conan generation to fix existing issues
  • deps/conan/conan/dependencies.bzl hacked to make compatible with bazel modules
  • deps/conan/conan/zlib/BUILD.bazel hacked to add missing dependency on zlib.dll
  • resulting files after hacks are checked into deps/conan/conan-hacks for demo purposes

Build

  • bazel build //...

Stage 3

In this stage we step it up and showcase how to integrate multiple cc_library targets from different packages.

Below, we see a similar configuration from Stage 2, except that this BUILD file is in a subdirectory called lib. In Bazel, subdirectories containing BUILD files are known as packages. The new property visibility will tell Bazel which package(s) can reference this target, in this case the //main package can use hello-time library.

cc_library(
    name = "hello-time",
    srcs = ["hello-time.cc"],
    hdrs = ["hello-time.h"],
    visibility = ["//main:__pkg__"],
)

To use our hello-time library, an extra dependency is added in the form of //path/to/package:target_name, in this case, it's //lib:hello-time

cc_binary(
    name = "hello-world",
    srcs = ["hello-world.cc"],
    deps = [
        ":hello-greet",
        "//lib:hello-time",
    ],
)

To build this example, use

bazel build //main:hello-world

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published