Skip to content

Commit

Permalink
bundle Julia executable to get Distributed somewhat working
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Oct 3, 2021
1 parent 4965668 commit c0ee82c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/MyApp/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "0.1.0"

[deps]
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Example = "7876af07-990d-54b4-ab0e-23690620f79a"
HelloWorldC_jll = "dca1746e-5efc-54fc-8249-22745bc95a49"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
16 changes: 16 additions & 0 deletions examples/MyApp/src/MyApp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module MyApp
using Example
using HelloWorldC_jll
using Pkg.Artifacts
using Distributed


fooifier_path() = joinpath(artifact"fooifier", "bin", "fooifier" * (Sys.iswindows() ? ".exe" : ""))

Expand Down Expand Up @@ -52,6 +54,20 @@ function real_main()
@show unsafe_string(Base.JLOptions().image_file)
@show Example.domath(5)
@show sin(0.0)

if nworkers() != 4
addprocs(4)
@eval @everywhere using MyApp
end

n = @distributed (+) for i = 1:20000000
1
end
println("n = $n")
# TODO: Code loading for distributed is currently only
# really possible by shipping a Project.toml.
# @eval @everywhere using Example
# @everywhere println(Example.domath(3))
return
end

Expand Down
15 changes: 11 additions & 4 deletions src/PackageCompiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,10 @@ function run_precompilation_script(project::String, sysimg::String, precompile_f
else
arg = `$precompile_file`
end
cmd = `$(get_julia_cmd()) --sysimage=$(sysimg) --project=$project
cmd = `$(get_julia_cmd()) --sysimage=$(sysimg)
--compile=all --trace-compile=$tracefile $arg`
# --project is not propagated well with Distributed, so use environment
cmd = addenv(cmd, "JULIA_LOAD_PATH" => project)
precompile_file === nothing || @info "PackageCompiler: Executing $(precompile_file) => $(tracefile)"
run(cmd) # `Run` this command so that we'll display stdout from the user's script.
precompile_file === nothing || @info "PackageCompiler: Done"
Expand Down Expand Up @@ -274,7 +276,6 @@ function create_sysimg_object_file(object_file::String,
push!(precompile_files, tracefile)
end
append!(precompile_files, precompile_statements_file)

precompile_code = """
# This @eval prevents symbols from being put into Main
@eval Module() begin
Expand Down Expand Up @@ -1020,7 +1021,7 @@ function _create_app(package_dir::String,

mkpath(dest_dir)

bundle_julia_libraries(dest_dir, library_only)
bundle_julia_libraries(dest_dir)
bundle_artifacts(ctx, dest_dir, library_only; include_lazy_artifacts=include_lazy_artifacts)

library_only && bundle_headers(dest_dir, header_files)
Expand Down Expand Up @@ -1088,6 +1089,7 @@ function _create_app(package_dir::String,
create_executable_from_sysimg(; sysimage_path, executable_path=name,
c_driver_program_path)
end
bundle_julia_executable(executable_path)
end

return
Expand All @@ -1105,7 +1107,12 @@ function create_executable_from_sysimg(;sysimage_path::String,
return nothing
end

function bundle_julia_libraries(dest_dir, library_only)
function bundle_julia_executable(dir::String)
name = Sys.iswindows() ? "julia.exe" : "julia"
cp(joinpath(Sys.BINDIR::String, name), joinpath(dir, name))
end

function bundle_julia_libraries(dest_dir)
app_libdir = joinpath(dest_dir, Sys.isunix() ? "lib" : "bin")
cp(julia_libdir(), app_libdir; force=true)
# We do not want to bundle the sysimg (nor the backup sysimage):
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ end
@test occursin("(Base.JLOptions()).check_bounds = 1", app_output)
# Check transitive inclusion of dependencies
@test occursin("is_crayons_loaded() = true", app_output)
# Check distributed
@test occursin("n = 20000000", app_output)
end
end

Expand Down

0 comments on commit c0ee82c

Please sign in to comment.