GP-1106: Platform naming convention now supports different

architectures. Support for building on ARM.
This commit is contained in:
Ryan Kurtz
2021-07-07 09:25:39 -04:00
parent b55d1049d4
commit 00533b2869
43 changed files with 523 additions and 461 deletions

View File

@@ -1,7 +1,6 @@
/* ###
* IP: Public Domain
*/
apply from: file("../gpl.gradle").getCanonicalPath()
if (findProject(':Generic') != null) {
apply from: "$rootProject.projectDir/gradle/javaProject.gradle"

View File

@@ -8,10 +8,10 @@ data/lib/hfsexplorer-0_21-src.zip||GPL 3||||END|
data/lib/hfsx.jar||GPL 3||||END|
data/lib/hfsx_dmglib.jar||GPL 3||||END|
data/lib/iharder-base64.jar||GPL 3||||END|
data/os/win32/llio_amd64.dll||GPL 3||||END|
data/os/win32/llio_i386.dll||GPL 3||||END|
data/os/win32/llio_ia64.dll||GPL 3||||END|
data/os/win64/llio_amd64.dll||GPL 3||||END|
data/os/win64/llio_i386.dll||GPL 3||||END|
data/os/win64/llio_ia64.dll||GPL 3||||END|
data/os/win_x86_32/llio_amd64.dll||GPL 3||||END|
data/os/win_x86_32/llio_i386.dll||GPL 3||||END|
data/os/win_x86_32/llio_ia64.dll||GPL 3||||END|
data/os/win_x86_64/llio_amd64.dll||GPL 3||||END|
data/os/win_x86_64/llio_i386.dll||GPL 3||||END|
data/os/win_x86_64/llio_ia64.dll||GPL 3||||END|
data/server_memory.cfg||Public Domain||||END|

View File

@@ -1,13 +1,14 @@
/* ###
* IP: Public Domain
*/
apply from: file("../gpl.gradle").getCanonicalPath()
if (findProject(':Generic') != null) {
apply from: "$rootProject.projectDir/gradle/nativeProject.gradle"
apply from: "$rootProject.projectDir/gradle/distributableGPLModule.gradle"
}
else {
apply from: "../utils.gradle"
apply from: "../nativePlatforms.gradle"
apply from: "../nativeBuildProperties.gradle"
}
@@ -21,30 +22,6 @@ def v24 = "demangler_gnu_v2_24"
def srcVersion33_1 = "src/demangler_gnu_v2_33_1"
def srcVersion24 = "src/demangler_gnu_v2_24"
/****************************************************************************
* Defines the platforms we have to support in Ghidra. This model is used
* for all native builds and should be extended by each module as-needed.
****************************************************************************/
model {
// define the platforms that we support in ghidra
platforms {
win64 {
architecture 'x86_64'
operatingSystem 'windows'
}
linux64 {
architecture 'x86_64'
operatingSystem 'linux'
}
osx64 {
architecture 'x86_64'
operatingSystem 'osx'
}
}
}
/**
* This project has some native 'c' code we need to include in the zip for licensing
* and build reasons. So include them here, but we have to do something special: the
@@ -100,9 +77,11 @@ model {
//
components {
demangler_gnu_v2_33_1(NativeExecutableSpec) {
targetPlatform "win64"
targetPlatform "linux64"
targetPlatform "osx64"
targetPlatform "win_x86_64"
targetPlatform "linux_x86_64"
targetPlatform "linux_arm_64"
targetPlatform "mac_x86_64"
targetPlatform "mac_arm_64"
sources {
c {
source {
@@ -119,9 +98,11 @@ model {
// Version 2.24
//
demangler_gnu_v2_24(NativeExecutableSpec) {
targetPlatform "win64"
targetPlatform "linux64"
targetPlatform "osx64"
targetPlatform "win_x86_64"
targetPlatform "linux_x86_64"
targetPlatform "linux_arm_64"
targetPlatform "mac_x86_64"
targetPlatform "mac_arm_64"
sources {
c {
source {

View File

@@ -36,13 +36,13 @@ ext.binutilsDistro = "${binutils}.tar.bz2"
// Find the GPL dir
def gplDir = null;
if (file("../gpl.gradle").exists()) {
if (file("../utils.gradle").exists()) {
gplDir = file("..").getCanonicalPath()
}
else {
// Module lives disconnected from the GPL directory, which it will need to build.
// Find a Ghidra installation directory and use its GPL directory.
if (file("../../Extensions").exists() && file("../../../GPL/gpl.gradle").exists()) {
if (file("../../Extensions").exists() && file("../../../GPL/utils.gradle").exists()) {
// Module is installed within a Ghidra installation (i.e, ghidra/Ghidra/Extensions)
gplDir = file("../../../GPL").getCanonicalPath()
}
@@ -76,7 +76,8 @@ if (findProject(':Generic') != null) {
}
else {
// Build GPL extension (gdis)
apply from: "${gplDir}/gpl.gradle"
apply from: "${gplDir}/utils.gradle"
apply from: "${gplDir}/nativePlatforms.gradle"
apply from: "${gplDir}/nativeBuildProperties.gradle"
apply from: "buildGdis.gradle"
}

View File

@@ -4,7 +4,7 @@
defaultTasks 'assemble'
ext.supportedPlatforms = ['osx64', 'linux64']
ext.supportedPlatforms = ['mac_x86_64', 'mac_arm_64', 'linux_x86_64', 'linux_arm_64']
ext.binutilsResource = new File("${projectDir}/${binutils}.tar.bz2")
@@ -18,17 +18,6 @@ def binutilsUnpackDir = file("${project.buildDir}/${binutils}/")
******************************************************************************************/
model {
platforms {
linux64 {
architecture 'x86_64'
operatingSystem 'linux'
}
osx64 {
architecture 'x86_64'
operatingSystem 'osx'
}
}
components {
gdis(NativeExecutableSpec) {
@@ -56,11 +45,17 @@ model {
}
}
tasks.compileGdisOsx64ExecutableGdisC {
dependsOn 'copyBinutilsArtifcats_osx64'
tasks.compileGdisMac_x86_64ExecutableGdisC {
dependsOn 'copyBinutilsArtifcats_mac_x86_64'
}
tasks.compileGdisLinux64ExecutableGdisC {
dependsOn 'copyBinutilsArtifcats_linux64'
tasks.compileGdisLinux_x86_64ExecutableGdisC {
dependsOn 'copyBinutilsArtifcats_linux_x86_64'
}
tasks.compileGdisMac_arm_64ExecutableGdisC {
dependsOn 'copyBinutilsArtifcats_mac_arm_64'
}
tasks.compileGdisLinux_arm_64ExecutableGdisC {
dependsOn 'copyBinutilsArtifcats_linux_arm_64'
}
}

View File

@@ -1,90 +0,0 @@
/* ###
* IP: Public Domain
*/
// BIN_REPO only useable in full Ghidra source configuration
project.ext.BIN_REPO = file("../../../ghidra.bin").absolutePath
/****************************************************************************
* Create a set containing all the platforms we need when building native
* artifacts.
****************************************************************************/
project.ext.set("OS_NAMES", ["osx64", "win32", "win64", "linux64"])
/****************************************************************************
* Establish Visual Studio configuration environment for Windows native builds
* NOTE: vsconfig.gradle path is relative to each GPL project module
****************************************************************************/
apply from: buildscript.sourceFile.getParent() + "/vsconfig.gradle"
/*********************************************************************************
* Returns the local platform name.
*********************************************************************************/
ext.getCurrentPlatformName = {
String osName = System.getProperty("os.name")
String archName = System.getProperty("os.arch")
boolean isX86_32 = archName.equals("x86") || archName.equals("i386");
boolean isX86_64 = archName.equals("x86_64") || archName.equals("amd64");
if (osName.startsWith("Windows")) {
if (isX86_32) {
return 'win32'
}
else if (isX86_64) {
return 'win64'
}
}
else if (osName.startsWith("Linux")) {
if (isX86_64) {
return 'linux64'
}
}
else if (osName.startsWith("Mac OS X")) {
if (isX86_64) {
return 'osx64'
}
}
throw new GradleException("Unrecognized current platform -> osName = $osName, archName = $archName")
}
/******************************************************************************************
* Helper method that returns a file that is the same relative location in the bin repo
* as the given project is in its repo.
******************************************************************************************/
ext.getProjectLocationInBinRepo = {
String relativePath = getGhidraRelativePath(this.project)
println("RELATIVE: $relativePath")
File binRepoRootProject = new File("${BIN_REPO}")
if (!binRepoRootProject.isDirectory()) {
throw new GradleException("Task requires Ghidra source and ghidra.bin")
}
return new File(binRepoRootProject, relativePath)
}
/****************************************************************************************
* Returns the "effective" relative path (Path starting with Ghidra)
* Normally, for files in the ghidra repo this is just the relative path from
* the root project (ghidra) to the given project.
*
* For example <...>/ghidra/Ghidra/Features/Base will return Ghidra/Features/Base
*
* If the project is in a sibling repo (ghidra.<other> that lives in the same directory
* as ghidra), then this method returns a relative path as though the project lived
* in ghidra.
*
* for example <...>/ghidra.foo/Ghidra/Features/OtherProject will return Ghidra/Features/OtherProject
****************************************************************************************/
String getGhidraRelativePath(Project p) {
String path = rootProject.relativePath(p.projectDir)
// If the project lives outside the ghidra repo, then its relative path will
// start with "../". In this case, we want to remove the "../" and the next path element
// so that the path will appear as though the project lived under the ghidra repo.
// example: "../ghidra/Ghidra/Features/Foo" will get changed to "Ghidra/Features/Foo"
String prefix = ".."+File.separator
if (path.startsWith(prefix)) {
int index = path.indexOf(File.separator,3)
path = path.substring(index+1)
}
return path
}

View File

@@ -24,25 +24,35 @@ apply plugin: 'c'
****************************************************************************/
model {
// define the platforms that we support in ghidra
// Use the PLATFORMS list to create the platforms that Ghidra supports.
platforms {
win32 {
architecture 'x86'
operatingSystem 'windows'
}
win64 {
architecture 'x86_64'
operatingSystem 'windows'
}
linux64 {
architecture 'x86_64'
operatingSystem 'linux'
}
osx64 {
architecture 'x86_64'
operatingSystem 'osx'
project.PLATFORMS.each { platform ->
"${platform.name}" {
architecture platform.arch
operatingSystem platform.os
}
}
}
// The toolChains block is needed because Gradle doesn't find gcc/clang on ARM-based Linux
// and macOS platforms without explicitly declaring their targets. Might be a bug in the
// native Gradle plugin.
toolChains {
if (isCurrentLinux()) {
gcc(Gcc) {
if (isCurrentArm_64()) {
target("linux_arm_64")
}
}
}
if (isCurrentMac()) {
clang(Clang) {
if (isCurrentArm_64()) {
target("mac_arm_64")
}
}
}
}
}
/*******************************************************************************************
@@ -51,7 +61,7 @@ model {
task CheckToolChain {
// Native C/Cpp plugins will trigger failure if no tool chain found
doFirst {
if (org.gradle.internal.os.OperatingSystem.current().isWindows()) {
if (isCurrentWindows()) {
// ensure that required MS Visual Studio is installed
if (!VISUAL_STUDIO_INSTALL_DIR) {
throw new GradleException("Visual Studio not found!");
@@ -100,7 +110,7 @@ def shouldSkipNative(task) {
/*******************************************************************************************
* Task Rule : builds all the natives in this module for a given platform.
*
* Example : gradle buildNatives_win64 will build all win64 native executables and shared libraries.
* Example : gradle buildNatives_win_x86_64 will build all win_x86_64 native executables and shared libraries.
*
* NOTE: you must be on the appropriate platform for this to work.
*
@@ -151,7 +161,7 @@ tasks.addRule("Pattern: buildNatives_<platform name>]: build all natives for giv
* Task Rule : builds all the natives in this module for a given platform and copies the
* results to the bin repo.
*
* Example : gradle prebuildNatives_win64 will build all win64 native executables and shared
* Example : gradle prebuildNatives_win_x86_64 will build all win_x86_64 native executables and shared
* libraries and copy the results to the appropriate project/os directory in the bin
* repo.
*

159
GPL/nativePlatforms.gradle Normal file
View File

@@ -0,0 +1,159 @@
/* ###
* IP: Public Domain
*/
/****************************************************************************
* nativePlatforms.gradle
*
* This script defines the various platforms that Ghidra supports being built
* on. Utility methods are provided for determining the current platform, as
* well as querying and extracting information about the platform, such as
* operating system and architecture.
****************************************************************************/
/****************************************************************************
* Create a list containing all the platforms we support for building native
* artifacts. Each platform has the following fields:
* name: Ghidra's naming convention for the platform. This is used in the
native build tasks, and is the name of the os/ subdirectories.
* os: Gradle's NativePlatform operatingSystem property naming convention.
* arch: Gradle's NativePlatform architecture property naming convention.
****************************************************************************/
project.ext.PLATFORMS = [
[name: "win_x86_32", os: "windows", arch: "x86"],
[name: "win_x86_64", os: "windows", arch: "x86_64"],
[name: "linux_x86_64", os: "linux", arch: "x86_64"],
[name: "linux_arm_64", os: "linux", arch: "arm64"],
[name: "mac_x86_64", os: "osx", arch: "x86_64"],
[name: "mac_arm_64", os: "osx", arch: "arm64"]
]
/*********************************************************************************
* Returns the local platform name.
*********************************************************************************/
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
ext.currentPlatformName = null
ext.getCurrentPlatformName = {
if (currentPlatformName) {
return currentPlatformName
}
def osGradle = DefaultNativePlatform.currentOperatingSystem.getName()
def osJvm = System.getProperty("os.name");
def os = osJvm
switch (osJvm) {
case ~/Windows.*/:
os = "win"
break
case ~/Linux.*/:
os = "linux"
break
case ~/Mac OS X.*/:
os = "mac"
break
default:
throw new GradleException("Unrecognized platform operating system: $os")
}
def archGradle = DefaultNativePlatform.currentArchitecture.getName()
def archJvm = System.getProperty("os.arch");
def arch = archJvm
switch (arch) {
case "x86":
case "i386":
arch = "x86_32"
break
case "x86_64":
case "amd64":
arch = "x86_64"
break
case "aarch64":
case "arm64":
arch = "arm_64"
break
default:
throw new GradleException("Unrecognized platform architecture: $arch" )
}
currentPlatformName = "${os}_${arch}"
println "OS: " + osJvm + (osJvm != osGradle ? " (gradle: " + osGradle + ")" : "")
println "Arch: " + archJvm + (archJvm != archGradle ? " (gradle: " + archGradle + ")" : "")
println "Using platform: " + currentPlatformName
return currentPlatformName
}
/*********************************************************************************
* Returns true if the given platform is linux.
*********************************************************************************/
ext.isLinux = { platform_name ->
return platform_name.startsWith("linux")
}
/*********************************************************************************
* Returns true if the current platform is linux.
*********************************************************************************/
ext.isCurrentLinux = {
return isLinux(getCurrentPlatformName())
}
/*********************************************************************************
* Returns true if the given platform is macOS.
*********************************************************************************/
ext.isMac = { platform_name ->
return platform_name.startsWith("mac")
}
/*********************************************************************************
* Returns true if the current platform is macOS.
*********************************************************************************/
ext.isCurrentMac = {
return isMac(getCurrentPlatformName())
}
/*********************************************************************************
* Returns true if the given platform is Windows.
*********************************************************************************/
ext.isWindows = { platform_name ->
return platform_name.startsWith("win")
}
/*********************************************************************************
* Returns true if the current platform is Windows.
*********************************************************************************/
ext.isCurrentWindows = {
return isWindows(getCurrentPlatformName())
}
/*********************************************************************************
* Returns true if the given platform is x86.
*********************************************************************************/
ext.isX86_64 = { platform_name ->
return platform_name.contains("x86")
}
/*********************************************************************************
* Returns true if the current platform is x86.
*********************************************************************************/
ext.isCurrentX86_64 = {
return isX86_64(getCurrentPlatformName())
}
/*********************************************************************************
* Returns true if the given platform is ARM.
*********************************************************************************/
ext.isArm_64 = { platform_name ->
return platform_name.contains("arm")
}
/*********************************************************************************
* Returns true if the current platform is ARM.
*********************************************************************************/
ext.isCurrentArm_64 = {
return isArm_64(getCurrentPlatformName())
}
/****************************************************************************
* Establish Visual Studio configuration environment for Windows native builds
* NOTE: vsconfig.gradle path is relative to each GPL project module
****************************************************************************/
apply from: buildscript.sourceFile.getParent() + "/vsconfig.gradle"

41
GPL/utils.gradle Normal file
View File

@@ -0,0 +1,41 @@
/* ###
* IP: Public Domain
*/
/******************************************************************************************
* Helper method that returns a file that is the same relative location in the bin repo
* as the given project is in its repo.
******************************************************************************************/
ext.getProjectLocationInBinRepo = { p ->
String relativePath = getGhidraRelativePath(p)
File binRepoRootProject = new File("${BIN_REPO}")
return new File(binRepoRootProject, relativePath)
}
/****************************************************************************************
* Returns the "effective" relative path (Path starting with Ghidra)
* Normally, for files in the ghidra repo this is just the relative path from
* the root project (ghidra) to the given project.
*
* For example <...>/ghidra/Ghidra/Features/Base will return Ghidra/Features/Base
*
* If the project is in a sibling repo (ghidra.<other> that lives in the same directory
* as ghidra), then this method returns a relative path as though the project lived
* in ghidra.
*
* for example <...>/ghidra.foo/Ghidra/Features/OtherProject will return Ghidra/Features/OtherProject
****************************************************************************************/
ext.getGhidraRelativePath = { p ->
String path = rootProject.relativePath(p.projectDir)
// If the project lives outside the ghidra repo, then its relative path will
// start with "../". In this case, we want to remove the "../" and the next path element
// so that the path will appear as though the project lived under the ghidra repo.
// example: "../ghidra/Ghidra/Features/Foo" will get changed to "Ghidra/Features/Foo"
String prefix = ".."+File.separator
if (path.startsWith(prefix)) {
int index = path.indexOf(File.separator,3)
path = path.substring(index+1)
}
return path
}

View File

@@ -27,7 +27,7 @@ if (!hasProperty("VISUAL_STUDIO_INSTALL_DIR")) {
def configureVisualStudio() {
if (org.gradle.internal.os.OperatingSystem.current().isWindows()) {
if (isCurrentWindows()) {
// Initialize variables
rootProject.ext.VISUAL_STUDIO_INSTALL_DIR = ""