Trying to add a new native platform

Hi,

I’m trying to and an Keil Arm toolchain. At the beginning I tried just change executable and a toolchain path:
arm(Gcc) {
path "somePath"
eachPlatform {
cCompiler.executable = 'armcc’
cppCompiler.executable = 'armcc’
staticLibArchiver.executable = 'armar’
linker.executable = 'armlink’
assembler.executable = ‘armasm’
}
}

Unfortunately it doesn’t work, since armcc.exe doesn’t support version read in the same way as gcc, so I have following error:

Tool chain 'arm' (GNU GCC): Could not determine GCC version: failed to execute armcc.exe -m32 -dM -E -.

So I decided to go with a solution proposed by daz in the following topic: How to pass arguments to gcc instead of ld during the linking step?

apply plugin: 'c'

model {
toolChains {
crossCompiler(Gcc) {
addPlatformConfiguration(new ArmArchitecture())
}
}
targetPlatforms {
arm {
architecture “arm”
}
}
components {
main(NativeExecutableSpec) {
targetPlatform “arm”
}
}
}
import org.gradle.nativeplatform.toolchain.internal.gcc.TargetPlatformConfiguration;
class ArmArchitecture implements TargetPlatformConfiguration {
boolean supportsPlatform(Platform element) {
return targetPlatform.getArchitecture().name == “arm”
}
}

Unfortunately it also fails due to following issue:

Can’t have an abstract method in a non-abstract class. The class ‘ArmArchitecture’ must be declared abstrct or the method ‘boolean supportsPlatform(org.gradle.nativeplatform.platform.internal.NativePlatformInternal)’ must be implemented.
@ line 44, column 1.
class ArmArchitecture implements TargetPlatformConfiguration {
^

So I changed code slightly to have ‘supportsPlatform’ and ‘apply’ implementation:

import org.gradle.nativeplatform.platform.internal.NativePlatformInternal; import org.gradle.nativeplatform.toolchain.internal.gcc.TargetPlatformConfiguration; import org.gradle.nativeplatform.toolchain.internal.gcc.DefaultGccPlatformToolChain; class ArmArchitecture implements TargetPlatformConfiguration { public boolean supportsPlatform(NativePlatformInternal targetPlatform) { return targetPlatform.getArchitecture().name == "arm" } public void apply(DefaultGccPlatformToolChain gccToolChain) { } } ... but then gradle fails: > Exception thrown while executing model rule: NativeComponentRules#createBinaries > Invalid NativePlatform: arm

Can somebody help me? What am I do wrongly?

Did you find any solution to this problem? I don’t think it’s exactly what I want to do, but if possible might be an alternative.

Unfortunately not. Neither I found something nor one helped me, so I would grateful if you could help me.

I think I have managed to do what I needed in 2.11 - though it was a massive effort to work out where everything goes. It turns out in my case code similar to your original worked OK.

I did think you could try something like your original with the hooks mentioned in https://docs.gradle.org/current/userguide/native_software.html that allow you edit command line arguments. Perhaps that would let you force the appropriate command line to pass the checks.

Hi Tom,

Thanks for your answer. I’ve tried the same with Gradle 2.11 and I saw no changes there. I mean I still cannot do my toolchain.
Would it be possible that you share your implementation?