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

Create a BUILD file for compatibility with bazel #1923

Merged
merged 1 commit into from May 17, 2020

Conversation

nitnelave
Copy link
Contributor

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"],
)

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
Copy link

codecov bot commented May 8, 2020

Codecov Report

Merging #1923 into master will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #1923   +/-   ##
=======================================
  Coverage   88.60%   88.60%           
=======================================
  Files         138      138           
  Lines        5606     5606           
=======================================
  Hits         4967     4967           
  Misses        639      639           

@nitnelave
Copy link
Contributor Author

Note that several people have adapted their own solution for bazel:

@horenmar
Copy link
Member

Eh, sure.

@horenmar horenmar merged commit 0e9bae1 into catchorg:master May 17, 2020
@nitnelave
Copy link
Contributor Author

That's the kind of enthusiasm I like to see 😄

Thanks!

@horenmar
Copy link
Member

Someone will have to provide the support for v3 branch or Bazel will be dropped again though.

@nitnelave
Copy link
Contributor Author

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?

@nitnelave
Copy link
Contributor Author

So, I had a look at the dev-v3 branch, and from what I understand, instead of #include <catch2/catch.hpp>, the user would include just what they need from catch2/*.hpp, right? And it's .hpp all the way, that's the only kind of file.

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 internal folder, and place it in a separate, non-visible target so users don't depend on it. WDYT?

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)

@horenmar
Copy link
Member

v3 is also moving to be a standard statically compiled library, so you need proper sources in the build specification.

@nitnelave
Copy link
Contributor Author

Do you have docs on how to use the v3 branch?

@horenmar
Copy link
Member

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).

@nitnelave
Copy link
Contributor Author

Created #1936

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

Successfully merging this pull request may close these issues.

None yet

2 participants