How to build with emcc in gradle using c plugin

Viewed 102

I'm trying to compile project with emcc using gradle and so far failing to find any decent example of how it can be done (or to learn to to it on my own).

What I've tried to do so far is to set path to clang this way:

model {
    toolChains {
        clang(Clang) {
            path "<path-to-emcc>"
        }
    }
    ...
}

I'm getting a "Could not find C compiler 'clang'." message. Next thing I've tried is to create a clang symlink to emcc, but, again, failed miserably.

1 Answers

Were you able to find a solution for this?

I am having the same exact problem and, after looking around in the Gradle source code, this seems to be an issue specific to running the build on Windows:

ToolSearchPath.java:

private File findExecutable(OperatingSystem operatingSystem, String name) {
    List<File> path = pathEntries.isEmpty() ? operatingSystem.getPath() : pathEntries;
    String exeName = operatingSystem.getExecutableName(name);
    try {
        if (name.contains(File.separator)) {
            return maybeResolveFile(operatingSystem, new File(name), new File(exeName));
        }
        for (File pathEntry : path) {
            File resolved = maybeResolveFile(operatingSystem, new File(pathEntry, name), new File(pathEntry, exeName));

Because of the String exeName = operatingSystem.getExecutableName(name); line, Gradle is actually looking for emcc.exe instead of emcc.bat.

Update @ 2020-07-14

I was able to get around above problem by making these changes. But now I am stuck with following issue which is much harder to tackle:

> Task :linkDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':linkDebug'.
> java.lang.NullPointerException (no error message)

After debugging Gradle's own code, I was able to determine that this issue is caused by emlink.py not handling special -dM -E -v arguments combination when Gradle's GccMetadataProvider probes it with these arguments in order to determine linker version.

Related