This message was deleted.
# community-support
s
This message was deleted.
m
I don't know about idiomatic, but we're querying
DefaultNativePlatform.currentArchitecture
etc. to find out which native binaries we need
v
I don't know about idiomatic
I would guess no, for the class being an internal one 😄
🙂 1
As
Ant
is a first-class citizen, I usually use
org.apache.tools.ant.taskdefs.condition.Os
for similar things. So for example
if (Os.isArch(...))
and similar
s
Yeah, it seems all the built-in means are flagged “internal” since like years. I tried what is suggested here: https://stackoverflow.com/a/39592861/1531124 and surprisingly enough, it prints
x86_64
even for ARM. Maybe I just run
uname -a
and get that information from there.
v
I'd guess you run through an emulation layer if you get
x86_64
s
My peer with the ARM mac ensures me that he ran that code in two shell instances, one with Rosetta/X86, and one as ARM, and both printed x86 🤷‍♂️
m
I don't know how transparently that's done by the OS, but could it be possible that your colleague is running an x86 jdk from the arm shell? In that case the output would be correct
s
As I get it, he either runs his iTerm to use Rosetta, or native ARM. How could the X86 JDK run in “ARM mode”?
m
It wouldn't. But since the shell just launches other processes, it might do that transparently enough that you can launch x86 processes in emulation without even noticing. Kind of like you can start 32bit processes from 64bit ones in Windows, though not the other way around.
d
Not necessarily idiomatic, but this is how I detect platforms, it has a bunch of tests that might be useful
m
Copy code
} else if (OS.contains("macosx")) {
    OS = "macosx"

     // determine architecture on the system for osx, we need to use uname since
     // the system property may mislead us on osx
     def architecture = new ByteArrayOutputStream()
     exec {
         commandLine "uname", "-v"
         standardOutput = architecture
     }
     MacArch = architecture.toString()
     println "Mac architecture: " + MacArch;
We have to use the above with our rented macincloud boxes because the M1 machines typically give us x86 emulated java instead of M1 java.
I think I got that from stackoverflow ... just to give proper credit.
c
Using this to determine the current architecture; note that, when running JDK on Mac M1 under Rosetta, it will report x86_64 as that is what the JDK is.
Copy code
private val currentArchHolder = lazy {
            when (val currentArch = System.getProperty("os.arch", "unknown").lowercase()) {
                "amd64", "x86_64" -> Amd64
                "arm64", "aarch64" -> Arm64
                else -> error("Unknown arch: $currentArch")
            }
        }
Also not exhaustive for all possible JDK architectures. MacOS M1 returns aarch64 for os.arch.
👍 1
v
os.arch
is also what the
Os
class uses / returns
e
Just to throw another solution into the mix. Here is a code sample for capturing the processor architecture as a Build Scan custom value & tag. There is a Kotlin version in a sibling directory. https://github.com/gradle/gradle-enterprise-build-config-samples/blob/153873430abac902b3a1b79f25079688a565c3ed/build-data-capturing-gradle-samples/capture-processor-arch/gradle-processor-arch.gradle
thank you 1