Skip to content

Commit

Permalink
support linux aarch64
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffery.wsj authored and superajun-wsj committed Apr 21, 2023
1 parent 5d245a0 commit 080fd07
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 28 deletions.
13 changes: 11 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ plugins {
// build script.
id 'org.ajoberstar.grgit' version '3.1.1'
id 'net.ltgt.errorprone' version '1.3.0'
id "com.google.osdetector" version "1.7.3"
}

subprojects {
Expand All @@ -40,8 +41,16 @@ subprojects {
toolChains {
visualCpp(VisualCpp)
// Prefer Clang over Gcc (order here matters!)
clang(Clang)
gcc(Gcc)
clang(Clang) {
target("linux_aarch64") {
cppCompiler.executable = "/usr/bin/clang"
}
}
gcc(Gcc) {
target("linux_aarch64") {
cppCompiler.executable = "/usr/bin/gcc"
}
}
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions constants/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ dependencies {
}

model {
platforms {
x86_32 {
architecture "x86"
}
x86_64 {
architecture "x86_64"
}
linux_aarch64 {
architecture "aarch64"
}
}
components {
// Builds exe/ which generates the content of NativeConstants.java
gen(NativeExecutableSpec) {
Expand Down
79 changes: 54 additions & 25 deletions openjdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,57 @@ apply plugin: 'biz.aQute.bnd.builder'

description = 'Tongsuo: OpenJdk'

enum NativeBuildInfo {
LINUX_X86_64("linux", "x86_64"),
LINUX_AARCH_64("linux", "aarch_64");

public final String os
public final String arch

private static final gradleArchMap = [
"aarch_64": "aarch64",
"x86_64" : "x86-64",
]

NativeBuildInfo(String os, String arch) {
this.os = os
this.arch = arch
}

// Gradle equivalent to Maven arch
String gradleArch() {
gradleArch(arch)
}

static String gradleArch(String arch) {
gradleArchMap.get(arch)
}

// Target platform identifier as used by Gradle
String targetPlatform() {
"${os}_${gradleArch()}"
}
}

ext {
jniSourceDir = "$rootDir/common/src/jni"
assert file("$jniSourceDir").exists()

// Build the list of classifiers that will be used in the build.
arch32Name = 'x86'
arch64Name = 'x86_64'
archName = NativeBuildInfo.gradleArch("${osdetector.arch}")
nativeClassifiers = []
nativeClassifier64Bit = null
nativeClassifier32Bit = null
preferredClassifier = null
preferredSourceSet = null
preferredNativeFileDir = null
if (build64Bit) {
// Add the 64-Bit classifier first, as the preferred classifier.
nativeClassifier64Bit = classifierFor(osName, arch64Name)
nativeClassifier64Bit = classifierFor(osName, archName)
nativeClassifiers += nativeClassifier64Bit
preferredClassifier = nativeClassifier64Bit
preferredSourceSet = sourceSetName(preferredClassifier)
preferredNativeFileDir = nativeResourcesDir(preferredClassifier)
}
if (build32Bit) {
nativeClassifier32Bit = classifierFor(osName, arch32Name)
nativeClassifiers += nativeClassifier32Bit
if (preferredClassifier == null) {
preferredClassifier = nativeClassifier32Bit
preferredSourceSet = sourceSetName(preferredClassifier)
preferredNativeFileDir = nativeResourcesDir(preferredClassifier)
}
}
}

sourceSets {
Expand Down Expand Up @@ -274,11 +295,13 @@ javadoc {

model {
platforms {
x86 {
architecture arch32Name
}
x86_64 {
architecture arch64Name
operatingSystem "linux"
architecture archName
}
linux_aarch64 {
operatingSystem "linux"
architecture "arm64"
}
}

Expand All @@ -289,9 +312,14 @@ model {
components {
// Builds the JNI library.
conscrypt_openjdk_jni(NativeLibrarySpec) {
if (build32Bit) { targetPlatform arch32Name }
if (build64Bit) { targetPlatform arch64Name }

if (build64Bit) {
if (archName == "aarch64") {
targetPlatform "linux_aarch64"
}
if (archName == "x86_64") {
targetPlatform "x86_64"
}
}
sources {
cpp {
source {
Expand All @@ -309,12 +337,10 @@ model {
// Set up 32-bit vs 64-bit build
def building64Bit = false
def libPath = "$tongsuoLibDir"
if (targetPlatform.getArchitecture().getName() == "x86") {
// nothing
} else if (targetPlatform.getArchitecture().getName() == "x86-64") {
if (targetPlatform.getArchitecture().getName() == "x86-64"
|| targetPlatform.getArchitecture().getName() == "arm-v8") {
building64Bit = true
if (file("$tongsuoLib64Dir").exists())
libPath = "$tongsuoLib64Dir"
if (file("$tongsuoLib64Dir").exists()) libPath = "$tongsuoLib64Dir"
} else {
throw new GradleException("Unknown architecture: " +
targetPlatform.getArchitecture().name)
Expand Down Expand Up @@ -413,6 +439,9 @@ model {
$.binaries.withType(SharedLibraryBinarySpec).each { binary ->
// Build the native artifact classifier from the OS and architecture.
def archName = binary.targetPlatform.architecture.name.replaceAll('-', '_')
if (archName == "arm_v8") {
archName = "aarch64"
}
def classifier = classifierFor(osName, archName)
def sourceSetName = sourceSetName("$classifier")
def source = binary.sharedLibraryFile
Expand Down
6 changes: 5 additions & 1 deletion openjdk/src/main/java/org/conscrypt/HostProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ enum Architecture {
SPARC_32,
SPARC_64,
ARM_32,
AARCH_64,
AARCH_64 {
@Override public String getFileComponent() {
return "aarch64";
}
},
PPC_32,
PPC_64,
PPCLE_64,
Expand Down

0 comments on commit 080fd07

Please sign in to comment.