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

Add Makefile caching helpers for lazy, expensive evaluations #35626

Merged
merged 1 commit into from
May 4, 2020

Conversation

staticfloat
Copy link
Member

@staticfloat staticfloat commented Apr 28, 2020

Makefiles natively offer two variable expansion modes: immediate and
deferred. When expanding variables that require invocations of external
programs (such as llvm-config) immediate expansion is almost always
preferred, as it will run the external command once, exactly when the
makefile variable is defined. Deferred mode, on the other hand, will
expand the variable every time it is used, running the external program
again and again.

When the external program is expensive, this cost can slow down the
build significantly, however when the external program requires some
setup (for instance, when it itself is downloaded through other rules in
the Makefile) it cannot always be immediately expanded. To address
this, we build a caching layer that allows for deferred expansion, but
once it has been expanded once, the variable is replaced with the result
of running the command, and further hits to the same variable will
return the cached value. (With the slight caveat that an empty result
will cause the external command to be run again in the future).

As an example usecase, this commit converts our relative path
calculation to use a python script and showcases how to cache this
operation. This will be used for further JLL stdlib work where the
invocation is much more expensive.

@staticfloat staticfloat added the building Build system, or building Julia or its dependencies label Apr 28, 2020
@staticfloat staticfloat force-pushed the sf/makefile_caching branch from aac2259 to 5d32089 Compare April 28, 2020 19:09
Makefiles natively offer two variable expansion modes: immediate and
deferred.  When expanding variables that require invocations of external
programs (such as `llvm-config`) immediate expansion is almost always
preferred, as it will run the external command once, exactly when the
makefile variable is defined.  Deferred mode, on the other hand, will
expand the variable every time it is used, running the external program
again and again.

When the external program is expensive, this cost can slow down the
build significantly, however when the external program requires some
setup (for instance, when it itself is downloaded through other rules in
the Makefile) it cannot always be immediately expanded.  To address
this, we build a caching layer that allows for deferred expansion, but
once it has been expanded once, the variable is replaced with the result
of running the command, and further hits to the same variable will
return the cached value.  (With the slight caveat that an empty result
will cause the external command to be run again in the future).

As an example usecase, this commit converts our relative path
calculation to use a python script and showcases how to cache this
operation.  This will be used for further JLL stdlib work where the
invocation is much more expensive.
@staticfloat staticfloat force-pushed the sf/makefile_caching branch from e8a56a8 to ad907d5 Compare May 4, 2020 18:00
@staticfloat staticfloat merged commit 39d7a18 into master May 4, 2020
@staticfloat staticfloat deleted the sf/makefile_caching branch May 4, 2020 18:19
libdir_rel := $(shell $(JULIAHOME)/contrib/relative_path.sh $(bindir) $(libdir))
build_private_libdir_rel := $(shell $(JULIAHOME)/contrib/relative_path.sh $(build_bindir) $(build_private_libdir))
private_libdir_rel := $(shell $(JULIAHOME)/contrib/relative_path.sh $(bindir) $(private_libdir))
datarootdir_rel := $(shell $(JULIAHOME)/contrib/relative_path.sh $(bindir) $(datarootdir))
Copy link
Member

Choose a reason for hiding this comment

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

This is lame imo. You can't grep for where this variable is defined anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
building Build system, or building Julia or its dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants