You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit adds the `CompilePreferences` standard library; a way to store a
TOML-serializable dictionary into top-level `Project.toml` files, then
force recompilation of child projects when the preferences are modified.
This commid adds the `CompilePreferences` standard library, which does
the actual writing to `Project.toml` files, as well as modifies the
loading code to check whether the preferences have changed.
@debug"Rejecting cache file $cachefile because preferences hash does not match 0x$(string(prefs_hash, base=16)) != 0x$(string(curr_prefs_hash, base=16))"
Julia's `CompilePreferences` API requires at least Julia 1.6.
5
+
6
+
`CompilePreferences` support embedding a simple `Dict` of metadata for a package on a per-project basis. These preferences allow for packages to set simple, persistent pieces of data, and trigger recompilation of the package when the preferences change, to allow for customization of package behavior at compile-time.
7
+
8
+
## API Overview
9
+
10
+
`CompilePreferences` are used primarily through the `@load_preferences`, `@save_preferences` and `@modify_preferences` macros. These macros will auto-detect the UUID of the calling package, throwing an error if the calling module does not belong to a package. The function forms can be used to load, save or modify preferences belonging to another package.
11
+
12
+
Example usage:
13
+
14
+
```julia
15
+
using CompilePreferences
16
+
17
+
functionget_preferred_backend()
18
+
prefs =@load_preferences()
19
+
returnget(prefs, "backend", "native")
20
+
end
21
+
22
+
functionset_backend(new_backend)
23
+
@modify_preferences!() do prefs
24
+
prefs["backend"] = new_backend
25
+
end
26
+
end
27
+
```
28
+
29
+
Preferences are stored within the first `Project.toml` that represents an environment that contains the given UUID, even as a transitive dependency.
30
+
If no project that contains the given UUID is found, the preference is recorded in the `Project.toml` file of the currently-active project.
31
+
The initial state for preferences is an empty dictionary, package authors that wish to have a default value set for their preferences should use the `get(prefs, key, default)` pattern as shown in the code example above.
32
+
33
+
# API Reference
34
+
35
+
!!! compat "Julia 1.6"
36
+
Julia's `CompilePreferences` API requires at least Julia 1.6.
0 commit comments