Skip to content

Commit d369c10

Browse files
trimming: Restore JLL support (#57587)
Add an extra indirection to our printing code for `@assert` so that that inferrability is restored after the override. Also partially revert d77c24f which, deleted init code important for JLL's ~This still requires that we bypass this inference-disabling code in JLLWrappers.jl:~ ```julia if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@compiler_options")) @eval Base.Experimental.@compiler_options compile=min optimize=0 infer=false end ```
2 parents 1ecbdd1 + 38eee42 commit d369c10

File tree

7 files changed

+42
-12
lines changed

7 files changed

+42
-12
lines changed

base/error.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,14 @@ macro assert(ex, msgs...)
240240
msg = Main.Base.string(msg)
241241
else
242242
# string() might not be defined during bootstrap
243-
msg = :(Main.Base.inferencebarrier(_assert_tostring)($(Expr(:quote,msg))))
243+
msg = :(_assert_tostring($(Expr(:quote,msg))))
244244
end
245245
return :($(esc(ex)) ? $(nothing) : throw(AssertionError($msg)))
246246
end
247247

248248
# this may be overridden in contexts where `string(::Expr)` doesn't work
249-
_assert_tostring(msg) = isdefined(Main, :Base) ? Main.Base.string(msg) :
249+
_assert_tostring(@nospecialize(msg)) = Core.compilerbarrier(:type, __assert_tostring)(msg)
250+
__assert_tostring(msg) = isdefined(Main, :Base) ? Main.Base.string(msg) :
250251
(Core.println(msg); "Error during bootstrap. See stdout.")
251252

252253
struct ExponentialBackOff

base/experimental.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ macro max_methods(n::Int, fdef::Expr)
163163
end
164164

165165
"""
166-
Experimental.@compiler_options optimize={0,1,2,3} compile={yes,no,all,min} infer={yes,no} max_methods={default,1,2,3,4}
166+
Experimental.@compiler_options optimize={0,1,2,3} compile={yes,no,all,min} infer={true,false} max_methods={default,1,2,3,4}
167167
168168
Set compiler options for code in the enclosing module. Options correspond directly to
169169
command-line options with the same name, where applicable. The following options

contrib/juliac-buildscript.jl

-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ end
3333
JuliaSyntax.enable_in_core!() = nothing
3434
init_active_project() = ACTIVE_PROJECT[] = nothing
3535
set_active_project(projfile::Union{AbstractString,Nothing}) = ACTIVE_PROJECT[] = projfile
36-
init_depot_path() = nothing
37-
init_load_path() = nothing
38-
init_active_project() = nothing
3936
disable_library_threading() = nothing
4037
start_profile_listener() = nothing
4138
invokelatest_trimmed(f, args...; kwargs...) = f(args...; kwargs...)

test/trimming/Makefile

+10-3
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,29 @@ LDFLAGS_ADD = -lm $(shell $(JULIA_CONFIG) --ldflags --ldlibs) -ljulia-internal
3030

3131
#=============================================================================
3232

33-
release: hello$(EXE)
33+
release: hello$(EXE) basic_jll$(EXE)
3434

3535
hello.o: $(SRCDIR)/hello.jl $(BUILDSCRIPT)
3636
$(JULIA) -t 1 -J $(BIN)/../lib/julia/sys.so --startup-file=no --history-file=no --output-o $@ --output-incremental=no --strip-ir --strip-metadata --experimental --trim $(BUILDSCRIPT) $(SRCDIR)/hello.jl --output-exe true
3737

3838
init.o: $(SRCDIR)/init.c
3939
$(CC) -c -o $@ $< $(CPPFLAGS_ADD) $(CPPFLAGS) $(CFLAGS_ADD) $(CFLAGS)
4040

41+
basic_jll.o: $(SRCDIR)/basic_jll.jl $(BUILDSCRIPT)
42+
$(JULIA) -t 1 -J $(BIN)/../lib/julia/sys.so --startup-file=no --history-file=no --project=$(SRCDIR) -e "using Pkg; Pkg.instantiate()"
43+
$(JULIA) -t 1 -J $(BIN)/../lib/julia/sys.so --startup-file=no --history-file=no --project=$(SRCDIR) --output-o $@ --output-incremental=no --strip-ir --strip-metadata --experimental --trim $(BUILDSCRIPT) $(SRCDIR)/basic_jll.jl --output-exe true
44+
4145
hello$(EXE): hello.o init.o
4246
$(CC) -o $@ $(WHOLE_ARCHIVE) hello.o $(NO_WHOLE_ARCHIVE) init.o $(CPPFLAGS_ADD) $(CPPFLAGS) $(CFLAGS_ADD) $(CFLAGS) $(LDFLAGS_ADD) $(LDFLAGS)
4347

44-
check: hello$(EXE)
48+
basic_jll$(EXE): basic_jll.o init.o
49+
$(CC) -o $@ $(WHOLE_ARCHIVE) basic_jll.o $(NO_WHOLE_ARCHIVE) init.o $(CPPFLAGS_ADD) $(CPPFLAGS) $(CFLAGS_ADD) $(CFLAGS) $(LDFLAGS_ADD) $(LDFLAGS)
50+
51+
check: hello$(EXE) basic_jll$(EXE)
4552
$(JULIA) --depwarn=error $(SRCDIR)/../runtests.jl $(SRCDIR)/trimming
4653

4754
clean:
48-
-rm -f hello$(EXE) init.o hello.o
55+
-rm -f hello$(EXE) basic_jll$(EXE) init.o hello.o basic_jll.o
4956

5057
.PHONY: release clean check
5158

test/trimming/Project.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[deps]
2+
JLLWrappers = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
3+
Zstd_jll = "3161d3a3-bdf6-5164-811a-617609db77b4"

test/trimming/basic_jll.jl

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module MyApp
2+
3+
using Libdl
4+
using Zstd_jll
5+
6+
Base.@ccallable function main()::Cint
7+
println(Core.stdout, "Julia! Hello, world!")
8+
fptr = dlsym(Zstd_jll.libzstd_handle, :ZSTD_versionString)
9+
println(Core.stdout, unsafe_string(ccall(fptr, Cstring, ())))
10+
println(Core.stdout, unsafe_string(ccall((:ZSTD_versionString, libzstd), Cstring, ())))
11+
return 0
12+
end
13+
14+
end

test/trimming/trimming.jl

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
using Test
22

3-
exe_path = joinpath(@__DIR__, "hello"*splitext(Base.julia_exename())[2])
3+
let exe_suffix = splitext(Base.julia_exename())[2]
44

5-
@test readchomp(`$exe_path`) == "Hello, world!"
5+
hello_exe = joinpath(@__DIR__, "hello" * exe_suffix)
6+
@test readchomp(`$hello_exe`) == "Hello, world!"
7+
@test filesize(hello_exe) < filesize(unsafe_string(Base.JLOptions().image_file))/10
68

7-
@test filesize(exe_path) < filesize(unsafe_string(Base.JLOptions().image_file))/10
9+
basic_jll_exe = joinpath(@__DIR__, "basic_jll" * exe_suffix)
10+
lines = split(readchomp(`$basic_jll_exe`), "\n")
11+
@test lines[1] == "Julia! Hello, world!"
12+
@test lines[2] == lines[3]
13+
@test Base.VersionNumber(lines[2]) v"1.5.7"
14+
@test filesize(basic_jll_exe) < filesize(unsafe_string(Base.JLOptions().image_file))/10
15+
end

0 commit comments

Comments
 (0)