Skip to content

Add disable_optimization JLLWrappers preference#89

Merged
topolarity merged 6 commits into
JuliaPackaging:masterfrom
asinghvi17:as/optimization-level-preference
May 8, 2026
Merged

Add disable_optimization JLLWrappers preference#89
topolarity merged 6 commits into
JuliaPackaging:masterfrom
asinghvi17:as/optimization-level-preference

Conversation

@asinghvi17

@asinghvi17 asinghvi17 commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

When using a system image generated by package compiler (that of course contains some JLLs) to perform JuliaC-based compilation with --trim, it turned out that the changing of the compile mode in JLL wrappers was causing issues. This introduces a preference to fix that.

Summary

  • Introduces a JLLWrappers-level disable_optimization Preference (default true) that gates every optimization-disabling compiler directive JLLWrappers emits — both in JLLWrappers.jl itself and in each generated *_jll via generate_compiler_options.
  • When the preference is set to false, no @compiler_options compile=min optimize=0 infer=false (or older @optlevel 0) directive is emitted, so JLLs and JLLWrappers compile at the user's normal optimization level.
  • Default behavior is unchanged. On Julia < 1.6 (no Preferences support) the const is unconditionally true.

Motivation

There was no way to opt JLL packages into normal compiler optimization. Users with hot JLL-resident code or those benchmarking JLL-loaded libraries want to be able to do so. This PR adds a single boolean preference scoped to JLLWrappers that controls all of JLLWrappers' optimization-disabling emissions in one place.

Set it via Preferences.set_preferences!:

using Preferences, JLLWrappers
set_preferences!(JLLWrappers, "disable_optimization" => false)

Preferences.jl invalidates the JLLWrappers precompile cache on change, which cascades to all *_jll packages.

Test plan

  • Existing test suite still passes (default disable_optimization=true path).
  • New tripwire @test JLLWrappers.disable_optimization === true asserts the const default.
  • New @testset "disable_optimization=false" exercises the false branch in a subprocess (since the const is fixed at module load time, can't be flipped within the same Julia session): writes LocalPreferences.toml with disable_optimization = false, develops JLLWrappers and HelloWorldC_jll in a fresh project, verifies the const reflects the override and that the JLL still loads and resolves binaries.

🤖 Generated with Claude Code

asinghvi17 and others added 4 commits April 30, 2026 11:28
Adds a module-level const read from Preferences (default true) and
gates JLLWrappers' own @compiler_options on it. Default behavior
unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
When the JLLWrappers preference disable_optimization is false,
generate_compiler_options returns nothing, suppressing the per-JLL
@compiler_options / @optlevel emission. excat already filters nothing
out, so no caller-side changes are needed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
JLLWrappers.disable_optimization is fixed at module load time, so
exercising the false branch requires a fresh Julia subprocess with the
preference set in LocalPreferences.toml before JLLWrappers is loaded.
The subprocess loads JLLWrappers and HelloWorldC_jll and verifies they
work correctly with optimization gating turned off.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The previous version interpolated Windows paths (with backslashes) into
a script string passed via -e, where Windows command-line quoting
mangled the backslashes ('syntax: "\\" is not a unary operator' on
Julia 1.7 Windows). Write the script to a file instead and use
repr(path) for portable Julia string literals; this sidesteps all
shell quoting on every platform.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread test/runtests.jl Outdated
Per review feedback, replace the chain of println() calls with a single
"""...""" string. repr() still quotes the interpolated paths so Windows
backslashes stay escaped.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@asinghvi17

Copy link
Copy Markdown
Contributor Author

FreeBSD CI failures are the same as on main.

@asinghvi17 asinghvi17 requested a review from vchuravy April 30, 2026 18:57
Comment thread test/runtests.jl Outdated
@topolarity topolarity merged commit 051d8cd into JuliaPackaging:master May 8, 2026
65 of 72 checks passed
@asinghvi17 asinghvi17 deleted the as/optimization-level-preference branch May 8, 2026 18:12
@asinghvi17 asinghvi17 restored the as/optimization-level-preference branch May 8, 2026 18:12
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.

3 participants