Skip to content
Discussion options

You must be logged in to vote

What did work was to dump the env vars into the same file as macros definitions - this finally ensures that Macros.scala is recompiled (previously it didn't recompile because outputs would be the same - still the same references to MacrosEnv).

So the final example:

  // in build.mill
  def envX42 = Task.Input { Task.env.getOrElse("X42", "") }
  def macrosTemplate = Task.Source(moduleDir / "tmpl" / "Macros.scala")
  override def generatedSources = Task {
    os.write(
      Task.dest / "Macros.scala",
      os.read(macrosTemplate().path)
        .replace("$X42", envX42())
    )
    super.generatedSources() ++ Seq(PathRef(Task.dest))
  }

  // in modules/macros/tmpl/Macros.scala
  object Ma…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@lefou
Comment options

lefou Jan 9, 2026
Maintainer

@Rogach
Comment options

Comment options

You must be logged in to vote
2 replies
@Rogach
Comment options

@Rogach
Comment options

Answer selected by Rogach
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants