Closed runningcode closed 8 months ago
Maybe I could contribute. In my project I created such check to solve this problem:
buildscript {
dependencies {
classpath "com.github.oshi:oshi-core:6.1.6" // dependency in order to get cpu architecture
}
}
def checkCpuAndJdkCompatibility = {
def cpuArchitecture = new SystemInfo()
.getHardware()
.getProcessor()
.processorIdentifier
.microarchitecture.replace(" ", "").toLowerCase()
if (cpuArchitecture.contains("arm")) {
def jdkTargetArchitecture = System.getProperty("os.arch").toLowerCase()
if (jdkTargetArchitecture.contains("x86")) {
throw new GradleException(
"Attempt to use x86 JDK in ARM-based device. Install JDK version for ARM CPU and try again."
)
}
}
}.call()
What do you think about such sketch? Maybe there is some idiomatic Gradle API to determine CPU type or that CPU is using Rosetta? Seems it's not possible to get such info via common jvm environment variables.
I think it's better to call this API: https://developer.apple.com/documentation/apple-silicon/about-the-rosetta-translation-environment#Determine-Whether-Your-App-Is-Running-as-a-Translated-Binary
sysctl.proc_translated
Released in 0.9.0
Detect when an M1 cpu is using the rosetta translation layer and add warning and/or fail the build