Gradle C/Native 插件:目录结构、平台和风格
Gradle C/Native Plugin: Directory Structure, Platforms and Flavors
我有一个简单的 C 程序 (helloworld
) 使用 Make 在我的 Windows 7 机器上编译和构建(通过 MinGW)。我现在想将我的构建系统切换为使用 Gradle(个人原因,没有对 Make 的不敬!)并试图将我的大脑围绕 Gradle Native Plugins(实际上是 C 插件)。
我有两个具体问题:
- C 插件是否像大多数其他 Gradle 插件一样需要特定的项目目录结构?在 C 插件的文档中,我看到名为
src/main/headers
的源文件夹的多个实例。在 Java-land 中,Gradle 默认情况下希望您拥有 src/main/java
和 src/main/resources
,以正常运行等。如果 C 插件也是如此, C 程序的 required/recommended 目录结构是什么?
- 我理解文档对平台的解释,但我的脑子里乱七八糟; 一起使用平台和风格是一个更大的谜团。假设我想定义一个构建变体来支持 x86 架构 Linux,另一个变体来支持 64 位 Windows。实现这些变体的 platform/flavor 组合的示例是什么?
Gradle 中本机二进制文件的约定是将头文件放在 src/{componentName}/headers
中,将 C 源文件放在 src/{componentName}/c
中,其中 componentName
是您命名组件的任何名称(鉴于这个问题,我猜那将是 helloworld
,但这取决于你如何声明它)。风味适用于构建的不同变体,就像您想要构建具有不同编译功能的版本一样。针对 x86 Linux 和 64 位 Windows 等不同目标的编译只需使用平台即可完成,如下所示:
model {
platforms {
linux32 {
architecture "x86"
operatingSystem "linux"
}
win64 {
architecture "x86_64"
operatingSystem "windows"
}
}
}
我假设您使用的是 Gradle 2.3,但在过去的几个版本中情况发生了很大变化。
我有一个简单的 C 程序 (helloworld
) 使用 Make 在我的 Windows 7 机器上编译和构建(通过 MinGW)。我现在想将我的构建系统切换为使用 Gradle(个人原因,没有对 Make 的不敬!)并试图将我的大脑围绕 Gradle Native Plugins(实际上是 C 插件)。
我有两个具体问题:
- C 插件是否像大多数其他 Gradle 插件一样需要特定的项目目录结构?在 C 插件的文档中,我看到名为
src/main/headers
的源文件夹的多个实例。在 Java-land 中,Gradle 默认情况下希望您拥有src/main/java
和src/main/resources
,以正常运行等。如果 C 插件也是如此, C 程序的 required/recommended 目录结构是什么? - 我理解文档对平台的解释,但我的脑子里乱七八糟; 一起使用平台和风格是一个更大的谜团。假设我想定义一个构建变体来支持 x86 架构 Linux,另一个变体来支持 64 位 Windows。实现这些变体的 platform/flavor 组合的示例是什么?
Gradle 中本机二进制文件的约定是将头文件放在 src/{componentName}/headers
中,将 C 源文件放在 src/{componentName}/c
中,其中 componentName
是您命名组件的任何名称(鉴于这个问题,我猜那将是 helloworld
,但这取决于你如何声明它)。风味适用于构建的不同变体,就像您想要构建具有不同编译功能的版本一样。针对 x86 Linux 和 64 位 Windows 等不同目标的编译只需使用平台即可完成,如下所示:
model {
platforms {
linux32 {
architecture "x86"
operatingSystem "linux"
}
win64 {
architecture "x86_64"
operatingSystem "windows"
}
}
}
我假设您使用的是 Gradle 2.3,但在过去的几个版本中情况发生了很大变化。