Re: Trying to build x86 version on windows using meson

2024-03-22 Thread Andres Freund
Hi,

On 2024-03-21 13:17:44 -0400, Dave Cramer wrote:
> Attached correct log file

Hm. So there's something a bit odd:


> Build started at 2024-03-21T13:07:08.707715
> Main binary: C:\Program Files\Meson\meson.exe
> Build Options: '-Dextra_include_dirs=c:\Program Files\OpenSSL-Win64\include' 
> -Derrorlogs=True '-Dextra_lib_dirs=c:\Program Files\OpenSSL-win64' 
> '-Dprefix=c:\postgres86'
> Python system: Windows
> The Meson build system
> Version: 1.3.1
> Source dir: C:\Users\davec\projects\postgresql
> Build dir: C:\Users\davec\projects\postgresql\build
> Build type: native build

So meson thinks this is a native build, not a cross build. But then later
realizes that generated binaries and the current platform aren't the same. And
thus errors out.

The line numbers don't match my tree, but I think what's failing is the
sizeof() check. Which has support for cross builds, but it only uses that
(slower) path if it knows that a cross build is being used.


I suggest actually telling meson to cross compile. I don't quite know what
properties you're going to need, but something like the following (put it in a
file, point meson to it wity --cross-file) might give you a start:


[properties]
needs_exe_wrapper = false

[binaries]
c = 'cl'
cpp = 'cl'
ar = 'lib'
windres = 'rc'

[host_machine]
system = 'windows'
cpu_family = 'x86_64'
cpu = 'x86_64'
endian = 'little'

Greetings,

Andres Freund




Re: Trying to build x86 version on windows using meson

2024-03-21 Thread Dave Cramer
Andres,


On Thu, 21 Mar 2024 at 12:51, Andres Freund  wrote:

> Hi,
>
> On 2024-03-21 07:11:23 -0400, Dave Cramer wrote:
> > It seems that attempting to cross-compile on an ARM machine might be
> asking
> > too much as the use cases are pretty limited.
>
> It for sure is if you don't even provide the precise commands and logs of a
> failed run...
>
>
> > So the impetus for this is that folks require 32bit versions of psqlODBC.
> > Unfortunately EDB is no longer distributing a 32 bit windows version.
> >
> > All I really need is a 32bit libpq. This seems like a much smaller lift.
> > Suggestions ?
>
> FWIW, I can cross compile postgres from linux to 32bit windows without an
> issue. If you really just need a 32bit libpq, that might actually be
> easier.
>
> cd /tmp/ && rm -rf /tmp/meson-w32 && m setup --buildtype debug
> -Dcassert=true -Db_pch=true --cross-file
> ~/src/meson/cross/linux-mingw-w64-32bit.txt /tmp/meson-w32 ~/src/postgresql
> && cd /tmp/meson-w32 && ninja
>
> file src/interfaces/libpq/libpq.dll
> src/interfaces/libpq/libpq.dll: PE32 executable (DLL) (console) Intel
> 80386, for MS Windows, 19 sections
>
> You'd need a windows openssl to actually have a useful libpq, but that
> should
> be fairly simple.
>
>
> There are two warnings that I think point to us doing something wrong, but
> they're not affecting libpq:
>
> [1585/1945 42  81%] Linking target src/bin/pgevent/pgevent.dll
> /usr/bin/i686-w64-mingw32-ld: warning: resolving _DllRegisterServer by
> linking to _DllRegisterServer@0
> Use --enable-stdcall-fixup to disable these warnings
> Use --disable-stdcall-fixup to disable these fixups
> /usr/bin/i686-w64-mingw32-ld: warning: resolving _DllUnregisterServer by
> linking to _DllUnregisterServer@0
>
>
>
Attached correct log file

Dave
Build started at 2024-03-21T13:07:08.707715
Main binary: C:\Program Files\Meson\meson.exe
Build Options: '-Dextra_include_dirs=c:\Program Files\OpenSSL-Win64\include' 
-Derrorlogs=True '-Dextra_lib_dirs=c:\Program Files\OpenSSL-win64' 
'-Dprefix=c:\postgres86'
Python system: Windows
The Meson build system
Version: 1.3.1
Source dir: C:\Users\davec\projects\postgresql
Build dir: C:\Users\davec\projects\postgresql\build
Build type: native build
Project name: postgresql
Project version: 17devel
---
Detecting compiler via: `icl ""` -> [WinError 2] The system cannot find the 
file specified
---
Detecting compiler via: `cl /?` -> 0
stdout:
C/C++ COMPILER OPTIONS


  -OPTIMIZATION-

/O1 maximum optimizations (favor space) /O2 maximum optimizations (favor speed)
/Ob inline expansion (default n=0)   /Od disable optimizations (default)
/Og enable global optimization  /Oi[-] enable intrinsic functions
/Os favor code space/Ot favor code speed
/Ox optimizations (favor speed) /Oy[-] enable frame pointer omission 
/favor: select processor to optimize for, one of:
blend - a combination of optimizations for several different x86 processors
ATOM - Intel(R) Atom(TM) processors 

 -CODE GENERATION-

/Gu[-] ensure distinct functions have distinct addresses
/Gw[-] separate global variables for linker
/GF enable read-only string pooling /Gm[-] enable minimal rebuild
/Gy[-] separate functions for linker/GS[-] enable security checks
/GR[-] enable C++ RTTI  /GX[-] enable C++ EH (same as /EHsc)
/guard:cf[-] enable CFG (control flow guard)
/guard:ehcont[-] enable EH continuation metadata (CET)
/EHs enable C++ EH (no SEH exceptions)  /EHa enable C++ EH (w/ SEH exceptions)
/EHc extern "C" defaults to nothrow 
/EHr always generate noexcept runtime termination checks
/fp: choose floating-point model:
contract - consider floating-point contractions when generating code
except[-] - consider floating-point exceptions when generating code
fast - "fast" floating-point model; results are less predictable
precise - "precise" floating-point model; results are predictable
strict - "strict" floating-point model (implies /fp:except)
/Qfast_transcendentals generate inline FP intrinsics even with /fp:except
/Qspectre[-] enable mitigations for CVE 2017-5753
/Qpar[-] enable parallel code generation
/Qpar-report:1 auto-parallelizer diagnostic; indicate parallelized loops
/Qpar-report:2 auto-parallelizer diagnostic; indicate loops not parallelized
/Qvec-report:1 auto-vectorizer diagnostic; indicate vectorized loops
/Qvec-report:2 auto-vectorizer diagnostic; indicate loops not vectorized
/GL[-] enable link-time code generation 
/volatile: choose volatile model:
iso - Acquire/release semantics not guaranteed on volatile accesses
ms  - Acquire/release semantics guaranteed on volatile accesses
/GA optimize for Windows Application/Ge force stack checking for all funcs
/Gs[num] control stack checking calls   /Gh enable _penter function call
/GH enable _pexit function call /GT generate fiber-safe TLS accesses
/RTC1 Enable fast checks 

Re: Trying to build x86 version on windows using meson

2024-03-21 Thread Andres Freund
Hi,

On 2024-03-21 07:11:23 -0400, Dave Cramer wrote:
> It seems that attempting to cross-compile on an ARM machine might be asking
> too much as the use cases are pretty limited.

It for sure is if you don't even provide the precise commands and logs of a
failed run...


> So the impetus for this is that folks require 32bit versions of psqlODBC.
> Unfortunately EDB is no longer distributing a 32 bit windows version.
>
> All I really need is a 32bit libpq. This seems like a much smaller lift.
> Suggestions ?

FWIW, I can cross compile postgres from linux to 32bit windows without an
issue. If you really just need a 32bit libpq, that might actually be easier.

cd /tmp/ && rm -rf /tmp/meson-w32 && m setup --buildtype debug -Dcassert=true 
-Db_pch=true --cross-file ~/src/meson/cross/linux-mingw-w64-32bit.txt 
/tmp/meson-w32 ~/src/postgresql && cd /tmp/meson-w32 && ninja

file src/interfaces/libpq/libpq.dll
src/interfaces/libpq/libpq.dll: PE32 executable (DLL) (console) Intel 80386, 
for MS Windows, 19 sections

You'd need a windows openssl to actually have a useful libpq, but that should
be fairly simple.


There are two warnings that I think point to us doing something wrong, but 
they're not affecting libpq:

[1585/1945 42  81%] Linking target src/bin/pgevent/pgevent.dll
/usr/bin/i686-w64-mingw32-ld: warning: resolving _DllRegisterServer by linking 
to _DllRegisterServer@0
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
/usr/bin/i686-w64-mingw32-ld: warning: resolving _DllUnregisterServer by 
linking to _DllUnregisterServer@0


Greetings,

Andres Freund




Re: Trying to build x86 version on windows using meson

2024-03-21 Thread Dave Cramer
On Thu, 21 Mar 2024 at 03:56, Peter Eisentraut  wrote:

> On 20.03.24 22:49, Dave Cramer wrote:
> >
> >
> >
> > On Wed, 20 Mar 2024 at 17:11, Andres Freund  > > wrote:
> >
> > Hi,
> >
> > On 2024-03-20 16:14:23 -0400, Dave Cramer wrote:
> >  > I am getting the following error
> >  >
> >  > meson.build:1479:17: ERROR: Can not run test applications in this
> > cross
> >  > environment.
> >  >
> >  > Have configured for amd64_x86
> >  >
> >  > Running `meson setup --wipe build --prefix=c:\postgres86`
> >
> > This is not enough information to debug anything. At the very least
> > we need
> > the exact steps performed to set up the build and
> > meson-logs/meson-log.txt
> >
> > First off this is on an ARM64 machine
> >
> > The last error from meson-log.txt is
> >
> > ...
> > Checking if "c99" compiles: YES
> >
> > meson.build:1479:17: ERROR: Can not run test applications in this cross
> > environment.
> > ...
>
> I have never tried this, but there are instructions for cross-compiling
> with meson: https://mesonbuild.com/Cross-compilation.html


It seems that attempting to cross-compile on an ARM machine might be asking
too much as the use cases are pretty limited.

So the impetus for this is that folks require 32bit versions of psqlODBC.
Unfortunately EDB is no longer distributing a 32 bit windows version.

All I really need is a 32bit libpq. This seems like a much smaller lift.
Suggestions ?

Dave


Re: Trying to build x86 version on windows using meson

2024-03-21 Thread Peter Eisentraut

On 20.03.24 22:49, Dave Cramer wrote:




On Wed, 20 Mar 2024 at 17:11, Andres Freund > wrote:


Hi,

On 2024-03-20 16:14:23 -0400, Dave Cramer wrote:
 > I am getting the following error
 >
 > meson.build:1479:17: ERROR: Can not run test applications in this
cross
 > environment.
 >
 > Have configured for amd64_x86
 >
 > Running `meson setup --wipe build --prefix=c:\postgres86`

This is not enough information to debug anything. At the very least
we need
the exact steps performed to set up the build and
meson-logs/meson-log.txt

First off this is on an ARM64 machine

The last error from meson-log.txt is

...
Checking if "c99" compiles: YES

meson.build:1479:17: ERROR: Can not run test applications in this cross 
environment.

...


I have never tried this, but there are instructions for cross-compiling 
with meson: https://mesonbuild.com/Cross-compilation.html







Re: Trying to build x86 version on windows using meson

2024-03-20 Thread Andrew Dunstan
On Wed, Mar 20, 2024 at 6:21 PM Andres Freund  wrote:

> Hi,
>
> On 2024-03-21 11:02:27 +1300, David Rowley wrote:
> > On Thu, 21 Mar 2024 at 11:00, Andres Freund  wrote:
> > >
> > > On 2024-03-20 17:49:14 -0400, Dave Cramer wrote:
> > > > First off this is on an ARM64 machine
> > >
> > > Uh, that's a fairly crucial bit - you're actually trying to cross
> compile
> > > then.  I don't know much about cross compiling on windows, so it's
> certainly
> > > possible there's still some gaps there.
> >
> > How would initdb.exe / pg_regress.exe even run on the x86 build
> > machine if it's compiled for ARM?
>
> I think this is building on an ARM64 host, targeting 32bit x86.
>
> Obviously tests can't run in that environment, but building should be
> possible. I can e.g. build postgres for x86-64 windows on my linux machine,
> but can't run the tests (in theory they could be run with wine, but wine
> isn't
> complete enough to run postgres).
>


