Re: Porting PG Extension from UNIX to Windows - Mailing list pgsql-hackers

From Craig Ringer
Subject Re: Porting PG Extension from UNIX to Windows
Date
Msg-id CAMsr+YHa_Lp+YtzWUGbPdaO3oJjkFtiPiM+oFZ93DUjm6Ao=Tg@mail.gmail.com
Whole thread Raw
In response to Porting PG Extension from UNIX to Windows  ("insaf.k" <insaf.k@zohocorp.com>)
List pgsql-hackers
On 25 April 2018 at 16:45, insaf.k <insaf.k@zohocorp.com> wrote:
> Hello,
>
> I have developed a postgres extension in Linux. I want to compile it in MS
> Windows as well.
>
> The extension extensively make use of POSIX threads and mutexes.
>
> I've done some research regarding compiling in Windows. I am not sure in
> what way I should compile the extension. AFAIK, Visual Studio is not POSIX
> compliant and so I'll have to rewrite all those POSIX calls using Windows
> API. So it's better to compile the extension in Cygwin.
>
> I have some questions regarding compiling the extension in Cygwin. Do I have
> to build PG in Cygwin, if I want to compile the extension in Cygwin?

If you want to compile the extension in cygwin with the cygwin
compiler, to get support for native(ish) pthreads, etc, then yes you
must use a PostgreSQL that is also for cygwin.

You can compile with mingw within cygwin - after all, msys is
basically a cut down cygwin. That produces a native Windows
executable, though it might still need mingw's runtime library, I
don't remember. You might as well use msys in that case, though. I
don't know what the state of pthreads support in mingw is.

> Our deployment pattern is like this, build everything in one machine and
> copy the DLLs into the production machine. So, if I compile in Cygwin, will
> the generated DLLs work in other Windows machines?

Only if they have a compatible cygwin AND a cygwin postgres.

> Would the target machine
> be required to install any dependencies related to Cygwin in order to use
> the DLLs?

Yes.

> Also, one more question, not related to PG. Cygwin vs native Windows API
> calls, will there be much difference in the performance?(We are not using
> fork() calls, btw).

Yes, Cygwin was significantly slower last I checked.

You might be able to run Pg under Windows Subsystem for Linux, using a
Linux PostgreSQL and a pthreads build of your extension.

Personally, I think you'll have to face adapting your threading layer.
But another option might be to use mingw64's threading support; see
the "POSIX Threads for Windows" section of
https://en.wikipedia.org/wiki/POSIX_Threads

-- 
 Craig Ringer                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services


pgsql-hackers by date:

Previous
From: Pavlo Golub
Date:
Subject: Re: Porting PG Extension from UNIX to Windows
Next
From: Robert Haas
Date:
Subject: Re: [doc fix] Trivial fix for PG 11 partitioning