Skip to content
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

Request: Add Windows for ARM support #36

Open
jraiford1 opened this issue Jul 30, 2024 · 15 comments
Open

Request: Add Windows for ARM support #36

jraiford1 opened this issue Jul 30, 2024 · 15 comments

Comments

@jraiford1
Copy link

Windows for ARM does not seem to like Intel x64 drivers. If you try to create a data source against any Intel x64 driver you get an error message. It seems that Intel x64 applications are expected to use ARM ODBC drivers.

@davecramer
Copy link
Contributor

that seems strange. I have tried to build this in the past with some luck. Will try again

@jraiford1
Copy link
Author

It may be that it builds ok. If so, that would be great. From what I can tell there is no way to download a precompiled driver. If I can simply compile it and use the generated driver that could be a short term workaround while we wait for an official driver build.

@davecramer
Copy link
Contributor

I can get you dll's I am having challenges getting the installer to build though

@jraiford1
Copy link
Author

Thanks. The DLL's would be helpful. I'll follow up via email.

@davecramer
Copy link
Contributor

psqlodbc30a.dll.gz

@jraiford1
Copy link
Author

I was able to download that DLL, thank you! Unfortunately this is only the ansi dll and does not include the other helper dll's. In particular, the dependency analyzer shows it is missing libpq.dll and pgelista.dll. Ultimately though I would need the Unicode dll's.

@davecramer
Copy link
Contributor

psqlodbc.zip

@jraiford1
Copy link
Author

I wanted to follow up on this. I have tried to get this manually installed but I have not had any luck. I'm running Windows 11 ARM and the driver doesn't seem to want to load. It seems to complain about the Crypt32.dll not being correct. I think that's a Windows DLL, so it may be a problem with the Windows SDK? I have to drop this for now and have just moved back to my Intel machine. I appreciate you giving me a chance to try this. I'll circle back to it when I can and try on a Windows 10 ARM environment to see if it behaves better.

@davecramer
Copy link
Contributor

@jraiford1 different version of openssl maybe

@kenjiuno
Copy link

kenjiuno commented Jan 7, 2025

Hi.
Is there an update about this issue?

I have tested psqlodbc with Windows 11 ARM on Azure VM service.

I can confirm that this VM runs on ARM64 CPU, by launching settings.

System type 64-bit operating system, ARM-based processor

settings

Downloading from https://www.postgresql.org/ftp/odbc/releases/REL-17_00_0004/

And installing psqlodbc-setup.exe prompts the following error:

---------------------------
psqlodbc Setup
---------------------------
Error installing ODBC driver: PostgreSQL ANSI(x64), ODBC error 13: The setup routines for the PostgreSQL ANSI(x64) ODBC driver could not be loaded due to system error code 193: .. Verify that the file PostgreSQL ANSI(x64) exists and that you can access it.
---------------------------
Abort   Retry   Ignore   
---------------------------

setup-exe-errr

Selecting Retry will continue to prompt the same message.

Selecting Ignore will ignore this step but it prompts a similar prompt like the following one:

---------------------------
psqlodbc Setup
---------------------------
Error installing ODBC driver: PostgreSQL ANSI, ODBC error 13: The setup routines for the PostgreSQL ANSI ODBC driver could not be loaded due to system error code 193: .. Verify that the file PostgreSQL ANSI exists and that you can access it.
---------------------------
Abort   Retry   Ignore   
---------------------------

Selecting Ignore again

---------------------------
psqlodbc Setup
---------------------------
Error installing ODBC driver: PostgreSQL Unicode(x64), ODBC error 13: The setup routines for the PostgreSQL Unicode(x64) ODBC driver could not be loaded due to system error code 193: .. Verify that the file PostgreSQL Unicode(x64) exists and that you can access it.
---------------------------
Abort   Retry   Ignore   
---------------------------

Again

---------------------------
psqlodbc Setup
---------------------------
Error installing ODBC driver: PostgreSQL Unicode, ODBC error 13: The setup routines for the PostgreSQL Unicode ODBC driver could not be loaded due to system error code 193: .. Verify that the file PostgreSQL Unicode exists and that you can access it.
---------------------------
Abort   Retry   Ignore   
---------------------------

Finally, the installation was successful by ignoring 4 severe error messages.

setup-exe-comp

Next, I'm going to add a data source with odbcad32

odbcad32-first

Add

odbcad32

It prompts the 2 error prompts continuously by selecting one of the 4 drivers: PostgreSQL ANSI, PostgreSQL ANSI(x64), PostgreSQL Unicode, or PostgreSQL Unicode(x64).

---------------------------
Microsoft ODBC Administrator
---------------------------
The setup routines for the PostgreSQL ANSI ODBC driver could not be loaded due to system error code 193: .
---------------------------
OK   
---------------------------

add-error

---------------------------
Driver's ConfigDSN, ConfigDriver, or ConfigTranslator failed
---------------------------
Errors Found:



The setup routines for the PostgreSQL ANSI ODBC driver could not be loaded due to system error code 193: .
---------------------------
OK   
---------------------------

add-error-2

It is not added to the data source list.

odbcad32-after

At first, I observed this issue in my company's case.
I maintain a Microsoft Access app.
It uses ODBC (psqlodbc in this case) in some situations.
Usually, PC is x64-based, so there is no problem.
Occasionally, some users tend to bring a Copilot+ PC device which features an Arm64 CPU.
That kind of PC features the ARM64 version of Microsft Office (Microsoft Access), thus native x64 DLLs cannot be loaded inside the ARM64 app.
This is why I needed an ARM64 version of psqlodbc.

But, at last, I could build a psqlodbc_arm64.msi and .msm package by struggling with many issues.
I may be able to help if going to implement arm64 version of psqlodbc.

@davecramer
Copy link
Contributor

But, at last, I could build a psqlodbc_arm64.msi and .msm package by struggling with many issues.
I may be able to help if going to implement arm64 version of psqlodbc.

Yes we upgraded to WIX 5 which is required for ARM. Any help you can provide would be awesome. Unfortunately Github does not provide windows arm machines to build on so we would have to build it and upload it.

Dave

@kenjiuno
Copy link

kenjiuno commented Jan 9, 2025

Yes we upgraded to WIX 5 which is required for ARM.

Thanks for your efforts, this and many efforts to maintain the build system up to date help very much to build ARM64 version at this time!

Any help you can provide would be awesome. Unfortunately Github does not provide windows arm machines to build on so we would have to build it and upload it.

Yes, you are right, and this is a severe problem for OSS developers.
Currently, it isn't easy to get ARM64-based Windows on CI services, because, probably, Windows Server for Arm64 hasn't been produced yet.

I built my psqlodbc_arm64.msi with cross-compilation on my dev PC.
This brings a ton of pain problems to resolve.
However, most problems are still unresolved for automated build purposes. (This means, it requires human hands to fix files manually and so on)

And there is still a big problem not resolved yet: I want to provide psqlODBC as ARM64X binaries.

For now, my psqlodbc_arm64.msi provides only ARM64 binaries.

It means:

  • Windows Installer can succeed.
  • Case of use by ARM64 apps: Microsoft Access runs on the ARM64 platform will load psqlODBC and it will work.
  • Case of use by x64 apps: A5:SQL Mk-2 (x64) runs on x64 (emulated) platform won't load psqlODBC and it won't work.

@davecramer
Copy link
Contributor

Yes we upgraded to WIX 5 which is required for ARM.

Thanks for your efforts, this and many efforts to maintain the build system up to date help very much to build ARM64 version at this time!
Don't thank me, thank @chrullrich, he did all the work

Any help you can provide would be awesome. Unfortunately Github does not provide windows arm machines to build on so we would have to build it and upload it.

Yes, you are right, and this is a severe problem for OSS developers. Currently, it isn't easy to get ARM64-based Windows on CI services, because, probably, Windows Server for Arm64 hasn't been produced yet.

I built my psqlodbc_arm64.msi with cross-compilation on my dev PC. This brings a ton of pain problems to resolve. However, most problems are still unresolved for automated build purposes. (This means, it requires human hands to fix files manually and so on)
Can you post the issues you ran into here or in a discussion?

And there is still a big problem not resolved yet: I want to provide psqlODBC as ARM64X binaries.
Again, please post the issues.

For now, my psqlodbc_arm64.msi provides only ARM64 binaries.
If you can upload it somehow I can make it available as a test.

Thanks,
Dave

@kenjiuno
Copy link

kenjiuno commented Jan 9, 2025

Hi.

I have uploaded the sample psqlodbc_arm64.msi installer at the cloned psqlodbc repository placed at psqlodbc-for-win10-arm64 organization to store files useful for creating arm64 build.

https://github.com/psqlodbc-for-win10-arm64/psqlodbc/releases/tag/17.00.0004-arm64.alpha1

@kenjiuno
Copy link

kenjiuno commented Jan 9, 2025

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

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

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.

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%.

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

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants