Build both 32 and 64bit native binary

Hi, does gradle automatically detect possibility to build both 32 and 64 bit native binary on a amd64 linux host?
If not, what is the easiest way to configure project to build both 32 and 64 bit versions?
I have 64bit ubuntu 16.04 with gcc, g++, gcc-multilib and g+±multilib installed, but gradle 2.13 creates task to build 64bit binary only. I tried to add diffeternt platforms (x86 and x86_64) to build script as suggested by documentation, but gradle builds 64 binary for all platforms. Do I have to add gcc options (-m32) manually?

I’m getting the impression that very few developers are using Gradle for C/C++ development.

@snhirsch Unfortunately, I have the same feeling :slight_smile: :wink:

@zgmnkv Yes, gradle can build both 32 and 64 bit binaries in one build run if appropriate toolchain is installed (AFAIK should be enough to install g{xx}-multilib on ubuntu).

as stated in 72.16.4. Selecting the build types, platforms and flavors for a component:

For a default component, Gradle will attempt to create a native binary variant for each and every combination of buildType, platform and flavor defined for the project. It is possible to override this on a per-component basis, by specifying the set of targetBuildTypes, targetPlatform and/or targetFlavors.

Just try to specify both “targetPlatform” for the component you want to build:
e.g.:

model {
    platforms {
        x86 {
            architecture "x86"
        }
        x64 {
            architecture "x86_64"
        }
    }
}
model {
    components {
        main(NativeLibrarySpec) {
            targetPlatform "x86"
            targetPlatform "x64"
        }
    }
}

Also, check the samples (also in gradle-all distribution):
https://github.com/gradle/gradle/blob/master/subprojects/docs/src/samples/native-binaries/target-platforms/build.gradle
or
https://github.com/gradle/gradle/blob/master/subprojects/docs/src/samples/native-binaries/variants/build.gradle

If you still have problems, share your build.gradle (or at least relevant part of it), I might help you.