Skip to content

Commit 9e3047f

Browse files
committed
juliac: Add rudimentary Windows support
This was essentially working as-is, except for our reliance on a C compiler.
1 parent 378a425 commit 9e3047f

File tree

2 files changed

+77
-5
lines changed

2 files changed

+77
-5
lines changed

contrib/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"

contrib/juliac.jl

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

4+
using LazyArtifacts
5+
46
module JuliaConfig
57
include(joinpath(@__DIR__, "julia-config.jl"))
68
end
@@ -28,6 +30,57 @@ if help !== nothing
2830
exit(0)
2931
end
3032

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

@@ -77,6 +130,7 @@ function get_rpath(; relative::Bool = false)
77130
end
78131
end
79132

133+
cc = get_compiler_cmd()
80134
absfile = abspath(file)
81135
cflags = JuliaConfig.cflags(; framework=false)
82136
cflags = Base.shell_split(cflags)
@@ -90,7 +144,6 @@ init_path = joinpath(tmpdir, "init.a")
90144
img_path = joinpath(tmpdir, "img.a")
91145
bc_path = joinpath(tmpdir, "img-bc.a")
92146

93-
94147
function precompile_env()
95148
# Pre-compile the environment
96149
# (otherwise obscure error messages will occur)
@@ -123,7 +176,7 @@ function compile_products()
123176
}
124177
""")
125178
end
126-
run(`cc $(cflags) -g -c -o $init_path $initsrc_path`)
179+
run(`$(cc) $(cflags) -g -c -o $init_path $initsrc_path`)
127180
end
128181

129182
function link_products()
@@ -139,11 +192,11 @@ function link_products()
139192
julia_libs = Base.shell_split(Base.isdebugbuild() ? "-ljulia-debug -ljulia-internal-debug" : "-ljulia -ljulia-internal")
140193
try
141194
if output_type == "--output-lib"
142-
cmd2 = `cc $(allflags) $(rpath) -o $outname -shared -Wl,$(Base.Linking.WHOLE_ARCHIVE) $img_path -Wl,$(Base.Linking.NO_WHOLE_ARCHIVE) $init_path $(julia_libs)`
195+
cmd2 = `$(cc) $(allflags) $(rpath) -o $outname -shared -Wl,$(Base.Linking.WHOLE_ARCHIVE) $img_path -Wl,$(Base.Linking.NO_WHOLE_ARCHIVE) $init_path $(julia_libs)`
143196
elseif output_type == "--output-sysimage"
144-
cmd2 = `cc $(allflags) $(rpath) -o $outname -shared -Wl,$(Base.Linking.WHOLE_ARCHIVE) $img_path -Wl,$(Base.Linking.NO_WHOLE_ARCHIVE) $(julia_libs)`
197+
cmd2 = `$(cc) $(allflags) $(rpath) -o $outname -shared -Wl,$(Base.Linking.WHOLE_ARCHIVE) $img_path -Wl,$(Base.Linking.NO_WHOLE_ARCHIVE) $(julia_libs)`
145198
else
146-
cmd2 = `cc $(allflags) $(rpath) -o $outname -Wl,$(Base.Linking.WHOLE_ARCHIVE) $img_path -Wl,$(Base.Linking.NO_WHOLE_ARCHIVE) $init_path $(julia_libs)`
199+
cmd2 = `$(cc) $(allflags) $(rpath) -o $outname -Wl,$(Base.Linking.WHOLE_ARCHIVE) $img_path -Wl,$(Base.Linking.NO_WHOLE_ARCHIVE) $init_path $(julia_libs)`
147200
end
148201
verbose && println("Running: $cmd2")
149202
run(cmd2)

0 commit comments

Comments
 (0)