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
Create a BUILD file for compatibility with bazel #1923
Conversation
With this change, it's much easier for bazel projects to depend on Catch. They just need to add: - In the workspace: ``` http_archive( name = "com_github_catchorg_catch2", urls = ["https://github.com/catchorg/Catch2/archive/v2.12.1.tar.gz"], strip_prefix = "Catch2-2.12.1", sha256 = "e5635c082282ea518a8dd7ee89796c8026af8ea9068cd7402fb1615deacd91c3", ) ``` Or the appropriate version/sha256. - For the tests, assuming that `test_main.cc` contains the `CATCH_CONFIG_MAIN`: ``` cc_library( name = "test_main", srcs = ["test_main.cc"], deps = ["@com_github_catchorg_catch2//:catch2"], ) ```
Codecov Report
@@ Coverage Diff @@
## master #1923 +/- ##
=======================================
Coverage 88.60% 88.60%
=======================================
Files 138 138
Lines 5606 5606
=======================================
Hits 4967 4967
Misses 639 639 |
Note that several people have adapted their own solution for bazel:
|
Eh, sure. |
That's the kind of enthusiasm I like to see 😄 Thanks! |
Someone will have to provide the support for v3 branch or Bazel will be dropped again though. |
I'm just a random user of catch, so I don't know much about v3, but I can help with support if needed. Can you point me to docs about the v3 branch, how to use it? |
So, I had a look at the dev-v3 branch, and from what I understand, instead of If that's the case, we can get by easily by providing a target that globs all the hpp files recursively. We might also want to exclude the It would look something like: cc_library(
name = "catch2_internal",
hdrs = glob(["src/catch2/internal/**/*.hpp"]),
visibility = ["//visibility:private"],
includes = ["src/"],
)
cc_library(
name = "catch2",
hdrs = glob(["src/catch2/**/*.hpp"], exclude=["src/catch2/internal/**"]),
visibility = ["//visibility:public"],
deps = [":catch2_internal"],
includes = ["src/"],
) (Not tested, just a design proposition) |
v3 is also moving to be a standard statically compiled library, so you need proper sources in the build specification. |
Do you have docs on how to use the v3 branch? |
Basically all .cpp files (except for the one that provides main) are compiled into one static library. The main is compiled into a different static library, that depends on the first one. User then can link either just the implementation and provide main themselves, or opt into the default main by linking the second one (or both, but both CMake and pkg-config express dependency between the one with main and the implementation one, so users can just link to the one with main). |
Created #1936 |
With this change, it's much easier for bazel projects to depend on
Catch. They just need to add:
Or the appropriate version/sha256.
test_main.cc
contains theCATCH_CONFIG_MAIN
: