Skip to content

Commit 34bb3e7

Browse files
authored
juliac: Add rudimentary Windows support (#57481)
This was essentially working as-is, except for our reliance on a C compiler. Not sure how we feel about having an `Artifacts.toml` floating around our `contrib` folder, but I'm not aware of an alternative other than moving `juliac.jl` to a subdirectory.
1 parent d7c70bc commit 34bb3e7

File tree

8 files changed

+81
-9
lines changed

8 files changed

+81
-9
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ julia-deps: | $(DIRS) $(build_datarootdir)/julia/base $(build_datarootdir)/julia
8989
julia-stdlib: | $(DIRS) julia-deps
9090
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/stdlib
9191

92-
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
92+
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
9393
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/base
9494

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

186186
$(build_datarootdir)/julia/%: $(JULIAHOME)/contrib/% | $(build_datarootdir)/julia
187+
mkdir -p $(dir $@)
187188
$(INSTALL_M) $< $(dir $@)
188189

189190
$(build_depsbindir)/stringreplace: $(JULIAHOME)/contrib/stringreplace.c | $(build_depsbindir)

contrib/juliac/Artifacts.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[[mingw-w64]]
2+
arch = "x86_64"
3+
git-tree-sha1 = "b17bda08a19173572926f43a48aad5ef3d845e7c"
4+
os = "windows"
5+
lazy = true
6+
7+
[[mingw-w64.download]]
8+
sha256 = "53645e06775a55733580426341395c67dda20a664af83bcda76a1d052b618b59"
9+
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"
10+
11+
[[mingw-w64]]
12+
arch = "i686"
13+
git-tree-sha1 = "76b9f278e7de1d7dfdfe3a786afbe9c1e29003ea"
14+
os = "windows"
15+
lazy = true
16+
17+
[[mingw-w64.download]]
18+
sha256 = "d049bd771e01b02f2ca9274435f0e6f9f4f295bf2af72a8059dd851c52144910"
19+
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.

contrib/juliac.jl renamed to contrib/juliac/juliac.jl

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
# Julia compiler wrapper script
44
# NOTE: The interface and location of this script are considered unstable/experimental
55

6+
using LazyArtifacts
7+
68
module JuliaConfig
7-
include(joinpath(@__DIR__, "julia-config.jl"))
9+
include(joinpath(@__DIR__, "..", "julia-config.jl"))
810
end
911

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

35+
# Copied from PackageCompiler
36+
# https://github.com/JuliaLang/PackageCompiler.jl/blob/1c35331d8ef81494f054bbc71214811253101993/src/PackageCompiler.jl#L147-L190
37+
function get_compiler_cmd(; cplusplus::Bool=false)
38+
cc = get(ENV, "JULIA_CC", nothing)
39+
path = nothing
40+
@static if Sys.iswindows()
41+
path = joinpath(LazyArtifacts.artifact"mingw-w64",
42+
"extracted_files",
43+
(Int==Int64 ? "mingw64" : "mingw32"),
44+
"bin",
45+
cplusplus ? "g++.exe" : "gcc.exe")
46+
compiler_cmd = `$path`
47+
end
48+
if cc !== nothing
49+
compiler_cmd = Cmd(Base.shell_split(cc))
50+
path = nothing
51+
elseif !Sys.iswindows()
52+
compilers_cpp = ("g++", "clang++")
53+
compilers_c = ("gcc", "clang")
54+
found_compiler = false
55+
if cplusplus
56+
for compiler in compilers_cpp
57+
if Sys.which(compiler) !== nothing
58+
compiler_cmd = `$compiler`
59+
found_compiler = true
60+
break
61+
end
62+
end
63+
end
64+
if !found_compiler
65+
for compiler in compilers_c
66+
if Sys.which(compiler) !== nothing
67+
compiler_cmd = `$compiler`
68+
found_compiler = true
69+
if cplusplus && !WARNED_CPP_COMPILER[]
70+
@warn "could not find a c++ compiler (g++ or clang++), falling back to $compiler, this might cause link errors"
71+
WARNED_CPP_COMPILER[] = true
72+
end
73+
break
74+
end
75+
end
76+
end
77+
found_compiler || error("could not find a compiler, looked for ",
78+
join(((cplusplus ? compilers_cpp : ())..., compilers_c...), ", ", " and "))
79+
end
80+
if path !== nothing
81+
compiler_cmd = addenv(compiler_cmd, "PATH" => string(ENV["PATH"], ";", dirname(path)))
82+
end
83+
return compiler_cmd
84+
end
85+
3386
# arguments to forward to julia compilation process
3487
julia_args = []
3588
enable_trim::Bool = false
@@ -82,6 +135,7 @@ function get_rpath(; relative::Bool = false)
82135
end
83136
end
84137

138+
cc = get_compiler_cmd()
85139
absfile = abspath(file)
86140
cflags = JuliaConfig.cflags(; framework=false)
87141
cflags = Base.shell_split(cflags)
@@ -93,7 +147,6 @@ tmpdir = mktempdir(cleanup=false)
93147
img_path = joinpath(tmpdir, "img.a")
94148
bc_path = joinpath(tmpdir, "img-bc.a")
95149

96-
97150
function precompile_env()
98151
# Pre-compile the environment
99152
# (otherwise obscure error messages will occur)
@@ -121,7 +174,6 @@ function compile_products(enable_trim::Bool)
121174
println(stderr, "\nFailed to compile $file")
122175
exit(1)
123176
end
124-
125177
end
126178

127179
function link_products()
@@ -137,11 +189,11 @@ function link_products()
137189
julia_libs = Base.shell_split(Base.isdebugbuild() ? "-ljulia-debug -ljulia-internal-debug" : "-ljulia -ljulia-internal")
138190
try
139191
if output_type == "--output-lib"
140-
cmd2 = `cc $(allflags) $(rpath) -o $outname -shared -Wl,$(Base.Linking.WHOLE_ARCHIVE) $img_path -Wl,$(Base.Linking.NO_WHOLE_ARCHIVE) $(julia_libs)`
192+
cmd2 = `$(cc) $(allflags) $(rpath) -o $outname -shared -Wl,$(Base.Linking.WHOLE_ARCHIVE) $img_path -Wl,$(Base.Linking.NO_WHOLE_ARCHIVE) $(julia_libs)`
141193
elseif output_type == "--output-sysimage"
142-
cmd2 = `cc $(allflags) $(rpath) -o $outname -shared -Wl,$(Base.Linking.WHOLE_ARCHIVE) $img_path -Wl,$(Base.Linking.NO_WHOLE_ARCHIVE) $(julia_libs)`
194+
cmd2 = `$(cc) $(allflags) $(rpath) -o $outname -shared -Wl,$(Base.Linking.WHOLE_ARCHIVE) $img_path -Wl,$(Base.Linking.NO_WHOLE_ARCHIVE) $(julia_libs)`
143195
else
144-
cmd2 = `cc $(allflags) $(rpath) -o $outname -Wl,$(Base.Linking.WHOLE_ARCHIVE) $img_path -Wl,$(Base.Linking.NO_WHOLE_ARCHIVE) $(julia_libs)`
196+
cmd2 = `$(cc) $(allflags) $(rpath) -o $outname -Wl,$(Base.Linking.WHOLE_ARCHIVE) $img_path -Wl,$(Base.Linking.NO_WHOLE_ARCHIVE) $(julia_libs)`
145197
end
146198
verbose && println("Running: $cmd2")
147199
run(cmd2)

doc/src/devdocs/sysimg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ debug info, respectively, and so will make debugging more difficult.
176176
We have identified many small changes to Base that significantly increase the set of programs
177177
that can be reliably trimmed. Unfortunately some of those changes would be considered breaking,
178178
and so are only applied when trimming is requested (this is done by an external build script,
179-
currently maintained inside the test suite as `contrib/juliac-buildscript.jl`).
179+
currently maintained inside the test suite as `contrib/juliac/juliac-buildscript.jl`).
180180
Therefore in many cases trimming will require you to opt in to new variants of Base and some
181181
standard libraries.
182182

test/trimming/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ CFLAGS_ADD = $(shell $(JULIA_CONFIG) --cflags)
2929
LDFLAGS_ADD = -lm $(shell $(JULIA_CONFIG) --ldflags --ldlibs) -ljulia-internal
3030

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

3434
#=============================================================================
3535

0 commit comments

Comments
 (0)