From f3b4a01ce24751da7a27d73db7a973e413ece88c Mon Sep 17 00:00:00 2001 From: FelixDuvalletKodiak <42152076+FelixDuvalletKodiak@users.noreply.github.com> Date: Thu, 8 Oct 2020 00:10:15 -0700 Subject: [PATCH] Add support for bazel (#56) * 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 --- .gitignore | 3 +++ BUILD.bazel | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 17 +++++++++++++++ WORKSPACE | 0 4 files changed, 83 insertions(+) create mode 100644 BUILD.bazel create mode 100644 WORKSPACE diff --git a/.gitignore b/.gitignore index ef6cd27..f67035b 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,6 @@ install_manifest.txt compile_commands.json CTestTestfile.cmake _deps + +### Bazel build artifacts ### +/bazel-* diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 0000000..aeefa75 --- /dev/null +++ b/BUILD.bazel @@ -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", + ], +) diff --git a/README.md b/README.md index dbf886b..6370850 100644 --- a/README.md +++ b/README.md @@ -219,6 +219,23 @@ CPMAddPackage( ) ``` +Bazel is also supported, simply add to your WORKSPACE file: +``` +http_archive( + name = "magic_enum", + strip_prefix = "magic_enum-", + urls = ["https://github.com/Neargye/magic_enum/archive/.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 compatibility * Clang/LLVM >= 5 diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 0000000..e69de29