Skip to content

Commit

Permalink
Add support for bazel (#56)
Browse files Browse the repository at this point in the history
* Add support for bazel

Bazel support for the magic_enum repository would help others using
bazel integrate this library into their projects.

This PR adds a BUILD file which enables magic_enum to be imported
seamlessly into other WORKSPACE files without having to write a custom
BUILD file.

It also adds bazel binaries & tests to enable running them via bazel
locally:

   export CC=clang ; bazel build //... ; bazel test //... ; bazel run //:example

Finally, bazel compilation artifacts are added to the gitignore file.

* Update BUILD file & specify http_archive in README

* Lint BUILD file
  • Loading branch information
FelixDuvalletKodiak authored Oct 8, 2020
1 parent 7063621 commit f3b4a01
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
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"])

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.

0 comments on commit f3b4a01

Please sign in to comment.