-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_native_and_copy.ps1
More file actions
131 lines (112 loc) · 4.08 KB
/
build_native_and_copy.ps1
File metadata and controls
131 lines (112 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
param(
[Parameter(Mandatory = $true, Position = 0)]
[ValidateNotNullOrEmpty()]
[string]$Platform
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
function Write-Info($msg) { Write-Host "[INFO] $msg" -ForegroundColor Cyan }
function Write-Warn($msg) { Write-Host "[WARN] $msg" -ForegroundColor Yellow }
function Write-Err($msg) { Write-Host "[ERROR] $msg" -ForegroundColor Red }
$repoRoot = Split-Path -Parent $PSCommandPath
$nativeDir = Join-Path $repoRoot 'TinyEXR.Native'
$buildDir = Join-Path $nativeDir 'build'
$assetsRoot = Join-Path (Join-Path $repoRoot 'TinyEXR.NET') 'Assets'
$supported = @('win-x64','win-arm','win-arm64','linux-x64','linux-arm64','osx-x64','osx-arm64')
if (-not ($supported -contains $Platform)) {
throw "Unsupported platform '$Platform'. Supported: $($supported -join ', ')"
}
Write-Info "Platform: $Platform"
switch -Regex ($Platform) {
'^win-' { $sharedName = 'TinyEXRNative.dll' }
'^linux-' { $sharedName = 'libTinyEXRNative.so' }
'^osx-' { $sharedName = 'TinyEXRNative.dylib' }
default { throw "Unrecognized platform: $Platform" }
}
if (Test-Path $buildDir) {
Remove-Item -Path $buildDir -Recurse -Force
}
if (-not (Test-Path $buildDir)) { New-Item -ItemType Directory -Path $buildDir | Out-Null }
function Invoke-CMakeConfigure {
param(
[string[]]$BaseArgs,
[string]$Platform
)
$isMac = $Platform.StartsWith('osx-')
$extraArgs = @()
if ($isMac) {
$arch = switch ($Platform) {
'osx-x64' { 'x86_64' }
'osx-arm64' { 'arm64' }
default { $null }
}
if ($arch) {
$extraArgs += ("-DCMAKE_OSX_ARCHITECTURES=$arch")
}
}
$args = @() + $BaseArgs + $extraArgs
Write-Info "Configuring with: cmake $($args -join ' ')"
& cmake @args
if ($LASTEXITCODE -ne 0) {
throw "CMake configure failed"
}
}
function Invoke-CMakeBuild {
param(
[string]$BuildDir
)
$buildArgs = @('--build', $BuildDir, '--target', 'TinyEXRNative', '--config', 'Release', '--parallel')
Write-Info "Building with: cmake $($buildArgs -join ' ')"
& cmake @buildArgs
if ($LASTEXITCODE -ne 0) { throw "CMake build failed" }
}
function Find-Artifact {
param(
[string]$Root,
[string]$FileName
)
$file = Get-ChildItem -Path $Root -Recurse -File -Filter $FileName -ErrorAction SilentlyContinue | Select-Object -First 1
if (-not $file) {
throw "Could not find build artifact '$FileName' under '$Root'"
}
return $file.FullName
}
$configureBase = @(
'-S', $nativeDir,
'-B', $buildDir,
'-DCMAKE_BUILD_TYPE=Release'
)
Invoke-CMakeConfigure -BaseArgs $configureBase -Platform $Platform
Invoke-CMakeBuild -BuildDir $buildDir
$artifactPath = $null
try {
$artifactPath = Find-Artifact -Root $buildDir -FileName $sharedName
} catch {
# On macOS, some toolchains may still emit lib-prefixed name; try fallback and rename
if ($Platform.StartsWith('osx-')) {
$fallback = 'lib' + $sharedName
try {
$fallbackPath = Find-Artifact -Root $buildDir -FileName $fallback
if ($fallbackPath) {
$newPath = Join-Path (Split-Path $fallbackPath -Parent) $sharedName
Write-Warn "Fallback found: $fallbackPath; renaming to $newPath"
Rename-Item -Path $fallbackPath -NewName (Split-Path $newPath -Leaf) -Force
$artifactPath = $newPath
}
} catch {}
}
if (-not $artifactPath) { throw }
}
Write-Info "Artifact located: $artifactPath"
$destDir = Join-Path (Join-Path $assetsRoot 'runtimes') (Join-Path $Platform 'native')
if (-not (Test-Path $destDir)) { New-Item -ItemType Directory -Path $destDir -Force | Out-Null }
$destPath = Join-Path $destDir (Split-Path $artifactPath -Leaf)
Copy-Item -Path $artifactPath -Destination $destPath -Force
Write-Info "Copied to: $destPath"
# Additionally, place a copy directly into TinyEXR.Test output for all platforms
$testOutDir = Join-Path $repoRoot (Join-Path 'TinyEXR.Test/TinyEXR.Test' 'bin/Release/net8.0')
if (-not (Test-Path $testOutDir)) { New-Item -ItemType Directory -Path $testOutDir -Force | Out-Null }
$testOutPath = Join-Path $testOutDir (Split-Path $artifactPath -Leaf)
Copy-Item -Path $artifactPath -Destination $testOutPath -Force
Write-Info "Copied to test output: $testOutPath"
Write-Host "Done." -ForegroundColor Green