gradle / gradle-native

The home of Gradle's support for natively compiled languages
https://blog.gradle.org/introducing-the-new-cpp-plugins
Apache License 2.0
92 stars 8 forks source link

Add method to specify TargetMachine as a Cross Compiler #1020

Open ThadHouse opened 5 years ago

ThadHouse commented 5 years ago

In the old Software Model, we have a cross compiler setup which is performed by extending AbstractGccCompatibleToolChain with our own functionality (We tried many different ways and this was the most reliable). Trying to get that setup working in the new plugin space is VERY close to working, however currently it is impossible to intersect the binaries model before it gets finalized, which is what would be needed. Gradle is hardcoded to only allow the host operating system to be built for (It will happily allow cross architectures with the same OS).

The call chains looks like https://github.com/gradle/gradle/blob/f85ebce195014542f0afd29454d28fa52fdc0434/subprojects/language-native/src/main/java/org/gradle/language/cpp/plugins/CppApplicationPlugin.java#L106 to https://github.com/gradle/gradle/blob/f4c91f586e6d8a115dce837b13a8ef9839dde0a0/subprojects/language-native/src/main/java/org/gradle/language/nativeplatform/internal/Dimensions.java

If I remove the check, and just attempt to build everything, it all works.

I think the best way to do this would be to add an API to TargetMachine to specify its a cross compiler, and add a callback performed during binary creation to determine if the cross setup is installed or not, and can be built.

I propose something like the following API added onto TargetMachine

void setCrossCompiledMachine(Predicate<TargetMachine> action);

From this, during the configuration in CppApplication and CppLibrary, check if the action is set, and use it after checking the host to see if that machine can be built on the current platform.

I am currently working on a demo of this functionality, and would be happy to implement it if this seems like a good idea.

dinocore1 commented 5 years ago

I second something like this. I would like to be able to target several different platforms with a cross compiler!