I am new to this forum, very new to Gradle and also a beginner in Software Engineering in general. So please be aware that some things I write may be a bunch of nonsense and I would be very thankful for being corrected then.
Here is my problem: I am trying to build a c project, which should run on a GHS V850 as embedded system. For using the GHS compiler, assembler & linker, I already installed the GHS IDE on my Windows platform. Now I am wondering how to cross compile my project with Gradle? It seems like I am restricted to use GCC or Clang for cross compiling native c projects with Gradle, which is no solution. Is there any way of solving my problem?
I insert my build.gradle file to show you my general approach, although it is surely full of faults.
model {
platforms {
"GHS_V850" {
architecture "V850"
}
}
toolChains {
ccrh850_toolChain(/*I dont know what to write here*/) {
target("GHS_V850") {
path 'C:\\ghs\\comp_201355'
cCompiler.executable 'ccrh850'
assembler.executable 'ccrh850'
linker.executable 'ccrh850'
}
}
}
buildTypes {
release
}
components {
myTestExe(NativeExecutableSpec) {
targetPlatform("GHS_V850")
targetBuildTypes("release")
binaries.all {
cCompiler.args CF_RELEASE //CF_RELEASE is a string with a lot of Compiler Flags, defined before model {}
assembler.args AF_RELEASE //AF_RELEASE is a string with a lot of Assembler Flags, defined before model {}
linker.args LD_RELEASE //LF_RELEASE is a string with a lot of Linker Flags, defined before model {}
//println "* Building binary ${binary.name} with toolChain ${binary.toolChain.name}"
}
sources {
c {
source {
srcDir "../../source"
include "**/*.c"
}
exportedHeaders {
srcDir "../../source"
}
}
}
}
}
}
Thanks Lucas for the well-written question. As a beginner, you are tackling a complex problem. However, Gradle should be easy to use, so any feedback you have is more than welcome.
That been said, you are on the right track in solving your issue. The native toolchain in Gradle can be seen as behavior. Meaning is your toolchain behave like Gcc, then you should use ccrh850_toolChain(Gcc). By default, Gradle will use well-known default for the C compiler, linker, etc. In the context of a cross-compiler, Gcc (as an example) will have custom executable names. The way you configured your toolchain seems to be all good. Keep in mind that C:\ghs\comp_201355\ccrh850 should be a valid executable. I would probably double check those as an executable on Windows usually ends with .exe and most of the time the compilers are located in a bin folder inside the toolchain installation folder. Given my lack of knowledge in GHS V850 toolchain, I could be wrong.
Everything else seems legit to me. If you are still having difficulty getting your project to compile. Run Gradle with --stacktrace flag and paste your stacktrace along with the output of your various tasks.
thank you very much for your help. I am happy, that I do not totally miss the idea of building a c project with gradle.
First of all, the missing .exe was my fault of course. I fixed this. Also, I am very sure, that the ccrh850.exe is a valid compiler executable because it is already used successfully with make in the same project.
If I understood you right, I can use my own compiler in the context of the GCC toolchain. I think that is what I do with the edited build.gradle below.
model {
platforms {
"GHS_V850" {
architecture "V850"
}
}
toolChains {
ccrh850_toolChain(Gcc){
target("GHS_V850") {
path 'C:\\\ghs\\\\comp_201355\\\\'
cCompiler.executable 'ccrh850.exe'
assembler.executable 'ccrh850.exe'
linker.executable 'ccrh850.exe'
}
}
}
buildTypes {
release
}
components {
myTestExe(NativeExecutableSpec) {
targetPlatform("GHS_V850")
targetBuildTypes("release")
binaries.all {
cCompiler.args CF_RELEASE //CF_RELEASE is a string with a lot of Compiler Flags, defined before model {}
assembler.args AF_RELEASE //AF_RELEASE is a string with a lot of Assembler Flags, defined before model {}
linker.args LD_RELEASE //LF_RELEASE is a string with a lot of Linker Flags, defined before model {}
}
sources {
c {
source {
srcDir "../../source"
include "**/*.c"
}
exportedHeaders {
srcDir "../../source"
}
}
}
}
}
Running gradle build --stacktrace gives me the following error (snippet):
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: org.gradle.api.GradleException: No buildable binaries found:
executable ‘myTestExe:executable’: No tool chain is available to build for platform ‘GHS_V850’:
Tool chain ‘ccrh850_toolChain’ (GNU GCC): Could not determine GCC version: failed to execute ccrh850.exe -dM -E -.
at org.gradle.language.base.plugins.ComponentModelBasePlugin$PluginRules$CheckForNotBuildableBinariesAction.execute(ComponentModelBasePlugin.java:212)
My guess is, that the usage of the GCC behavior sets some default compiler flags (-dM -E), which my custom compiler can not handle. Could that be? Is there no way of using a completely customized toolchain without GCC or Clang?
According to the exception you are receiving, and what I can read on Green Hills Software website, the compilers aren’t GCC or Clang compatible. It must be its own compiler toolchain. Unfortunately, there isn’t a way to easily create custom toolchain model. You can have a look at Gradle code base to see how you could create a new one until we add support for such feature. However, using internal API has it’s drawback like no documentation and a chance of breaking change on every release.
Any update on that topic? I need to do something very similar (using a compiler that is not GCC/Clang compatible) and it would be great to know what’s going on on that topic.