baseName isn't applied for 64bit debug mode in cpp plugin

I’m building a mixed Java and C++ (JNI) library project called avio and I’m having some issues with the baseName property not being properly applied for combination debug and x86_64 while it is being applied to all other build modes.

I’m using the default source sets for source files and some other folders for supporting the build:

src/main/java/.java
src/main/cpp/
.{cpp, hpp}
src/main/resources/native/windows_x{64,86}/.dll
libs/cpp/windows_x{64,86}/
.lib
libs/cpp/include/*.{h,hpp}

so my java module is called main which is OK as I prefer convention over configuration. And as the JNI project is part of this module, I find it suitable that it lives in the same module. However I will need to change the name of the produced shared library to avoid a naming conflict, so I set baseName in my cpp model.

Building all configurations results in the following outputs:

build/libs/main/shared/windows_x64/debug/main.dll
build/libs/main/shared/windows_x64/release/avio.dll
build/libs/main/shared/windows_x86/debug/avio.dll
build/libs/main/shared/windows_x86/release/avio.dll

Note how the baseName attribute isn’t applied to 64 bit debug builds but all other builds.

Relevant excerpt from my build.gradle file, I’m using default source sets for a mixed Java and JNI project. I.e:

def mavenArtifactID = 'avio'
model {
    toolChains {
        mingw_x86(Gcc) {
            path "$System.env.MINGW32"
            target("windows_x86")
        }
        mingw_x86_64(Gcc) {
            path "$System.env.MINGW64"
            target("windows_x86_64")
        }
    }
    platforms {
        windows_x86 {
            architecture "x86"
        }
        windows_x64 {
            architecture "x86_64"
        }
    }
    buildTypes {
        release
        debug
    }
    components {
        main(NativeLibrarySpec){         
            targetPlatform "windows_x86"
            targetPlatform "windows_x64"
             
            binaries.all{
                baseName = mavenArtifactID;
            
                def javaHome = org.gradle.internal.jvm.Jvm.current().javaHome.absolutePath
                cppCompiler.args "-I${javaHome}/include"
                cppCompiler.args "-I${javaHome}/include/win32"
                cppCompiler.args "-I${projectDir}/libs/cpp/include"
                cppCompiler.args "-Wall", "-Wextra", "-pedantic"
            
                if(buildType == buildTypes.release){
                    cppCompiler.args "-O2"
                }
                
                if(buildType == buildTypes.debug){
                    cppCompiler.args "-O0", "-g3", "-fno-inline"
                    linker.args "-g3"
                }
                
                linker.args "-static-libgcc", "-static-libstdc++", "-static"
                linker.args "-Wl,--kill-at"
                if(targetPlatform == platforms.windows_x64){
                    linker.args "-L${projectDir}/libs/cpp/windows_x64"
               	}
               	else{
           	    linker.args "-L${projectDir}/libs/cpp/windows_x86"
               	}
               	linker.args "-lavformat", "-lavcodec", "-lavdevice", "-lavfilter", "-lavutil",  "-lswscale"
            }
        }
    }
}

Gradle Version: 3.1
Operating System and JVM version: Windows 7 JDK 8u101

Hi Emily,

I suspect the baseName property is being set too late. Note that baseName belongs to NativeLibrarySpec itself and not to its binaries.

Please try to move it up to the NativeLibrarySpec level just after you set the target platforms and see if that makes a difference:

main(NativeLibrarySpec){         
    targetPlatform "windows_x86"
    targetPlatform "windows_x64"
    baseName = mavenArtifactID

    binaries.all{ ...

Cheers,
Rodrigo

That works, thanks!

Being new to gradle I wholly expected it to work when put under binaries, or at least not fail silently for 25% of the cases :confounded: