drogon icon indicating copy to clipboard operation
drogon copied to clipboard

Support for bazel C++ - adding compilation rules (BUILD.bazel)

Open janeusz2000 opened this issue 3 years ago • 2 comments

I Would like to have an option for easy compilation of the Drogon in my Bazel project, something like:

WORKSPACE.bazel

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "drogon",
    urls = ["https://github.com/drogonframework/drogon/archive/refs/heads/master.zip"],
    strip_prefix = "drogon-master",
)

BUILD.bazel

load("@rules_cc//cc:defs.bzl", "cc_library")
cc_library(
    name="drogon",
    deps = [
        "@drogon//:drogon"
    ]
)

An excellent example of this is in one of the Drogon dependencies (https://github.com/open-source-parsers/jsoncpp) which you can compile with Bazel via: WORKSPACE.bazel

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name="jsoncpp",
    urls=["https://github.com/open-source-parsers/jsoncpp/archive/refs/heads/master.zip"],
    strip_prefix="jsoncpp-master"
)

BUILD.bazel

load("@rules_cc//cc:defs.bzl", "cc_library")
cc_library(
    name = "jsoncpp",
    deps = [
        "@jsoncpp//:jsoncpp"
    ]
)

This is possible because in the repo jsoncpp there is a library target specified (BUILD.bazel): jsoncpp*

If I want to use Drogon right now, I need to run make via Bazel which is not ideal and not straightforward. This change would allow me to have very clear access to this library and my project would be less prone to linking errors, because the whole process would be way easier to debug

For invoking bazel in all of this cases I am using bazel build --config=gcc :all command, where config is defined in .bazelrc file that contains:

build -c opt
build:gcc --cxxopt=-std=c++17 --color=auto

I am using GCC 9.4.0

janeusz2000 avatar Jul 24 '22 23:07 janeusz2000

An extra cool feature for this would be also to define WORKSPACE.bazel file with all the Drogon dependencies, but since not every dependency have a BUILD.bazel file specified, this would be hard to achieve. This would allow bazel to automatically fetch, build and link all the dependency that is needed in order to build Drogon repo.

janeusz2000 avatar Jul 25 '22 00:07 janeusz2000

Thanks for the feature request. I think this is a good idea. I added the enhancement label to this issue. Every PR in this regard is welcome.

rbugajewski avatar Jul 25 '22 09:07 rbugajewski