Skip to content
This repository was archived by the owner on Jun 9, 2023. It is now read-only.
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
9 changes: 9 additions & 0 deletions Artifacts.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[[x86_64-w64-mingw32]]
git-tree-sha1 = "572b61b5075459e3ed62317e674398166ca98dd4"
os = "windows"
arch = "x86_64"
lazy = true

[[x86_64-w64-mingw32.download]]
sha256 = "fe3f401bc936fbe6af940b26c5e0f266f762a3416f979c706e599b24082dc5c7"
url = "https://github.com/JuliaComputing/PackageCompilerX.jl/releases/download/v0.1/x86_64-8.1.0-release-posix-seh-rt_v6-rev0.tar.gz"
7 changes: 1 addition & 6 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,4 @@ For macOS, using something like `homebrew` and for Linux the system package mana

### Windows

For Windows, the minGW compiler toolchain is needed. It can be downloaded from e.g.
[https://sourceforge.net/projects/mingw-w64/files/](https://sourceforge.net/projects/mingw-w64/files/) or by following the
instructions for setting up a toolchain capable of compiling Julia itself on Windows at
[https://github.com/JuliaLang/julia/blob/master/doc/build/windows.md#cygwin-to-mingw-cross-compiling](https://github.com/JuliaLang/julia/blob/master/doc/build/windows.md#cygwin-to-mingw-cross-compiling)
and then run PackageCompilerX from the cygwin terminal. Alternatively, the package manager
[chocolatey](https://chocolatey.org/) can be used to get mingw on Windows.
A suitable compiler will be automatically installed the first time it is neeed.
37 changes: 26 additions & 11 deletions src/PackageCompilerX.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,28 @@ yesno(b::Bool) = b ? "yes" : "no"
bitflag() = Int == Int32 ? `-m32` : `-m64`
march() = (Int == Int32 ? `-march=pentium4` : ``)

function windows_compiler_artifact_path(f, compiler)
if Sys.iswindows()
withenv("PATH" => string(ENV["PATH"], ";", dirname(compiler))) do
f()
end
else
f()
end
end

function get_compiler()
cc = get(ENV, "JULIA_CC", nothing)
if cc !== nothing
return `$cc`
return cc
end
if Sys.iswindows()
return joinpath(Pkg.Artifacts.artifact"x86_64-w64-mingw32", "mingw64", "bin", "gcc.exe")
end
if Sys.which("gcc") !== nothing
return `gcc`
return "gcc"
elseif Sys.which("clang") !== nothing
return `clang`
end
if Sys.iswindows()
if Sys.which("x86_64-w64-mingw32-gcc") !== nothing
return `x86_64-w64-mingw32-gcc`
end
return "clang"
end
error("could not find a compiler, looked for `gcc` and `clang`")
end
Expand Down Expand Up @@ -362,9 +370,12 @@ function create_sysimg_from_object_file(input_object::String, sysimage_path::Str
o_file = `-Wl,--whole-archive $input_object -Wl,--no-whole-archive`
end
extra = Sys.iswindows() ? `-Wl,--export-all-symbols` : ``
cmd = `$(get_compiler()) $(bitflag()) $(march()) -shared -L$(julia_libdir) -o $sysimage_path $o_file -ljulia $extra`
compiler = get_compiler()
cmd = `$compiler $(bitflag()) $(march()) -shared -L$(julia_libdir) -o $sysimage_path $o_file -ljulia $extra`
@debug "running $cmd"
run(cmd)
windows_compiler_artifact_path(compiler) do
run(cmd)
end
return nothing
end

Expand Down Expand Up @@ -560,9 +571,13 @@ function create_executable_from_sysimg(;sysimage_path::String,
else
rpath = `-Wl,-rpath,\$ORIGIN:\$ORIGIN/../lib`
end
cmd = `$(get_compiler()) -DJULIAC_PROGRAM_LIBNAME=$(repr(sysimage_path)) $(bitflag()) $(march()) -o $(executable_path) $(wrapper) $(sysimage_path) -O2 $rpath $flags`
compiler = get_compiler()
cmd = `$compiler -DJULIAC_PROGRAM_LIBNAME=$(repr(sysimage_path)) $(bitflag()) $(march()) -o $(executable_path) $(wrapper) $(sysimage_path) -O2 $rpath $flags`
@debug "running $cmd"
run(cmd)
windows_compiler_artifact_path(compiler) do
run(cmd)
end
return nothing
end

Expand Down