Skip to content

Commit 80ebaa2

Browse files
committed
Allow the user to define arbitrary C variables on all platforms.
Since PC.jl now exposes `c_driver_program` which allows the users to specify their own C wrapper program, it would be nice to be able to pass in more variables which might be best defined at build time. Currently this functionality is effectively limited to Linux as specifying $JULIA_CC will prevent PC.jl from inferring gcc.exe from the relative mingw installation.
1 parent 94fdba2 commit 80ebaa2

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/PackageCompiler.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ const WARNED_CPP_COMPILER = Ref{Bool}(false)
118118

119119
function run_compiler(cmd::Cmd; cplusplus::Bool=false)
120120
cc = get(ENV, "JULIA_CC", nothing)
121+
cc_flags = get(ENV, "JULIA_CC_FLAGS", nothing)
121122
path = nothing
122123
@static if Sys.iswindows()
123124
path = joinpath(LazyArtifacts.artifact"mingw-w64", (Int==Int64 ? "mingw64" : "mingw32"), "bin", cplusplus ? "g++.exe" : "gcc.exe")
@@ -158,7 +159,10 @@ function run_compiler(cmd::Cmd; cplusplus::Bool=false)
158159
if path !== nothing
159160
compiler_cmd = addenv(compiler_cmd, "PATH" => string(ENV["PATH"], ";", dirname(path)))
160161
end
161-
full_cmd = `$compiler_cmd $cmd`
162+
if cc_flags !== nothing
163+
compiler_flags = Cmd(Base.shell_split(cc_flags))
164+
end
165+
full_cmd = `$compiler_cmd $compiler_flags $cmd`
162166
@debug "running $full_cmd"
163167
run(full_cmd)
164168
end
@@ -366,7 +370,7 @@ project will be put into the sysimage.
366370
367371
An attempt to automatically find a compiler will be done but can also be given
368372
explicitly by setting the environment variable `JULIA_CC` to a path to a
369-
compiler (can also include extra arguments to the compiler, like `-g`).
373+
compiler. Extra arguments to the compiler (like `-g`) can be specified with `JULIA_CC_FLAGS`.
370374
371375
### Keyword arguments:
372376
@@ -633,7 +637,7 @@ argument, for example:
633637
634638
An attempt to automatically find a compiler will be done but can also be given
635639
explicitly by setting the environment variable `JULIA_CC` to a path to a
636-
compiler (can also include extra arguments to the compiler, like `-g`).
640+
compiler. Extra arguments to the compiler (like `-g`) can be specified with `JULIA_CC_FLAGS`.
637641
638642
### Keyword arguments:
639643
@@ -792,7 +796,7 @@ simply calls `jl_atexit_hook(retcode)`.)
792796
793797
An attempt to automatically find a compiler will be done but can also be given
794798
explicitly by setting the environment variable `JULIA_CC` to a path to a
795-
compiler (can also include extra arguments to the compiler, like `-g`).
799+
compiler. Extra arguments to the compiler (like `-g`) can be specified with `JULIA_CC_FLAGS`.
796800
797801
### Keyword arguments:
798802

0 commit comments

Comments
 (0)