Skip to content

Enable scala_macro_library targets to have dependencies #1681

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

Conversation

jadenPete
Copy link
Contributor

Description

This PR should fix #445. Before, macro targets couldn't depend on ijard targets because targets depending on those macros would get the compile (ijard) versions of those ijard targets, which can't be executed at compile time due to necessary information being stripped out. Instead, we need to include macro targets' transitive runtime JARs on the compile classpath.

This PR makes Scala targets export a ScalaInfo provider containing a contains_macros attribute. If one of a target's dependencies exports a ScalaInfo provider with contains_macros set to True (i.e. the dependency is a macro), that dependencies' transitive runtime JARs are hoisted to the top of the compile classpath. This is necessary because if they were included anywhere else in the classpath, we'd risk the compile-time versions of those transitive runtime JARs being used instead.

The approach is explained in more detail in collect_jars in scala/private/common.bzl. Another benefit of this approach is that we can ijar macro targets and their transitive dependencies and therefore benefit from reduced incremental build times.

Motivation

Closing #445.

@simuons
Copy link
Collaborator

simuons commented Jan 22, 2025

Hi, @jadenPete, thanks for PR. Are failing tests related to your changes?

@jadenPete
Copy link
Contributor Author

No problem! Yes, my changes caused those failures. I just pushed a fix.

Copy link
Collaborator

@simuons simuons left a comment

Choose a reason for hiding this comment

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

Thanks, @jadenPete!

@jadenPete
Copy link
Contributor Author

No problem! Let me rebase this branch, after which it can be merged.

@jadenPete jadenPete force-pushed the fix-scala-macro-library-dependencies branch from a8991a6 to 0dd3073 Compare February 4, 2025 21:34
@jadenPete
Copy link
Contributor Author

Squashed.

@jadenPete jadenPete force-pushed the fix-scala-macro-library-dependencies branch from 0dd3073 to 905cf96 Compare February 4, 2025 21:36
@jadenPete
Copy link
Contributor Author

Done!

@liucijus liucijus merged commit 3ca60fb into bazel-contrib:master Feb 5, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

macros that reference Java libraries don't work
3 participants