Skip to content

Add ARM64 Support to ParquetSharp #519

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

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ endforeach()

if (MSVC)

foreach (flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if (${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif()
endforeach()
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
foreach (flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if (${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif()
endforeach()

add_compile_options(/MP) # Compile files in parallel with MSVC.
endif()

add_compile_options("/MP") # Compile files in parallel.
add_compile_options("/WX") # Threat warnings as errors.

endif ()
Expand Down
86 changes: 86 additions & 0 deletions build_windows_arm.ps1
Copy link
Contributor Author

@JoshuaOloton JoshuaOloton Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new Windows PowerShell script was introduced to support ARM64 builds, primarily targeting arm64-windows triplets instead of the previous x64-windows-static triplet.
Some of the key changes introduced:

    • Since Arrow is now manually built from source, the script prompts users to set ARROW_HOME to the Arrow install directory, and ensures the debug/release sub-directories exist before continuing.
  • The build system was switched from Visual Studio generator (-G "Visual Studio 17 2022" -A "x64") to Ninja Multi-Config generator (-G "Ninja Multi-Config"), for faster and more flexible builds with better support on Windows ARM64.
  • Compiler change: Clang was chosen as the compiler (CMAKE_C_COMPILER=clang-cl, CMAKE_CXX_COMPILER=clang-cl).

Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
Set-StrictMode -Version 3
$ErrorActionPreference = "Stop"

# Find vcpkg or download it if required
if ($null -ne $Env:VCPKG_INSTALLATION_ROOT) {
$vcpkgDir = $Env:VCPKG_INSTALLATION_ROOT
Write-Output "Using vcpkg at $vcpkgDir from VCPKG_INSTALLATION_ROOT"
}
elseif ($null -ne $Env:VCPKG_ROOT) {
$vcpkgDir = $Env:VCPKG_ROOT
Write-Output "Using vcpkg at $vcpkgDir from VCPKG_ROOT"
}
else {
$vcpkgDir = "$(Get-Location)/build/vcpkg"
Write-Output "Using local vcpkg at $vcpkgDir"
if (-not (Test-Path $vcpkgDir)) {
git clone https://github.com/microsoft/vcpkg.git $vcpkgDir
if (-not $?) { throw "git clone failed" }
& $vcpkgDir/bootstrap-vcpkg.bat
if (-not $?) { throw "bootstrap-vcpkg failed" }
}
}

$triplet = "arm64-windows"

$build_types = @("Debug", "Release")

if ($null -eq $env:ARROW_HOME) {
Write-Host "Error: ARROW_HOME environment variable not set." -ForegroundColor Red
Write-Host "Please set it to your Arrow installation directory, for example:" -ForegroundColor Yellow
Write-Host " $env:ARROW_HOME = 'C:\path\to\arrow\install\$triplet'" -ForegroundColor Yellow
exit 1
}

$arrow_install_dir = $env:ARROW_HOME

if (-not (Test-Path "$arrow_install_dir/release") -or -not (Test-Path "$arrow_install_dir/debug")) {
Write-Host "Error: ARROW_HOME directory doesn't contain expected 'debug' and 'release' subdirectories." -ForegroundColor Red
Write-Host "Please ensure your Arrow installation has both debug and release builds." -ForegroundColor Yellow
exit 1
}

Write-Host "Using Arrow installation from: $arrow_install_dir" -ForegroundColor Green

$options = @()
if ($Env:GITHUB_ACTIONS -eq "true") {
$build_types = @("Release")
$customTripletsDir = "$(Get-Location)/build/custom-triplets"
New-Item -Path $customTripletsDir -ItemType "directory" -Force > $null
$sourceTripletFile = "$vcpkgDir/triplets/$triplet.cmake"
$customTripletFile = "$customTripletsDir/$triplet.cmake"
Copy-Item -Path $sourceTripletFile -Destination $customTripletFile
Add-Content -Path $customTripletFile -Value "set(VCPKG_BUILD_TYPE release)"

# Ensure vcpkg uses the same MSVC version to build dependencies as we use to build the ParquetSharp library.
# By default, vcpkg uses the most recent version it can find, which might not be the same as what msbuild uses.
$vsInstPath = & "${env:ProgramFiles(x86)}/Microsoft Visual Studio/Installer/vswhere.exe" -latest -property installationPath
Import-Module "$vsInstPath/Common7/Tools/Microsoft.VisualStudio.DevShell.dll"
Enter-VsDevShell -VsInstallPath $vsInstPath -SkipAutomaticLocation
$clPath = Get-Command cl.exe | Select -ExpandProperty "Source"
$toolsetVersion = $clPath.Split("\")[8]
if (-not $toolsetVersion.StartsWith("14.")) { throw "Couldn't get toolset version from path '$clPath'" }
Write-Output "Using platform toolset version = $toolsetVersion"
Add-Content -Path $customTripletFile -Value "set(VCPKG_PLATFORM_TOOLSET_VERSION $toolsetVersion)"

$options += "-D"
$options += "VCPKG_OVERLAY_TRIPLETS=$customTripletsDir"
}

cmake -B build/$triplet -S . `
-G "Ninja Multi-Config" `
-DCMAKE_C_COMPILER=clang-cl `
-DCMAKE_CXX_COMPILER=clang-cl `
-DCMAKE_TOOLCHAIN_FILE=C:/src/vcpkg/scripts/buildsystems/vcpkg.cmake `
-DCMAKE_MAKE_PROGRAM=ninja `
-DVCPKG_TARGET_TRIPLET="$triplet" `
-DARROW_ROOT_DEBUG="$arrow_install_dir/debug" `
-DARROW_ROOT_RELEASE="$arrow_install_dir/release" `
$options

if (-not $?) { throw "cmake failed" }

foreach ($build_type in $build_types) {
cmake --build build/$triplet --config $build_type --target ParquetSharpNative
if (-not $?) { throw "ninja build failed" }
}
18 changes: 13 additions & 5 deletions cpp/CMakeLists.txt
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored the native CMake configuration to reference the locally built Arrow and Parquet libraries directly. Instead of using find_package, it now specifies the include directories and library paths for Debug and Release builds via the ARROW_ROOT_DEBUG and ARROW_ROOT_RELEASE variables.
This was to ensure the project links against the correct Arrow build from source.

Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
include(GenerateExportHeader)

find_package(Arrow CONFIG REQUIRED)
find_package(unofficial-brotli CONFIG REQUIRED)
find_package(BZip2 REQUIRED)
find_package(lz4 CONFIG REQUIRED)
find_package(Parquet CONFIG REQUIRED)
find_package(re2 CONFIG REQUIRED)
find_package(Snappy CONFIG REQUIRED)
find_package(Thrift CONFIG REQUIRED)
Expand Down Expand Up @@ -86,9 +84,19 @@ include_directories(
${PROJECT_BINARY_DIR}
${PARQUET_INCLUDE_DIRS})

target_include_directories(ParquetSharpNative PRIVATE
"$<$<CONFIG:Debug>:${ARROW_ROOT_DEBUG}/include>"
"$<$<CONFIG:Release>:${ARROW_ROOT_RELEASE}/include>"
)

target_link_libraries(ParquetSharpNative PRIVATE
debug ${ARROW_ROOT_DEBUG}/lib/arrow.lib
optimized ${ARROW_ROOT_RELEASE}/lib/arrow.lib
debug ${ARROW_ROOT_DEBUG}/lib/parquet.lib
optimized ${ARROW_ROOT_RELEASE}/lib/parquet.lib
)

target_link_libraries(ParquetSharpNative PRIVATE
Parquet::parquet_static
Arrow::arrow_static
unofficial::brotli::brotlidec unofficial::brotli::brotlienc unofficial::brotli::brotlicommon
BZip2::BZip2
lz4::lz4
Expand All @@ -97,7 +105,7 @@ target_link_libraries(ParquetSharpNative PRIVATE
thrift::thrift
utf8proc
ZLIB::ZLIB
zstd::libzstd_static
zstd::libzstd
)

add_definitions(-DARROW_STATIC)
Expand Down
15 changes: 12 additions & 3 deletions csharp/ParquetSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
</PropertyGroup>

<ItemGroup Label="Native Library">
<Content Include="..\bin\x64-windows-static\ParquetSharpNatived.dll" Link="ParquetSharpNatived.dll" PackagePath="runtimes/win-x64/native" Condition="'$(Configuration)'=='Debug' AND ('$(IsWindows)'=='true' OR Exists('..\bin\x64-windows-static\ParquetSharpNatived.dll'))">
<Content Include="..\bin\x64-windows-static\ParquetSharpNatived.dll" Link="ParquetSharpNatived.dll" PackagePath="runtimes/win-x64/native" Condition="'$(Configuration)'=='Debug' AND ('$(IsWindows)'=='true' AND Exists('..\bin\x64-windows-static\ParquetSharpNatived.dll'))">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\bin\x64-windows-static\ParquetSharpNatived.pdb" Link="ParquetSharpNatived.pdb" PackagePath="runtimes/win-x64/native" Condition="'$(Configuration)'=='Debug' AND ('$(IsWindows)'=='true' OR Exists('..\bin\x64-windows-static\ParquetSharpNatived.pdb'))">
<Content Include="..\bin\x64-windows-static\ParquetSharpNatived.pdb" Link="ParquetSharpNatived.pdb" PackagePath="runtimes/win-x64/native" Condition="'$(Configuration)'=='Debug' AND ('$(IsWindows)'=='true' AND Exists('..\bin\x64-windows-static\ParquetSharpNatived.pdb'))">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\bin\x64-windows-static\ParquetSharpNative.dll" Link="ParquetSharpNative.dll" PackagePath="runtimes/win-x64/native" Condition="'$(Configuration)'=='Release' AND ('$(IsWindows)'=='true' OR Exists('..\bin\x64-windows-static\ParquetSharpNative.dll'))">
<Content Include="..\bin\x64-windows-static\ParquetSharpNative.dll" Link="ParquetSharpNative.dll" PackagePath="runtimes/win-x64/native" Condition="'$(Configuration)'=='Release' AND ('$(IsWindows)'=='true' AND Exists('..\bin\x64-windows-static\ParquetSharpNative.dll'))">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\bin\x64-linux\ParquetSharpNatived.so" Link="ParquetSharpNatived.so" PackagePath="runtimes/linux-x64/native" Condition="'$(Configuration)'=='Debug' AND (('$(IsLinux)'=='true' AND '$(OSArchitecture)'=='X64') OR Exists('..\bin\x64-linux\ParquetSharpNatived.so'))">
Expand All @@ -71,6 +71,15 @@
<Content Include="..\bin\arm64-osx\ParquetSharpNative.dylib" Link="ParquetSharpNative.dylib" PackagePath="runtimes/osx-arm64/native" Condition="'$(Configuration)'=='Release' AND (('$(IsOSX)'=='true' AND '$(OSArchitecture)'=='Arm64') OR Exists('..\bin\arm64-osx\ParquetSharpNative.dylib'))">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\bin\arm64-windows\ParquetSharpNatived.dll" Link="ParquetSharpNatived.dll" PackagePath="runtimes/win-arm64/native" Condition="'$(Configuration)'=='Debug' AND ('$(IsWindows)'=='true' AND Exists('..\bin\arm64-windows\ParquetSharpNatived.dll'))">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\bin\arm64-windows\ParquetSharpNatived.pdb" Link="ParquetSharpNatived.pdb" PackagePath="runtimes/win-arm64/native" Condition="'$(Configuration)'=='Debug' AND ('$(IsWindows)'=='true' AND Exists('..\bin\arm64-windows\ParquetSharpNatived.pdb'))">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\bin\arm64-windows\ParquetSharpNative.dll" Link="ParquetSharpNative.dll" PackagePath="runtimes/win-arm64/native" Condition="'$(Configuration)'=='Release' AND ('$(IsWindows)'=='true' AND Exists('..\bin\arm64-windows\ParquetSharpNative.dll'))">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions csharp/ParquetSharp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@
<Link>ParquetSharpNative.dll</Link>
<Visible>False</Visible>
</Content>
<Content Include="$(MSBuildThisFileDirectory)..\runtimes\win-arm64\native\ParquetSharpNatived.dll" Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework'">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>ParquetSharpNatived.dll</Link>
<Visible>False</Visible>
</Content>
</ItemGroup>
</Project>
53 changes: 52 additions & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,58 @@
"version-string": "undefined",
"builtin-baseline": "d9ccd77bb554e67137f3f754a2e2f11f4188c82c",
"dependencies": [
"arrow"
{
"name": "arrow",
"platform": "!arm"
},
{
"name": "brotli",
"platform": "arm"
},
{
"name": "bzip2",
"platform": "arm"
},
{
"name": "lz4",
"platform": "arm"
},
{
"name": "re2",
"platform": "arm"
},
{
"name": "abseil",
"platform": "arm"
},
{
"name": "snappy",
"platform": "arm"
},
{
"name": "thrift",
"platform": "arm"
},
{
"name": "zlib",
"platform": "arm"
},
{
"name": "libevent",
"platform": "arm"
},
{
"name": "utf8proc",
"platform": "arm"
},
{
"name": "zstd",
"platform": "arm"
},
{
"name": "openssl",
"platform": "arm"
}
],
"overrides": [
{
Expand Down
Loading