Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed access to environment variables in ScalaNativeModule #1556

Merged
merged 1 commit into from
Nov 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions scalanativelib/src/ScalaNativeModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,17 @@ trait ScalaNativeModule extends ScalaModule { outer =>

def logLevel: Target[NativeLogLevel] = T { NativeLogLevel.Info }

protected def releaseModeInput = T.input(
sys.env.get("SCALANATIVE_MODE").map(v =>
protected def releaseModeInput: Target[Option[ReleaseMode]] = T.input {
T.env.get("SCALANATIVE_MODE").map(v =>
ReleaseMode
.values
.find(_.value == v)
.getOrElse(throw new Exception(
s"SCALANATIVE_MODE=$v is not valid. Allowed values are: [${ReleaseMode.values.map(_.value).mkString(", ")}]"
))
)
)
}

def releaseMode: Target[ReleaseMode] = T {
releaseModeInput().getOrElse(ReleaseMode.Debug)
}
Expand All @@ -114,7 +115,10 @@ trait ScalaNativeModule extends ScalaModule { outer =>
def nativeClangPP = T { os.Path(scalaNativeWorker().discoverClangPP) }

// GC choice, either "none", "boehm", "immix" or "commix"
protected def nativeGCInput = T.input(sys.env.get("SCALANATIVE_GC"))
protected def nativeGCInput: Target[Option[String]] = T.input {
T.env.get("SCALANATIVE_GC")
}

def nativeGC = T {
nativeGCInput().getOrElse(scalaNativeWorker().defaultGarbageCollector)
}
Expand All @@ -131,20 +135,24 @@ trait ScalaNativeModule extends ScalaModule { outer =>
def nativeLinkStubs = T { false }

// The LTO mode to use used during a release build
protected def nativeLTOInput = T.input(
sys.env.get("SCALANATIVE_LTO").map(v =>
protected def nativeLTOInput: Target[Option[LTO]] = T.input {
T.env.get("SCALANATIVE_LTO").map(v =>
LTO
.values
.find(_.value == v)
.getOrElse(throw new Exception(
s"SCALANATIVE_LTO=$v is not valid. Allowed values are: [${LTO.values.map(_.value).mkString(", ")}]"
))
)
)
}

def nativeLTO: Target[LTO] = T { nativeLTOInput().getOrElse(LTO.None) }

// Shall we optimize the resulting NIR code?
protected def nativeOptimizeInput = T.input(sys.env.get("SCALANATIVE_OPTIMIZE").map(_.toBoolean))
protected def nativeOptimizeInput: Target[Option[Boolean]] = T.input {
T.env.get("SCALANATIVE_OPTIMIZE").map(_.toBoolean)
}

def nativeOptimize: Target[Boolean] = T { nativeOptimizeInput().getOrElse(true) }

def nativeConfig = T.task {
Expand Down