Skip to content

Commit

Permalink
fix(r): Build with __USE_MINGW_ANSI_STDIO to enable use of lld in for…
Browse files Browse the repository at this point in the history
…mat strings (#1180)

Closes #1113.

The mingw headers appear to be a little inconsistent with respect to the
definitions of `PRId64` and the format check attribute. I think this fix
it the least intrusive way to deal with that but I'm open to thoughts!
  • Loading branch information
paleolimbot authored Oct 11, 2023
1 parent c78398b commit 4cecdc2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
7 changes: 4 additions & 3 deletions c/driver/common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ extern "C" {

int AdbcStatusCodeToErrno(AdbcStatusCode code);

// The printf checking attribute doesn't work properly on gcc 4.8
// and results in spurious compiler warnings
#if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 5)
// If using mingw's c99-compliant printf, we need a different format-checking attribute
#if defined(__USE_MINGW_ANSI_STDIO) && defined(__MINGW_PRINTF_FORMAT)
#define ADBC_CHECK_PRINTF_ATTRIBUTE __attribute__((format(__MINGW_PRINTF_FORMAT, 2, 3)))
#elif defined(__GNUC__)
#define ADBC_CHECK_PRINTF_ATTRIBUTE __attribute__((format(printf, 2, 3)))
#else
#define ADBC_CHECK_PRINTF_ATTRIBUTE
Expand Down
2 changes: 1 addition & 1 deletion r/adbcpostgresql/src/Makevars.win
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

VERSION = 13.2.0
RWINLIB = ../windows/libpq-$(VERSION)
PKG_CPPFLAGS = -I$(RWINLIB)/include -I../src -DADBC_EXPORT=""
PKG_CPPFLAGS = -I$(RWINLIB)/include -I../src -DADBC_EXPORT="" -D__USE_MINGW_ANSI_STDIO
PKG_LIBS = -L$(RWINLIB)/lib${R_ARCH}${CRT} \
-lpq -lpgport -lpgcommon -lssl -lcrypto -lwsock32 -lsecur32 -lws2_32 -lgdi32 -lcrypt32 -lwldap32

Expand Down
7 changes: 6 additions & 1 deletion r/adbcsqlite/configure
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ echo "Testing R CMD SHLIB with $PKG_CPPFLAGS $PKG_LIBS -lsqlite3"
PKG_CPPFLAGS="$PKG_CPPFLAGS" PKG_LIBS="$PKG_LIBS -lsqlite3" \
$R_HOME/bin/R CMD SHLIB tools/test.c -o sqlite_test >sqlite_test.log 2>&1

if [ $? -ne 0 ] || [ ! -z "$FORCE_VENDORED_SQLITE3"]; then
if [ $? -ne 0 ] || [ ! -z "$FORCE_VENDORED_SQLITE3" ]; then
echo "Forcing vendored sqlite3 or #include <sqlite3.h>/-lsqlite3 failed:"
cat sqlite_test.log

Expand All @@ -52,6 +52,11 @@ else
PKG_LIBS="$PKG_LIBS -lsqlite3"
fi

# Add mingw printf flag if on Windows
if [ ! -z "$R_ADBC_SQLITE_ON_WINDOWS" ]; then
PKG_CPPFLAGS="$PKG_CPPFLAGS -D__USE_MINGW_ANSI_STDIO"
fi

rm -f tools/test.o sqlite_test sqlite_test.log || true

sed \
Expand Down
2 changes: 1 addition & 1 deletion r/adbcsqlite/configure.win
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
# under the License.

# Just call the original configure script
./configure
R_ADBC_SQLITE_ON_WINDOWS=1 ./configure

0 comments on commit 4cecdc2

Please sign in to comment.