How can I configure a native toolchain after downloading it as a dependency?

Hello,

I have a configuration to download my native toolchain and a task to extract it.

configurations {
  compiler
}

dependencies {
   compiler ( group: 'com.my.company', name: 'my-compiler', version: '4.6.2', ext: 'tgz' )
}

I have a toolchain configuration:

model {
  toolChains {
    myArm(Gcc) {
      target('arm') {
        path '/usr/local/project/build_deps/compilers/arm-cs-tools/bin'
        cCompiler.executable 'arm-unknown-linux-gnueabi-g++'
        cppCompiler.executable 'arm-unknown-linux-gnueabi-g++'
        linker.executable 'arm-unknown-linux-gnueabi-g++'
        assembler.executable 'arm-unknown-linux-gnueabi-as'
        staticLibArchiver.executable 'arm-unknown-linux-gnueabi-ar'
      }
    }
  }

When I run ./gradlew build, it successfully resolves the dependency and extracts it to the specified location, but on the first execution the compiler fails with this message:

No tool chain is available to build for platform 'arm':

presumably because the compiler was not there when the toolchain configuration took place, only after the task ran. If I run ./gradlew build again and it goes through the configuration phase again, it works fine.

I’d like to be able to give my developers a single command to run to set up their build environment and do the build. What would be the best way to automatically re-configure the toolchain after it is extracted by a task?

Should I get and extract the compiler in an init script? Is there a better way?

Thanks.

Hello,
Looking into this again. Is this an appropriate use for an initscript, or is there a better way to delay the configuration of the compiler until it is downloaded and extracted?
Thanks.

I know there’s been no activity on this for a while, but I have the same question. Is there a good way to download and configure toolchains from Maven and then use them in the build?

I’m able to use some workarounds such as creating a separate “gradle toolchain” task that grabs the toolchain (which must be run separately and before any other build tasks)…but it would be nice to have the toolchains automatically downloaded and configured when performing any build task.