Skip to content

Commit 1c7184d

Browse files
fix: Synchronize with scala-native main (#34)
* Synch with scala-native main * Fix installing llvm on Windows * Fix ScalaNativeP
1 parent 9879dda commit 1c7184d

File tree

4 files changed

+40
-16
lines changed

4 files changed

+40
-16
lines changed

.github/workflows/CI.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,31 @@ jobs:
2424
if: ${{ startsWith(matrix.OS, 'windows') }}
2525
shell: pwsh
2626
run: |
27-
Choco-Install -PackageName llvm -ArgumentList "--version=16.0.6", "--allow-downgrade", "--force"
27+
$retryCount = 3
28+
$retryDelay = 5 # seconds
29+
30+
function InstallLLVM {
31+
Write-Host "Attempting to install LLVM (try $($retryCount + 1 - $global:retryAttempt) of $($retryCount + 1))..."
32+
choco install llvm --version=17.0.6 --allow-downgrade --force
33+
}
34+
35+
# Attempt to install LLVM with retries
36+
for ($global:retryAttempt = 1; $global:retryAttempt -le $retryCount; $global:retryAttempt++) {
37+
try {
38+
InstallLLVM
39+
Write-Host "LLVM installation successful!"
40+
break # Exit the loop if installation is successful
41+
} catch {
42+
Write-Host "Error installing LLVM: $_"
43+
if ($global:retryAttempt -lt $retryCount) {
44+
Write-Host "Retrying in $retryDelay seconds..."
45+
Start-Sleep -Seconds $retryDelay
46+
} else {
47+
Write-Host "Maximum retry attempts reached. Exiting."
48+
exit 1
49+
}
50+
}
51+
}
2852
echo "${env:ProgramFiles}\LLVM\bin" | Out-File -FilePath ${env:GITHUB_PATH} -Encoding utf8 -Append
2953
echo "LLVM_BIN=${env:ProgramFiles}\LLVM\bin" >> ${env:GITHUB_OUTPUT}
3054

cli/src/main/scala/scala/scalanative/cli/ScalaNativeP.scala

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import java.nio.file.Path
1111
import scala.scalanative.io.VirtualDirectory
1212
import scala.scalanative.nir.serialization.deserializeBinary
1313
import scala.annotation.tailrec
14-
import java.nio.ByteBuffer
1514

1615
object ScalaNativeP {
1716

@@ -109,40 +108,37 @@ object ScalaNativeP {
109108
def findInClasspathAndRead(
110109
classpath: Stream[VirtualDirectory],
111110
path: Path
112-
): Option[ByteBuffer] = {
111+
): Option[(VirtualDirectory, Path)] = {
113112
classpath match {
114-
case Stream.Empty => None
115113
case dir #:: tail =>
116114
val found = dir.files
117115
.find(virtualDirPathMatches(_, path))
118-
.map(dir.read(_))
119116
if (found.isEmpty) findInClasspathAndRead(tail, path)
120-
else found
117+
else Some(dir -> path)
118+
case _ => None
121119
}
122120
}
123121

124-
def tryReadFromPath(path: Path): Option[ByteBuffer] = {
122+
def tryReadFromPath(path: Path): Option[(VirtualDirectory, Path)] = {
125123
val file = path.toFile()
126124
val absPath = path.toAbsolutePath()
127125
// When classpath is explicitly provided don't try to read directly
128126
if (!options.usingDefaultClassPath || !file.exists()) None
129127
else
130-
util.Try {
131-
VirtualDirectory
132-
.real(absPath.getParent())
133-
.read(absPath.getFileName())
134-
}.toOption
128+
Some(
129+
VirtualDirectory.real(absPath.getParent()) -> absPath.getFileName()
130+
)
135131
}
136132

137133
for {
138134
fileName <- options.classNames
139135
path = Paths.get(fileName).normalize()
140-
content <-
136+
(directory, dirPath) <-
141137
tryReadFromPath(path)
142138
.orElse(findInClasspathAndRead(cp, path))
143139
.orElse(fail(s"Not found file with name `${fileName}`"))
144140
} {
145-
val defns = deserializeBinary(content, fileName)
141+
val defns = deserializeBinary(directory, dirPath)
146142
printNIR(defns, options.verbose)
147143
}
148144
}

cli/src/main/scala/scala/scalanative/cli/utils/ConfigConverter.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ object ConfigConverter {
101101
.withOptimizerConfig(generateOptimizerConfig(options.optimizerConifg))
102102
.withBaseName(baseName)
103103
.withMultithreadingSupport(options.nativeConfig.multithreadingSupport)
104-
.withDebugMetadata(options.nativeConfig.debugMetadata)
104+
.withSourceLevelDebuggingConfig(
105+
_.enabled(options.nativeConfig.debugMetadata)
106+
)
105107
}
106108

107109
private def generateOptimizerConfig(

cli/src/test/scala/scala/scalanative/cli/utils/ConfigConverterTest.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ class ConfigConverterTest extends AnyFlatSpec {
230230
fail(_),
231231
{ case (positive, negative) =>
232232
assert(positive.multithreadingSupport != negative.multithreadingSupport)
233-
assert(positive.debugMetadata != negative.debugMetadata)
233+
assert(
234+
positive.sourceLevelDebuggingConfig.enabled != negative.sourceLevelDebuggingConfig.enabled
235+
)
234236
}
235237
)
236238
}

0 commit comments

Comments
 (0)