File tree 2 files changed +50
-1
lines changed
2 files changed +50
-1
lines changed Original file line number Diff line number Diff line change @@ -305,6 +305,8 @@ lazy val Benchmark = config("bench") extend sbt.Test
305
305
lazy val rebuildNativeImage = taskKey[Unit ](" Force to rebuild native image" )
306
306
lazy val buildNativeImage =
307
307
taskKey[Unit ](" Ensure that the Native Image is built." )
308
+ lazy val checkNativeImageSize =
309
+ taskKey[Unit ](" Ensures the generated Native Image has reasonable size" )
308
310
309
311
// ============================================================================
310
312
// === Global Project =========================================================
@@ -4064,7 +4066,16 @@ lazy val `engine-runner` = project
4064
4066
" enso" ,
4065
4067
targetDir = engineDistributionRoot.value / " bin"
4066
4068
)
4067
- }.value
4069
+ }.value,
4070
+ checkNativeImageSize := Def
4071
+ .taskDyn {
4072
+ NativeImage .checkNativeImageSize(
4073
+ name = " enso" ,
4074
+ targetDir = engineDistributionRoot.value / " bin"
4075
+ )
4076
+ }
4077
+ .dependsOn(buildNativeImage)
4078
+ .value
4068
4079
)
4069
4080
.dependsOn(`version-output`)
4070
4081
.dependsOn(pkg)
@@ -5671,6 +5682,7 @@ buildEngineDistributionNoIndex := Def.taskIf {
5671
5682
createEnginePackageNoIndex.value
5672
5683
if (shouldBuildNativeImage.value) {
5673
5684
(`engine-runner` / buildNativeImage).value
5685
+ (`engine-runner` / checkNativeImageSize).value
5674
5686
}
5675
5687
}.value
5676
5688
Original file line number Diff line number Diff line change @@ -320,6 +320,43 @@ object NativeImage {
320
320
}
321
321
}
322
322
323
+ def checkNativeImageSize (
324
+ name : String ,
325
+ targetDir : File
326
+ ): Def .Initialize [Task [Unit ]] = Def .task {
327
+ val generatedBin = artifactFile(targetDir, name)
328
+ val logger = streams.value.log
329
+ if (! generatedBin.exists) {
330
+ logger.error(s " Generated binary $generatedBin does not exist. " )
331
+ logger.error(
332
+ " Ensure that the dependency on `buildNativeImage` is properly set."
333
+ )
334
+ }
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
+ }
344
+ val isInBounds =
345
+ bounds._1 <= mb && mb <= bounds._2
346
+ if (! isInBounds) {
347
+ logger.error(
348
+ s " Generated binary $generatedBin has unexpected size: $mb MB. " +
349
+ s " Expected size is between ${bounds._1} and ${bounds._2} MB. "
350
+ )
351
+ throw new RuntimeException (s " Generated binary $generatedBin is too large " )
352
+ } else {
353
+ logger.info(
354
+ s " Generated binary $generatedBin size ( $mb MB) " +
355
+ s " is within the expected size: [ ${bounds._1}, ${bounds._2}] MB. "
356
+ )
357
+ }
358
+ }
359
+
323
360
/** [[File ]] representing the artifact called `name` built with the Native
324
361
* Image.
325
362
*/
You can’t perform that action at this time.
0 commit comments