martmists
08/21/2023, 11:40 PMamd64
for x64 (or maybe both? not very clear)Chris Lee
08/21/2023, 11:43 PMos.arch
for that, though with some caveats. Using this, for example:
public open val arch: Arch by lazy {
when (val archName = System.getProperty("os.arch", "unknown").lowercase()) {
"amd64", "x86_64" -> Arch.Amd64
"arm64", "aarch64" -> Arch.Arm64
else -> error("Unknown architecture $archName")
}
}
However, be aware that this only reports the JVM’s view on the architecture; for example, an x86_64 JVM on an Apple Arm M1 (using Rosetta) will report x86_64 (as its an x86_64 JVM), even though the OS is aarch64.Chris Lee
08/21/2023, 11:52 PMpublic object MacOsX : Os() {
public val appleSilicon: Boolean by lazy { execAndGetStdout("uname", "-p") == "arm" }
public val translatedByRosetta: Boolean by lazy {
execAndGetStdout(
"sysctl",
"sysctl.proc_translated"
) == "sysctl.proc_translated: 1"
}
public override val arch: Arch by lazy {
when {
appleSilicon -> Arch.Arm64
else -> Arch.Amd64
}
}
}