@@ -11,6 +11,9 @@ import java.io.File
11
11
import java .nio .file .Paths
12
12
import scala .util .Using
13
13
import java .io .FileWriter
14
+ import java .nio .file .Files
15
+ import cats .syntax .writer
16
+ import util .chaining .*
14
17
15
18
enum Compiler :
16
19
case Clang , ClangPP
@@ -515,26 +518,65 @@ object VcpkgCLI extends VcpkgPluginImpl, VcpkgPluginNativeImpl:
515
518
scalaCliArgs.addOne(scalaCliBin)
516
519
scalaCliArgs.addAll(rest)
517
520
518
- computeNativeFlags(
521
+ val flags = computeNativeFlags(
519
522
OutputOptions (compile = true , linking = true ),
520
523
allDeps,
521
524
result.filter((k, v) => allDeps.contains(k)),
522
525
rename
523
- ).foreach {
524
- case NativeFlag .Compilation (value) =>
525
- scalaCliArgs.addOne(" --native-compile" )
526
- scalaCliArgs.addOne(value)
526
+ )
527
+
528
+ val (linkingFlags, compileFlags) =
529
+ val (l, c) = flags.partition:
530
+ case NativeFlag .Compilation (value) => false
531
+ case NativeFlag .Linking (value) => true
532
+
533
+ (l.map(_.get), c.map(_.get))
534
+
535
+ val linkFlagsFile = Files
536
+ .createTempFile(" linking" , " .txt" )
537
+ .toFile()
538
+ .tap(_.deleteOnExit())
539
+
540
+ val linkFlagsFileWriter =
541
+ new FileWriter (
542
+ linkFlagsFile
543
+ )
544
+
545
+ val compileFlagsFile = Files
546
+ .createTempFile(" compile" , " .txt" )
547
+ .toFile()
548
+ .tap(_.deleteOnExit())
527
549
528
- case NativeFlag .Linking (value) =>
529
- scalaCliArgs.addOne(" --native-linking" )
530
- scalaCliArgs.addOne(value)
531
- }
550
+ val compileFlagsFileWriter =
551
+ new FileWriter (
552
+ compileFlagsFile
553
+ )
554
+
555
+ Using (linkFlagsFileWriter): linkFlagsFileWriter =>
556
+ linkingFlags.foreach(f => linkFlagsFileWriter.write(f + " \n " ))
557
+
558
+ Using (compileFlagsFileWriter): compileFlagsWriter =>
559
+ compileFlags.foreach(f => compileFlagsWriter.write(f + " \n " ))
560
+
561
+ scalaCliArgs.addAll(
562
+ Seq (
563
+ " --native-linking" ,
564
+ s " @ ${linkFlagsFile.toPath().toAbsolutePath().toString}"
565
+ )
566
+ )
567
+ scalaCliArgs.addAll(
568
+ Seq (
569
+ " --native-compile" ,
570
+ s " @ ${compileFlagsFile.toPath().toAbsolutePath().toString}"
571
+ )
572
+ )
532
573
533
574
scribe.debug(
534
575
s " Invoking Scala CLI with arguments: [ ${scalaCliArgs.result().mkString(" " )}] "
535
576
)
536
577
537
- val exitCode = scala.sys.process.Process (scalaCliArgs.result()).!
578
+ val exitCode =
579
+ scala.sys.process.Process (scalaCliArgs.result()).!
538
580
539
581
sys.exit(exitCode)
540
582
0 commit comments