Skip to content

Commit

Permalink
add bzlmod support (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
zaucy authored Apr 26, 2023
1 parent fc88b49 commit 48054f6
Show file tree
Hide file tree
Showing 18 changed files with 134 additions and 63 deletions.
19 changes: 19 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
common --enable_bzlmod
build --enable_platform_specific_config
build --incompatible_use_platforms_repo_for_constraints
build --enable_runfiles
build --incompatible_strict_action_env

build:linux --host_platform=@magic_enum//bazel/platforms:linux
build:linux --platforms=@magic_enum//bazel/platforms:linux

build:macos --host_platform=@magic_enum//bazel/platforms:macos
build:macos --platforms=@magic_enum//bazel/platforms:macos

build:windows --host_platform=@magic_enum//bazel/platforms:windows
build:windows --platforms=@magic_enum//bazel/platforms:windows

common:ci --announce_rc
test:ci --test_output=errors
build:ci --curses=no

1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.1.2
3 changes: 3 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ jobs:
cmake .. -DCMAKE_BUILD_TYPE=Debug
cmake --build . --config Debug
ctest --output-on-failure -C Debug
- name: Bazel Test
run: bazelisk test //... --config=ci
12 changes: 3 additions & 9 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ jobs:
sudo apt install ${{matrix.compiler.cxx}} -y
fi
- name: Configure bazel
run: |
wget -O - https://bazel.build/bazel-release.pub.gpg|sudo apt-key add -
sudo apt-add-repository "deb https://storage.googleapis.com/bazel-apt stable jdk1.8"
sudo apt update
sudo apt install bazel -y
- name: Build Release
run: |
rm -rf build
Expand All @@ -76,5 +69,6 @@ jobs:
cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
cmake --build . --config Debug
ctest --output-on-failure -C Debug
cd ..
bazel test //... --curses no
- name: Bazel Test
run: bazelisk test //... --config=ci
2 changes: 2 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ jobs:
cmake --build . --config Debug
ctest --output-on-failure -C Debug
- name: Bazel Test
run: bazelisk test //... --config=ci
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ _deps

### Bazel build artifacts ###
/bazel-*
/test/bazel-*
58 changes: 5 additions & 53 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//bazel:copts.bzl", "COPTS")

licenses(["notice"])

exports_files(["LICENSE"])
Expand All @@ -6,58 +9,7 @@ package(default_visibility = ["//visibility:public"])

cc_library(
name = "magic_enum",
hdrs = ["include/magic_enum.hpp", "include/magic_enum_format.hpp", "include/magic_enum_fuse.hpp", "include/magic_enum_switch.hpp"],
hdrs = glob(["include/*.hpp"]),
copts = COPTS,
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/include/catch2/catch.hpp"],
strip_include_prefix = "test/3rdparty/Catch2/include",
)

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",
],
)
8 changes: 8 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module(
name = "magic_enum",
version = "0.8.2",
compatibility_level = 0,
)

bazel_dep(name = "platforms", version = "0.0.6")
bazel_dep(name = "rules_cc", version = "0.0.6")
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ Header-only C++17 library provides static reflection for enums, work with any en
```
bazel build //...
bazel test //...
bazel run //:example
bazel run //example
```

(Note that you must use a supported compiler or specify it with `export CC= <compiler>`.)
Expand Down
File renamed without changes.
Empty file added bazel/BUILD.bazel
Empty file.
4 changes: 4 additions & 0 deletions bazel/copts.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
COPTS = select({
"@bazel_tools//tools/cpp:msvc": ["/std:c++17", "/permissive-"],
"//conditions:default": ["-std=c++17"],
})
25 changes: 25 additions & 0 deletions bazel/platforms/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package(default_visibility = ["//:__subpackages__"])

platform(
name = "linux",
constraint_values = [
"@platforms//os:linux",
"@bazel_tools//tools/cpp:clang",
],
)

platform(
name = "macos",
constraint_values = [
"@platforms//os:macos",
"@bazel_tools//tools/cpp:clang",
],
)

platform(
name = "windows",
constraint_values = [
"@platforms//os:windows",
"@bazel_tools//tools/cpp:msvc",
],
)
28 changes: 28 additions & 0 deletions example/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@magic_enum//bazel:copts.bzl", "COPTS")

_EXAMPLES = [
"enum_flag_example",
"example",
"example_containers_array",
"example_containers_bitset",
"example_containers_set",
"example_custom_name",
"example_switch",
]

[cc_binary(
name = example,
srcs = ["{}.cpp".format(example)],
deps = ["@magic_enum"],
copts = COPTS,
) for example in _EXAMPLES]

cc_binary(
name = "example_nonascii_name",
srcs = ["example_nonascii_name.cpp"],
deps = ["@magic_enum"],
copts = COPTS,
defines = ["MAGIC_ENUM_ENABLE_NONASCII"],
tags = ["manual"],
)
2 changes: 2 additions & 0 deletions test/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import %workspace%/../.bazelrc

25 changes: 25 additions & 0 deletions test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
load("@rules_cc//cc:defs.bzl", "cc_test")
load("@magic_enum//bazel:copts.bzl", "COPTS")

# bazel central registry has a catch2 module, but is newer than the one included
# in this repository
cc_library(
name = "catch2",
includes = ["3rdparty/Catch2/include"],
hdrs = ["3rdparty/Catch2/include/catch2/catch.hpp"],
copts = COPTS,
)

_TESTS = [
"test",
"test_aliases",
"test_containers",
"test_flags",
]

[cc_test(
name = test,
srcs = ["{}.cpp".format(test)],
deps = ["@magic_enum", ":catch2"],
copts = COPTS,
) for test in _TESTS]
7 changes: 7 additions & 0 deletions test/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module(name = "magic_enum_tests")

bazel_dep(name = "magic_enum")
bazel_dep(name = "platforms", version = "0.0.6")
bazel_dep(name = "rules_cc", version = "0.0.6")

local_path_override(module_name = "magic_enum", path = "..")
Empty file added test/WORKSPACE.bazel
Empty file.

0 comments on commit 48054f6

Please sign in to comment.