@@ -89,32 +89,36 @@ function move_default_sysimage_if_windows()
8989 end
9090end
9191
92- function run_with_env (cmd, compiler)
93- if Sys. iswindows ()
94- env = copy (ENV )
95- env[" PATH" ] = string (env[" PATH" ], " ;" , dirname (compiler))
96- run (Cmd (cmd; env= env))
97- else
98- run (cmd)
99- end
100- end
101-
102- function get_compiler ()
92+ function run_compiler (cmd:: Cmd )
10393 cc = get (ENV , " JULIA_CC" , nothing )
104- if cc != = nothing
105- return cc
94+ path = nothing
95+ local compiler_cmd
96+ @static if Sys. iswindows ()
97+ if Int == Int64
98+ path = joinpath (LazyArtifacts. artifact " x86_64-w64-mingw32" , " mingw64" , " bin" , " gcc.exe" )
99+ compiler_cmd = ` $path `
100+ else # Int == Int32
101+ path = joinpath (LazyArtifacts. artifact " i868-w64-mingw32" , " mingw32" , " bin" , " gcc.exe" )
102+ compiler_cmd = ` $path `
103+ end
106104 end
107- @static if Sys. iswindows () && Int== Int64
108- return joinpath (LazyArtifacts. artifact " x86_64-w64-mingw32" , " mingw64" , " bin" , " gcc.exe" )
109- elseif Sys. iswindows () && Int== Int32
110- return joinpath (LazyArtifacts. artifact " i868-w64-mingw32" , " mingw32" , " bin" , " gcc.exe" )
105+ if cc != = nothing
106+ compiler_cmd = Cmd (Base. shell_split (cc))
107+ elseif ! Sys. iswindows ()
108+ if Sys. which (" gcc" ) != = nothing
109+ compiler_cmd = ` gcc`
110+ elseif Sys. which (" clang" ) != = nothing
111+ compiler_cmd = ` clang`
112+ else
113+ error (" could not find a compiler, looked for `gcc` and `clang`" )
114+ end
111115 end
112- if Sys. which (" gcc" ) != = nothing
113- return " gcc"
114- elseif Sys. which (" clang" ) != = nothing
115- return " clang"
116+ if path != = nothing
117+ compiler_cmd = addenv (compiler_cmd, " PATH" => string (ENV [" PATH" ], " ;" , dirname (path)))
116118 end
117- error (" could not find a compiler, looked for `gcc` and `clang`" )
119+ full_cmd = ` $compiler_cmd $cmd `
120+ @debug " running $full_cmd "
121+ run (full_cmd)
118122end
119123
120124function get_julia_cmd ()
409413 create_sysimage(packages::Vector{String}; kwargs...)
410414
411415Create a system image that includes the package(s) in `packages` given as a
412- string or vector). An attempt to automatically find a compiler will be done but
413- can also be given explicitly by setting the environment variable `JULIA_CC` to a
414- path to a compiler.
416+ string or vector).
417+
418+ An attempt to automatically find a compiler will be done but can also be given
419+ explicitly by setting the environment variable `JULIA_CC` to a path to a
420+ compiler (can also include extra arguments to the compiler, like `-g`).
415421
416422### Keyword arguments:
417423
@@ -567,15 +573,12 @@ end
567573
568574function compile_c_init_julia (julia_init_c_file:: String , sysimage_path:: String )
569575 @debug " Compiling $julia_init_c_file "
570- compiler = get_compiler ()
571576 m = something (march (), ` ` )
572577 flags = Base. shell_split (cflags ())
573578
574579 o_init_file = splitext (julia_init_c_file)[1 ] * " .o"
575- cmd = ` $compiler -c -O2 -DJULIAC_PROGRAM_LIBNAME=$(repr (sysimage_path)) $TLS_SYNTAX $(bitflag ()) $flags $m -o $o_init_file $julia_init_c_file `
576-
577- @debug " running $cmd "
578- run_with_env (cmd, compiler)
580+ cmd = ` -c -O2 -DJULIAC_PROGRAM_LIBNAME=$(repr (sysimage_path)) $TLS_SYNTAX $(bitflag ()) $flags $m -o $o_init_file $julia_init_c_file `
581+ run_compiler (cmd)
579582 return o_init_file
580583end
581584
@@ -624,7 +627,6 @@ function create_sysimg_from_object_file(input_object::String,
624627
625628 extra = get_extra_linker_flags (version, compat_level, soname)
626629
627- compiler = get_compiler ()
628630 m = something (march (), ` ` )
629631 private_libdir = if Base. DARWIN_FRAMEWORK # taken from Libdl tests
630632 if ccall (:jl_is_debugbuild , Cint, ()) != 0
@@ -637,9 +639,8 @@ function create_sysimg_from_object_file(input_object::String,
637639 else
638640 dirname (abspath (Libdl. dlpath (" libjulia-internal" )))
639641 end
640- cmd = ` $compiler $(bitflag ()) $m -shared -L$(julia_libdir) -L$(private_libdir) -o $sysimage_path $o_file_flags -ljulia-internal -ljulia $extra `
641- @debug " running $cmd "
642- run_with_env (cmd, compiler)
642+ cmd = ` $(bitflag ()) $m -shared -L$(julia_libdir) -L$(private_libdir) -o $sysimage_path $o_file_flags -ljulia-internal -ljulia $extra `
643+ run_compiler (cmd)
643644 return nothing
644645end
645646
@@ -719,7 +720,7 @@ argument, for example:
719720
720721An attempt to automatically find a compiler will be done but can also be given
721722explicitly by setting the environment variable `JULIA_CC` to a path to a
722- compiler.
723+ compiler (can also include extra arguments to the compiler, like `-g`) .
723724
724725### Keyword arguments:
725726
@@ -819,7 +820,7 @@ simply calls `jl_atexit_hook(retcode)`.)
819820
820821An attempt to automatically find a compiler will be done but can also be given
821822explicitly by setting the environment variable `JULIA_CC` to a path to a
822- compiler.
823+ compiler (can also include extra arguments to the compiler, like `-g`) .
823824
824825### Keyword arguments:
825826
@@ -1034,11 +1035,9 @@ function create_executable_from_sysimg(;sysimage_path::String,
10341035 flags = join ((cflags (), ldflags (), ldlibs ()), " " )
10351036 flags = Base. shell_split (flags)
10361037 wrapper = c_driver_program_path
1037- compiler = get_compiler ()
10381038 m = something (march (), ` ` )
1039- cmd = ` $compiler -DJULIAC_PROGRAM_LIBNAME=$(repr (sysimage_path)) $TLS_SYNTAX $(bitflag ()) $m -o $(executable_path) $(wrapper) $(sysimage_path) -O2 $(rpath_executable ()) $flags `
1040- @debug " running $cmd "
1041- run_with_env (cmd, compiler)
1039+ cmd = ` -DJULIAC_PROGRAM_LIBNAME=$(repr (sysimage_path)) $TLS_SYNTAX $(bitflag ()) $m -o $(executable_path) $(wrapper) $(sysimage_path) -O2 $(rpath_executable ()) $flags `
1040+ run_compiler (cmd)
10421041 return nothing
10431042end
10441043
0 commit comments