Skip to content

Support setting chisel.project.root via -Xmacro-settings - #5535

Merged
jackkoenig merged 4 commits into
mainfrom
jackkoenig/chisel-project-root
Oct 30, 2026
Merged

jackkoenig merged 4 commits into
mainfrom
jackkoenig/chisel-project-root

Conversation

@jackkoenig

Copy link
Copy Markdown
Contributor

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.root via -Xmacro-settings which works better than setting system properties for build servers like Bloop.

Development notes

  • AI tool(s) used: Opencode (Claude Opus 5.5)
  • Merge strategy (defaults to squash): squash

@jackkoenig
jackkoenig requested a review from seldridge October 28, 2026 22:51
Comment on lines +23 to +31
/** 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 }
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jackkoenig jackkoenig added the Feature New feature, will be included in release notes label Oct 28, 2026

@seldridge seldridge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines +26 to +29
val projectRoot = macroSettings.reverseIterator.collectFirst {
case setting if setting.startsWith("chisel.project.root=") =>
setting.stripPrefix("chisel.project.root=")
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing this as a regular expression with a match might be cleaner than the startsWith/stripPrefix. Non blocking.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@jackkoenig
jackkoenig enabled auto-merge (squash) October 30, 2026 21:19
@jackkoenig
jackkoenig merged commit f9c4af9 into main Oct 30, 2026
28 checks passed
@jackkoenig
jackkoenig deleted the jackkoenig/chisel-project-root branch October 30, 2026 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature New feature, will be included in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants