Skip to content

Commit ee07a3c

Browse files
committed
NativeImageSize constants are more visible, and platform specific
1 parent c324144 commit ee07a3c

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

project/GraalVM.scala

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,40 @@ object GraalVM {
7272
def release = native && !test && !debug && !fast && !disableLanguageServer
7373
}
7474

75+
case class NativeImageSize(
76+
minMb: Int,
77+
maxMb: Int
78+
)
79+
80+
object NativeImageSize {
81+
def expectedSizeForCurrentPlatform(): NativeImageSize = {
82+
if (EnsoLauncher.release) {
83+
if (Platform.isWindows) {
84+
windowsX64Release
85+
} else if (Platform.isLinux) {
86+
linuxX64Release
87+
} else if (Platform.isMacOS && Platform.isAmd64) {
88+
macX64Release
89+
} else if (Platform.isMacOS && Platform.isArm64) {
90+
macARM64Release
91+
} else {
92+
throw new IllegalArgumentException("Unexpected platform")
93+
}
94+
} else {
95+
testNISize
96+
}
97+
}
98+
99+
// Expected production NI sizes deduced from sizes on latest
100+
// nightly builds: https://github.com/enso-org/enso/pull/12996#discussion_r2073742680
101+
// With maximal size relaxed by 30 MB.
102+
private val windowsX64Release = NativeImageSize(200, 420)
103+
private val linuxX64Release = NativeImageSize(200, 463)
104+
private val macX64Release = NativeImageSize(200, 408)
105+
private val macARM64Release = NativeImageSize(200, 423)
106+
private val testNISize = NativeImageSize(100, 550)
107+
}
108+
75109
/** Has the user requested to use Espresso for Java interop? */
76110
private def isEspressoMode(): Boolean =
77111
"espresso".equals(System.getenv("ENSO_JAVA"))

project/NativeImage.scala

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -332,27 +332,21 @@ object NativeImage {
332332
"Ensure that the dependency on `buildNativeImage` is properly set."
333333
)
334334
}
335-
val bytes = generatedBin.attributes.size()
336-
val productionNIBounds = (150, 450)
337-
val testNIBounds = (110, 550)
338-
val mb = bytes / (1024 * 1024)
339-
val bounds = if (GraalVM.EnsoLauncher.release) {
340-
productionNIBounds
341-
} else {
342-
testNIBounds
343-
}
335+
val bytes = generatedBin.attributes.size()
336+
val mb = bytes / (1024 * 1024)
337+
val expectedSize = GraalVM.NativeImageSize.expectedSizeForCurrentPlatform()
344338
val isInBounds =
345-
bounds._1 <= mb && mb <= bounds._2
339+
expectedSize.minMb <= mb && mb <= expectedSize.maxMb
346340
if (!isInBounds) {
347341
logger.error(
348342
s"Generated binary $generatedBin has unexpected size: $mb MB. " +
349-
s"Expected size is between ${bounds._1} and ${bounds._2} MB."
343+
s"Expected size is between ${expectedSize.minMb} and ${expectedSize.maxMb} MB."
350344
)
351345
throw new RuntimeException(s"Generated binary $generatedBin is too large")
352346
} else {
353347
logger.info(
354348
s"Generated binary $generatedBin size ($mb MB) " +
355-
s"is within the expected size: [${bounds._1}, ${bounds._2}] MB."
349+
s"is within the expected size: [${expectedSize.minMb}, ${expectedSize.maxMb}] MB."
356350
)
357351
}
358352
}

0 commit comments

Comments
 (0)