Skip to content

Commit 8135650

Browse files
Fix Scala Native build (#647)
1 parent bcaf5cf commit 8135650

5 files changed

Lines changed: 24 additions & 16 deletions

File tree

.github/workflows/release-build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- uses: actions/checkout@v6
1717
- uses: actions/setup-java@v5
1818
with:
19-
java-version: 17
19+
java-version: 21
2020
distribution: 'zulu'
2121
- name: Set up Node.js 24
2222
uses: actions/setup-node@v6

sjsonnet/src-js/sjsonnet/Platform.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,6 @@ object Platform {
144144
}
145145

146146
def regexQuote(s: String): String = Pattern.quote(s)
147+
148+
def appendMemoryStats(sb: StringBuilder): Unit = {}
147149
}

sjsonnet/src-jvm/sjsonnet/Platform.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,22 @@ object Platform {
165165
quote
166166
}
167167
}
168+
169+
def appendMemoryStats(sb: StringBuilder): Unit = {
170+
val rt = Runtime.getRuntime
171+
val usedBytes = rt.totalMemory() - rt.freeMemory()
172+
val maxBytes = rt.maxMemory()
173+
sb.append(formatBytesLine("heap_used", usedBytes))
174+
sb.append(formatBytesLine("heap_max", maxBytes))
175+
}
176+
177+
private def formatBytesLine(label: String, bytes: Long): String =
178+
f"$label%-25s ${formatBytes(bytes)}%s%n"
179+
180+
private def formatBytes(bytes: Long): String = {
181+
if (bytes < 1024L) s"${bytes}B"
182+
else if (bytes < 1024L * 1024) f"${bytes / 1024.0}%.1fKB"
183+
else if (bytes < 1024L * 1024 * 1024) f"${bytes / (1024.0 * 1024)}%.1fMB"
184+
else f"${bytes / (1024.0 * 1024 * 1024)}%.2fGB"
185+
}
168186
}

sjsonnet/src-native/sjsonnet/Platform.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,6 @@ object Platform {
188188
quote
189189
}
190190
}
191+
192+
def appendMemoryStats(sb: StringBuilder): Unit = {}
191193
}

sjsonnet/src/sjsonnet/DebugStats.scala

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,7 @@ final class DebugStats {
5353
sb.append(formatTimeLine("materialize_time", materializeTimeNs))
5454
sb.append(formatTimeLine("total_time", totalTimeNs))
5555

56-
val rt = Runtime.getRuntime
57-
val usedBytes = rt.totalMemory() - rt.freeMemory()
58-
val maxBytes = rt.maxMemory()
59-
sb.append(formatBytesLine("heap_used", usedBytes))
60-
sb.append(formatBytesLine("heap_max", maxBytes))
56+
Platform.appendMemoryStats(sb)
6157

6258
sb.toString
6359
}
@@ -68,22 +64,12 @@ final class DebugStats {
6864
private def formatTimeLine(label: String, ns: Long): String =
6965
f"$label%-25s ${formatNs(ns)}%s%n"
7066

71-
private def formatBytesLine(label: String, bytes: Long): String =
72-
f"$label%-25s ${formatBytes(bytes)}%s%n"
73-
7467
private def formatNs(ns: Long): String = {
7568
if (ns < 1000L) s"${ns}ns"
7669
else if (ns < 1000000L) f"${ns / 1000.0}%.1fμs"
7770
else if (ns < 1000000000L) f"${ns / 1000000.0}%.1fms"
7871
else f"${ns / 1000000000.0}%.3fs"
7972
}
80-
81-
private def formatBytes(bytes: Long): String = {
82-
if (bytes < 1024L) s"${bytes}B"
83-
else if (bytes < 1024L * 1024) f"${bytes / 1024.0}%.1fKB"
84-
else if (bytes < 1024L * 1024 * 1024) f"${bytes / (1024.0 * 1024)}%.1fMB"
85-
else f"${bytes / (1024.0 * 1024 * 1024)}%.2fGB"
86-
}
8773
}
8874

8975
/**

0 commit comments

Comments
 (0)