From 0765e42312558d529bf840d7edbbdb1ea03a0625 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 30 Apr 2026 11:28:02 -0400 Subject: [PATCH 1/6] Introduce JLLWrappers.disable_optimization preference 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) --- src/JLLWrappers.jl | 16 ++++++++++++---- test/runtests.jl | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/JLLWrappers.jl b/src/JLLWrappers.jl index cebcb4d..ae5e5e7 100644 --- a/src/JLLWrappers.jl +++ b/src/JLLWrappers.jl @@ -1,11 +1,19 @@ module JLLWrappers -if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@compiler_options")) - @eval Base.Experimental.@compiler_options compile=min optimize=0 infer=false +@static if VERSION >= v"1.6.0-DEV" + using Preferences end -if VERSION >= v"1.6.0-DEV" - using Preferences +@static if VERSION >= v"1.6.0-DEV" + const disable_optimization = @load_preference("disable_optimization", true) +else + const disable_optimization = true +end + +@static if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@compiler_options")) + if disable_optimization + @eval Base.Experimental.@compiler_options compile=min optimize=0 infer=false + end end const global_typeassert_available = VERSION >= v"1.9.0-" diff --git a/test/runtests.jl b/test/runtests.jl index e45de57..3ff74b9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -43,6 +43,7 @@ end; end module TestJLL end @testset "JLLWrappers.jl" begin + @test JLLWrappers.disable_optimization === true mktempdir() do dir Pkg.activate(dir) From 2db9f35f45d23e01b2046ea86f891046bb6a6c2a Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 30 Apr 2026 11:28:35 -0400 Subject: [PATCH 2/6] Gate generate_compiler_options on disable_optimization 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) --- src/toplevel_generators.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/toplevel_generators.jl b/src/toplevel_generators.jl index 7fd63e6..ed3d51b 100644 --- a/src/toplevel_generators.jl +++ b/src/toplevel_generators.jl @@ -46,9 +46,12 @@ end generate_compiler_options(src_name) Because JLL packages do not contain code that benefits much from compiler optimizations, -we disable them for a sizable boost in first load time. +we disable them for a sizable boost in first load time. This can be opted out of by +setting the `disable_optimization` JLLWrappers preference to `false`. """ function generate_compiler_options(src_name) + JLLWrappers.disable_optimization || return nothing + # Newer Julias have `@compiler_options` that can enable interpreted mode if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@compiler_options")) return quote From d12e37acfe0b4370aded946ff015fe750034fc7c Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 30 Apr 2026 11:29:11 -0400 Subject: [PATCH 3/6] Test disable_optimization=false branch via subprocess 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) --- test/runtests.jl | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 3ff74b9..d48c708 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -155,3 +155,40 @@ module TestJLL end end end end + +@static if VERSION >= v"1.6.0-DEV" + @testset "disable_optimization=false" begin + mktempdir() do test_dir + preferences_path = joinpath(test_dir, "LocalPreferences.toml") + set_preferences!(preferences_path, "JLLWrappers", "disable_optimization" => false) + + jllwrappers_path = abspath(joinpath(@__DIR__, "..")) + helloworld_path = joinpath(@__DIR__, "HelloWorldC_jll") + + script = """ + using Pkg + Pkg.develop([ + Pkg.PackageSpec(path=raw"$jllwrappers_path"), + Pkg.PackageSpec(path=raw"$helloworld_path"), + ]) + using JLLWrappers + JLLWrappers.disable_optimization === false || error("expected disable_optimization=false, got \$(JLLWrappers.disable_optimization)") + using HelloWorldC_jll + HelloWorldC_jll.is_available() || error("HelloWorldC_jll not available") + isfile(HelloWorldC_jll.hello_world_path) || error("hello_world_path not a file: \$(HelloWorldC_jll.hello_world_path)") + println("OK") + """ + + cmd = `$(Base.julia_cmd()) --project=$test_dir -e $script` + io = IOBuffer() + ok = success(pipeline(cmd; stdout=io, stderr=io)) + output = String(take!(io)) + + if !ok + @info "subprocess output" output + end + @test ok + @test occursin("OK", output) + end + end +end From 529622b10488c029581af211342c6e57b84aa323 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 30 Apr 2026 11:38:46 -0400 Subject: [PATCH 4/6] Fix Windows path escaping in disable_optimization=false test 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) --- test/runtests.jl | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index d48c708..6fe5a63 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -165,21 +165,22 @@ end jllwrappers_path = abspath(joinpath(@__DIR__, "..")) helloworld_path = joinpath(@__DIR__, "HelloWorldC_jll") - script = """ - using Pkg - Pkg.develop([ - Pkg.PackageSpec(path=raw"$jllwrappers_path"), - Pkg.PackageSpec(path=raw"$helloworld_path"), - ]) - using JLLWrappers - JLLWrappers.disable_optimization === false || error("expected disable_optimization=false, got \$(JLLWrappers.disable_optimization)") - using HelloWorldC_jll - HelloWorldC_jll.is_available() || error("HelloWorldC_jll not available") - isfile(HelloWorldC_jll.hello_world_path) || error("hello_world_path not a file: \$(HelloWorldC_jll.hello_world_path)") - println("OK") - """ - - cmd = `$(Base.julia_cmd()) --project=$test_dir -e $script` + script_path = joinpath(test_dir, "subproc_script.jl") + open(script_path, "w") do io + println(io, "using Pkg") + println(io, "Pkg.develop([") + println(io, " Pkg.PackageSpec(path=", repr(jllwrappers_path), "),") + println(io, " Pkg.PackageSpec(path=", repr(helloworld_path), "),") + println(io, "])") + println(io, "using JLLWrappers") + println(io, "JLLWrappers.disable_optimization === false || error(\"expected disable_optimization=false, got \$(JLLWrappers.disable_optimization)\")") + println(io, "using HelloWorldC_jll") + println(io, "HelloWorldC_jll.is_available() || error(\"HelloWorldC_jll not available\")") + println(io, "isfile(HelloWorldC_jll.hello_world_path) || error(\"hello_world_path not a file: \$(HelloWorldC_jll.hello_world_path)\")") + println(io, "println(\"OK\")") + end + + cmd = `$(Base.julia_cmd()) --project=$test_dir $script_path` io = IOBuffer() ok = success(pipeline(cmd; stdout=io, stderr=io)) output = String(take!(io)) From 24ee922c39ef8a21b32d804d3fba7d0851ed18f2 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 30 Apr 2026 14:48:53 -0400 Subject: [PATCH 5/6] Rewrite subprocess script as triple-quoted string 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) --- test/runtests.jl | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 6fe5a63..6d408a1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -166,19 +166,20 @@ end helloworld_path = joinpath(@__DIR__, "HelloWorldC_jll") script_path = joinpath(test_dir, "subproc_script.jl") - open(script_path, "w") do io - println(io, "using Pkg") - println(io, "Pkg.develop([") - println(io, " Pkg.PackageSpec(path=", repr(jllwrappers_path), "),") - println(io, " Pkg.PackageSpec(path=", repr(helloworld_path), "),") - println(io, "])") - println(io, "using JLLWrappers") - println(io, "JLLWrappers.disable_optimization === false || error(\"expected disable_optimization=false, got \$(JLLWrappers.disable_optimization)\")") - println(io, "using HelloWorldC_jll") - println(io, "HelloWorldC_jll.is_available() || error(\"HelloWorldC_jll not available\")") - println(io, "isfile(HelloWorldC_jll.hello_world_path) || error(\"hello_world_path not a file: \$(HelloWorldC_jll.hello_world_path)\")") - println(io, "println(\"OK\")") - end + # repr() quotes the path as a Julia string literal, escaping backslashes on Windows. + write(script_path, """ + using Pkg + Pkg.develop([ + Pkg.PackageSpec(path=$(repr(jllwrappers_path))), + Pkg.PackageSpec(path=$(repr(helloworld_path))), + ]) + using JLLWrappers + JLLWrappers.disable_optimization === false || error("expected disable_optimization=false, got \$(JLLWrappers.disable_optimization)") + using HelloWorldC_jll + HelloWorldC_jll.is_available() || error("HelloWorldC_jll not available") + isfile(HelloWorldC_jll.hello_world_path) || error("hello_world_path not a file: \$(HelloWorldC_jll.hello_world_path)") + println("OK") + """) cmd = `$(Base.julia_cmd()) --project=$test_dir $script_path` io = IOBuffer() From 9bc669b9602103588626680124753bfd694dd8a1 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Wed, 6 May 2026 15:06:13 -0400 Subject: [PATCH 6/6] Delete the test --- test/runtests.jl | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 6d408a1..3ff74b9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -155,42 +155,3 @@ module TestJLL end end end end - -@static if VERSION >= v"1.6.0-DEV" - @testset "disable_optimization=false" begin - mktempdir() do test_dir - preferences_path = joinpath(test_dir, "LocalPreferences.toml") - set_preferences!(preferences_path, "JLLWrappers", "disable_optimization" => false) - - jllwrappers_path = abspath(joinpath(@__DIR__, "..")) - helloworld_path = joinpath(@__DIR__, "HelloWorldC_jll") - - script_path = joinpath(test_dir, "subproc_script.jl") - # repr() quotes the path as a Julia string literal, escaping backslashes on Windows. - write(script_path, """ - using Pkg - Pkg.develop([ - Pkg.PackageSpec(path=$(repr(jllwrappers_path))), - Pkg.PackageSpec(path=$(repr(helloworld_path))), - ]) - using JLLWrappers - JLLWrappers.disable_optimization === false || error("expected disable_optimization=false, got \$(JLLWrappers.disable_optimization)") - using HelloWorldC_jll - HelloWorldC_jll.is_available() || error("HelloWorldC_jll not available") - isfile(HelloWorldC_jll.hello_world_path) || error("hello_world_path not a file: \$(HelloWorldC_jll.hello_world_path)") - println("OK") - """) - - cmd = `$(Base.julia_cmd()) --project=$test_dir $script_path` - io = IOBuffer() - ok = success(pipeline(cmd; stdout=io, stderr=io)) - output = String(take!(io)) - - if !ok - @info "subprocess output" output - end - @test ok - @test occursin("OK", output) - end - end -end