gradle-doctor icon indicating copy to clipboard operation
gradle-doctor copied to clipboard

Warn when using translated rosetta

Open runningcode opened this issue 3 years ago • 2 comments

Detect when an M1 cpu is using the rosetta translation layer and add warning and/or fail the build

runningcode avatar May 09 '22 16:05 runningcode

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.

GediminasZukas avatar May 20 '22 08:05 GediminasZukas

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

runningcode avatar May 23 '22 12:05 runningcode

Released in 0.9.0

runningcode avatar Nov 07 '23 21:11 runningcode