Skip to content

Commit 696380b

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

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
@@ -3,6 +3,8 @@
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
79
include(joinpath(@__DIR__, "julia-config.jl"))
810
end
@@ -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)

0 commit comments

Comments
 (0)