Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing the "-j" argument to ninja from gradle

I need to pass -j argument to ninja while building Android app with gradle. (on Windows)

Why do I need this? - We have huge unified c++ files that require lots of memory to compile. Currently I have no enough memory (~10GB free) to compile them in parallel on 8 cores. Thus clang fails when memory runs out.

I see that gradle runs cmake with --build key so I've tried to add my -j1 arg there. But seems arguments field is used only for cmake generation, because it doesn't affect command line passed to cmake in build stage.

externalNativeBuild {
    cmake {
        cFlags "..."
        cppFlags "..."
        arguments "... -- -j1"
    }
}

The only way I see now it to replace ninja with some wrapper to pass -j from there. But this is the last options I would like to use. Appreciate any ideas about how to achieve this valid way.

like image 879
Abuksigun Avatar asked Jul 17 '19 10:07

Abuksigun


People also ask

How do you pass arguments in gradle?

If the task you want to pass parameters to is of type JavaExec and you are using Gradle 5, for example the application plugin's run task, then you can pass your parameters through the --args=... command line option. For example gradle run --args="foo --bar=true" .

Is Ninja faster than Make?

Differences between Make and Ninja For incremental builds, Make is significantly slow. Ninja is faster and helps developers spend less time on building software. This becomes a driving force for large projects such as Google Chrome. In general, performance of Ninja is much better than Make.

What does Ninja command do?

ninja in the current directory and builds all out-of-date targets. You can specify which targets (files) to build as command line arguments. There is also a special syntax target^ for specifying a target as the first output of some rule containing the source you put in the command line, if one exists.

What is Ninja CMake?

cmake is a build system; you define how your project should be put together. It can create ninja. build files for you. Ninja will do the building. cmake --build just calls the builder for you.


1 Answers

You should set CMAKE_BUILD_PARALLEL_LEVEL environment variable to number of concurrent processes you want to use for the build.

It's available since cmake 3.12.4.

https://cmake.org/cmake/help/v3.12/envvar/CMAKE_BUILD_PARALLEL_LEVEL.html

like image 172
zettd Avatar answered Sep 23 '22 16:09

zettd