From f8606e5e76579442a1c6563e718ea54c673f1a04 Mon Sep 17 00:00:00 2001 From: Ryan Beasley Date: Tue, 8 Dec 2020 11:42:25 -0800 Subject: [PATCH] linux-sandbox: don't assume -lrt, -D__STDC_FORMAT_MACROS Resolves #12327. Closes #12662. PiperOrigin-RevId: 346374211 --- src/main/tools/BUILD | 17 +++++++++++++++-- src/main/tools/logging.h | 4 ++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/tools/BUILD b/src/main/tools/BUILD index 9f64e096a88349..6d8b0269c40904 100644 --- a/src/main/tools/BUILD +++ b/src/main/tools/BUILD @@ -41,7 +41,11 @@ cc_binary( }), linkopts = select({ "//src/conditions:windows": [], - "//conditions:default": ["-lm"], + "//src/conditions:darwin": ["-lm"], + "//conditions:default": [ + "-lm", + "-lrt", + ], }), deps = select({ "//src/conditions:windows": [], @@ -86,7 +90,16 @@ cc_binary( "linux-sandbox-pid1.h", ], }), - linkopts = ["-lm"], + linkopts = select({ + "//src/conditions:darwin": [], + "//src/conditions:freebsd": [], + "//src/conditions:openbsd": [], + "//src/conditions:windows": [], + "//conditions:default": [ + "-lm", + "-lrt", + ], + }), deps = select({ "//src/conditions:darwin": [], "//src/conditions:freebsd": [], diff --git a/src/main/tools/logging.h b/src/main/tools/logging.h index c3abe35e231758..14b46c92561b10 100644 --- a/src/main/tools/logging.h +++ b/src/main/tools/logging.h @@ -15,6 +15,10 @@ #ifndef SRC_MAIN_TOOLS_LOGGING_H_ #define SRC_MAIN_TOOLS_LOGGING_H_ +// See https://stackoverflow.com/a/8132440 . +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS +#endif #include #include #include