Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ inputs:
required: false
default: ''
description: 'Launches unity without specifying `-nographics`.'
enableParallelLinking:
required: false
default: 'true'
description: 'Enable parallel linking for IL2CPP builds to speed up linking phase.'
customParameters:
required: false
default: ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ public static void BuildProject()
AndroidSettings.Apply(options);
}

// Enable parallel linking for IL2CPP builds
if (options.TryGetValue("enableParallelLinking", out var enableParallelLinking) &&
enableParallelLinking != "false") {
SetParallelLinking(buildTarget);
}

}

// Perform build
Expand All @@ -129,5 +135,47 @@ public static void BuildProject()
BuildResult result = summary.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}");
}
}
}
7 changes: 7 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/platforms/mac/steps/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ echo ""
-androidTargetSdkVersion "$ANDROID_TARGET_SDK_VERSION" \
-androidExportType "$ANDROID_EXPORT_TYPE" \
-androidSymbolType "$ANDROID_SYMBOL_TYPE" \
$( [ "${ENABLE_PARALLEL_LINKING}" == "true" ] && echo "-enableParallelLinking" ) \
$CUSTOM_PARAMETERS

# Catch exit code
Expand Down
1 change: 1 addition & 0 deletions dist/platforms/ubuntu/steps/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ unity-editor \
-androidTargetSdkVersion "$ANDROID_TARGET_SDK_VERSION" \
-androidExportType "$ANDROID_EXPORT_TYPE" \
-androidSymbolType "$ANDROID_SYMBOL_TYPE" \
$( [ "${ENABLE_PARALLEL_LINKING}" == "true" ] && echo "-enableParallelLinking" ) \
$CUSTOM_PARAMETERS

# Catch exit code
Expand Down
6 changes: 5 additions & 1 deletion dist/platforms/windows/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ $unityArgs = @(
"-androidExportType", "`"$Env:ANDROID_EXPORT_TYPE`"",
"-androidSymbolType", "`"$Env:ANDROID_SYMBOL_TYPE`"",
"-logfile", "-"
) + $customParametersArray
)
if ($Env:ENABLE_PARALLEL_LINKING -eq "true") {
$unityArgs += @("-enableParallelLinking")
}
$unityArgs = $unityArgs + $customParametersArray

if (-not $Env:BUILD_PROFILE) {
$unityArgs += @("-buildTarget", "`"$Env:BUILD_TARGET`"")
Expand Down
2 changes: 2 additions & 0 deletions src/model/build-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class BuildParameters {
public buildVersion!: string;
public manualExit!: boolean;
public enableGpu!: boolean;
public enableParallelLinking!: boolean;
public androidVersionCode!: string;
public androidKeystoreName!: string;
public androidKeystoreBase64!: string;
Expand Down Expand Up @@ -162,6 +163,7 @@ class BuildParameters {
buildVersion,
manualExit: Input.manualExit,
enableGpu: Input.enableGpu,
enableParallelLinking: Input.enableParallelLinking,
androidVersionCode,
androidKeystoreName: Input.androidKeystoreName,
androidKeystoreBase64: Input.androidKeystoreBase64,
Expand Down
1 change: 1 addition & 0 deletions src/model/image-environment-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ImageEnvironmentFactory {
{ name: 'BUILD_METHOD', value: parameters.buildMethod },
{ name: 'MANUAL_EXIT', value: parameters.manualExit },
{ name: 'ENABLE_GPU', value: parameters.enableGpu },
{ name: 'ENABLE_PARALLEL_LINKING', value: parameters.enableParallelLinking },
{ name: 'VERSION', value: parameters.buildVersion },
{ name: 'ANDROID_VERSION_CODE', value: parameters.androidVersionCode },
{ name: 'ANDROID_KEYSTORE_NAME', value: parameters.androidKeystoreName },
Expand Down
6 changes: 6 additions & 0 deletions src/model/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ class Input {
return input === 'true';
}

static get enableParallelLinking(): boolean {
const input = Input.getInput('enableParallelLinking') ?? false;

return input === 'true';
}

static get customParameters(): string {
return Input.getInput('customParameters') ?? '';
}
Expand Down
1 change: 1 addition & 0 deletions src/model/platform-setup/setup-mac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ class SetupMac {
process.env.CHOWN_FILES_TO = buildParameters.chownFilesTo;
process.env.MANUAL_EXIT = buildParameters.manualExit.toString();
process.env.ENABLE_GPU = buildParameters.enableGpu.toString();
process.env.ENABLE_PARALLEL_LINKING = buildParameters.enableParallelLinking.toString();
}
}

Expand Down
Loading