From 90a4af0ca3624cf31c3f5c1df4168e244c0e5ce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathan=20Gau=C3=ABr?= Date: Wed, 15 Feb 2023 16:18:38 +0100 Subject: [PATCH] build: change the way we set cxx version for bazel. Before, we did set cxx version to c++17 using COPTS in our bazel files. This was wrong, and part of the dependencies were then built with the default standard version. This was not an issue until we moved to c++17. Then, we decided to use the bazel --cxxopt=-std=c++17, but this was only valid for nix platforms. The last option left is to ask the user to specify the standard when building using bazel. --- .bazelrc | 1 - .github/workflows/bazel.yml | 16 ++++++++++++---- README.md | 4 ++-- kokoro/macos-clang-release-bazel/build.sh | 4 ++-- kokoro/scripts/linux/build-docker.sh | 4 ++-- 5 files changed, 18 insertions(+), 11 deletions(-) delete mode 100644 .bazelrc diff --git a/.bazelrc b/.bazelrc deleted file mode 100644 index 5b3d13f534d..00000000000 --- a/.bazelrc +++ /dev/null @@ -1 +0,0 @@ -build --cxxopt=-std=c++17 diff --git a/.github/workflows/bazel.yml b/.github/workflows/bazel.yml index 77ef6575684..dfb5e5ae322 100644 --- a/.github/workflows/bazel.yml +++ b/.github/workflows/bazel.yml @@ -26,7 +26,15 @@ jobs: with: path: ~/.bazel/cache key: bazel-cache-${{ runner.os }} - - name: Build All - run: bazel --output_user_root=~/.bazel/cache build //... - - name: Test All - run: bazel --output_user_root=~/.bazel/cache test //... + - name: Build All (Windows) + if: ${{matrix.os == 'windows-latest' }} + run: bazel --output_user_root=~/.bazel/cache build --cxxopt=/std:c++17 //... + - name: Test All (Windows) + if: ${{matrix.os == 'windows-latest' }} + run: bazel --output_user_root=~/.bazel/cache test --cxxopt=/std:c++17 //... + - name: Build All (Linux, MacOS) + if: ${{ matrix.os != 'windows-latest' }} + run: bazel --output_user_root=~/.bazel/cache build --cxxopt=-std=c++17 //... + - name: Test All (Linux, MacOS) + if: ${{ matrix.os != 'windows-latest' }} + run: bazel --output_user_root=~/.bazel/cache test --cxxopt=-std=c++17 //... diff --git a/README.md b/README.md index baa44e7077f..e9001455d6e 100644 --- a/README.md +++ b/README.md @@ -382,7 +382,7 @@ fuzzer tests. You can also use [Bazel](https://bazel.build/) to build the project. ```sh cd -bazel build :all +bazel build --cxxopt=-std=c++17 :all ``` ### Build a node.js package using Emscripten @@ -724,7 +724,7 @@ To run a single test target, specify `:my_test_target` instead of `:all`. Test t names get printed when you run `bazel test :all`. For example, you can run `opt_def_use_test` with: ```shell -bazel test :opt_def_use_test +bazel test --cxxopt=-std=c++17 :opt_def_use_test ``` diff --git a/kokoro/macos-clang-release-bazel/build.sh b/kokoro/macos-clang-release-bazel/build.sh index 50ad42bc81c..2465d9c6023 100644 --- a/kokoro/macos-clang-release-bazel/build.sh +++ b/kokoro/macos-clang-release-bazel/build.sh @@ -41,9 +41,9 @@ gsutil cp gs://bazel/5.0.0/release/bazel-5.0.0-darwin-x86_64 . chmod +x bazel-5.0.0-darwin-x86_64 echo $(date): Build everything... -./bazel-5.0.0-darwin-x86_64 build :all +./bazel-5.0.0-darwin-x86_64 build --cxxopt=-std=c++17 :all echo $(date): Build completed. echo $(date): Starting bazel test... -./bazel-5.0.0-darwin-x86_64 test :all +./bazel-5.0.0-darwin-x86_64 test --cxxopt=-std=c++17 :all echo $(date): Bazel test completed. diff --git a/kokoro/scripts/linux/build-docker.sh b/kokoro/scripts/linux/build-docker.sh index 52fbb9e4bbf..6bd71ce864b 100755 --- a/kokoro/scripts/linux/build-docker.sh +++ b/kokoro/scripts/linux/build-docker.sh @@ -191,10 +191,10 @@ elif [ $TOOL = "bazel" ]; then using bazel-5.0.0 echo $(date): Build everything... - bazel build :all + bazel build --cxxopt=-std=c++17 :all echo $(date): Build completed. echo $(date): Starting bazel test... - bazel test :all + bazel test --cxxopt=-std=c++17 :all echo $(date): Bazel test completed. fi