Skip to content

Commit

Permalink
singlejar: fixes to build with msys2 on Windows
Browse files Browse the repository at this point in the history
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 `<cstdint>` for `int32_t`.

Fixes bazelbuild#18632

Closes bazelbuild#18660.

PiperOrigin-RevId: 540463565
Change-Id: Ide389949894bdaeffc8771dd1682ad0df1e79330
  • Loading branch information
jayconrod authored and copybara-github committed Jun 15, 2023
1 parent 30af6f1 commit 5dc1293
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/main/cpp/util/numbers.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#ifndef BAZEL_SRC_MAIN_CPP_UTIL_NUMBERS_H_
#define BAZEL_SRC_MAIN_CPP_UTIL_NUMBERS_H_

#include <cstdint>
#include <string>

namespace blaze_util {
Expand Down
16 changes: 8 additions & 8 deletions src/tools/singlejar/diag.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@
#include <stdio.h>
#include <string.h>
#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
Expand Down

0 comments on commit 5dc1293

Please sign in to comment.