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

Add onnx and onnxruntime-gpu packages #42

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions .pipelines/build-package-preconfigured.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ parameters:
- libzip-static
- libzip-dynamic
- minizip
- onnx
- onnxruntime-gpu
- openssl-static
- opencv4
- pango
Expand Down
2 changes: 1 addition & 1 deletion build-package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Write-Banner -Level 1 -Title "Installing preconfigured package: `"$PackageName`"
$pkg = Get-PackageInfo -PackageName $PackageName

Write-Message "$(NL)Running invoke-build.ps1...$(NL)"
./invoke-build.ps1 -PackageName $PackageName -PackageAndFeatures $pkg.package -LinkType $pkg.linkType -BuildType $pkg.buildType -StagedArtifactsPath $StagedArtifactsPath -VcpkgHash $pkg.vcpkgHash -Publish $pkg.publish -ShowDebug:$ShowDebug
./invoke-build.ps1 -PackageName $PackageName -PackageAndFeatures $pkg.package -LinkType $pkg.linkType -BuildType $pkg.buildType -StagedArtifactsPath $StagedArtifactsPath -VcpkgHash $pkg.vcpkgHash -BuildOptions $pkg.buildOptions -PublishDirs $pkg.publishDirs -ShowDebug:$ShowDebug
72 changes: 72 additions & 0 deletions custom-ports/onnxruntime-gpu/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
vcpkg_check_linkage(ONLY_DYNAMIC_LIBRARY)

set(PKG_NAME "")
if(VCPKG_HOST_IS_WINDOWS)
set(PKG_NAME "onnxruntime-win-x64-gpu-${VERSION}")
vcpkg_download_distfile(ARCHIVE
URLS "https://github.com/microsoft/onnxruntime/releases/download/v${VERSION}/${PKG_NAME}.zip"
FILENAME "${PKG_NAME}.zip"
SHA512 1a7f5c1ca0cecb50505e0f33fd5b485b557c8930c79869b25acab036683c376d8e5e429f46cd30cbb592456203eca791948a7bcf1b730685c45196e85300c95e
)
elseif(VCPKG_HOST_IS_OSX)
set(PKG_NAME "onnxruntime-osx-universal2-${VERSION}")
vcpkg_download_distfile(ARCHIVE
URLS "https://github.com/microsoft/onnxruntime/releases/download/v${VERSION}/${PKG_NAME}.tgz"
FILENAME "${PKG_NAME}.tgz"
SHA512 5a59c36a683aed3c984e2eb97d91a50923f906ff5969edeeb941659a395411dd6f0f36d87f51e170f2fda70b2381a1afe3b40ef0c4395f393e50981e227cdbc5
)
endif()

vcpkg_extract_source_archive(
SOURCE_PATH
ARCHIVE "${ARCHIVE}"
NO_REMOVE_ONE_LEVEL
)

# Download repo for experimental features
vcpkg_from_github(
OUT_SOURCE_PATH REPO_PATH
REPO microsoft/onnxruntime
REF v${VERSION}
SHA512 192cb95e131d7a7796f29556355d0c9055c05723e1120e21155ed21e05301d862f2ba3fd613d8f9289b61577f64cc4b406db7bb25d1bd666b75c29a0f29cc9d8
)

file(COPY
${REPO_PATH}/include/onnxruntime/core/session/experimental_onnxruntime_cxx_api.h
${REPO_PATH}/include/onnxruntime/core/session/experimental_onnxruntime_cxx_inline.h
DESTINATION ${CURRENT_PACKAGES_DIR}/include
)

file(MAKE_DIRECTORY
${CURRENT_PACKAGES_DIR}/include
${CURRENT_PACKAGES_DIR}/lib
)

if(VCPKG_HOST_IS_WINDOWS)
file(MAKE_DIRECTORY
${CURRENT_PACKAGES_DIR}/bin
)
endif()

file(COPY
${SOURCE_PATH}/${PKG_NAME}/include
DESTINATION ${CURRENT_PACKAGES_DIR}
)

if(VCPKG_HOST_IS_WINDOWS)
file(GLOB LIB_FILES "${SOURCE_PATH}/${PKG_NAME}/lib/*.lib")
file(GLOB BIN_FILES "${SOURCE_PATH}/${PKG_NAME}/lib/*.dll" "${SOURCE_PATH}/${PKG_NAME}/lib/*.pdb")
elseif(VCPKG_HOST_IS_OSX)
file(GLOB LIB_FILES "${SOURCE_PATH}/${PKG_NAME}/lib/*.dylib" "${SOURCE_PATH}/${PKG_NAME}/lib/*.dSYM")
endif()

foreach(file ${LIB_FILES})
file(COPY ${file} DESTINATION ${CURRENT_PACKAGES_DIR}/lib)
endforeach()

foreach(file ${BIN_FILES})
file(COPY ${file} DESTINATION ${CURRENT_PACKAGES_DIR}/bin)
endforeach()

# Handle copyright
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/${PKG_NAME}/LICENSE")
8 changes: 8 additions & 0 deletions custom-ports/onnxruntime-gpu/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "onnxruntime-gpu",
"version": "1.18.1",
"description": "onnxruntime (GPU)",
"homepage": "https://github.com/microsoft/onnxruntime",
"license": "MIT",
"supports": "!x86 & !uwp & !static"
}
5 changes: 5 additions & 0 deletions custom-steps/onnx/pre-build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Import-Module "$PSScriptRoot/../../scripts/ps-modules/Build" -DisableNameChecking

if ((Get-IsOnMacOS)) {
brew install autoconf automake autoconf-archive
}
7 changes: 4 additions & 3 deletions invoke-build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ param(
[string]$BuildType = "release", # Build type: release or debug
[string]$StagedArtifactsPath = "StagedArtifacts", # Output path to stage these artifacts to
[string]$VcpkgHash = "", # The hash of vcpkg to checkout (if applicable)
[PSObject]$PublishInfo = $false, # Optional info on what to publish or not publish to the final artifact
[PSObject]$BuildOptions = $null, # Additional options to control how this package is built
[PSObject]$PublishDirs = $null, # Optional info on what to publish or not publish to the final artifact
[switch]$ShowDebug = $false # Show additional debugging information
)

Expand All @@ -16,9 +17,9 @@ Run-CleanupStep
Run-SetupVcPkgStep $VcPkgHash
Run-PreBuildStep $PackageAndFeatures
Run-InstallPackageStep -packageAndFeatures $PackageAndFeatures -linkType $LinkType -buildType $BuildType
Run-PrestageAndFinalizeBuildArtifactsStep -linkType $LinkType -buildType $BuildType -publishInfo $PublishInfo
Run-PrestageAndFinalizeBuildArtifactsStep -linkType $LinkType -buildType $BuildType -buildOptions $BuildOptions -publishDirs $PublishDirs
Run-PostBuildStep -packageAndFeatures $PackageAndFeatures -linkType $LinkType -buildType $BuildType
Run-StageBuildArtifactsStep -packageName $PackageName -packageAndFeatures $PackageAndFeatures -linkType $LinkType -buildType $BuildType -stagedArtifactsPath $StagedArtifactsPath -publishInfo $PublishInfo
Run-StageBuildArtifactsStep -packageName $PackageName -packageAndFeatures $PackageAndFeatures -linkType $LinkType -buildType $BuildType -stagedArtifactsPath $StagedArtifactsPath
Run-StageSourceArtifactsStep -packageName $PackageName -packageAndFeatures $PackageAndFeatures -linkType $LinkType -buildType $BuildType -stagedArtifactsPath $StagedArtifactsPath

Write-Message "$(NL)$(NL)Done.$(NL)"
34 changes: 32 additions & 2 deletions preconfigured-packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"linkType": "static",
"buildType": "release",
"vcpkgHash": "6db51d86a9c2796581d74c9a7eb46e52ee8cb7eb",
"publish": {
"publishDirs": {
"include": false,
"lib": false,
"bin": false,
Expand All @@ -35,7 +35,7 @@
"linkType": "static",
"buildType": "release",
"vcpkgHash": "6db51d86a9c2796581d74c9a7eb46e52ee8cb7eb",
"publish": {
"publishDirs": {
"include": false,
"lib": false,
"bin": false,
Expand Down Expand Up @@ -244,6 +244,36 @@
"linkType": "dynamic",
"buildType": "release"
}
},
{
"name": "onnx",
"mac": {
"package": "onnx",
"linkType": "dynamic",
"buildType": "release"
},
"win": {
"package": "onnx",
"linkType": "dynamic",
"buildType": "release"
}
},
{
"name": "onnxruntime-gpu",
"mac": {
"package": "onnxruntime-gpu",
"linkType": "dynamic",
"buildType": "release",
"buildOptions": {
"createUniversalBinaries": false,
"createDsyms": false
}
},
"win": {
"package": "onnxruntime-gpu",
"linkType": "dynamic",
"buildType": "release"
}
}
]
}
10 changes: 5 additions & 5 deletions scripts/ps-modules/Build/Build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ function Run-PrestageAndFinalizeBuildArtifactsStep {
param(
[string]$linkType,
[string]$buildType,
[PSObject]$publishInfo
[PSObject]$buildOptions,
[PSObject]$publishDirs
)
$preStagePath = (Get-PreStagePath)
Create-EmptyDir $preStagePath
Expand Down Expand Up @@ -293,7 +294,7 @@ function Run-PrestageAndFinalizeBuildArtifactsStep {
foreach ($srcDir in $srcToDestDirs.Keys) {
$destDir = $srcToDestDirs[$srcDir]
$dirName = [System.IO.Path]::GetFileName($srcDir)
if ($publishInfo.$dirName -eq $false) {
if ($publishDirs.$dirName -eq $false) {
$keysToRemove += $srcDir
}
}
Expand All @@ -318,7 +319,7 @@ function Run-PrestageAndFinalizeBuildArtifactsStep {
# Finalize artifacts (Mac-only)
if((Get-IsOnMacOS) -and (Test-Path $destArm64LibDir)) {
$destUniversalLibDir = "$preStagePath/lib"
Create-FinalizedMacBuildArtifacts -arm64LibDir "$destArm64LibDir" -x64LibDir "$destX64LibDir" -universalLibDir "$destUniversalLibDir"
Create-FinalizedMacBuildArtifacts -arm64LibDir "$destArm64LibDir" -x64LibDir "$destX64LibDir" -universalLibDir "$destUniversalLibDir" -createUniversalBinaries $buildOptions.createUniversalBinaries -createDsyms $buildOptions.createDsyms
}
}

Expand Down Expand Up @@ -346,8 +347,7 @@ function Run-StageBuildArtifactsStep {
[string]$packageAndFeatures,
[string]$linkType,
[string]$buildType,
[string]$stagedArtifactsPath,
[PSObject]$publishInfo
[string]$stagedArtifactsPath
)

Write-Banner -Level 3 -Title "Stage build artifacts"
Expand Down
44 changes: 41 additions & 3 deletions scripts/ps-modules/MacBuild/MacBuild.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ function Create-UniversalBinaries {
}
}

function Copy-SrcLibToDestLib {
param(
[string]$srcLibDir,
[string]$destLibDir
)
New-Item -Path "$destLibDir" -ItemType Directory -Force | Out-Null
Write-Message "Copying files from: $srcLibDir ==> $destLibDir..."
$items = Get-ChildItem -Path "$srcLibDir/*" -Include "*.dylib","*.a","*.dSYM"
foreach($item in $items) {
$fileName = $item.Name
Write-Message "> $fileName"
$srcPath = $item.FullName
$destPath = (Join-Path $destLibDir $fileName)

if (-not $item.PSIsContainer) {
Invoke-Expression -Command "cp -R `"$srcPath`" `"$destPath`""
}
}
}

