On 7 March 2014 at 7:04:37 am, Xavier Ducrohet (x...@google.com) wrote:

wow, indeed!

Shouldn't gradle complain that it doesn't recognize "toolchains"?
It will eventually. This is just a current shortcoming of the new incubating 
model configuration mechanism.





Anyway, now I'm getting errors because my toolchain isn't properly configured 
but I'm making progress. Thanks a lot!


On Thu, Mar 6, 2014 at 12:53 PM, johnrengelman <john.r.engel...@gmail.com> 
wrote:
Inside the model { }, you need 'toolChains' instead of 'toolchain'

-- John

On Thursday, March 6, 2014 at 2:46 PM, Xavier Ducrohet [via Gradle] wrote:

Thanks Daz for confirming what John said.

So here's my current attempt:

model {
    platforms {
        linux32 {
            architecture "i386"
            operatingSystem "linux"
        }
        linux64 {
            architecture "x86_64"
            operatingSystem "linux"
        }
        windows32 {
            architecture "i386"
            operatingSystem "windows"
        }
        darwin32 {
            architecture "i386"
            operatingSystem "osx"
        }
    }
    toolchains {
        mingw(Gcc) {
            path '/usr/bin/i586-mingw32msvc-gcc'
            addPlatformConfiguration(new MingwOnLinuxConfiguration())
        }
    }
}

class MingwOnLinuxConfiguration implements TargetPlatformConfiguration {
    boolean supportsPlatform(Platform element) {
        return element.getOperatingSystem().name == "windows"
    }

    List<String> getCppCompilerArgs() {
        []
    }

    List<String> getCCompilerArgs() {
        []
    }

    List<String> getObjectiveCCompilerArgs() {
        []
    }

    List<String> getObjectiveCppCompilerArgs() {
        []
    }

    List<String> getAssemblerArgs() {
        []
    }

    List<String> getLinkerArgs() {
        []
    }

    List<String> getStaticLibraryArchiverArgs() {
        []
    }
}

When I try to build the windows exe on linux it says:

* What went wrong:
Execution failed for task ':compileWindows32MksdcardExecutableMksdcardC'.
> No tool chain is available to build for platform 'windows32':
    - Tool chain 'visualCpp' (Visual Studio): Visual Studio is not available on 
this operating system.
    - Tool chain 'gcc' (GNU GCC): Don't know how to build for platform 
'windows32'.
    - Tool chain 'clang' (Clang): Could not find C++ compiler 'clang++' in 
system path.

It seems it didn't even add my custom toolchain?


On Thu, Mar 6, 2014 at 11:52 AM, Daz DeBoer <[hidden email]> wrote:
Hi Xav
The current DSL for configuring a cross compiler is not great, but it should be 
functional. The way it works is you can define any number of Gcc tool chains: 
Gradle will iterate over them in order, checking if each can build for the 
target platform. By default a Gcc tool chain can target 'i386', 'x86-64', and 
the 'tool chain default' architecture. The last one is what you get if you 
don't define a platform for your binary.

You can specify that a tool chain can support a platform with 
`PlatformConfigurableToolChain.addPlatformConfiguration()`.  One ugly part of 
the DSL is that you need to implement TargetPlatformConfiguration to do this.

So let's say you have:
toolChains {
   gcc(Gcc) // The default gcc install
   mingw(Gcc) {
       path "path-to-my-cross-compiler"
       addPlatformConfiguration(new MingwOnLinuxConfiguration()) // returns 
"true" for supportsPlatform(windows), and supplies necessary args
   }
}

Then when trying to build for windows, Gradle will first check 'gcc', which 
cannot target windows, then mingw, which can.

Let me know if that still doesn't make sense.

There are some plans to improve the DSL for this. Any suggestion would be 
welcome:

https://github.com/gradle/gradle/blob/master/design-docs/continuous-delivery-for-c-plus-plus.md#story-improved-dsl-for-tool-chain-configuration
https://github.com/gradle/gradle/blob/master/design-docs/continuous-delivery-for-c-plus-plus.md#story-improved-dsl-for-platform-specific-tool-chain-configuration

cheers
Daz



On Thu, Mar 6, 2014 at 11:39 AM, Xavier Ducrohet <[hidden email]> wrote:
thanks for this pointer, I'll take a look.

I'm still not clear how the platform thing work and how "Gradle will attempt to 
locate a ToolChain that is able to build for the target platform." In my case I 
need it to use a custom toolchain and all the things that goes with it. I'll 
experiment.




On Wed, Mar 5, 2014 at 7:10 PM, johnrengelman <[hidden email]> wrote:
I have no experience using the native tools but I think you can reference the 
GccToolChainCustomisationIntegrationTest class in gradle-core.

In that test they are doing the following:
            model {
                toolChains {
                    ${gcc.id} {
                        addPlatformConfiguration(new ArmArchitecture())
                    }
                }
                platforms {
                    arm {
                        architecture "arm"
                    }
                    i386 {
                        architecture "i386"
                    }
                }
            }

            class ArmArchitecture implements TargetPlatformConfiguration {
                boolean supportsPlatform(Platform element) {
                    return element.getArchitecture().name == "arm"
                }

                List<String> getCppCompilerArgs() {
                    ["-m32", "-DFRENCH"]
                }

                List<String> getCCompilerArgs() {
                    ["-m32", "-DFRENCH"]
                }

                List<String> getObjectiveCCompilerArgs() {
                    []
                }

                List<String> getObjectiveCppCompilerArgs() {
                    []
                }

                List<String> getAssemblerArgs() {
                    []
                }

                List<String> getLinkerArgs() {
                    ["-m32"]
                }

                List<String> getStaticLibraryArchiverArgs() {
                    []
                }
            }

My guess is that you'll want to do something like that.

-- John

On Wednesday, March 5, 2014 at 8:44 PM, Xavier Ducrohet [via Gradle] wrote:

Hey all,

I'm looking at the native support to attempt to build the tools part of the 
Android SDK with gradle. We have a few small native tools that needs to be 
compile and we cross compile the windows version on linux using mingw32.

I was wondering if that would be supported since it's (like?) gcc? also I've 
been looking for an example of cross compilation but there isn't any, and the 
PlatformConfigurableToolChain DSL reference isn't super helpful :\

A quick pointer on how to define a cross compilation target would be awesome, 
thanks!
Xav


If you reply to this email, your message will be added to the discussion below:
http://gradle.1045684.n5.nabble.com/Sample-for-native-cross-compilation-tp5712413.html
To start a new topic under gradle-dev, email [hidden email]
To unsubscribe from gradle-dev, click here.
NAML


View this message in context: Re: Sample for native cross compilation?
Sent from the gradle-dev mailing list archive at Nabble.com.





If you reply to this email, your message will be added to the discussion below:
http://gradle.1045684.n5.nabble.com/Sample-for-native-cross-compilation-tp5712413p5712429.html
To start a new topic under gradle-dev, email [hidden email]
To unsubscribe from gradle-dev, click here.
NAML


View this message in context: Re: Sample for native cross compilation?
Sent from the gradle-dev mailing list archive at Nabble.com.



Reply via email to