OK - so, it’s not sufficient to define the platforms
element with all the desired variants, I need to also specify targetPlatform
on each component in order to get the platform variants I’m interested in?
This doesn’t seem self-consistent with buildType
definitions, which I only need to specify under the model
element in order to get all of those variants built by default, and it also doesn’t seem consistent with the documentation:
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.
Reading the above, you get the impression that you only need to add component level entries to constrain the default build to produce only the variants defined there.
@sterling: I’m finding what looks like two kinds of problems, and I don’t (yet) know whether this is only happening with the visualCpp
toolchain or is common across all tool chains:
- The default build behavior only automatically builds the
buildType
and (for libraries) the shared
and static
variants, not the available platform
variants, and it seems to prefer building the 32-bit platform
variant, even on 64-bit operating systems, at least for the visualCpp
tool chain.
- At least for
visualCpp
, even if you only define a single platform
with an architecture of x86_64
, the default build will not produce a 64-bit build.
Here is an example build.gradle
that exhibits this behavior on my system:
apply plugin: 'cpp'
model {
platforms {
x64 { architecture 'x86_64' }
}
buildTypes {
debug
release
}
binaries {
all {
println 'configuring variant: ' + name + '.' + targetPlatform.name + '.' + buildType.name
}
}
components {
example(NativeLibrarySpec) {
sources {
binaries.withType(SharedLibraryBinarySpec) { buildable = false }
}
}
}
}
When I run .\gradlew build
on this project, this is the output I get:
configuring variant: debugSharedLibrary.windows_x86.debug
configuring variant: debugStaticLibrary.windows_x86.debug
configuring variant: releaseSharedLibrary.windows_x86.release
configuring variant: releaseStaticLibrary.windows_x86.release
…and I can verify from --debug
output that the 32-bit cross-compiler is invoked. So, I haven’t even defined a 32-bit platform, but I’m only getting 32-bit libs. This feels like a bug to me. It’s definitely unexpected, given the content of this build.gradle
file.
The only way I can get a 64-bit binary out of this build is by modifying the components
element like so:
components {
example(NativeLibrarySpec) {
targetPlatform 'x64'
sources {
binaries.withType(SharedLibraryBinarySpec) { buildable = false }
}
}
}
After making this modification, I then get this output (and I can see from --debug
output that the 64-bit compiler is invoked):
configuring variant: debugSharedLibrary.x64.debug
configuring variant: debugStaticLibrary.x64.debug
configuring variant: releaseSharedLibrary.x64.release
configuring variant: releaseStaticLibrary.x64.release