From ce9cf4ad7bfd9313f8820eb5b75ef29824007952 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Thu, 21 May 2026 11:18:03 -0700 Subject: [PATCH] Fix ARM64 nightly build: dotnet NuGet packaging broken under Ninja/cmake (#9589) The Windows ARM64 nightly build (`mk_win_dist_cmake.py --arm64-only`) was failing because the cmake-built `Microsoft.Z3` NuGet package was produced without any native Windows DLL, causing the downstream dotnet example build to fail. ## Root causes - **Wrong DLL path in `Microsoft.Z3.csproj.in`**: Path included `/$(_DN_CMAKE_CONFIG)/` (e.g., `.../RelWithDebInfo/libz3.dll`), but `CMakeLists.txt` sets `CMAKE_RUNTIME_OUTPUT_DIRECTORY = PROJECT_BINARY_DIR` with no config subdir. With Ninja single-config, the DLL lands at `build-dir/libz3.dll`. The `Exists()` guard silently excluded the DLL from the package. - **Wrong runtime identifier**: ARM64 DLL was being packed under `runtimes\win-x64\native` instead of `runtimes\win-arm64\native`. - **Legacy copy fires for `net8.0`**: `Microsoft.Z3.targets` excluded `netstandard`/`netcoreapp` but not modern TFMs like `net8.0`, so `CopyToOutputDirectory` fired and failed trying to copy the absent `win-x64` DLL. ## Changes - **`src/api/dotnet/CMakeLists.txt`**: Introduce `Z3_DOTNET_WIN_RID` cmake variable (`win-x64` / `win-x86` / `win-arm64`) derived from `TARGET_ARCHITECTURE`; used at `configure_file` time. - **`src/api/dotnet/Microsoft.Z3.csproj.in`**: Remove `/$(_DN_CMAKE_CONFIG)` from the Windows DLL path; replace hardcoded `runtimes\win-x64\native` with `runtimes\${Z3_DOTNET_WIN_RID}\native`. - **`src/api/dotnet/Microsoft.Z3.targets`**: Add `!$(TargetFramework.Contains('.'))` to the legacy-copy condition, which correctly excludes `net5.0`/`net6.0`/`net7.0`/`net8.0` (all use dotted TFMs) while keeping `net45`/`net472` etc. - **`src/api/dotnet/Microsoft.Z3.props`**: Add explicit `arm64` condition mapping `$(Platform) == 'arm64'` to `runtimes\win-arm64\native\libz3.dll` for legacy .NET Framework ARM64 consumers. Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> --- src/api/dotnet/CMakeLists.txt | 5 +++++ src/api/dotnet/Microsoft.Z3.csproj.in | 8 ++++---- src/api/dotnet/Microsoft.Z3.props | 3 ++- src/api/dotnet/Microsoft.Z3.targets | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/api/dotnet/CMakeLists.txt b/src/api/dotnet/CMakeLists.txt index c309f4027..3d3864139 100644 --- a/src/api/dotnet/CMakeLists.txt +++ b/src/api/dotnet/CMakeLists.txt @@ -147,8 +147,13 @@ endforeach() set(Z3_DOTNET_NUPKG_VERSION "${VER_MAJOR}.${VER_MINOR}.${VER_BUILD}") if(TARGET_ARCHITECTURE STREQUAL "i686") set(Z3_DOTNET_PLATFORM "x86") + set(Z3_DOTNET_WIN_RID "win-x86") +elseif(TARGET_ARCHITECTURE STREQUAL "arm64") + set(Z3_DOTNET_PLATFORM "AnyCPU") + set(Z3_DOTNET_WIN_RID "win-arm64") else() set(Z3_DOTNET_PLATFORM "AnyCPU") + set(Z3_DOTNET_WIN_RID "win-x64") endif() # TODO conditional for signing. we can then enable the ``Release_delaysign`` configuration diff --git a/src/api/dotnet/Microsoft.Z3.csproj.in b/src/api/dotnet/Microsoft.Z3.csproj.in index ec136809d..cf5aacf46 100644 --- a/src/api/dotnet/Microsoft.Z3.csproj.in +++ b/src/api/dotnet/Microsoft.Z3.csproj.in @@ -84,10 +84,10 @@ ${Z3_DOTNET_COMPILE_ITEMS} - + - - runtimes\win-x64\native + + runtimes\${Z3_DOTNET_WIN_RID}\native runtimes\linux-x64\native @@ -99,7 +99,7 @@ ${Z3_DOTNET_COMPILE_ITEMS} - + runtimes\win-x86\native diff --git a/src/api/dotnet/Microsoft.Z3.props b/src/api/dotnet/Microsoft.Z3.props index a5db71359..4625fdd18 100644 --- a/src/api/dotnet/Microsoft.Z3.props +++ b/src/api/dotnet/Microsoft.Z3.props @@ -9,7 +9,8 @@ $(MSBuildThisFileDirectory)..\ - $(Z3_PACKAGE_PATH)runtimes\win-x64\native\libz3.dll + $(Z3_PACKAGE_PATH)runtimes\win-arm64\native\libz3.dll + $(Z3_PACKAGE_PATH)runtimes\win-x64\native\libz3.dll $(Z3_PACKAGE_PATH)runtimes\win-x86\native\libz3.dll $(Z3_PACKAGE_PATH)runtimes\linux-x64\native\libz3.so diff --git a/src/api/dotnet/Microsoft.Z3.targets b/src/api/dotnet/Microsoft.Z3.targets index 38e56b350..a1436242c 100644 --- a/src/api/dotnet/Microsoft.Z3.targets +++ b/src/api/dotnet/Microsoft.Z3.targets @@ -1,7 +1,7 @@ - + %(RecursiveDir)%(FileName)%(Extension) PreserveNewest