Add support for parallel linking in IL2CPP builds
* Introduced 'enableParallelLinking' input in action.yml to control parallel linking. * Updated Builder.cs to apply parallel linking settings based on the new input. * Modified build scripts for macOS, Ubuntu, and Windows to include the parallel linking option.pull/764/head
parent
0c82a58873
commit
1c09f7ad31
|
|
@ -43,6 +43,10 @@ inputs:
|
||||||
required: false
|
required: false
|
||||||
default: ''
|
default: ''
|
||||||
description: 'Launches unity without specifying `-nographics`.'
|
description: 'Launches unity without specifying `-nographics`.'
|
||||||
|
enableParallelLinking:
|
||||||
|
required: false
|
||||||
|
default: 'true'
|
||||||
|
description: 'Enable parallel linking for IL2CPP builds to speed up linking phase.'
|
||||||
customParameters:
|
customParameters:
|
||||||
required: false
|
required: false
|
||||||
default: ''
|
default: ''
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,12 @@ namespace UnityBuilderAction
|
||||||
AndroidSettings.Apply(options);
|
AndroidSettings.Apply(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable parallel linking for IL2CPP builds
|
||||||
|
if (options.TryGetValue("enableParallelLinking", out var enableParallelLinking) &&
|
||||||
|
enableParallelLinking != "false") {
|
||||||
|
SetParallelLinking(buildTarget);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform build
|
// Perform build
|
||||||
|
|
@ -129,5 +135,47 @@ namespace UnityBuilderAction
|
||||||
BuildResult result = summary.result;
|
BuildResult result = summary.result;
|
||||||
StdOutReporter.ExitWithResult(result);
|
StdOutReporter.ExitWithResult(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void SetParallelLinking(BuildTarget buildTarget) {
|
||||||
|
string additionalArgs = PlayerSettings.additionalIl2CppArgs;
|
||||||
|
|
||||||
|
// Determine number of parallel jobs (use CPU count, or default to 4)
|
||||||
|
int numJobs = System.Environment.ProcessorCount;
|
||||||
|
if (numJobs <= 0) numJobs = 2;
|
||||||
|
|
||||||
|
// Platform-specific parallel linking flags
|
||||||
|
switch (buildTarget) {
|
||||||
|
case BuildTarget.StandaloneWindows:
|
||||||
|
case BuildTarget.StandaloneWindows64:
|
||||||
|
string cgthreadsFlag = $"--linker-flags=/CGTHREADS:{numJobs}";
|
||||||
|
if (!additionalArgs.Contains("/CGTHREADS:")) {
|
||||||
|
additionalArgs = string.IsNullOrEmpty(additionalArgs)
|
||||||
|
? cgthreadsFlag
|
||||||
|
: $"{additionalArgs} {cgthreadsFlag}";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BuildTarget.StandaloneLinux64:
|
||||||
|
case BuildTarget.Android:
|
||||||
|
case BuildTarget.iOS:
|
||||||
|
if (!additionalArgs.Contains("--threads")) {
|
||||||
|
additionalArgs = string.IsNullOrEmpty(additionalArgs)
|
||||||
|
? $"-Wl,--threads={numJobs}"
|
||||||
|
: $"{additionalArgs} -Wl,--threads={numJobs}";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BuildTarget.StandaloneOSX:
|
||||||
|
if (!additionalArgs.Contains("thread_count")) {
|
||||||
|
additionalArgs = string.IsNullOrEmpty(additionalArgs)
|
||||||
|
? $"-Wl,-thread_count,{numJobs}"
|
||||||
|
: $"{additionalArgs} -Wl,-thread_count,{numJobs}";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerSettings.additionalIl2CppArgs = additionalArgs;
|
||||||
|
Debug.Log($"IL2CPP parallel linking enabled with {numJobs} jobs. Additional args: {additionalArgs}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -305,6 +305,7 @@ class BuildParameters {
|
||||||
buildVersion,
|
buildVersion,
|
||||||
manualExit: input_1.default.manualExit,
|
manualExit: input_1.default.manualExit,
|
||||||
enableGpu: input_1.default.enableGpu,
|
enableGpu: input_1.default.enableGpu,
|
||||||
|
enableParallelLinking: input_1.default.enableParallelLinking,
|
||||||
androidVersionCode,
|
androidVersionCode,
|
||||||
androidKeystoreName: input_1.default.androidKeystoreName,
|
androidKeystoreName: input_1.default.androidKeystoreName,
|
||||||
androidKeystoreBase64: input_1.default.androidKeystoreBase64,
|
androidKeystoreBase64: input_1.default.androidKeystoreBase64,
|
||||||
|
|
@ -6452,6 +6453,7 @@ class ImageEnvironmentFactory {
|
||||||
{ name: 'BUILD_METHOD', value: parameters.buildMethod },
|
{ name: 'BUILD_METHOD', value: parameters.buildMethod },
|
||||||
{ name: 'MANUAL_EXIT', value: parameters.manualExit },
|
{ name: 'MANUAL_EXIT', value: parameters.manualExit },
|
||||||
{ name: 'ENABLE_GPU', value: parameters.enableGpu },
|
{ name: 'ENABLE_GPU', value: parameters.enableGpu },
|
||||||
|
{ name: 'ENABLE_PARALLEL_LINKING', value: parameters.enableParallelLinking },
|
||||||
{ name: 'VERSION', value: parameters.buildVersion },
|
{ name: 'VERSION', value: parameters.buildVersion },
|
||||||
{ name: 'ANDROID_VERSION_CODE', value: parameters.androidVersionCode },
|
{ name: 'ANDROID_VERSION_CODE', value: parameters.androidVersionCode },
|
||||||
{ name: 'ANDROID_KEYSTORE_NAME', value: parameters.androidKeystoreName },
|
{ name: 'ANDROID_KEYSTORE_NAME', value: parameters.androidKeystoreName },
|
||||||
|
|
@ -7019,6 +7021,10 @@ class Input {
|
||||||
const input = Input.getInput('enableGpu') ?? false;
|
const input = Input.getInput('enableGpu') ?? false;
|
||||||
return input === 'true';
|
return input === 'true';
|
||||||
}
|
}
|
||||||
|
static get enableParallelLinking() {
|
||||||
|
const input = Input.getInput('enableParallelLinking') ?? false;
|
||||||
|
return input === 'true';
|
||||||
|
}
|
||||||
static get customParameters() {
|
static get customParameters() {
|
||||||
return Input.getInput('customParameters') ?? '';
|
return Input.getInput('customParameters') ?? '';
|
||||||
}
|
}
|
||||||
|
|
@ -7495,6 +7501,7 @@ class SetupMac {
|
||||||
process.env.CHOWN_FILES_TO = buildParameters.chownFilesTo;
|
process.env.CHOWN_FILES_TO = buildParameters.chownFilesTo;
|
||||||
process.env.MANUAL_EXIT = buildParameters.manualExit.toString();
|
process.env.MANUAL_EXIT = buildParameters.manualExit.toString();
|
||||||
process.env.ENABLE_GPU = buildParameters.enableGpu.toString();
|
process.env.ENABLE_GPU = buildParameters.enableGpu.toString();
|
||||||
|
process.env.ENABLE_PARALLEL_LINKING = buildParameters.enableParallelLinking.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SetupMac.unityHubBasePath = `/Applications/"Unity Hub.app"`;
|
SetupMac.unityHubBasePath = `/Applications/"Unity Hub.app"`;
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -166,6 +166,7 @@ echo ""
|
||||||
-androidTargetSdkVersion "$ANDROID_TARGET_SDK_VERSION" \
|
-androidTargetSdkVersion "$ANDROID_TARGET_SDK_VERSION" \
|
||||||
-androidExportType "$ANDROID_EXPORT_TYPE" \
|
-androidExportType "$ANDROID_EXPORT_TYPE" \
|
||||||
-androidSymbolType "$ANDROID_SYMBOL_TYPE" \
|
-androidSymbolType "$ANDROID_SYMBOL_TYPE" \
|
||||||
|
$( [ "${ENABLE_PARALLEL_LINKING}" == "true" ] && echo "-enableParallelLinking" ) \
|
||||||
$CUSTOM_PARAMETERS
|
$CUSTOM_PARAMETERS
|
||||||
|
|
||||||
# Catch exit code
|
# Catch exit code
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,7 @@ unity-editor \
|
||||||
-androidTargetSdkVersion "$ANDROID_TARGET_SDK_VERSION" \
|
-androidTargetSdkVersion "$ANDROID_TARGET_SDK_VERSION" \
|
||||||
-androidExportType "$ANDROID_EXPORT_TYPE" \
|
-androidExportType "$ANDROID_EXPORT_TYPE" \
|
||||||
-androidSymbolType "$ANDROID_SYMBOL_TYPE" \
|
-androidSymbolType "$ANDROID_SYMBOL_TYPE" \
|
||||||
|
$( [ "${ENABLE_PARALLEL_LINKING}" == "true" ] && echo "-enableParallelLinking" ) \
|
||||||
$CUSTOM_PARAMETERS
|
$CUSTOM_PARAMETERS
|
||||||
|
|
||||||
# Catch exit code
|
# Catch exit code
|
||||||
|
|
|
||||||
|
|
@ -178,7 +178,11 @@ $unityArgs = @(
|
||||||
"-androidExportType", "`"$Env:ANDROID_EXPORT_TYPE`"",
|
"-androidExportType", "`"$Env:ANDROID_EXPORT_TYPE`"",
|
||||||
"-androidSymbolType", "`"$Env:ANDROID_SYMBOL_TYPE`"",
|
"-androidSymbolType", "`"$Env:ANDROID_SYMBOL_TYPE`"",
|
||||||
"-logfile", "-"
|
"-logfile", "-"
|
||||||
) + $customParametersArray
|
)
|
||||||
|
if ($Env:ENABLE_PARALLEL_LINKING -eq "true") {
|
||||||
|
$unityArgs += @("-enableParallelLinking")
|
||||||
|
}
|
||||||
|
$unityArgs = $unityArgs + $customParametersArray
|
||||||
|
|
||||||
if (-not $Env:BUILD_PROFILE) {
|
if (-not $Env:BUILD_PROFILE) {
|
||||||
$unityArgs += @("-buildTarget", "`"$Env:BUILD_TARGET`"")
|
$unityArgs += @("-buildTarget", "`"$Env:BUILD_TARGET`"")
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ class BuildParameters {
|
||||||
public buildVersion!: string;
|
public buildVersion!: string;
|
||||||
public manualExit!: boolean;
|
public manualExit!: boolean;
|
||||||
public enableGpu!: boolean;
|
public enableGpu!: boolean;
|
||||||
|
public enableParallelLinking!: boolean;
|
||||||
public androidVersionCode!: string;
|
public androidVersionCode!: string;
|
||||||
public androidKeystoreName!: string;
|
public androidKeystoreName!: string;
|
||||||
public androidKeystoreBase64!: string;
|
public androidKeystoreBase64!: string;
|
||||||
|
|
@ -162,6 +163,7 @@ class BuildParameters {
|
||||||
buildVersion,
|
buildVersion,
|
||||||
manualExit: Input.manualExit,
|
manualExit: Input.manualExit,
|
||||||
enableGpu: Input.enableGpu,
|
enableGpu: Input.enableGpu,
|
||||||
|
enableParallelLinking: Input.enableParallelLinking,
|
||||||
androidVersionCode,
|
androidVersionCode,
|
||||||
androidKeystoreName: Input.androidKeystoreName,
|
androidKeystoreName: Input.androidKeystoreName,
|
||||||
androidKeystoreBase64: Input.androidKeystoreBase64,
|
androidKeystoreBase64: Input.androidKeystoreBase64,
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ class ImageEnvironmentFactory {
|
||||||
{ name: 'BUILD_METHOD', value: parameters.buildMethod },
|
{ name: 'BUILD_METHOD', value: parameters.buildMethod },
|
||||||
{ name: 'MANUAL_EXIT', value: parameters.manualExit },
|
{ name: 'MANUAL_EXIT', value: parameters.manualExit },
|
||||||
{ name: 'ENABLE_GPU', value: parameters.enableGpu },
|
{ name: 'ENABLE_GPU', value: parameters.enableGpu },
|
||||||
|
{ name: 'ENABLE_PARALLEL_LINKING', value: parameters.enableParallelLinking },
|
||||||
{ name: 'VERSION', value: parameters.buildVersion },
|
{ name: 'VERSION', value: parameters.buildVersion },
|
||||||
{ name: 'ANDROID_VERSION_CODE', value: parameters.androidVersionCode },
|
{ name: 'ANDROID_VERSION_CODE', value: parameters.androidVersionCode },
|
||||||
{ name: 'ANDROID_KEYSTORE_NAME', value: parameters.androidKeystoreName },
|
{ name: 'ANDROID_KEYSTORE_NAME', value: parameters.androidKeystoreName },
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,12 @@ class Input {
|
||||||
return input === 'true';
|
return input === 'true';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static get enableParallelLinking(): boolean {
|
||||||
|
const input = Input.getInput('enableParallelLinking') ?? false;
|
||||||
|
|
||||||
|
return input === 'true';
|
||||||
|
}
|
||||||
|
|
||||||
static get customParameters(): string {
|
static get customParameters(): string {
|
||||||
return Input.getInput('customParameters') ?? '';
|
return Input.getInput('customParameters') ?? '';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -194,6 +194,7 @@ class SetupMac {
|
||||||
process.env.CHOWN_FILES_TO = buildParameters.chownFilesTo;
|
process.env.CHOWN_FILES_TO = buildParameters.chownFilesTo;
|
||||||
process.env.MANUAL_EXIT = buildParameters.manualExit.toString();
|
process.env.MANUAL_EXIT = buildParameters.manualExit.toString();
|
||||||
process.env.ENABLE_GPU = buildParameters.enableGpu.toString();
|
process.env.ENABLE_GPU = buildParameters.enableGpu.toString();
|
||||||
|
process.env.ENABLE_PARALLEL_LINKING = buildParameters.enableParallelLinking.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue