Skip to content

Commit

Permalink
Windows support: Use pg_config_os.h to include port/win32.h if needed
Browse files Browse the repository at this point in the history
We previously had the hardcoded macOS ("darwin") contents for this file,
which is unnecessary and incorrect. Instead keep this file empty in all
cases except on Windows, where we include port/win32.h (just like Postgres
itself does), since it is actually necessary for our use case.

Different from Postgres itself we undef PGDLLIMPORT and PGDLLEXPORT, since
they are not needed for pg_query, and PGDLLIMPORT conflicts with the
thread local attribute.

Additionally, we workaround a Windows-specific problem with sigsetjmp
defines when using clang whilst __MINGW64__ is defined (which can happen
on MSYS2-based environments).
  • Loading branch information
lfittl committed Jan 1, 2024
1 parent 14bef9a commit 0a2e7d9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ extract_source: $(PGDIR)
mkdir ./src/postgres
mkdir ./src/postgres/include
LIBCLANG=/Library/Developer/CommandLineTools/usr/lib/libclang.dylib ruby ./scripts/extract_source.rb $(PGDIR)/ ./src/postgres/
# Override OS-specific pg_config_os.h to only load Win32 logic (the primary port logic that matters for libpg_query), if needed
echo "#if defined(_WIN32) || defined(_WIN64)" > ./src/postgres/include/pg_config_os.h
echo "#include \"port/win32.h\"" >> ./src/postgres/include/pg_config_os.h
# Don't mark anything as visible based on how Postgres defines it
echo "#undef PGDLLIMPORT" >> ./src/postgres/include/pg_config_os.h
echo "#undef PGDLLEXPORT" >> ./src/postgres/include/pg_config_os.h
# Avoid getting incorrect sigsetjmp overrides
echo "#ifdef __clang__" >> ./src/postgres/include/pg_config_os.h
echo "#undef __MINGW64__" >> ./src/postgres/include/pg_config_os.h
echo "#endif /* __clang__ */" >> ./src/postgres/include/pg_config_os.h
echo "#endif" >> ./src/postgres/include/pg_config_os.h
# Adjust version string to ignore differences in build environments
sed -i "" '$(shell echo 's/\#define PG_VERSION_STR .*/#define PG_VERSION_STR "PostgreSQL $(PG_VERSION) \(libpg_query\)"/')' ./src/postgres/include/pg_config.h
# Copy version information so its easily accessible
Expand Down
14 changes: 7 additions & 7 deletions src/postgres/include/pg_config_os.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* src/include/port/darwin.h */

#define __darwin__ 1

#if HAVE_DECL_F_FULLFSYNC /* not present before macOS 10.3 */
#define HAVE_FSYNC_WRITETHROUGH

#if defined(_WIN32) || defined(_WIN64)
#include "port/win32.h"
#undef PGDLLIMPORT
#undef PGDLLEXPORT
#ifdef __clang__
#undef __MINGW64__
#endif /* __clang__ */
#endif

0 comments on commit 0a2e7d9

Please sign in to comment.