Skip to content

Commit

Permalink
Add Mac universal bin support for items in tools dir
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-malburg committed Oct 28, 2024
1 parent 2a8d660 commit 262c692
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 23 deletions.
11 changes: 8 additions & 3 deletions scripts/ps-modules/Build/Build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,15 @@ function Run-PrestageAndFinalizeBuildArtifactsStep {
$srcX64Dir = "./vcpkg/installed/$($triplets[1])"
$destArm64LibDir = "$preStagePath/arm64Lib"
$destX64LibDir = "$preStagePath/x64Lib"
$destArm64ToolsDir = "$preStagePath/arm64Tools"
$destX64ToolsDir = "$preStagePath/x64Tools"
$srcToDestDirs = @{
"$srcArm64Dir/include" = "$preStagePath"
"$srcArm64Dir/share" = "$preStagePath"
"$srcArm64Dir/$libDir" = "$destArm64LibDir"
"$srcX64Dir/$libDir" = "$destX64LibDir"
"$srcArm64Dir/$toolsDir" = "$destArm64ToolsDir"
"$srcX64Dir/$toolsDir" = "$destX64ToolsDir"
}
}
else {
Expand Down Expand Up @@ -324,9 +328,10 @@ 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"
if((Get-IsOnMacOS) -and ((Test-Path $destArm64LibDir) -or (Test-Path $destArm64ToolsDir))) {
$destUniversalLibDir = "$preStagePath/lib"
$destUniversalToolsDir = "$preStagePath/tools"
Create-FinalizedMacBuildArtifacts -arm64LibDir "$destArm64LibDir" -x64LibDir "$destX64LibDir" -universalLibDir "$destUniversalLibDir" -arm64ToolsDir "$destArm64ToolsDir" -x64ToolsDir "$destX64ToolsDir" -universalToolsDir "$destUniversalToolsDir"
}
}

Expand Down
64 changes: 44 additions & 20 deletions scripts/ps-modules/MacBuild/MacBuild.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,38 @@ function Update-LibsToRelativePaths {
ConvertTo-RelativeInstallPaths -directory $x64LibDir -extension "dylib"
}

function Create-UniversalBinary {
param(
[string]$srcArm64BinPath,
[string]$srcX64BinPath,
[string]$destBinPath
)

Invoke-Expression -Command "lipo -create -output `"$destBinPath`" `"$srcArm64BinPath`" `"$srcX64BinPath`""
}

function Create-UniversalBinaries {
param(
[string]$arm64LibDir,
[string]$x64LibDir,
[string]$universalLibDir
[string]$arm64Dir,
[string]$x64Dir,
[string]$universalDir,
[string[]] $includeFilter
)
New-Item -Path "$universalLibDir" -ItemType Directory -Force | Out-Null
Write-Message "Creating universal bins: $arm64LibDir..."
$items = Get-ChildItem -Path "$arm64LibDir/*" -Include "*.dylib","*.a"
New-Item -Path "$universalDir" -ItemType Directory -Force | Out-Null
Write-Message "Creating universal bins: $arm64Dir..."
$items = Get-ChildItem -Path "$arm64Dir/*" -Include $includeFilter
foreach($item in $items) {
$fileName = $item.Name
Write-Message "> $fileName"
$srcPathArm64 = $item.FullName
$srcPathX64 = (Join-Path $x64LibDir $fileName)
$destPath = (Join-Path $universalLibDir $fileName)
$srcArm64BinPath = $item.FullName
$srcX64BinPath = (Join-Path $x64Dir $fileName)
$destBinPath = (Join-Path $universalDir $fileName)

if ($item.Attributes -band [System.IO.FileAttributes]::ReparsePoint) {
Invoke-Expression -Command "cp -R `"$srcPathArm64`" `"$destPath`""
Invoke-Expression -Command "cp -R `"$srcPathArm64`" `"$destBinPath`""
}
elseif (-not $item.PSIsContainer) {
Invoke-Expression -Command "lipo -create -output `"$destPath`" `"$srcPathArm64`" `"$srcPathX64`""
Create-UniversalBinary -destBinPath $destBinPath -srcArm64BinPath $srcArm64BinPath -srcX64BinPath $srcX64BinPath
}
}
}
Expand All @@ -53,17 +64,30 @@ function Create-FinalizedMacBuildArtifacts {
param (
[string]$arm64LibDir,
[string]$x64LibDir,
[string]$universalLibDir
[string]$universalLibDir,
[string]$arm64ToolsDir,
[string]$x64ToolsDir,
[string]$universalToolsDir
)
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
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(Test-Path $arm64LibDir)
{
Write-Message "arm64LibDir: $arm64LibDir"
Update-LibsToRelativePaths -arm64LibDir $arm64LibDir -x64LibDir $x64LibDir
Create-UniversalBinaries -arm64Dir $arm64LibDir -x64Dir $x64LibDir -universalDir $universalLibDir -includeFilter "*.dylib","*.a"
Copy-NonLibraryFiles -srcDir $arm64LibDir -destDir $universalLibDir
Remove-Item -Force -Recurse -Path $arm64LibDir,$x64LibDir
Remove-DylibSymlinks -libDir $universalLibDir
Run-CreateDysmAndStripDebugSymbols -libDir $universalLibDir
}

if(Test-Path $arm64ToolsDir)
{
Write-Message "arm64ToolsDir: $arm64ToolsDir"
Create-UniversalBinaries -arm64Dir $arm64ToolsDir -x64Dir $x64ToolsDir -universalDir $universalToolsDir -includeFilter "*"
Remove-Item -Force -Recurse -Path $arm64ToolsDir,$x64ToolsDir
}
}

function Update-LibraryPath {
Expand Down

0 comments on commit 262c692

Please sign in to comment.