From 5dc1293a7b0bb463a81a6d3850e32ef7866a4c41 Mon Sep 17 00:00:00 2001 From: Jay Conrod Date: Wed, 14 Jun 2023 21:17:56 -0700 Subject: [PATCH] singlejar: fixes to build with msys2 on Windows singlejar is a C++ tool that Bazel builds for the executor platform. This change resolves some compile-time errors on Windows with msys2. In src/tools/singlejar/diag.h, use `##__VA_ARGS__` instead of `__VA_ARGS__`. This uses a language extension implemented in MSVC, GCC, and Clang that elides the leading comma when there are no arguments. MSVC did this implicitly without `##`, which is why this compiles now. In src/main/util/numbers.h, include `` for `int32_t`. Fixes #18632 Closes #18660. PiperOrigin-RevId: 540463565 Change-Id: Ide389949894bdaeffc8771dd1682ad0df1e79330 --- src/main/cpp/util/numbers.h | 1 + src/tools/singlejar/diag.h | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/cpp/util/numbers.h b/src/main/cpp/util/numbers.h index f1ef6f79913f3f..f6052b123042d9 100644 --- a/src/main/cpp/util/numbers.h +++ b/src/main/cpp/util/numbers.h @@ -14,6 +14,7 @@ #ifndef BAZEL_SRC_MAIN_CPP_UTIL_NUMBERS_H_ #define BAZEL_SRC_MAIN_CPP_UTIL_NUMBERS_H_ +#include #include namespace blaze_util { diff --git a/src/tools/singlejar/diag.h b/src/tools/singlejar/diag.h index 9120911678b705..ee0793ac7f5a20 100644 --- a/src/tools/singlejar/diag.h +++ b/src/tools/singlejar/diag.h @@ -38,18 +38,18 @@ #include #include #define _diag_msg(prefix, msg, ...) \ - { fprintf(stderr, prefix msg "\n", __VA_ARGS__); } + { fprintf(stderr, prefix msg "\n", ##__VA_ARGS__); } #define _diag_msgx(exit_value, prefix, msg, ...) \ - { \ - _diag_msg(prefix, msg, __VA_ARGS__); \ - ::ExitProcess(exit_value); \ + { \ + _diag_msg(prefix, msg, ##__VA_ARGS__); \ + ::ExitProcess(exit_value); \ } #define diag_err(exit_value, fmt, ...) \ - _diag_msgx(exit_value, "ERROR: ", fmt, __VA_ARGS__) + _diag_msgx(exit_value, "ERROR: ", fmt, ##__VA_ARGS__) #define diag_errx(exit_value, fmt, ...) \ - _diag_msgx(exit_value, "ERROR: ", fmt, __VA_ARGS__) -#define diag_warn(fmt, ...) _diag_msg("WARNING: ", fmt, __VA_ARGS__) -#define diag_warnx(fmt, ...) _diag_msg("WARNING: ", fmt, __VA_ARGS__) + _diag_msgx(exit_value, "ERROR: ", fmt, ##__VA_ARGS__) +#define diag_warn(fmt, ...) _diag_msg("WARNING: ", fmt, ##__VA_ARGS__) +#define diag_warnx(fmt, ...) _diag_msg("WARNING: ", fmt, ##__VA_ARGS__) #else #error Unknown platform