diff --git a/Il2CppTests/generate-binaries.ps1 b/Il2CppTests/il2cpp.ps1 similarity index 69% rename from Il2CppTests/generate-binaries.ps1 rename to Il2CppTests/il2cpp.ps1 index 69a9909..87057a6 100644 --- a/Il2CppTests/generate-binaries.ps1 +++ b/Il2CppTests/il2cpp.ps1 @@ -15,23 +15,25 @@ param ( $ErrorActionPreference = "SilentlyContinue" -# Path to C¤ compiler (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. -if ($unityVersion -match "[\\/]"){ -$UnityFolder = $unityVersion -}else{ -$UnityFolder = "$env:ProgramFiles\Unity\Hub\Editor\$unityVersion" +# If supplied Unity version is a path, use it, otherwise assume default path from version number alone +if ($unityVersion -match "[\\/]") { + $UnityFolder = $unityVersion +} else { + # The introduction of Unity Hub changed the base path of the Unity editor + $UnityFolder = "$env:ProgramFiles\Unity\Hub\Editor\$unityVersion" } + # Look for Unity Roslyn installs $CSC = (gci "$UnityFolder\Editor\Data\Tools\Roslyn\csc.exe" | sort FullName)[-1].FullName # Look for .NET Framework installs $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 # 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 # Path to il2cpp.exe @@ -106,7 +108,7 @@ $bin = "$PSScriptRoot/TestBinaries" # We try to make the arguments as close as possible to a real Unity build # "--lump-runtime-library" was added to reduce the number of C++ files generated by UnityEngine (Unity 2019) # "--disable-runtime-lumping" replaced the above (Unity 2019.3) -$cppArg = '--convert-to-cpp', '-emit-null-checks', '--enable-array-bounds-check', '--dotnetprofile="unityaot"' +$cppArg = '--convert-to-cpp', '-emit-null-checks', '--enable-array-bounds-check', '--dotnetprofile="unityaot"' $compileArg = '--compile-cpp', '--libil2cpp-static', '--configuration=Release', ` '--map-file-parser=$UnityPath\il2cpp\MapFileParser\MapFileParser.exe', '--dotnetprofile="unityaot"', ` @@ -132,7 +134,6 @@ gci "$src/*" -Include $cs | % { # 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 - $dll = $assemblies | % {"$_.dll"} gci "$asm/*" -Include $dll | % { @@ -144,73 +145,58 @@ gci "$asm/*" -Include $dll | % { # 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 +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 | % { # x86 - $name = "GameAssembly-$($_.BaseName)-x86" - 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 + Do-IL2CPP-Build WindowsDesktop x86 $_.BaseName # x64 - $name = "GameAssembly-$($_.BaseName)-x64" - 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 + Do-IL2CPP-Build WindowsDesktop x64 $_.BaseName # ARMv7 if ($AndroidBuildEnabled) { - $name = "$($_.BaseName)-ARMv7" - echo "Running il2cpp compiler for $name (Android/ARMv7)..." - md $bin/$name 2>&1 >$null - & $il2cpp $compileArg '--platform=Android', '--architecture=ARMv7', ` - "--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 + Do-IL2CPP-Build Android ARMv7 $_.BaseName ` + "--additional-include-directories=$AndroidPlayer/Tools/bdwgc/include", ` + "--additional-include-directories=$AndroidPlayer/Tools/libil2cpp/include", ` + "--tool-chain-path=$AndroidNDK" } # ARMv8 / A64 if ($AndroidBuildEnabled) { - $name = "$($_.BaseName)-ARM64" - echo "Running il2cpp compiler for $name (Android/ARM64)..." - md $bin/$name 2>&1 >$null - & $il2cpp $compileArg '--platform=Android', '--architecture=ARM64', ` - "--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 + Do-IL2CPP-Build Android ARM64 $_.BaseName ` + "--additional-include-directories=$AndroidPlayer/Tools/bdwgc/include", ` + "--additional-include-directories=$AndroidPlayer/Tools/libil2cpp/include", ` + "--tool-chain-path=$AndroidNDK" } }