From 3506f6a678dd9d85535ea3c633bcf118114857ac Mon Sep 17 00:00:00 2001 From: Vertexwahn Date: Sun, 9 Aug 2020 16:27:56 +0200 Subject: [PATCH] Add support for Bazel --- bazel/.bazelversion | 1 + bazel/BUILD.bazel | 8 ++++++++ bazel/README.md | 30 ++++++++++++++++++++++++++++++ bazel/WORKSPACE.bazel | 14 ++++++++++++++ bazel/main.cpp | 12 ++++++++++++ bazel/spdlog.BUILD | 28 ++++++++++++++++++++++++++++ 6 files changed, 93 insertions(+) create mode 100644 bazel/.bazelversion create mode 100644 bazel/BUILD.bazel create mode 100644 bazel/README.md create mode 100644 bazel/WORKSPACE.bazel create mode 100644 bazel/main.cpp create mode 100644 bazel/spdlog.BUILD diff --git a/bazel/.bazelversion b/bazel/.bazelversion new file mode 100644 index 00000000..47b322c9 --- /dev/null +++ b/bazel/.bazelversion @@ -0,0 +1 @@ +3.4.1 diff --git a/bazel/BUILD.bazel b/bazel/BUILD.bazel new file mode 100644 index 00000000..121ea066 --- /dev/null +++ b/bazel/BUILD.bazel @@ -0,0 +1,8 @@ +# Copyright(c) 2015-present, Gabi Melman & spdlog contributors. +# Distributed under the MIT License (http://opensource.org/licenses/MIT) + +cc_binary( + name = "HelloWorld", + srcs = ["main.cpp"], + deps = ["@spdlog"] +) diff --git a/bazel/README.md b/bazel/README.md new file mode 100644 index 00000000..93049f8e --- /dev/null +++ b/bazel/README.md @@ -0,0 +1,30 @@ +# How to use spdlog with Bazel? + +1. Add to your `WORKSPACE` file this: + + ```python + http_archive( + name = "spdlog", + build_file = "//:spdlog.BUILD", + sha256 = "f0114a4d3c88be9e696762f37a7c379619443ce9d668546c61b21d41affe5b62", + strip_prefix = "spdlog-1.7.0", + urls = ["https://github.com/gabime/spdlog/archive/v1.7.0.tar.gz"], + ) + ``` + + + +2. Copy `spdlog.BUILD` to your workspace directry. + +Note: If you make use of the FMT library already in your project you can use that one also for spdlog: Remove the comments in the `spdlog.BUILD` file. + +**Example** + +This directory contains `WORKSPACE.bazel` file that how to integrate `spdlog` into your Bazel project. + +To test it run: + +```bash +bazel run //:HelloWorld +``` + diff --git a/bazel/WORKSPACE.bazel b/bazel/WORKSPACE.bazel new file mode 100644 index 00000000..c0a0d516 --- /dev/null +++ b/bazel/WORKSPACE.bazel @@ -0,0 +1,14 @@ +# Copyright(c) 2015-present, Gabi Melman & spdlog contributors. +# Distributed under the MIT License (http://opensource.org/licenses/MIT) + +workspace(name = "spdlogDemo") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "spdlog", + build_file = "//:spdlog.BUILD", + sha256 = "f0114a4d3c88be9e696762f37a7c379619443ce9d668546c61b21d41affe5b62", + strip_prefix = "spdlog-1.7.0", + urls = ["https://github.com/gabime/spdlog/archive/v1.7.0.tar.gz"], +) \ No newline at end of file diff --git a/bazel/main.cpp b/bazel/main.cpp new file mode 100644 index 00000000..2bf8f4a2 --- /dev/null +++ b/bazel/main.cpp @@ -0,0 +1,12 @@ +// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) + +#include +#include + +#include + +int main() { + spdlog::info("Welcome to spdlog!"); + spdlog::error("Some error message with arg: {}", 1); +} diff --git a/bazel/spdlog.BUILD b/bazel/spdlog.BUILD new file mode 100644 index 00000000..4e5648df --- /dev/null +++ b/bazel/spdlog.BUILD @@ -0,0 +1,28 @@ +# Copyright(c) 2015-present, Gabi Melman & spdlog contributors. +# Distributed under the MIT License (http://opensource.org/licenses/MIT) + +cc_library( + name = "spdlog", + srcs = [ + "src/async.cpp", + "src/cfg.cpp", + "src/color_sinks.cpp", + "src/file_sinks.cpp", + "src/fmt.cpp", + "src/spdlog.cpp", + "src/stdout_sinks.cpp", + ], + hdrs = glob(["include/**/*.h*"]), + defines = [ + "SPDLOG_COMPILED_LIB", + #"SPDLOG_FMT_EXTERNAL", + ], + includes = ["include"], + linkopts = select({ + "@bazel_tools//src/conditions:windows": [], + "@bazel_tools//src/conditions:darwin": [], + "//conditions:default": ["-lpthread"], + }), + visibility = ["//visibility:public"], + #deps = ["@fmt"], +)