runningcode / gradle-doctor

The right prescription for your Gradle build.
http://runningcode.github.io/gradle-doctor
Apache License 2.0
723 stars 46 forks source link

Warn when using translated rosetta #209

Closed runningcode closed 8 months ago

runningcode commented 2 years ago

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

GediminasZukas commented 2 years 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.

runningcode commented 2 years ago

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 commented 8 months ago

Released in 0.9.0