function Copy-NonLibraryFiles {
param(
[string]$srcDir,
Expand All @@ -53,17 +73,28 @@ function Create-FinalizedMacBuildArtifacts {
param (
[string]$arm64LibDir,
[string]$x64LibDir,
[string]$universalLibDir
[string]$universalLibDir,
[bool]$createUniversalBinaries,
[bool]$createDsyms
)
Write-Banner -Level 3 -Title "Finalizing Mac artifacts"
Write-Message "arm64LibDir: $arm64LibDir"
Update-LibsToRelativePaths -arm64LibDir $arm64LibDir -x64LibDir $x64LibDir
Create-UniversalBinaries -arm64LibDir $arm64LibDir -x64LibDir $x64LibDir -universalLibDir $universalLibDir
if($createUniversalBinaries) {
Write-Host ">> Create-UniversalBinaries"
Create-UniversalBinaries -arm64LibDir $arm64LibDir -x64LibDir $x64LibDir -universalLibDir $universalLibDir
}
else {
Write-Host ">> Copy-SrcLibToDestLib"
Copy-SrcLibToDestLib -srcLibDir $arm64LibDir -destLibDir $universalLibDir
}
Copy-NonLibraryFiles -srcDir $arm64LibDir -destDir $universalLibDir
Remove-Item -Force -Recurse -Path $arm64LibDir
Remove-Item -Force -Recurse -Path $x64LibDir
Remove-DylibSymlinks -libDir $universalLibDir
Run-CreateDysmAndStripDebugSymbols -libDir $universalLibDir
if($createDsyms) {
Run-CreateDysmAndStripDebugSymbols -libDir $universalLibDir
}
}

function Update-LibraryPath {
Expand Down Expand Up @@ -260,6 +291,13 @@ function Remove-DylibSymlinks {
foreach ($item in $filesAndSymlinks) {
Write-Message "> Renaming: $($item.Filename) ==> $($item.NewFilename)"
Move-Item -Path "$($item.Filename)" -Destination "$($item.NewFilename)"
$dsymDir = "$($item.Filename).dSYM"
if (Test-Path -Path $dsymDir -PathType Container) {
$newDsymDir = "$($item.NewFilename).dSYM"
Write-Message "> Renaming: $dsymDir ==> $newDsymDir"
Move-Item -Path "$dsymDir" -Destination "$newDsymDir"
# TODO: Rename the inner .dylib in the dwarf dir
}
}

Pop-Location
Expand Down