postgresql-interfaces/psqlodbc GitHub issues and pull requests (mirror)  
help / color / mirror / Atom feed
From: kenjiuno (@kenjiuno) <[email protected]>
To: postgresql-interfaces/psqlodbc <[email protected]>
Subject: Re: [postgresql-interfaces/psqlodbc] issue #36: Request: Add Windows for ARM support
Date: Thu, 09 Jan 2025 11:59:48 +0000
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

> Can you post the issues you ran into here or in a discussion?

Yes, here are the issues I have identified.

### psqlODBC requires dev pkg (bin/lib/include) of both `postgres` and `openssl`

#### ARM64 Windows version of PostgreSQL isn't available yet

It is known that Windows binary of PostgreSQL is provided by EDB site.

[EDB: Open-Source, Enterprise Postgres Database Management](https://www.enterprisedb.com/downloads/postgres-postgresql-downloads)

Currently, only the `Windows x86-64` version is available.

It means that we have to prepare the ARM64 version by our method.

#### ARM64 Windows version of OpenSSL binary is available

We can download the pre-compiled binary.

[Win32/Win64 OpenSSL Installer for Windows - Shining Light Productions](https://slproweb.com/products/Win32OpenSSL.html)

### Cross-build the PostgreSQL

I can use unmodified meson, fortunately.
But I need crafted pkg-config binary and pkg-config files to adapt ARM64 openssl binaries.

```bat
meson.exe setup --cross-file arm64ec.txt --prefix V:\postgres-17-1-arm64ec-release-install build-17-1-arm64ec-release --backend vs2022 --buildtype release -Dplpython=disabled -Dldap=disabled -Dssl=openssl -Dplperl=disabled --pkg-config-path V:\postgres-pkg-config
```

`arm64ec.txt` (`arm64ec.txt` filename is bad. It should be `arm64.txt`)

```
[binaries]
c = 'H:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.42.34433\bin\Hostx64\arm64\cl.exe'
cpp = 'H:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.42.34433\bin\Hostx64\arm64\cl.exe'
link = 'H:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.42.34433\bin\Hostx64\arm64\link.exe'
pkg-config = 'H:\Proj\StaticPopplerBuilder\PkgConfigAlternative\bin\Debug\net6.0\pkg-config.exe'

[host_machine]
system = 'windows'
cpu_family = 'aarch64'
cpu = 'arm64ec'
endian = 'little'
```

### ws2_32.lib is not found

Unfortunately, CL.exe cannot find `ws2_32.lib` for any reason. I need to specify `%CL%`.

```bat
SET CL=/I"H:\DL\Win64ARMOpenSSL-3_4_0-installed\OpenSSL-Win64-ARM\include" /link /LIBPATH:"H:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.42.34433\lib\arm64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22621.0\um\arm64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22621.0\ucrt\arm64" /LIBPATH:"H:\DL\Win64ARMOpenSSL-3_4_0-installed\OpenSSL-Win64-ARM\lib\VC\arm64\MD"
```

### meson generates `postgresql.sln` with mixed configurations `release|x64` and `release|arm64`

I always need to replace `release|x64` with `release|arm64` in Notepad++ after meson setup.

### need to patch to PostgreSQL core code to build for Windows ARM64

```patch
diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h
index 29ac6cdcd9..60056c0999 100644
--- a/src/include/storage/s_lock.h
+++ b/src/include/storage/s_lock.h
@@ -691,7 +691,13 @@ typedef LONG slock_t;
 /* If using Visual C++ on Win64, inline assembly is unavailable.
  * Use a _mm_pause intrinsic instead of rep nop.
  */
-#if defined(_WIN64)
+#if defined(_M_ARM64) || defined(_M_ARM64EC)
+static __forceinline void
+spin_delay(void)
+{
+	__yield();
+}
+#elif defined(_WIN64)
 static __forceinline void
 spin_delay(void)
 {
diff --git a/src/tools/msvc_gendef.pl b/src/tools/msvc_gendef.pl
index 404076dbbc..c23320b1d2 100644
--- a/src/tools/msvc_gendef.pl
+++ b/src/tools/msvc_gendef.pl
@@ -122,7 +122,7 @@ sub writedef
 
 		# Strip the leading underscore for win32, but not x64
 		$f =~ s/^_//
-		  unless ($arch eq "x86_64");
+		  unless ($arch eq 'x86_64' || $arch eq 'aarch64');
 
 		# Emit just the name if it's a function symbol, or emit the name
 		# decorated with the DATA option for variables.
@@ -143,7 +143,7 @@ sub writedef
 sub usage
 {
 	die("Usage: msvc_gendef.pl --arch <arch> --deffile <deffile> --tempdir <tempdir> files-or-directories\n"
-		  . "    arch: x86 | x86_64\n"
+		  . "    arch: x86 | x86_64 | aarch64\n"
 		  . "    deffile: path of the generated file\n"
 		  . "    tempdir: directory for temporary files\n"
 		  . "    files or directories: object files or directory containing object files\n"
@@ -160,7 +160,7 @@ GetOptions(
 	'tempdir:s' => \$tempdir,) or usage();
 
 usage("arch: $arch")
-  unless ($arch eq 'x86' || $arch eq 'x86_64');
+  unless ($arch eq 'x86' || $arch eq 'x86_64' || $arch eq 'aarch64');
 
 my @files;
```

### src\timezone\meson.build:31:10: ERROR: Program 'zic' not found or not executable

It seems that `zic` needs to be run on a dev PC.
So I need to build a runnable PostgreSQL installation that can run a dev PC.
This is an insignificant problem.

### it needs to invoke CL.exe twice to build single ARM64X binary

I have sent feedback about this to the Visual Studio team today.

[Want to create only single ARM64X COFF and binaries with CL.exe / LIB.exe / LINK.exe commands - Developer Community](https://developercommunity.visualstudio.com/t/Want-to-create-only-single-ARM64X-COFF-a/10825476)

But I'm not sure that this can be resolved easily.

So I'm writing proxy tools of CL/LIB/LINK commands that can build ARM64X binary in a single invocation.

### need ARM64X binaries of both `postgres` and `openssl`

ARM64 binary is not compatible with ARM64X for both compiling and linking purposes.

So we need to prepare ARM64X binaries (LIBs and DLLs) from first to last.

This means the build system of them needs to be fixed validly.


view thread (31+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: github://postgresql-interfaces/psqlodbc
  Cc: [email protected], [email protected]
  Subject: Re: [postgresql-interfaces/psqlodbc] issue #36: Request: Add Windows for ARM support
  In-Reply-To: <<[email protected]>>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox