Skip to content

Commit 3bd3fa1

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 3bd3fa1

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/PackageCompiler.jl

Lines changed: 10 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,12 @@ 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+
else
165+
compiler_flags = ``
166+
end
167+
full_cmd = `$compiler_cmd $compiler_flags $cmd`
162168
@debug "running $full_cmd"
163169
run(full_cmd)
164170
end
@@ -366,7 +372,7 @@ project will be put into the sysimage.
366372
367373
An attempt to automatically find a compiler will be done but can also be given
368374
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`).
375+
compiler. Extra arguments to the compiler (like `-g`) can be specified with `JULIA_CC_FLAGS`.
370376
371377
### Keyword arguments:
372378
@@ -633,7 +639,7 @@ argument, for example:
633639
634640
An attempt to automatically find a compiler will be done but can also be given
635641
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`).
642+
compiler. Extra arguments to the compiler (like `-g`) can be specified with `JULIA_CC_FLAGS`.
637643
638644
### Keyword arguments:
639645
@@ -792,7 +798,7 @@ simply calls `jl_atexit_hook(retcode)`.)
792798
793799
An attempt to automatically find a compiler will be done but can also be given
794800
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`).
801+
compiler. Extra arguments to the compiler (like `-g`) can be specified with `JULIA_CC_FLAGS`.
796802
797803
### Keyword arguments:
798804

0 commit comments

Comments
 (0)