Windows apparently has some magic built in for this:

https://learn.microsoft.com/en-us/windows/arm/apps-on-arm-x86-emulation

cheers

andrew


Re: Trying to build x86 version on windows using meson

2024-03-20 Thread Andres Freund
Hi,

On 2024-03-21 11:02:27 +1300, David Rowley wrote:
> On Thu, 21 Mar 2024 at 11:00, Andres Freund  wrote:
> >
> > On 2024-03-20 17:49:14 -0400, Dave Cramer wrote:
> > > First off this is on an ARM64 machine
> >
> > Uh, that's a fairly crucial bit - you're actually trying to cross compile
> > then.  I don't know much about cross compiling on windows, so it's certainly
> > possible there's still some gaps there.
> 
> How would initdb.exe / pg_regress.exe even run on the x86 build
> machine if it's compiled for ARM?

I think this is building on an ARM64 host, targeting 32bit x86.

Obviously tests can't run in that environment, but building should be
possible. I can e.g. build postgres for x86-64 windows on my linux machine,
but can't run the tests (in theory they could be run with wine, but wine isn't
complete enough to run postgres).

Greetings,

Andres Freund




Re: Trying to build x86 version on windows using meson

2024-03-20 Thread David Rowley
On Thu, 21 Mar 2024 at 11:00, Andres Freund  wrote:
>
> On 2024-03-20 17:49:14 -0400, Dave Cramer wrote:
> > First off this is on an ARM64 machine
>
> Uh, that's a fairly crucial bit - you're actually trying to cross compile
> then.  I don't know much about cross compiling on windows, so it's certainly
> possible there's still some gaps there.

How would initdb.exe / pg_regress.exe even run on the x86 build
machine if it's compiled for ARM?

David




Re: Trying to build x86 version on windows using meson

2024-03-20 Thread Andres Freund
Hi,

On 2024-03-20 17:49:14 -0400, Dave Cramer wrote:
> On Wed, 20 Mar 2024 at 17:11, Andres Freund  wrote:
> > On 2024-03-20 16:14:23 -0400, Dave Cramer wrote:
> > > I am getting the following error
> > >
> > > meson.build:1479:17: ERROR: Can not run test applications in this cross
> > > environment.
> > >
> > > Have configured for amd64_x86
> > >
> > > Running `meson setup --wipe build --prefix=c:\postgres86`
> >
> > This is not enough information to debug anything. At the very least we need
> > the exact steps performed to set up the build and meson-logs/meson-log.txt
> >
> First off this is on an ARM64 machine

Uh, that's a fairly crucial bit - you're actually trying to cross compile
then.  I don't know much about cross compiling on windows, so it's certainly
possible there's still some gaps there.


> 
> The last error from meson-log.txt is
> 
> ...
> Checking if "c99" compiles: YES
> 
> meson.build:1479:17: ERROR: Can not run test applications in this cross
> environment.
> ...

That's not the meson-log.txt that you attached though?

Greetings,

Andres Freund




Re: Trying to build x86 version on windows using meson

2024-03-20 Thread Andres Freund
Hi,

On 2024-03-20 16:14:23 -0400, Dave Cramer wrote:
> I am getting the following error
> 
> meson.build:1479:17: ERROR: Can not run test applications in this cross
> environment.
> 
> Have configured for amd64_x86
> 
> Running `meson setup --wipe build --prefix=c:\postgres86`

This is not enough information to debug anything. At the very least we need
the exact steps performed to set up the build and meson-logs/meson-log.txt


> The docs say it is possible to build postgres for x86. Are there specific
> instructions ?

It should work.

Greetings,

Andres Freund




Trying to build x86 version on windows using meson

2024-03-20 Thread Dave Cramer
Greetings,

I am getting the following error

meson.build:1479:17: ERROR: Can not run test applications in this cross
environment.

Have configured for amd64_x86

Running `meson setup --wipe build --prefix=c:\postgres86`

The docs say it is possible to build postgres for x86. Are there specific
instructions ?


Dave Cramer