Repository navigation
Support setting chisel.project.root via -Xmacro-settings - #5535
Conversation
| /** Reads `-Xmacro-settings` via a structural call so users need not enable experimental mode. | ||
| * If `XmacroSettings` is renamed or removed, fall back to Nil, which makes the resolver use the | ||
| * `chisel.project.root` system property instead of failing every SourceInfo expansion. | ||
| */ | ||
| private def macroSettings(using Quotes): List[String] = { | ||
| import quotes.reflect.* | ||
| try CompilationInfo.asInstanceOf[{ def XmacroSettings: List[String] }].XmacroSettings | ||
| catch { case scala.util.control.NonFatal(_) => Nil } | ||
| } |
There was a problem hiding this comment.
I know this looks crazy but this is the best way to do it. If you try to use experimental APIs it infects everything requiring you to enable experimental. The basic issue is that this macro is invoked by user code so the users would have to mark everything they do that calls Chisel APIs as experimental which is obviously untenable.
| val projectRoot = macroSettings.reverseIterator.collectFirst { | ||
| case setting if setting.startsWith("chisel.project.root=") => | ||
| setting.stripPrefix("chisel.project.root=") | ||
| } |
There was a problem hiding this comment.
Doing this as a regular expression with a match might be cleaner than the startsWith/stripPrefix. Non blocking.
There was a problem hiding this comment.
It might be cleaner but it might be slower and this is code I'm somewhat worried about the performance of. That being said I have some follow up work that memoizes the results that is probably the move anyway (it's just that memoizing this is actually a bit tricky).
Co-authored-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Summary
Our relative path handling for source locators works pretty well for simple builds, but using system properties does not work well for shared build servers (like Bloop). Even in this repository using Mill we've had to create .mill-jvm-opts which required getting upstream to support the interpolated
${PWD}. Scalac options are a better way to do it.Release Notes
You can now set
chisel.project.rootvia-Xmacro-settingswhich works better than setting system properties for build servers like Bloop.Development notes