From 5eb7153b88893eca2b9f53f6e3987dd65a2792c1 Mon Sep 17 00:00:00 2001 From: Andrey Shapovalov Date: Sun, 1 Aug 2021 18:37:42 -0700 Subject: [PATCH] Fixes for building on Windows. * Updated glog to version 0.5.0 to account for https://github.com/google/glog/issues/472. * Updated .bazelrc to specify C++17 correctly for Windows. * Added documentation. --- .bazelrc | 8 +++++++- README_Build.md | 17 +++++++++++++++++ README_Install_Linux.md | 23 +++++++++++++++++++++++ README_Install_MacOS.md | 38 ++++++++++++++++++++++++++++++++++++++ README_Install_Windows.md | 36 ++++++++++++++++++++++++++++++++++++ WORKSPACE.bazel | 8 +++++--- stout/callback.h | 1 + stout/semaphore.h | 9 +++++---- 8 files changed, 132 insertions(+), 8 deletions(-) create mode 100644 README_Build.md create mode 100644 README_Install_Linux.md create mode 100644 README_Install_MacOS.md create mode 100644 README_Install_Windows.md diff --git a/.bazelrc b/.bazelrc index 39a2ec7a..438d0b0a 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,3 +1,9 @@ # Specific Bazel build/test options. -build --cxxopt='-std=c++17' +build --enable_platform_specific_config + +build:windows --compiler="clang-cl" --cxxopt="/std:c++17" + +build:macos --cxxopt=-std=c++17 + +build:linux --cxxopt=-std=c++17 \ No newline at end of file diff --git a/README_Build.md b/README_Build.md new file mode 100644 index 00000000..743fdf95 --- /dev/null +++ b/README_Build.md @@ -0,0 +1,17 @@ +# Building/Testing +Currently we only support Bazel and expect/use C++17. + ``` +1. Build the library Eventuals with: +``` +bazel build :eventuals +``` +After the running command above the new directory "bazel-bin" in your project folder is created which includes eventuals.lib. + +2. Build the tests with: +``` +bazel build test:eventuals +``` +Build and run the tests with: +``` +bazel test test:eventuals +``` \ No newline at end of file diff --git a/README_Install_Linux.md b/README_Install_Linux.md new file mode 100644 index 00000000..70f7c76b --- /dev/null +++ b/README_Install_Linux.md @@ -0,0 +1,23 @@ +# Installation + +## Linux installation + +Here we offer a proven way to configure the development environment for [Bazel](https://bazel.build) in the [Linux](https://www.linux.org) operating system. + +1. Install a convenient development environment [Visual Studio Code](https://code.visualstudio.com/download) that is adapted to work with [Bazel](https://bazel.build). +2. Run [Visual Studio Code](https://code.visualstudio.com/download) and install the necessary extensions: + 1. [Bazel plugin](https://marketplace.visualstudio.com/items?itemName=BazelBuild.vscode-bazel). This extension provides support for Bazel in Visual Studio Code. + 2. [C/C++ plugin](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools). The C/C++ extension adds language support for C/C++ to Visual Studio Code, including features such as IntelliSense and debugging. + 3. [Clang-format plugin](https://marketplace.visualstudio.com/items?itemName=xaver.clang-format). This extension allows you to comply with the clang format for your code. Read the plugin overview for configuration. + 4. [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb). This extension allows you to debug your code. Read the plugin overview for configuration. +3. Install [Bazel](https://bazel.build). +4. Install the latest version of the compiler [LLLM](https://llvm.org) ([LLVM Download Page](https://releases.llvm.org/download.html)). +5. Install [Git](https://git-scm.com/downloads) +6. Make an empty directory for your projects and clone the [stout-eventuals](https://github.com/3rdparty/stout-eventuals) via the git clone link: +``` +https://github.com/3rdparty/stout-eventuals.git +``` +7. Start [VS Code](https://code.visualstudio.com). +8. Open the stout-eventuals folder via VS Code. +9. Check the checkboxes about "Trust the authors". +10. VS Code -> Terminal -> New Terminal \ No newline at end of file diff --git a/README_Install_MacOS.md b/README_Install_MacOS.md new file mode 100644 index 00000000..dc68713e --- /dev/null +++ b/README_Install_MacOS.md @@ -0,0 +1,38 @@ +# Installation + +## MacOS installation + +Here we offer a proven way to configure the development environment for [Bazel](https://bazel.build) in the [MacOS](https://www.apple.com) operating system. + +1. Install a convenient development environment [Visual Studio Code](https://code.visualstudio.com/download) that is adapted to work with [Bazel](https://bazel.build). +2. Run [Visual Studio Code](https://code.visualstudio.com/download) and install the necessary extensions: + 1. [Bazel plugin](https://marketplace.visualstudio.com/items?itemName=BazelBuild.vscode-bazel). This extension provides support for Bazel in Visual Studio Code. + 2. [C/C++ plugin](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools). The C/C++ extension adds language support for C/C++ to Visual Studio Code, including features such as IntelliSense and debugging. + 3. [Clang-format plugin](https://marketplace.visualstudio.com/items?itemName=xaver.clang-format). This extension allows you to comply with the clang format for your code. Read the plugin overview for configuration. + 4. [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb). This extension allows you to debug your code. Read the plugin overview for configuration. +3. Install [Bazel](https://bazel.build). +Here we provide some details to help you: + 1. Check the presence of [Bazel](https://bazel.build) in your [MacOS](https://www.apple.com) using the following command in your terminal: + ``` + $ bazel --version + ``` + 2. If you have no Bazel - install it using Homebrew. Install Homebrew(if needed): + ``` + $ /bin/bash -c "$(curl -fsSL \ https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" + ``` + 3. Install the Bazel package via Homebrew as follows: + ``` + $ brew install bazel + ``` + 4. Upgrade to a newer version of Bazel using the following command(if needed): + ``` + $ brew upgrade bazel + ``` +4. Make an empty directory for your projects and clone the [stout-eventuals](https://github.com/3rdparty/stout-eventuals) via the git clone link: +``` +https://github.com/3rdparty/stout-eventuals.git +``` +5. Start [VS Code](https://code.visualstudio.com). +6. Open the stout-eventuals folder via VS Code. +7. Check the checkboxes about "Trust the authors". +8. VS Code -> Terminal -> New Terminal \ No newline at end of file diff --git a/README_Install_Windows.md b/README_Install_Windows.md new file mode 100644 index 00000000..12979b13 --- /dev/null +++ b/README_Install_Windows.md @@ -0,0 +1,36 @@ +# Installation + +## Windows installation + +Here we offer a proven way to configure the development environment for [Bazel](https://bazel.build) in the [Windows](https://www.microsoft.com) operating system. + +1. Install a convenient development environment [Visual Studio Code](https://code.visualstudio.com/download) that is adapted to work with [Bazel](https://bazel.build). +2. Run [Visual Studio Code](https://code.visualstudio.com/download) and install the necessary extensions: + 1. [Bazel plugin](https://marketplace.visualstudio.com/items?itemName=BazelBuild.vscode-bazel). This extension provides support for Bazel in Visual Studio Code. + 2. [C/C++ plugin](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools). The C/C++ extension adds language support for C/C++ to Visual Studio Code, including features such as IntelliSense and debugging. + 3. [Clang-format plugin](https://marketplace.visualstudio.com/items?itemName=xaver.clang-format). This extension allows you to comply with the clang format for your code. Read the plugin overview for configuration. + Short instuction how you can use Visual Studio `clang-format`: + 1. Create a folder `.vscode`in your project folder. + 2. Create a file `settings.json` in the folder `.vscode` + 3. Add the data to the file (check the path to your `clang-format.exe`): + ``` + { + "clang-format.style": "Google", + "clang-format.executable": "C:/Program Files (x86)/Microsoft Visual Studio/2019/ + Community/VC/Tools/Llvm/x64/bin/clang-format.exe", + "editor.formatOnSave": true + } + ``` + 4. [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb). This extension allows you to debug your code. Read the plugin overview for configuration. +3. Install [Bazel](https://bazel.build). Detailed installation instructions for Windows can be found here: [Installing Bazel on Windows](https://docs.bazel.build/versions/4.1.0/install-windows.html). This is an important step. You must follow all the instructions, otherwise you will get various errors at the compilation stage. +4. Install the latest version of the compiler [LLLM](https://llvm.org) ([LLVM Download Page](https://releases.llvm.org/download.html)). +5. Install [Git](https://git-scm.com/downloads) +6. Restart your PC. +7. Make an empty directory for your projects and clone the [stout-eventuals](https://github.com/3rdparty/stout-eventuals) via the git clone link: +``` +https://github.com/3rdparty/stout-eventuals.git +``` +8. Start [VS Code](https://code.visualstudio.com). +9. Open the stout-eventuals folder via VS Code. +10. Check the checkboxes about "Trust the authors". +11. VS Code -> Terminal -> New Terminal \ No newline at end of file diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 1820a957..148e2604 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -11,11 +11,13 @@ http_archive( ######################################################################## +# NOTE: using glog version 0.5.0 since older versions failed to +# compile on Windows, see: https://github.com/google/glog/issues/472 http_archive( name = "com_github_google_glog", - url = "https://github.com/google/glog/archive/v0.4.0.tar.gz", - sha256 = "f28359aeba12f30d73d9e4711ef356dc842886968112162bc73002645139c39c", - strip_prefix = "glog-0.4.0", + sha256 = "eede71f28371bf39aa69b45de23b329d37214016e2055269b3b5e7cfd40b59f5", + strip_prefix = "glog-0.5.0", + url = "https://github.com/google/glog/archive/refs/tags/v0.5.0.tar.gz", ) ######################################################################## diff --git a/stout/callback.h b/stout/callback.h index 874e37cf..c84f5129 100644 --- a/stout/callback.h +++ b/stout/callback.h @@ -1,5 +1,6 @@ #pragma once +#include #include // For std::aligned_storage. //////////////////////////////////////////////////////////////////////// diff --git a/stout/semaphore.h b/stout/semaphore.h index def51a02..ef2cc0a7 100644 --- a/stout/semaphore.h +++ b/stout/semaphore.h @@ -1,14 +1,15 @@ #pragma once +#include "glog/logging.h" // NOTE: must be included before . + #ifdef __MACH__ #include -#elif __WINDOWS__ +#elif _WIN32 +#include #else #include #endif // __MACH__ -#include "glog/logging.h" - //////////////////////////////////////////////////////////////////////// namespace stout { @@ -50,7 +51,7 @@ class Semaphore private: semaphore_t semaphore; }; -#elif __WINDOWS__ +#elif _WIN32 class Semaphore { public: