From b1cffe11f9faa2b5797a97ce9e30c9e5932a6cf4 Mon Sep 17 00:00:00 2001 From: nhmall Date: Tue, 18 Nov 2025 10:10:32 -0500 Subject: [PATCH] Cross-compiling on Windows 11 with Visual Studio Cross-compiling NetHack with Visual Studio from an x64 platform to an ARM64 target presents some new build challenges. In the current nethack.sln solution, the build attempts to execute the several just-built tools during the build of various subprojects. For example, when cross-compiling on a typical Windows 11 x64 machine to build a target ARM64 Windows 11 package, the build process tries to run the following just-built target tools: (under a Debug build) "$(ToolsDir)\Debug\ARM64\uudecode.exe" "$(ToolsDir)\Debug\ARM64\makedefs.exe" "$(ToolsDir)\Debug\ARM64\tilemap.exe" "$(ToolsDir)\Debug\ARM64\tile2bmp.exe" "$(ToolsDir)\Debug\ARM64\dlb.exe" (under a Release build) "$(ToolsDir)\Release\ARM64\uudecode.exe" "$(ToolsDir)\Release\ARM64\makedefs.exe" "$(ToolsDir)\Release\ARM64\tilemap.exe" "$(ToolsDir)\Release\ARM64\tile2bmp.exe" "$(ToolsDir)\Release\ARM64\dlb.exe" Those fail to execute successfully on Intel x64 (or x86) since they are actually ARM64 executables, and the build attempts to execute them on the host Intel x64 hardware. The situation is a little different if the cross-compile is carried out on a Windows 11 ARM64 machine (such as SnapDragon). On an ARM64 machine, the cross-compile to build a target Intel x64 Windows 11 package, tries to execute the following: (under a Debug build) "$(ToolsDir)\Debug\x64\uudecode.exe" "$(ToolsDir)\Debug\x64\makedefs.exe" "$(ToolsDir)\Debug\x64\tilemap.exe" "$(ToolsDir)\Debug\x64\tile2bmp.exe" "$(ToolsDir)\Debug\x64\dlb.exe" (under a Release build) "$(ToolsDir)\Release\x64\uudecode.exe" "$(ToolsDir)\Release\x64\makedefs.exe" "$(ToolsDir)\Release\x64\tilemap.exe" "$(ToolsDir)\Release\x64\tile2bmp.exe" "$(ToolsDir)\Release\x64\dlb.exe" Those actual do succeed in executing on ARM64, because of the "prism emulation" that is available on Windows 11 ARM64 operating systems to allow x64 and x86 executables to run. The following change adds some detection to build environment, leading to the definition of a "HostTools" macro that leads to the native host tools for those steps. There is a catch: It means that the native build of the interim tools for Windows 11 must be executed prior to attempting a cross-compile build to a non-native target. That ensures that the native x64 interim uudecode, makedefs, tilemap, tile2bmp and dlb tools are available on the disk for use by a subsequent cross-compile. This change consistently switches to the use of the host-native interim tools for uudecode, makedefs, tilemap, tile2bmp and dlb tools. Technically, this change would not be strictly necessary on an ARM64-hosted build that was targeting x64 or x86, because of the available prism-emulation that allows ARM64, x64, and x86 images to execute, but this maintains consistency of the build process on either platform. It is also likely that the native host versions execute more quickly than versions requiring the prism emulation, although that isn't really a concern for a NetHack build. The use of native host uudecode, makedefs, tilemap, tile2bmp and dlb tools is done with the Unix-hosted cross-compiles to other target platforms as well (on Linux or macOS). --- sys/windows/vs/dirs.props | 21 +++ sys/windows/vs/dlb/afterdlb.proj | 4 +- sys/windows/vs/makedefs/aftermakedefs.proj | 10 +- sys/windows/vs/tile2bmp/aftertile2bmp.proj | 4 +- sys/windows/vs/tilemap/aftertilemap.proj | 4 +- sys/windows/vs/uudecode/afteruudecode.proj | 142 ++++++++++----------- 6 files changed, 103 insertions(+), 82 deletions(-) diff --git a/sys/windows/vs/dirs.props b/sys/windows/vs/dirs.props index 8f1f17062..f481482b1 100644 --- a/sys/windows/vs/dirs.props +++ b/sys/windows/vs/dirs.props @@ -40,4 +40,25 @@ $(SubmodulesDir)pdcursesmod\ $(PDCURSESMOD) + + + + + ..\ARM64\ + + + ..\ARM64\ + + + ..\ARM64\ + + + ..\x64\ + + + ..\x64\ + + + ..\x64\ + diff --git a/sys/windows/vs/dlb/afterdlb.proj b/sys/windows/vs/dlb/afterdlb.proj index 515473a3a..44a663187 100644 --- a/sys/windows/vs/dlb/afterdlb.proj +++ b/sys/windows/vs/dlb/afterdlb.proj @@ -2,12 +2,12 @@ - + diff --git a/sys/windows/vs/makedefs/aftermakedefs.proj b/sys/windows/vs/makedefs/aftermakedefs.proj index 8aaf1e314..1a9e7d8bc 100644 --- a/sys/windows/vs/makedefs/aftermakedefs.proj +++ b/sys/windows/vs/makedefs/aftermakedefs.proj @@ -2,12 +2,12 @@ - - - - + + + + diff --git a/sys/windows/vs/tile2bmp/aftertile2bmp.proj b/sys/windows/vs/tile2bmp/aftertile2bmp.proj index 0d7525d5f..e5576ee61 100644 --- a/sys/windows/vs/tile2bmp/aftertile2bmp.proj +++ b/sys/windows/vs/tile2bmp/aftertile2bmp.proj @@ -2,9 +2,9 @@ - + diff --git a/sys/windows/vs/tilemap/aftertilemap.proj b/sys/windows/vs/tilemap/aftertilemap.proj index a8795e96a..703f2c46a 100644 --- a/sys/windows/vs/tilemap/aftertilemap.proj +++ b/sys/windows/vs/tilemap/aftertilemap.proj @@ -2,9 +2,9 @@ - + diff --git a/sys/windows/vs/uudecode/afteruudecode.proj b/sys/windows/vs/uudecode/afteruudecode.proj index e8b4da4c0..32cb45898 100644 --- a/sys/windows/vs/uudecode/afteruudecode.proj +++ b/sys/windows/vs/uudecode/afteruudecode.proj @@ -2,78 +2,78 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +