Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ julia-deps: | $(DIRS) $(build_datarootdir)/julia/base $(build_datarootdir)/julia
julia-stdlib: | $(DIRS) julia-deps
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/stdlib

julia-base: julia-deps $(build_sysconfdir)/julia/startup.jl $(build_man1dir)/julia.1 $(build_datarootdir)/julia/julia-config.jl $(build_datarootdir)/julia/juliac.jl $(build_datarootdir)/julia/juliac-buildscript.jl $(build_datarootdir)/julia/juliac-trim-base.jl $(build_datarootdir)/julia/juliac-trim-stdlib.jl
julia-base: julia-deps $(build_sysconfdir)/julia/startup.jl $(build_man1dir)/julia.1 $(build_datarootdir)/julia/julia-config.jl $(build_datarootdir)/julia/juliac/juliac.jl $(build_datarootdir)/julia/juliac/juliac-buildscript.jl $(build_datarootdir)/julia/juliac/juliac-trim-base.jl $(build_datarootdir)/julia/juliac/juliac-trim-stdlib.jl
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/base

julia-libccalltest: julia-deps
Expand Down Expand Up @@ -184,6 +184,7 @@ $(build_sysconfdir)/julia/startup.jl: $(JULIAHOME)/etc/startup.jl | $(build_sysc
@cp $< $@

$(build_datarootdir)/julia/%: $(JULIAHOME)/contrib/% | $(build_datarootdir)/julia
mkdir -p $(dir $@)
$(INSTALL_M) $< $(dir $@)

$(build_depsbindir)/stringreplace: $(JULIAHOME)/contrib/stringreplace.c | $(build_depsbindir)
Expand Down
19 changes: 19 additions & 0 deletions contrib/juliac/Artifacts.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[[mingw-w64]]
arch = "x86_64"
git-tree-sha1 = "b17bda08a19173572926f43a48aad5ef3d845e7c"
os = "windows"
lazy = true

[[mingw-w64.download]]
sha256 = "53645e06775a55733580426341395c67dda20a664af83bcda76a1d052b618b59"
url = "https://github.com/JuliaLang/PackageCompiler.jl/releases/download/v2.1.24/x86_64-14.2.0-release-posix-seh-msvcrt-rt_v12-rev0.tar.gz"

[[mingw-w64]]
arch = "i686"
git-tree-sha1 = "76b9f278e7de1d7dfdfe3a786afbe9c1e29003ea"
os = "windows"
lazy = true

[[mingw-w64.download]]
sha256 = "d049bd771e01b02f2ca9274435f0e6f9f4f295bf2af72a8059dd851c52144910"
url = "https://github.com/JuliaLang/PackageCompiler.jl/releases/download/v2.1.24/i686-14.2.0-release-posix-dwarf-msvcrt-rt_v12-rev0.tar.gz"
File renamed without changes.
File renamed without changes.
File renamed without changes.
64 changes: 58 additions & 6 deletions contrib/juliac.jl → contrib/juliac/juliac.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
# Julia compiler wrapper script
# NOTE: The interface and location of this script are considered unstable/experimental

using LazyArtifacts

module JuliaConfig
include(joinpath(@__DIR__, "julia-config.jl"))
include(joinpath(@__DIR__, "..", "julia-config.jl"))
end

julia_cmd = `$(Base.julia_cmd()) --startup-file=no --history-file=no`
Expand All @@ -30,6 +32,57 @@ if help !== nothing
exit(0)
end

# Copied from PackageCompiler
# https://github.com/JuliaLang/PackageCompiler.jl/blob/1c35331d8ef81494f054bbc71214811253101993/src/PackageCompiler.jl#L147-L190
function get_compiler_cmd(; cplusplus::Bool=false)
cc = get(ENV, "JULIA_CC", nothing)
path = nothing
@static if Sys.iswindows()
path = joinpath(LazyArtifacts.artifact"mingw-w64",
"extracted_files",
(Int==Int64 ? "mingw64" : "mingw32"),
"bin",
cplusplus ? "g++.exe" : "gcc.exe")
compiler_cmd = `$path`
end
if cc !== nothing
compiler_cmd = Cmd(Base.shell_split(cc))
path = nothing
elseif !Sys.iswindows()
compilers_cpp = ("g++", "clang++")
compilers_c = ("gcc", "clang")
found_compiler = false
if cplusplus
for compiler in compilers_cpp
if Sys.which(compiler) !== nothing
compiler_cmd = `$compiler`
found_compiler = true
break
end
end
end
if !found_compiler
for compiler in compilers_c
if Sys.which(compiler) !== nothing
compiler_cmd = `$compiler`
found_compiler = true
if cplusplus && !WARNED_CPP_COMPILER[]
@warn "could not find a c++ compiler (g++ or clang++), falling back to $compiler, this might cause link errors"
WARNED_CPP_COMPILER[] = true
end
break
end
end
end
found_compiler || error("could not find a compiler, looked for ",
join(((cplusplus ? compilers_cpp : ())..., compilers_c...), ", ", " and "))
end
if path !== nothing
compiler_cmd = addenv(compiler_cmd, "PATH" => string(ENV["PATH"], ";", dirname(path)))
end
return compiler_cmd
end

# arguments to forward to julia compilation process
julia_args = []
enable_trim::Bool = false
Expand Down Expand Up @@ -82,6 +135,7 @@ function get_rpath(; relative::Bool = false)
end
end

cc = get_compiler_cmd()
absfile = abspath(file)
cflags = JuliaConfig.cflags(; framework=false)
cflags = Base.shell_split(cflags)
Expand All @@ -93,7 +147,6 @@ tmpdir = mktempdir(cleanup=false)
img_path = joinpath(tmpdir, "img.a")
bc_path = joinpath(tmpdir, "img-bc.a")


function precompile_env()
# Pre-compile the environment
# (otherwise obscure error messages will occur)
Expand Down Expand Up @@ -121,7 +174,6 @@ function compile_products(enable_trim::Bool)
println(stderr, "\nFailed to compile $file")
exit(1)
end

end

function link_products()
Expand All @@ -137,11 +189,11 @@ function link_products()
julia_libs = Base.shell_split(Base.isdebugbuild() ? "-ljulia-debug -ljulia-internal-debug" : "-ljulia -ljulia-internal")
try
if output_type == "--output-lib"
cmd2 = `cc $(allflags) $(rpath) -o $outname -shared -Wl,$(Base.Linking.WHOLE_ARCHIVE) $img_path -Wl,$(Base.Linking.NO_WHOLE_ARCHIVE) $(julia_libs)`
cmd2 = `$(cc) $(allflags) $(rpath) -o $outname -shared -Wl,$(Base.Linking.WHOLE_ARCHIVE) $img_path -Wl,$(Base.Linking.NO_WHOLE_ARCHIVE) $(julia_libs)`
elseif output_type == "--output-sysimage"
cmd2 = `cc $(allflags) $(rpath) -o $outname -shared -Wl,$(Base.Linking.WHOLE_ARCHIVE) $img_path -Wl,$(Base.Linking.NO_WHOLE_ARCHIVE) $(julia_libs)`
cmd2 = `$(cc) $(allflags) $(rpath) -o $outname -shared -Wl,$(Base.Linking.WHOLE_ARCHIVE) $img_path -Wl,$(Base.Linking.NO_WHOLE_ARCHIVE) $(julia_libs)`
else
cmd2 = `cc $(allflags) $(rpath) -o $outname -Wl,$(Base.Linking.WHOLE_ARCHIVE) $img_path -Wl,$(Base.Linking.NO_WHOLE_ARCHIVE) $(julia_libs)`
cmd2 = `$(cc) $(allflags) $(rpath) -o $outname -Wl,$(Base.Linking.WHOLE_ARCHIVE) $img_path -Wl,$(Base.Linking.NO_WHOLE_ARCHIVE) $(julia_libs)`
end
verbose && println("Running: $cmd2")
run(cmd2)
Expand Down
2 changes: 1 addition & 1 deletion doc/src/devdocs/sysimg.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ debug info, respectively, and so will make debugging more difficult.
We have identified many small changes to Base that significantly increase the set of programs
that can be reliably trimmed. Unfortunately some of those changes would be considered breaking,
and so are only applied when trimming is requested (this is done by an external build script,
currently maintained inside the test suite as `contrib/juliac-buildscript.jl`).
currently maintained inside the test suite as `contrib/juliac/juliac-buildscript.jl`).
Therefore in many cases trimming will require you to opt in to new variants of Base and some
standard libraries.

Expand Down
2 changes: 1 addition & 1 deletion test/trimming/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ CFLAGS_ADD = $(shell $(JULIA_CONFIG) --cflags)
LDFLAGS_ADD = -lm $(shell $(JULIA_CONFIG) --ldflags --ldlibs) -ljulia-internal

# get the JuliaC build script
JULIAC_BUILDSCRIPT := $(shell $(JULIA) -e 'print(joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia", "juliac-buildscript.jl"))')
JULIAC_BUILDSCRIPT := $(shell $(JULIA) -e 'print(joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia", "juliac", "juliac-buildscript.jl"))')

#=============================================================================

Expand Down