How can I change the toolchain so that it compiles wit CLang for a specified build type in c?

Hello world !

I am trying to compile c files with clang only for a specific build type (gradle debug) amd use gcc for all the others.

Is there an easy way to do that ?

No this is not currently possible. Tool chain is selected for target platform, not build type. 

You could define a different Platform, then use addPlatformConfiguration() to ensure that it is only built by Clang. This is still rather clunky, since you’ll need to define a platform that won’t be handled by GCC by default, by using an unsupported architecture. This mechanism will get some rework pretty soon.

Most importantly, why do you want to do this? (use a particular tool chain for a particular build type)

No this is not currently possible. Tool chain is selected for target platform, not build type. 

You could define a different Platform, then use addPlatformConfiguration() to ensure that it is only built by Clang. This is still rather clunky, since you’ll need to define a platform that won’t be handled by GCC by default, by using an unsupported architecture. This mechanism will get some rework pretty soon.

Most importantly, why do you want to do this? (use a particular tool chain for a particular build type)

Hi !

I usually use gcc to compile my c programs (because it’s usually faster) On the other hand when developing and debugging a program I find Clang more useful with error messages.

I wanted to “replicate” this process with gradle. Well thanks anyways

One way to replicate your workflow would be to conditionally define the ‘Clang’ tool chain only if you pass in a certain project property. So rather than being dependent on the build type you’re creating, it would be dependent on some explicit developer action.

model {

toolChains {

if (project.hasProperty(“useClang”)) {

clang(Clang)

} else {

gcc(Gcc)

}

}


You then would build with ‘gradle -PuseClang’ if you want to build with Clang. An alternative would be to include both tool chains, but ensure that Clang is not in the path when building production binaries.