How to specify C++ compiler executable

I would like to set up a build for an embedded system which can either produce a Xilinx MicroBlaze binary or a Windows binary (compiled by Mingw for simulation). I have succeeded in compiling a simple test project under Windows, but I haven’t figured out how to specify the MicroBlaze compiler (mb-g++ instead of g++).

I could resort to tricks such as redirecting the PATH to a g++.bat file which calls mb-g++, but I would still need to declare a “microblaze” processor architecture so that the build would produce the correct variant – and I cannot seem to find how to do that, either.

You might consider having a look at https://nokee.dev/ which is greatly simplified the native support that Gradle should have built-in. :smiley:

Thanks for the link! I’ll definitely check that out.

I took a look at nokee, but aside from providing an additional plugin for compiling JNI modules, it seems very similar to the Gradle 8.1 C++ plugins. The site did mention the deprecated model-based native plugin, though. Since that one supports cross-compilation, I thought I’d give it a try, assuming it won’t be discontinued until the new version reaches feature parity.

Using the build script below, I successfully got Gradle to invoke the mb-gcc compiler, but it looks like the compiler does not accept @option files. Is there a way to get Gradle to specify compiler options directly on the command line?

build.gradle:

plugins {
    id 'c'
}

model {
    platforms {
        x86 {
            architecture 'x86'
        }
        microblaze {
            architecture 'microblaze'
        }
    }

    toolChains {
        gcc(Gcc) {
            target('x86')
            target('microblaze') {
                cCompiler.executable = 'mb-gcc.exe'
                linker.executable = 'mb-ld.exe'

                cCompiler.withArguments { args ->
                    args << '-mno-xl-soft-mul'
                    args << '-mxl-barrel-shift'
                    args << '-mno-xl-soft-div'
                    args << '-mhard-float'
                    args << '-mxl-float-convert'
                    args << '-mxl-float-sqrt'
                    args << '-mcpu=v7.10.a'
                }
            }
        }
    }

    components {
        main(NativeExecutableSpec) {
            targetPlatform 'x86'
            targetPlatform 'microblaze'
        }
    }
}

Result:

> Task :compileMainMicroblazeExecutableMainC FAILED
Found all include files for ':compileMainMicroblazeExecutableMainC'
Caching disabled for task ':compileMainMicroblazeExecutableMainC' because:
  Build cache is disabled
Task ':compileMainMicroblazeExecutableMainC' is not up-to-date because:
  Task has failed previously.
The input changes require a full rebuild for incremental task ':compileMainMicroblazeExecutableMainC'.
See file:///C:/globe/c-application/build/tmp/compileMainMicroblazeExecutableMainC/output.txt for all output for compileMainMicroblazeExecutableMainC.
Starting process 'command 'C:\Xilinx\13.4\ISE_DS\EDK\gnu\microblaze\nt64\bin\mb-gcc.exe''. Working directory: C:\globe\c-application\build\objs\main\microblaze\mainC Command: C:\Xilinx\13.4\ISE_DS\EDK\gnu\microblaze\nt64\bin\mb-gcc.exe @C:\globe\c-application\build\tmp\compileMainMicroblazeExecutableMainC\options.txt C:\globe\c-application\src\main\c\main.c -o C:\globe\c-application\build\objs\main\microblaze\mainC\7ywyobd9l7sopuxey9ya912jy\main.obj
Successfully started process 'command 'C:\Xilinx\13.4\ISE_DS\EDK\gnu\microblaze\nt64\bin\mb-gcc.exe''
mb-gcc.exe: @C:\globe\c-application\build\tmp\compileMainMicroblazeExecutableMainC\options.txt: Invalid argument

What you are experiencing is a limitation of the toolchain declaration in Gradle. Internally, it supports not using command files, and for this, you have to use canUseCommandFile = false under the microblaze configuration action. I hope that help.

Thanks for that, it almost worked. Gradle accepts the syntax, but it still attempts to specify the options in a command file.

    toolChains {
        gcc(Gcc) {
            target('x86')
            target('microblaze') {
                cCompiler.executable = 'mb-gcc.exe'
                linker.executable = 'mb-ld.exe'
                canUseCommandFile = false

                cCompiler.withArguments { args ->
                    args << '-mno-xl-soft-mul'
                    args << '-mxl-barrel-shift'
                    args << '-mno-xl-soft-div'
                    args << '-mhard-float'
                    args << '-mxl-float-convert'
                    args << '-mxl-float-sqrt'
                    args << '-mcpu=v7.10.a'
                }
            }
        }
    }

Let me trace the property a bit more. I may have overlooked something.