Skip to content

Commit

Permalink
Simplify Bazel
Browse files Browse the repository at this point in the history
Please see Neargye#309 for context, but this sidesteps the bazel dependencies and cleans up the copts where they're not actually used.
  • Loading branch information
cpsauer committed Nov 14, 2023
1 parent ea5b977 commit 588861e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 32 deletions.
6 changes: 1 addition & 5 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//bazel:copts.bzl", "COPTS")

licenses(["notice"])

exports_files(["LICENSE"])
Expand All @@ -10,6 +7,5 @@ package(default_visibility = ["//visibility:public"])
cc_library(
name = "magic_enum",
hdrs = glob(["include/magic_enum/*.hpp"]),
copts = COPTS,
includes = ["include"],
includes = ["include/magic_enum"],
)
3 changes: 0 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@ module(
version = "0.9.4",
compatibility_level = 0,
)

bazel_dep(name = "rules_cc", version = "0.0.8")
bazel_dep(name = "bazel_skylib", version = "1.4.2")
10 changes: 0 additions & 10 deletions bazel/copts.bzl
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
load("@bazel_skylib//lib:selects.bzl", "selects")

COPTS = selects.with_or({
("//conditions:default", "@rules_cc//cc/compiler:clang", "@rules_cc//cc/compiler:gcc", "@rules_cc//cc/compiler:mingw-gcc"): [
"-std=c++17",
],
("@rules_cc//cc/compiler:msvc-cl", "@rules_cc//cc/compiler:clang-cl"): [
"/std:c++17",
"/permissive-",
],
})
28 changes: 15 additions & 13 deletions test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,23 +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_flags",
]

_MSVC_FLAGS = ["/std:c++17", "/permissive-"]
_COPTS = select({
"//conditions:default": ["-std=c++17"],
"@bazel_tools//tools/cpp:clang-cl": _MSVC_FLAGS,
"@bazel_tools//tools/cpp:msvc": _MSVC_FLAGS,
})
[cc_test(
name = test,
srcs = ["{}.cpp".format(test)],
deps = ["@magic_enum", ":catch2"],
copts = COPTS,
copts = _COPTS,
) for test in _TESTS]

# 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"],
)
1 change: 0 additions & 1 deletion test/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module(name = "magic_enum_tests")

bazel_dep(name = "magic_enum")
bazel_dep(name = "rules_cc", version = "0.0.8")

local_path_override(module_name = "magic_enum", path = "..")

0 comments on commit 588861e

Please sign in to comment.