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

Add support for bazel #56

Merged
merged 3 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps

### Bazel build artifacts ###
/bazel-*
63 changes: 63 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
licenses(["notice"])

exports_files(["LICENSE"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK bazel only has plans to support license files as part of the build, but since the repo provides it I am following (what I believe to be) an accepted convention of exporting it.
GoogleTest does this, for instance.


package(default_visibility = ["//visibility:public"])

cc_library(
name = "magic_enum",
hdrs = ["include/magic_enum.hpp"],
includes = ["include"],
)

cc_binary(
name = "example",
srcs = ["example/example.cpp"],
copts = ["-std=c++17"],
deps = [":magic_enum"],
)

cc_binary(
name = "enum_flag_example",
srcs = ["example/enum_flag_example.cpp"],
copts = ["-std=c++17"],
deps = [":magic_enum"],
)

cc_binary(
name = "example_custom_name",
srcs = ["example/example_custom_name.cpp"],
copts = ["-std=c++17"],
deps = [":magic_enum"],
)

cc_library(
name = "catch",
srcs = [],
hdrs = ["test/3rdparty/Catch2/catch.hpp"],
strip_include_prefix = "test/3rdparty/Catch2",
)

cc_test(
name = "test",
srcs = [
"test/test.cpp",
],
copts = ["-std=c++17"],
deps = [
":catch",
":magic_enum",
],
)

cc_test(
name = "test_flags",
srcs = [
"test/test_flags.cpp",
],
copts = ["-std=c++17"],
deps = [
":catch",
":magic_enum",
],
)
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,23 @@ CPMAddPackage(
)
```

Bazel is also supported, simply add to your WORKSPACE file:
```
http_archive(
name = "magic_enum",
strip_prefix = "magic_enum-<commit>",
urls = ["https://github.com/Neargye/magic_enum/archive/<commit>.zip"],
)
```

To use bazel inside the repository it's possible to do:
```
bazel build //...
bazel test //...
bazel run //:example
```
(Note that you must use a supported compiler or specify it with `export CC= <compiler>`.)

## Compiler compatibility

* Clang/LLVM >= 5
Expand Down
Empty file added WORKSPACE
Empty file.