game-ci / unity-builder

Build Unity projects for different platforms
https://github.com/marketplace/actions/unity-builder
MIT License
853 stars 253 forks source link

Cache the build target directory to enable Incremental building for faster build #612

Open jacattrongnlh opened 1 year ago

jacattrongnlh commented 1 year ago

Context

Unity has this incremental building for IL2CPP that allow faster build:

Use incremental building

When using incremental building, the C++ compiler only recompiles files that have changed since the last build. To use incremental building, build your project to a previous build location (without deleting the target directory).

So in Unity 2021, after an APK finished building, it generates some additional folders in the build target directory: (file name)_BackUpThisFolder_ButDontShipItWithYourGame and (file name)_BurstDebugInformation_DoNotShip. In subsequent build, if Unity builds to the same directory that contains files from the previous build (the APK and the 2 ...DoNotShip folders), the incremental build will only recompile files that have changed, resulting in much faster build.

Suggested solution

Please add the features that cache build directory in addition to caching the Library folder.

Considered alternatives

I don't have enough knowledge about CI to make my own solution yet.

Additional details

https://docs.unity3d.com/2020.1/Documentation/Manual/IL2CPP-OptimizingBuildTimes.html

webbertakken commented 1 year ago

Excellent suggestion. We really need to look into this!

jacattrongnlh commented 1 year ago

I've tried implementing the cache of the Build folder to see if it was sufficient, but in my experiment, Unity still did a full build instead of incremental build. I've checked the runner's storage with ls and the Build folder did get cached and extracted properly. I don't know if I'm missing something.


.library-cache: &library-cache
    key: "$CI_PROJECT_NAMESPACE-$CI_PROJECT_NAME"
    paths:
      - $UNITY_DIR/Library/
.builds-cache: &builds-cache
    key: "$CI_PROJECT_NAMESPACE-$CI_PROJECT_NAME-builds"
    paths:
      - $UNITY_DIR/Builds/
.cache: &cache
  cache:
    - <<: *builds-cache
    - <<: *library-cache

This is for .gitlab-ci.yml, I'm running this on a runner for a repo on gitlab

JimmyAkl commented 12 months ago

Any updates on this?