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

Revisit target machine DSL ergonomics #924

Closed big-guy closed 5 years ago

big-guy commented 5 years ago

After using it and converting our samples.

A simple cross-platform app might look like:

targetMachines = [ 
    machines.windows().x86(),
    machines.macOS().x86_64(),
    machines.linux().x86_64() 
]

If you were building only for Windows, but for multiple architectures, you could do something like:

def windowsOn = machines.windows()
targetMachines = [ 
    windowsOn.x86(),
    windowsOn.x86_64(),
    windowsOn.architecture("arm")
]

On the downsides, you can do something weird (this is very 32-bit):

targetMachines = [ 
    machines.linux().x86().x86().x86(),
]

And the factory-ish parts of TargetMachine seem out of place or maybe hard to find.

In the review, I also raised a couple of other alternatives:

TargetMachine target(Map osAndArch)

targetMachines = [ machines.target(os: "windows", architecture: "x86") ]

I don't like this because it's pretty stringy and not friendly for Kotlin.

TargetMachine target(Action<ConfigurableTargetMachine> action)

targetMachines = [ 
   machines.target { 
      os = "windows"
      architecture = "x86" 
   } 
]
// or, assume windows and x86 are getters on ConfigurableTargetMachine 
targetMachines = [ 
   machines.target { 
      os = windows
      architecture = x86
   } 
]

This is still pretty stringy, but discoverable.

I'm including this here just so we have it in one place, we don't need to act on this immediately.

big-guy commented 5 years ago

Another alternative: Change windows() and x86() helpers on TargetMachineFactory and TargetMachine into getWindows() and getx86(), so in Groovy (and Kotlin?) we can write:

targetMachines = [ machines.windows.x86 ]
big-guy commented 5 years ago

Let's go with the getter-approach

big-guy commented 5 years ago

PR: https://github.com/gradle/gradle/pull/7920