Skip to content

Commit 7808dfe

Browse files
committed
juliac: Add rudimentary Windows support
This was essentially working as-is, except for our reliance on a C compiler.
1 parent 8caacdb commit 7808dfe

File tree

2 files changed

+76
-5
lines changed

2 files changed

+76
-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: 57 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
enable_trim::Bool = false
@@ -80,6 +133,7 @@ function get_rpath(; relative::Bool = false)
80133
end
81134
end
82135

136+
cc = get_compiler_cmd()
83137
absfile = abspath(file)
84138
cflags = JuliaConfig.cflags(; framework=false)
85139
cflags = Base.shell_split(cflags)
@@ -91,7 +145,6 @@ tmpdir = mktempdir(cleanup=false)
91145
img_path = joinpath(tmpdir, "img.a")
92146
bc_path = joinpath(tmpdir, "img-bc.a")
93147

94-
95148
function precompile_env()
96149
# Pre-compile the environment
97150
# (otherwise obscure error messages will occur)
@@ -119,7 +172,6 @@ function compile_products(enable_trim::Bool)
119172
println(stderr, "\nFailed to compile $file")
120173
exit(1)
121174
end
122-
123175
end
124176

125177
function link_products()
@@ -135,11 +187,11 @@ function link_products()
135187
julia_libs = Base.shell_split(Base.isdebugbuild() ? "-ljulia-debug -ljulia-internal-debug" : "-ljulia -ljulia-internal")
136188
try
137189
if output_type == "--output-lib"
138-
cmd2 = `cc $(allflags) $(rpath) -o $outname -shared -Wl,$(Base.Linking.WHOLE_ARCHIVE) $img_path -Wl,$(Base.Linking.NO_WHOLE_ARCHIVE) $(julia_libs)`
190+
cmd2 = `$(cc) $(allflags) $(rpath) -o $outname -shared -Wl,$(Base.Linking.WHOLE_ARCHIVE) $img_path -Wl,$(Base.Linking.NO_WHOLE_ARCHIVE) $(julia_libs)`
139191
elseif output_type == "--output-sysimage"
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
else
142-
cmd2 = `cc $(allflags) $(rpath) -o $outname -Wl,$(Base.Linking.WHOLE_ARCHIVE) $img_path -Wl,$(Base.Linking.NO_WHOLE_ARCHIVE) $(julia_libs)`
194+
cmd2 = `$(cc) $(allflags) $(rpath) -o $outname -Wl,$(Base.Linking.WHOLE_ARCHIVE) $img_path -Wl,$(Base.Linking.NO_WHOLE_ARCHIVE) $(julia_libs)`
143195
end
144196
verbose && println("Running: $cmd2")
145197
run(cmd2)

0 commit comments

Comments
 (0)