Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/JLLWrappers.jl
Original file line number Diff line number Diff line change
@@ -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-"
Expand Down
5 changes: 4 additions & 1 deletion src/toplevel_generators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ end; end

module TestJLL end
@testset "JLLWrappers.jl" begin
@test JLLWrappers.disable_optimization === true
mktempdir() do dir
Pkg.activate(dir)

Expand Down Expand Up @@ -154,3 +155,41 @@ 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")
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
Comment thread
asinghvi17 marked this conversation as resolved.
Outdated

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
Loading