Set linux compile options for make-clone

This scripted tests failed on the linux travis ci build with an
error around relocation. It said to use -fPIC in the compilation so
that's what I'm doing. It also said I needed to set the -std=c99 flag.
This commit is contained in:
Ethan Atkins 2019-07-16 21:28:17 -07:00
parent 995a1c6b8b
commit 36f37d2fe3
2 changed files with 8 additions and 6 deletions

View File

@ -32,10 +32,10 @@ val checkAdded = taskKey[Unit]("check that modified files are returned")
checkAdded := Def.taskDyn {
val files = (foo / allInputFiles).value
val added = (foo / changedInputFiles).value.map(_.created).getOrElse(Nil)
if (added.isEmpty || files.sameElements(added)) Def.task(assert(true))
if (added.isEmpty || (files.toSet == added.toSet)) Def.task(assert(true))
else Def.task {
val base = baseDirectory.value / "base"
assert(files.sameElements(Seq("Bar.md", "Foo.txt").map(p => (base / p).toPath)))
assert(files.toSet == Set("Bar.md", "Foo.txt").map(p => (base / p).toPath))
assert(added == Seq((baseDirectory.value / "base" / "Bar.md").toPath))
}
}.value

View File

@ -1,6 +1,8 @@
import java.nio.file.{ Files, Path }
import scala.sys.process._
val compileOpts = settingKey[Seq[String]]("Extra compile options")
compileOpts := { if (scala.util.Properties.isLinux) "-fPIC" :: "-std=gnu99" :: Nil else Nil }
val compileLib = taskKey[Seq[Path]]("Compile the library")
compileLib / sourceDirectory := sourceDirectory.value / "lib"
compileLib / fileInputs := {
@ -34,7 +36,8 @@ compileLib := {
cFiles.map { file =>
val outFile = objectDir.resolve(objectFileName(file))
logger.info(s"Compiling $file to $outFile")
Seq("gcc", "-c", file.toString, s"-I$include", "-o", outFile.toString).!!
(Seq("gcc") ++ compileOpts.value ++
Seq("-c", file.toString, s"-I$include", "-o", outFile.toString)).!!
outFile
}
}
@ -87,15 +90,14 @@ compileMain := {
case Seq(main) =>
Files.createDirectories(outDir)
logger.info(s"Building executable $outPath")
Seq(
"gcc",
(Seq("gcc") ++ compileOpts.value ++ Seq(
main.toString,
s"-I$include",
"-o",
outPath.toString,
s"-L${library.getParent}",
"-lfoo"
).!!
)).!!
outPath
case main =>
throw new IllegalStateException(s"multiple main files detected: ${main.mkString(",")}")