-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for running on Windows #233
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2a919d8
Extract source: Output special includes as include files, not source …
lfittl c546c48
Add src/include folder for internal headers and included .c files
lfittl 5913775
Avoid use of mmap, asprintf and strndup to improve portability
lfittl 1a39cc9
Improve handling of Postgres version-related defines
lfittl 85c0264
GH actions: Update to actions/checkout@v4
lfittl d081aa7
extract_source: Improve rewriting of thread local variables in includes
lfittl b2be8d5
Remove strnlen fallback implementation
lfittl eb9c256
Further improve compatibility with non-POSIX systems and C89 compilers
lfittl 52164d8
extract_source: Handle additional includes that are always needed dir…
lfittl ee67862
Windows support: Keep port/win32{,_msvc} includes and add to CFLAGS
lfittl ab3adeb
Windows support: Simplify write_stderr and should_output_to_client
lfittl c3d58c6
Windows support: Pull in necessary code during source extraction
lfittl c407f72
Windows support: Add fallback implementation for strlcpy
lfittl d564c68
Windows support: Use correct pg_config defines when on _WIN32/_WIN64
lfittl 8e91de2
Windows support: Use pg_config_os.h to include port/win32.h if needed
lfittl f23298f
Windows support: Add Makefile.msvc for building with MSVC and "nmake"
lfittl 8ca6228
Windows support: Add GitHub actions for testing with MSVC and MSYS2
lfittl 59586e4
Windows support: Don't use CRLFs for regression test .sql files
lfittl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.sql binary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# Makefile for "nmake", part of Microsoft Visual Studio Compiler (MSVC) on Windows | ||
|
||
TARGET = pg_query | ||
ARLIB = $(TARGET).lib | ||
|
||
SRC_FILES = src/*.c src/postgres/*.c vendor/protobuf-c/protobuf-c.c vendor/xxhash/xxhash.c protobuf/pg_query.pb-c.c | ||
|
||
CFLAGS = -I. -I./vendor -I./src/postgres/include -I./src/include -I./src/postgres/include/port/win32 -I./src/postgres/include/port/win32_msvc | ||
|
||
RM = del | ||
|
||
all: examples test build | ||
|
||
build: $(ARLIB) | ||
|
||
clean: | ||
$(RM) *.obj | ||
$(RM) pg_query.lib | ||
|
||
.PHONY: all clean build build_shared extract_source examples test install | ||
|
||
$(ARLIB): clean $(SRC_FILES) | ||
$(CC) $(CFLAGS) /c $(SRC_FILES) | ||
lib /OUT:pg_query.lib *.obj | ||
|
||
EXAMPLES = examples/simple examples/scan examples/normalize examples/simple_error examples/normalize_error examples/simple_plpgsql | ||
examples: $(EXAMPLES) | ||
.\examples\simple | ||
.\examples\scan | ||
.\examples\normalize | ||
.\examples\simple_error | ||
.\examples\normalize_error | ||
.\examples\simple_plpgsql | ||
|
||
examples/simple: examples/simple.c $(ARLIB) | ||
$(CC) $(CFLAGS) -o $@ examples/simple.c $(ARLIB) | ||
|
||
examples/scan: examples/scan.c $(ARLIB) | ||
$(CC) $(CFLAGS) -o $@ examples/scan.c $(ARLIB) | ||
|
||
examples/normalize: examples/normalize.c $(ARLIB) | ||
$(CC) $(CFLAGS) -o $@ examples/normalize.c $(ARLIB) | ||
|
||
examples/simple_error: examples/simple_error.c $(ARLIB) | ||
$(CC) $(CFLAGS) -o $@ examples/simple_error.c $(ARLIB) | ||
|
||
examples/normalize_error: examples/normalize_error.c $(ARLIB) | ||
$(CC) $(CFLAGS) -o $@ examples/normalize_error.c $(ARLIB) | ||
|
||
examples/simple_plpgsql: examples/simple_plpgsql.c $(ARLIB) | ||
$(CC) $(CFLAGS) -o $@ examples/simple_plpgsql.c $(ARLIB) | ||
|
||
TESTS = test/deparse test/fingerprint test/fingerprint_opts test/normalize test/parse test/parse_opts test/parse_protobuf test/parse_protobuf_opts test/parse_plpgsql test/scan test/split | ||
test: $(TESTS) | ||
.\test\deparse | ||
.\test\fingerprint | ||
.\test\fingerprint_opts | ||
.\test\normalize | ||
.\test\parse | ||
.\test\parse_opts | ||
.\test\parse_protobuf | ||
.\test\parse_protobuf_opts | ||
.\test\scan | ||
.\test\split | ||
|
||
# Doesn't work because of C2026: string too big, trailing characters truncated | ||
#test/complex: test/complex.c $(ARLIB) | ||
# We have "-Isrc/" because this test uses pg_query_fingerprint_with_opts | ||
# $(CC) $(CFLAGS) -o $@ -Isrc/ test/complex.c $(ARLIB) | ||
|
||
# Doesn't work since this requires pthreads | ||
#test/concurrency: test/concurrency.c test/parse_tests.c $(ARLIB) | ||
# $(CC) $(CFLAGS) -o $@ test/concurrency.c $(ARLIB) | ||
|
||
test/deparse: test/deparse.c test/deparse_tests.c $(ARLIB) | ||
$(CC) $(CFLAGS) -o $@ test/deparse.c $(ARLIB) | ||
|
||
test/fingerprint: test/fingerprint.c test/fingerprint_tests.c $(ARLIB) | ||
# We have "-Isrc/" because this test uses pg_query_fingerprint_with_opts | ||
$(CC) $(CFLAGS) -o $@ -Isrc/ test/fingerprint.c $(ARLIB) | ||
|
||
test/fingerprint_opts: test/fingerprint_opts.c test/fingerprint_opts_tests.c $(ARLIB) | ||
# We have "-Isrc/" because this test uses pg_query_fingerprint_with_opts | ||
$(CC) $(CFLAGS) -o $@ -Isrc/ test/fingerprint_opts.c $(ARLIB) | ||
|
||
test/normalize: test/normalize.c test/normalize_tests.c $(ARLIB) | ||
$(CC) $(CFLAGS) -o $@ test/normalize.c $(ARLIB) | ||
|
||
test/parse: test/parse.c test/parse_tests.c $(ARLIB) | ||
$(CC) $(CFLAGS) -o $@ test/parse.c $(ARLIB) | ||
|
||
test/parse_opts: test/parse_opts.c test/parse_opts_tests.c $(ARLIB) | ||
$(CC) $(CFLAGS) -o $@ test/parse_opts.c $(ARLIB) | ||
|
||
test/parse_plpgsql: test/parse_plpgsql.c test/parse_tests.c $(ARLIB) | ||
$(CC) $(CFLAGS) -o $@ test/parse_plpgsql.c $(ARLIB) | ||
|
||
test/parse_protobuf: test/parse_protobuf.c test/parse_tests.c $(ARLIB) | ||
$(CC) $(CFLAGS) -o $@ test/parse_protobuf.c $(ARLIB) | ||
|
||
test/parse_protobuf_opts: test/parse_protobuf_opts.c test/parse_opts_tests.c $(ARLIB) | ||
$(CC) $(CFLAGS) -o $@ test/parse_protobuf_opts.c $(ARLIB) | ||
|
||
test/scan: test/scan.c test/scan_tests.c $(ARLIB) | ||
$(CC) $(CFLAGS) -o $@ test/scan.c $(ARLIB) | ||
|
||
test/split: test/split.c test/split_tests.c $(ARLIB) | ||
$(CC) $(CFLAGS) -o $@ test/split.c $(ARLIB) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should go ahead and switch to a platform-independent build script to avoid makefile drift. Since we already include Ruby, maybe it could be a set of rake tasks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point re: Makefile drift. I wonder if there is a way to maintain the list of tests (and examples) another way, or just discover all of them in the test/examples directories, to avoid having to add new tests to both.
Generating Makefiles could work, but I worry that the indirection (i.e. having to go through a generation script first) isn't obvious - i.e. I'd prefer if we could find a way to avoid that extra step.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about something like CMake / Meson, which generates
Makefile
s on *nix platforms and NMake specificMakefile
s on Windows?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Postgres itself started using Meson for this purpose, but that of course then introduces a build-time dependency (which I'm 50/50 on whether its okay to add).
I think for now I'll not adjust this since this is already a massive PR, but I think we could come back to this at a future time.
One approach to solving the duplication for tests/examples specifically could be to have a Makefile in the
tests
andexamples
folders that can run on either platform. The main motivation for not doing that in the root folderMakefile
is that there are a bunch of features not supported bynmake
that make it hard to write a portable Makefile that can do the code generation/etc conditionally.