PS: Refactor generate-binaries.ps1 (now il2cpp.ps1)
This commit is contained in:
@@ -15,23 +15,25 @@ param (
|
|||||||
|
|
||||||
$ErrorActionPreference = "SilentlyContinue"
|
$ErrorActionPreference = "SilentlyContinue"
|
||||||
|
|
||||||
# Path to C¤ compiler (14.0 = Visual Studio 2017, 15.0 = Visual Studio 2019 etc.)
|
# If supplied Unity version is a path, use it, otherwise assume default path from version number alone
|
||||||
# These are ordered from least to most preferred. If no files exist at the specified path,
|
|
||||||
# a silent exception will be thrown and the variable will not be re-assigned.
|
|
||||||
if ($unityVersion -match "[\\/]") {
|
if ($unityVersion -match "[\\/]") {
|
||||||
$UnityFolder = $unityVersion
|
$UnityFolder = $unityVersion
|
||||||
} else {
|
} else {
|
||||||
|
# The introduction of Unity Hub changed the base path of the Unity editor
|
||||||
$UnityFolder = "$env:ProgramFiles\Unity\Hub\Editor\$unityVersion"
|
$UnityFolder = "$env:ProgramFiles\Unity\Hub\Editor\$unityVersion"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Look for Unity Roslyn installs
|
# Look for Unity Roslyn installs
|
||||||
$CSC = (gci "$UnityFolder\Editor\Data\Tools\Roslyn\csc.exe" | sort FullName)[-1].FullName
|
$CSC = (gci "$UnityFolder\Editor\Data\Tools\Roslyn\csc.exe" | sort FullName)[-1].FullName
|
||||||
# Look for .NET Framework installs
|
# Look for .NET Framework installs
|
||||||
$CSC = (gci "${env:ProgramFiles(x86)}\MSBuild\*\Bin\csc.exe" | sort FullName)[-1].FullName
|
$CSC = (gci "${env:ProgramFiles(x86)}\MSBuild\*\Bin\csc.exe" | sort FullName)[-1].FullName
|
||||||
# Look for Visual Studio Roslyn installs
|
|
||||||
|
# Look for Visual Studio Roslyn installs (14.0 = Visual Studio 2017, 15.0 = Visual Studio 2019 etc.)
|
||||||
|
# These are ordered from least to most preferred. If no files exist at the specified path,
|
||||||
|
# a silent exception will be thrown and the variable will not be re-assigned.
|
||||||
$CSC = (gci "${env:ProgramFiles(x86)}\Microsoft Visual Studio\*\*\MSBuild\*\Bin\Roslyn\csc.exe" | sort FullName)[-1].FullName
|
$CSC = (gci "${env:ProgramFiles(x86)}\Microsoft Visual Studio\*\*\MSBuild\*\Bin\Roslyn\csc.exe" | sort FullName)[-1].FullName
|
||||||
|
|
||||||
# Path to latest installed version of Unity
|
# Path to latest installed version of Unity
|
||||||
# The introduction of Unity Hub changed the base path of the Unity editor
|
|
||||||
$UnityPath = (gi "$UnityFolder\Editor\Data" | sort FullName)[-1].FullName
|
$UnityPath = (gi "$UnityFolder\Editor\Data" | sort FullName)[-1].FullName
|
||||||
|
|
||||||
# Path to il2cpp.exe
|
# Path to il2cpp.exe
|
||||||
@@ -132,7 +134,6 @@ gci "$src/*" -Include $cs | % {
|
|||||||
|
|
||||||
# Transpile all of the DLLs to C++
|
# Transpile all of the DLLs to C++
|
||||||
# We split this up from the binary compilation phase to avoid unnecessary DLL -> C++ transpiles for the same application
|
# We split this up from the binary compilation phase to avoid unnecessary DLL -> C++ transpiles for the same application
|
||||||
|
|
||||||
$dll = $assemblies | % {"$_.dll"}
|
$dll = $assemblies | % {"$_.dll"}
|
||||||
|
|
||||||
gci "$asm/*" -Include $dll | % {
|
gci "$asm/*" -Include $dll | % {
|
||||||
@@ -144,73 +145,58 @@ gci "$asm/*" -Include $dll | % {
|
|||||||
|
|
||||||
# Run IL2CPP on all generated assemblies for both x86 and ARM
|
# Run IL2CPP on all generated assemblies for both x86 and ARM
|
||||||
# Earlier builds of Unity included mscorlib.dll automatically; in current versions we must specify its location
|
# Earlier builds of Unity included mscorlib.dll automatically; in current versions we must specify its location
|
||||||
|
function Do-IL2CPP-Build {
|
||||||
|
param (
|
||||||
|
[string] $Platform,
|
||||||
|
[string] $Architecture,
|
||||||
|
[string] $Name,
|
||||||
|
[string[]] $AdditionalArgs
|
||||||
|
)
|
||||||
|
|
||||||
|
# Determine target name
|
||||||
|
$prefix = if ($Architecture -eq 'x86' -or $Architecture -eq 'x64') {'GameAssembly-'}
|
||||||
|
$ext = if ($Architecture -eq 'x86' -or $Architecture -eq 'x64') {"dll"} else {"so"}
|
||||||
|
$TargetBaseName = "$prefix$Name-$Architecture"
|
||||||
|
|
||||||
|
echo "Running il2cpp compiler for $TargetBaseName ($Platform/$Architecture)..."
|
||||||
|
|
||||||
|
# Compile
|
||||||
|
md $bin/$TargetBaseName 2>&1 >$null
|
||||||
|
& $il2cpp $compileArg $AdditionalArgs "--platform=$Platform", "--architecture=$Architecture", `
|
||||||
|
"--outputpath=$bin/$TargetBaseName/$TargetBaseName.$ext", `
|
||||||
|
"--generatedcppdir=$cpp/$Name" >$null
|
||||||
|
|
||||||
|
if ($LastExitCode -ne 0) {
|
||||||
|
Write-Error "IL2CPP error - aborting"
|
||||||
|
Exit
|
||||||
|
}
|
||||||
|
|
||||||
|
mv -Force $bin/$TargetBaseName/Data/metadata/global-metadata.dat $bin/$TargetBaseName
|
||||||
|
rm -Force -Recurse $bin/$TargetBaseName/Data
|
||||||
|
}
|
||||||
|
|
||||||
|
# Generate build for each target platform and architecture
|
||||||
gci "$asm/*" -Include $dll | % {
|
gci "$asm/*" -Include $dll | % {
|
||||||
# x86
|
# x86
|
||||||
$name = "GameAssembly-$($_.BaseName)-x86"
|
Do-IL2CPP-Build WindowsDesktop x86 $_.BaseName
|
||||||
echo "Running il2cpp compiler for $name (Windows/x86)..."
|
|
||||||
md $bin/$name 2>&1 >$null
|
|
||||||
& $il2cpp $compileArg '--platform=WindowsDesktop', '--architecture=x86', `
|
|
||||||
"--outputpath=$bin/$name/$name.dll", `
|
|
||||||
"--generatedcppdir=$cpp/$($_.BaseName)" >$null
|
|
||||||
if ($LastExitCode -ne 0) {
|
|
||||||
Write-Error "IL2CPP error - aborting"
|
|
||||||
Exit
|
|
||||||
}
|
|
||||||
|
|
||||||
mv -Force $bin/$name/Data/metadata/global-metadata.dat $bin/$name
|
|
||||||
rm -Force -Recurse $bin/$name/Data
|
|
||||||
|
|
||||||
# x64
|
# x64
|
||||||
$name = "GameAssembly-$($_.BaseName)-x64"
|
Do-IL2CPP-Build WindowsDesktop x64 $_.BaseName
|
||||||
echo "Running il2cpp compiler for $name (Windows/x64)..."
|
|
||||||
md $bin/$name 2>&1 >$null
|
|
||||||
& $il2cpp $compileArg '--platform=WindowsDesktop', '--architecture=x64', `
|
|
||||||
"--outputpath=$bin/$name/$name.dll", `
|
|
||||||
"--generatedcppdir=$cpp/$($_.BaseName)" >$null
|
|
||||||
if ($LastExitCode -ne 0) {
|
|
||||||
Write-Error "IL2CPP error - aborting"
|
|
||||||
Exit
|
|
||||||
}
|
|
||||||
mv -Force $bin/$name/Data/metadata/global-metadata.dat $bin/$name
|
|
||||||
rm -Force -Recurse $bin/$name/Data
|
|
||||||
|
|
||||||
# ARMv7
|
# ARMv7
|
||||||
if ($AndroidBuildEnabled) {
|
if ($AndroidBuildEnabled) {
|
||||||
$name = "$($_.BaseName)-ARMv7"
|
Do-IL2CPP-Build Android ARMv7 $_.BaseName `
|
||||||
echo "Running il2cpp compiler for $name (Android/ARMv7)..."
|
"--additional-include-directories=$AndroidPlayer/Tools/bdwgc/include", `
|
||||||
md $bin/$name 2>&1 >$null
|
"--additional-include-directories=$AndroidPlayer/Tools/libil2cpp/include", `
|
||||||
& $il2cpp $compileArg '--platform=Android', '--architecture=ARMv7', `
|
"--tool-chain-path=$AndroidNDK"
|
||||||
"--outputpath=$bin/$name/$name.so", `
|
|
||||||
"--generatedcppdir=$cpp/$($_.BaseName)", `
|
|
||||||
"--additional-include-directories=$AndroidPlayer/Tools/bdwgc/include" `
|
|
||||||
"--additional-include-directories=$AndroidPlayer/Tools/libil2cpp/include" `
|
|
||||||
"--tool-chain-path=$AndroidNDK" >$null
|
|
||||||
if ($LastExitCode -ne 0) {
|
|
||||||
Write-Error "IL2CPP error - aborting"
|
|
||||||
Exit
|
|
||||||
}
|
|
||||||
mv -Force $bin/$name/Data/metadata/global-metadata.dat $bin/$name
|
|
||||||
rm -Force -Recurse $bin/$name/Data
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# ARMv8 / A64
|
# ARMv8 / A64
|
||||||
if ($AndroidBuildEnabled) {
|
if ($AndroidBuildEnabled) {
|
||||||
$name = "$($_.BaseName)-ARM64"
|
Do-IL2CPP-Build Android ARM64 $_.BaseName `
|
||||||
echo "Running il2cpp compiler for $name (Android/ARM64)..."
|
"--additional-include-directories=$AndroidPlayer/Tools/bdwgc/include", `
|
||||||
md $bin/$name 2>&1 >$null
|
"--additional-include-directories=$AndroidPlayer/Tools/libil2cpp/include", `
|
||||||
& $il2cpp $compileArg '--platform=Android', '--architecture=ARM64', `
|
"--tool-chain-path=$AndroidNDK"
|
||||||
"--outputpath=$bin/$name/$name.so", `
|
|
||||||
"--generatedcppdir=$cpp/$($_.BaseName)", `
|
|
||||||
"--additional-include-directories=$AndroidPlayer/Tools/bdwgc/include" `
|
|
||||||
"--additional-include-directories=$AndroidPlayer/Tools/libil2cpp/include" `
|
|
||||||
"--tool-chain-path=$AndroidNDK" >$null
|
|
||||||
if ($LastExitCode -ne 0) {
|
|
||||||
Write-Error "IL2CPP error - aborting"
|
|
||||||
Exit
|
|
||||||
}
|
|
||||||
mv -Force $bin/$name/Data/metadata/global-metadata.dat $bin/$name
|
|
||||||
rm -Force -Recurse $bin/$name/Data
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user